2020-06-23 19:08:30 +01:00
|
|
|
"use strict";
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2020-09-29 14:43:37 +01:00
|
|
|
const path = __importStar(require("path"));
|
2020-10-01 11:03:30 +01:00
|
|
|
const githubUtils = __importStar(require("@actions/github/lib/utils"));
|
2020-06-23 19:08:30 +01:00
|
|
|
const console_log_level_1 = __importDefault(require("console-log-level"));
|
2020-09-15 14:00:25 +01:00
|
|
|
const actions_util_1 = require("./actions-util");
|
2020-08-04 14:35:20 -07:00
|
|
|
const util_1 = require("./util");
|
2020-10-26 22:58:05 +00:00
|
|
|
var DisallowedAPIVersionReason;
|
|
|
|
|
(function (DisallowedAPIVersionReason) {
|
|
|
|
|
DisallowedAPIVersionReason[DisallowedAPIVersionReason["ACTION_TOO_OLD"] = 0] = "ACTION_TOO_OLD";
|
|
|
|
|
DisallowedAPIVersionReason[DisallowedAPIVersionReason["ACTION_TOO_NEW"] = 1] = "ACTION_TOO_NEW";
|
|
|
|
|
})(DisallowedAPIVersionReason = exports.DisallowedAPIVersionReason || (exports.DisallowedAPIVersionReason = {}));
|
2021-04-09 14:17:46 -07:00
|
|
|
exports.getApiClient = function (apiDetails, { allowLocalRun = false, allowExternal = false } = {}) {
|
2020-08-04 14:35:20 -07:00
|
|
|
if (util_1.isLocalRun() && !allowLocalRun) {
|
2020-09-14 10:44:43 +01:00
|
|
|
throw new Error("Invalid API call in local run");
|
2020-08-04 14:35:20 -07:00
|
|
|
}
|
2021-04-09 14:17:46 -07:00
|
|
|
const auth = (allowExternal && apiDetails.externalRepoAuth) || apiDetails.auth;
|
|
|
|
|
return new githubUtils.GitHub(githubUtils.getOctokitOptions(auth, {
|
2020-11-23 14:18:05 +00:00
|
|
|
baseUrl: getApiUrl(apiDetails.url),
|
2020-07-06 16:04:02 +01:00
|
|
|
userAgent: "CodeQL Action",
|
2020-09-14 10:44:43 +01:00
|
|
|
log: console_log_level_1.default({ level: "debug" }),
|
2020-09-21 11:06:21 +01:00
|
|
|
}));
|
2020-07-06 16:04:02 +01:00
|
|
|
};
|
2020-08-25 16:19:15 +01:00
|
|
|
function getApiUrl(githubUrl) {
|
|
|
|
|
const url = new URL(githubUrl);
|
2020-11-30 16:33:38 +00:00
|
|
|
// If we detect this is trying to connect to github.com
|
2020-08-25 16:19:15 +01:00
|
|
|
// then return with a fixed canonical URL.
|
2020-09-14 10:44:43 +01:00
|
|
|
if (url.hostname === "github.com" || url.hostname === "api.github.com") {
|
|
|
|
|
return "https://api.github.com";
|
2020-08-25 16:19:15 +01:00
|
|
|
}
|
|
|
|
|
// Add the /api/v3 API prefix
|
2020-09-14 10:44:43 +01:00
|
|
|
url.pathname = path.join(url.pathname, "api", "v3");
|
2020-08-25 16:19:15 +01:00
|
|
|
return url.toString();
|
|
|
|
|
}
|
2020-08-11 12:43:27 +01:00
|
|
|
// Temporary function to aid in the transition to running on and off of github actions.
|
2020-11-20 11:35:59 +01:00
|
|
|
// Once all code has been converted this function should be removed or made canonical
|
2020-08-11 12:43:27 +01:00
|
|
|
// and called only from the action entrypoints.
|
|
|
|
|
function getActionsApiClient(allowLocalRun = false) {
|
2020-11-24 11:20:13 +00:00
|
|
|
const apiDetails = {
|
2020-11-23 14:18:05 +00:00
|
|
|
auth: actions_util_1.getRequiredInput("token"),
|
|
|
|
|
url: actions_util_1.getRequiredEnvParam("GITHUB_SERVER_URL"),
|
2020-11-24 11:20:13 +00:00
|
|
|
};
|
2021-04-09 14:17:46 -07:00
|
|
|
return exports.getApiClient(apiDetails, { allowLocalRun });
|
2020-08-11 12:43:27 +01:00
|
|
|
}
|
|
|
|
|
exports.getActionsApiClient = getActionsApiClient;
|
2020-06-23 19:08:30 +01:00
|
|
|
//# sourceMappingURL=api-client.js.map
|