mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Turn Env into a class, and add ReadOnlyEnv
This commit is contained in:
43
lib/entry-points.js
generated
43
lib/entry-points.js
generated
@@ -141483,15 +141483,32 @@ function getOptionalEnvVarFrom(env, paramName) {
|
||||
function getOptionalEnvVar(paramName) {
|
||||
return getOptionalEnvVarFrom(process.env, paramName);
|
||||
}
|
||||
var ReadOnlyEnv = class {
|
||||
constructor(vars) {
|
||||
this.vars = vars;
|
||||
}
|
||||
vars;
|
||||
/** Tries to get the value for `name` and throws if there isn't one. */
|
||||
getRequired(name) {
|
||||
return getRequiredEnvVar(this.vars, name);
|
||||
}
|
||||
/** Gets the value for `name`, or `undefined` if it isn't set or empty. */
|
||||
getOptional(name) {
|
||||
return getOptionalEnvVarFrom(this.vars, name);
|
||||
}
|
||||
/** Gets the entries of the underlying `ProcessEnv`. */
|
||||
entries() {
|
||||
return Object.entries(this.vars);
|
||||
}
|
||||
};
|
||||
var Env = class extends ReadOnlyEnv {
|
||||
/** Sets an environment variable. */
|
||||
set(name, value) {
|
||||
this.vars[name] = value;
|
||||
}
|
||||
};
|
||||
function getEnv(env = process.env) {
|
||||
return {
|
||||
getRequired: (name) => getRequiredEnvVar(env, name),
|
||||
getOptional: (name) => getOptionalEnvVarFrom(env, name),
|
||||
entries: () => Object.entries(env),
|
||||
set: (name, value) => {
|
||||
env[name] = value;
|
||||
}
|
||||
};
|
||||
return new Env(env);
|
||||
}
|
||||
|
||||
// src/util.ts
|
||||
@@ -145613,15 +145630,15 @@ function createApiClientWithDetails(apiDetails, { allowExternal = false } = {})
|
||||
})
|
||||
);
|
||||
}
|
||||
function getApiDetails() {
|
||||
function getApiDetails(env = getEnv()) {
|
||||
return {
|
||||
auth: getRequiredInput("token"),
|
||||
url: getRequiredEnvParam("GITHUB_SERVER_URL" /* GITHUB_SERVER_URL */),
|
||||
apiURL: getRequiredEnvParam("GITHUB_API_URL" /* GITHUB_API_URL */)
|
||||
url: env.getRequired("GITHUB_SERVER_URL" /* GITHUB_SERVER_URL */),
|
||||
apiURL: env.getRequired("GITHUB_API_URL" /* GITHUB_API_URL */)
|
||||
};
|
||||
}
|
||||
function getApiClient() {
|
||||
return createApiClientWithDetails(getApiDetails());
|
||||
function getApiClient(env = getEnv()) {
|
||||
return createApiClientWithDetails(getApiDetails(env));
|
||||
}
|
||||
function getApiClientWithExternalAuth(apiDetails) {
|
||||
return createApiClientWithDetails(apiDetails, { allowExternal: true });
|
||||
|
||||
Reference in New Issue
Block a user