Pass a logger in to getApiClient() rather than constructing one there.
This commit is contained in:
parent
1f7bae7ab8
commit
865b4bd832
12 changed files with 29 additions and 27 deletions
9
lib/api-client.js
generated
9
lib/api-client.js
generated
|
|
@ -17,7 +17,7 @@ const console_log_level_1 = __importDefault(require("console-log-level"));
|
|||
const semver = __importStar(require("semver"));
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const apiCompatibility = __importStar(require("./api-compatibility.json"));
|
||||
const logging = __importStar(require("./logging"));
|
||||
const logging_1 = require("./logging");
|
||||
const util_1 = require("./util");
|
||||
var DisallowedAPIVersionReason;
|
||||
(function (DisallowedAPIVersionReason) {
|
||||
|
|
@ -26,7 +26,7 @@ var DisallowedAPIVersionReason;
|
|||
})(DisallowedAPIVersionReason = exports.DisallowedAPIVersionReason || (exports.DisallowedAPIVersionReason = {}));
|
||||
const GITHUB_ENTERPRISE_VERSION_HEADER = "x-github-enterprise-version";
|
||||
let hasBeenWarnedAboutVersion = false;
|
||||
exports.getApiClient = function (githubAuth, githubUrl, mode, allowLocalRun = false) {
|
||||
exports.getApiClient = function (githubAuth, githubUrl, mode, logger, allowLocalRun = false) {
|
||||
if (util_1.isLocalRun() && !allowLocalRun) {
|
||||
throw new Error("Invalid API call in local run");
|
||||
}
|
||||
|
|
@ -36,9 +36,6 @@ exports.getApiClient = function (githubAuth, githubUrl, mode, allowLocalRun = fa
|
|||
response.headers[GITHUB_ENTERPRISE_VERSION_HEADER] !== undefined) {
|
||||
const installedVersion = response.headers[GITHUB_ENTERPRISE_VERSION_HEADER];
|
||||
const disallowedAPIVersionReason = apiVersionInRange(installedVersion, apiCompatibility.minimumVersion, apiCompatibility.maximumVersion);
|
||||
const logger = mode === "actions"
|
||||
? logging.getActionsLogger()
|
||||
: logging.getRunnerLogger(false);
|
||||
const toolName = mode === "actions" ? "Action" : "Runner";
|
||||
if (disallowedAPIVersionReason ===
|
||||
DisallowedAPIVersionReason.ACTION_TOO_OLD) {
|
||||
|
|
@ -73,7 +70,7 @@ function getApiUrl(githubUrl) {
|
|||
// Once all code has been coverted this function should be removed or made canonical
|
||||
// and called only from the action entrypoints.
|
||||
function getActionsApiClient(allowLocalRun = false) {
|
||||
return exports.getApiClient(actions_util_1.getRequiredInput("token"), actions_util_1.getRequiredEnvParam("GITHUB_SERVER_URL"), "actions", allowLocalRun);
|
||||
return exports.getApiClient(actions_util_1.getRequiredInput("token"), actions_util_1.getRequiredEnvParam("GITHUB_SERVER_URL"), "actions", logging_1.getActionsLogger(), allowLocalRun);
|
||||
}
|
||||
exports.getActionsApiClient = getActionsApiClient;
|
||||
function apiVersionInRange(version, minimumVersion, maximumVersion) {
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA6B;AAE7B,uEAAyD;AACzD,6DAA+C;AAE/C,0EAAgD;AAChD,+CAAiC;AAEjC,iDAAuE;AACvE,2EAA6D;AAC7D,mDAAqC;AACrC,iCAA0C;AAE1C,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,+FAAc,CAAA;IACd,+FAAc,CAAA;AAChB,CAAC,EAHW,0BAA0B,GAA1B,kCAA0B,KAA1B,kCAA0B,QAGrC;AAED,MAAM,gCAAgC,GAAG,6BAA6B,CAAC;AACvE,IAAI,yBAAyB,GAAG,KAAK,CAAC;AAEzB,QAAA,YAAY,GAAG,UAC1B,UAAkB,EAClB,SAAiB,EACjB,IAAU,EACV,aAAa,GAAG,KAAK;IAErB,IAAI,iBAAU,EAAE,IAAI,CAAC,aAAa,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAClD;IACD,MAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;QAC1E,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE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AAC,EAAE;QACrD,OAAO,0BAA0B,CAAC,cAAc,CAAC;KAClD;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,cAAc,EAAE,CAAC,EAAE;QACrD,OAAO,0BAA0B,CAAC,cAAc,CAAC;KAClD;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAZD,8CAYC"}
|
||||
2
lib/codeql.js
generated
2
lib/codeql.js
generated
|
|
@ -88,7 +88,7 @@ async function getCodeQLBundleDownloadURL(githubAuth, githubUrl, mode, logger) {
|
|||
const [repositoryOwner, repositoryName] = repository.split("/");
|
||||
try {
|
||||
const release = await api
|
||||
.getApiClient(githubAuth, githubUrl, mode)
|
||||
.getApiClient(githubAuth, githubUrl, mode, logger)
|
||||
.repos.getReleaseByTag({
|
||||
owner: repositoryOwner,
|
||||
repo: repositoryName,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
8
lib/config-utils.js
generated
8
lib/config-utils.js
generated
|
|
@ -304,7 +304,7 @@ exports.getUnknownLanguagesError = getUnknownLanguagesError;
|
|||
async function getLanguagesInRepo(repository, githubAuth, githubUrl, mode, logger) {
|
||||
logger.debug(`GitHub repo ${repository.owner} ${repository.repo}`);
|
||||
const response = await api
|
||||
.getApiClient(githubAuth, githubUrl, mode, true)
|
||||
.getApiClient(githubAuth, githubUrl, mode, logger, true)
|
||||
.repos.listLanguages({
|
||||
owner: repository.owner,
|
||||
repo: repository.repo,
|
||||
|
|
@ -418,7 +418,7 @@ async function loadConfig(languagesInput, queriesInput, configFile, repository,
|
|||
parsedYAML = getLocalConfig(configFile, checkoutPath);
|
||||
}
|
||||
else {
|
||||
parsedYAML = await getRemoteConfig(configFile, githubAuth, githubUrl, mode);
|
||||
parsedYAML = await getRemoteConfig(configFile, githubAuth, githubUrl, mode, logger);
|
||||
}
|
||||
// Validate that the 'name' property is syntactically correct,
|
||||
// even though we don't use the value yet.
|
||||
|
|
@ -546,7 +546,7 @@ function getLocalConfig(configFile, checkoutPath) {
|
|||
}
|
||||
return yaml.safeLoad(fs.readFileSync(configFile, "utf8"));
|
||||
}
|
||||
async function getRemoteConfig(configFile, githubAuth, githubUrl, mode) {
|
||||
async function getRemoteConfig(configFile, githubAuth, githubUrl, mode, logger) {
|
||||
// retrieve the various parts of the config location, and ensure they're present
|
||||
const format = new RegExp("(?<owner>[^/]+)/(?<repo>[^/]+)/(?<path>[^@]+)@(?<ref>.*)");
|
||||
const pieces = format.exec(configFile);
|
||||
|
|
@ -555,7 +555,7 @@ async function getRemoteConfig(configFile, githubAuth, githubUrl, mode) {
|
|||
throw new Error(getConfigFileRepoFormatInvalidMessage(configFile));
|
||||
}
|
||||
const response = await api
|
||||
.getApiClient(githubAuth, githubUrl, mode, true)
|
||||
.getApiClient(githubAuth, githubUrl, mode, logger, true)
|
||||
.repos.getContent({
|
||||
owner: pieces.groups.owner,
|
||||
repo: pieces.groups.repo,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
2
lib/upload-lib.js
generated
2
lib/upload-lib.js
generated
|
|
@ -50,7 +50,7 @@ async function uploadPayload(payload, repositoryNwo, githubAuth, githubUrl, mode
|
|||
if (testMode) {
|
||||
return;
|
||||
}
|
||||
const client = api.getApiClient(githubAuth, githubUrl, mode);
|
||||
const client = api.getApiClient(githubAuth, githubUrl, mode, logger);
|
||||
const reqURL = mode === "actions"
|
||||
? "PUT /repos/:owner/:repo/code-scanning/analysis"
|
||||
: "POST /repos/:owner/:repo/code-scanning/sarifs";
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -8,7 +8,7 @@ import * as semver from "semver";
|
|||
|
||||
import { getRequiredEnvParam, getRequiredInput } from "./actions-util";
|
||||
import * as apiCompatibility from "./api-compatibility.json";
|
||||
import * as logging from "./logging";
|
||||
import { Logger, getActionsLogger } from "./logging";
|
||||
import { isLocalRun, Mode } from "./util";
|
||||
|
||||
export enum DisallowedAPIVersionReason {
|
||||
|
|
@ -23,6 +23,7 @@ export const getApiClient = function (
|
|||
githubAuth: string,
|
||||
githubUrl: string,
|
||||
mode: Mode,
|
||||
logger: Logger,
|
||||
allowLocalRun = false
|
||||
) {
|
||||
if (isLocalRun() && !allowLocalRun) {
|
||||
|
|
@ -43,10 +44,6 @@ export const getApiClient = function (
|
|||
apiCompatibility.maximumVersion
|
||||
);
|
||||
|
||||
const logger =
|
||||
mode === "actions"
|
||||
? logging.getActionsLogger()
|
||||
: logging.getRunnerLogger(false);
|
||||
const toolName = mode === "actions" ? "Action" : "Runner";
|
||||
|
||||
if (
|
||||
|
|
@ -100,6 +97,7 @@ export function getActionsApiClient(allowLocalRun = false) {
|
|||
getRequiredInput("token"),
|
||||
getRequiredEnvParam("GITHUB_SERVER_URL"),
|
||||
"actions",
|
||||
getActionsLogger(),
|
||||
allowLocalRun
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ async function getCodeQLBundleDownloadURL(
|
|||
const [repositoryOwner, repositoryName] = repository.split("/");
|
||||
try {
|
||||
const release = await api
|
||||
.getApiClient(githubAuth, githubUrl, mode)
|
||||
.getApiClient(githubAuth, githubUrl, mode, logger)
|
||||
.repos.getReleaseByTag({
|
||||
owner: repositoryOwner,
|
||||
repo: repositoryName,
|
||||
|
|
|
|||
|
|
@ -598,7 +598,7 @@ async function getLanguagesInRepo(
|
|||
): Promise<Language[]> {
|
||||
logger.debug(`GitHub repo ${repository.owner} ${repository.repo}`);
|
||||
const response = await api
|
||||
.getApiClient(githubAuth, githubUrl, mode, true)
|
||||
.getApiClient(githubAuth, githubUrl, mode, logger, true)
|
||||
.repos.listLanguages({
|
||||
owner: repository.owner,
|
||||
repo: repository.repo,
|
||||
|
|
@ -798,7 +798,13 @@ async function loadConfig(
|
|||
configFile = path.resolve(checkoutPath, configFile);
|
||||
parsedYAML = getLocalConfig(configFile, checkoutPath);
|
||||
} else {
|
||||
parsedYAML = await getRemoteConfig(configFile, githubAuth, githubUrl, mode);
|
||||
parsedYAML = await getRemoteConfig(
|
||||
configFile,
|
||||
githubAuth,
|
||||
githubUrl,
|
||||
mode,
|
||||
logger
|
||||
);
|
||||
}
|
||||
|
||||
// Validate that the 'name' property is syntactically correct,
|
||||
|
|
@ -1022,7 +1028,8 @@ async function getRemoteConfig(
|
|||
configFile: string,
|
||||
githubAuth: string,
|
||||
githubUrl: string,
|
||||
mode: Mode
|
||||
mode: Mode,
|
||||
logger: Logger
|
||||
): Promise<UserConfig> {
|
||||
// retrieve the various parts of the config location, and ensure they're present
|
||||
const format = new RegExp(
|
||||
|
|
@ -1035,7 +1042,7 @@ async function getRemoteConfig(
|
|||
}
|
||||
|
||||
const response = await api
|
||||
.getApiClient(githubAuth, githubUrl, mode, true)
|
||||
.getApiClient(githubAuth, githubUrl, mode, logger, true)
|
||||
.repos.getContent({
|
||||
owner: pieces.groups.owner,
|
||||
repo: pieces.groups.repo,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ async function uploadPayload(
|
|||
return;
|
||||
}
|
||||
|
||||
const client = api.getApiClient(githubAuth, githubUrl, mode);
|
||||
const client = api.getApiClient(githubAuth, githubUrl, mode, logger);
|
||||
|
||||
const reqURL =
|
||||
mode === "actions"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue