Pass a logger in to getApiClient() rather than constructing one there.

This commit is contained in:
Chris Gavin 2020-11-02 08:53:25 +00:00
parent 1f7bae7ab8
commit 865b4bd832
No known key found for this signature in database
GPG key ID: 07F950B80C27E4DA
12 changed files with 29 additions and 27 deletions

9
lib/api-client.js generated
View file

@ -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) {