use @actions/github

This commit is contained in:
Robert Brignull 2020-07-06 16:04:02 +01:00
parent 9da537eb33
commit 0086c2ecdb
199 changed files with 95598 additions and 6141 deletions

View file

@ -10,7 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const octokit = __importStar(require("@octokit/rest"));
const github = __importStar(require("@actions/github"));
const ava_1 = __importDefault(require("ava"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
@ -19,7 +19,7 @@ const api = __importStar(require("./api-client"));
const configUtils = __importStar(require("./config-utils"));
const testing_utils_1 = require("./testing-utils");
const util = __importStar(require("./util"));
testing_utils_1.silenceDebugOutput(ava_1.default);
testing_utils_1.setupTests(ava_1.default);
function setInput(name, value) {
// Transformation copied from
// https://github.com/actions/toolkit/blob/05e39f551d33e1688f61b209ab5cdd335198f1b8/packages/core/src/core.ts#L69
@ -151,17 +151,12 @@ ava_1.default("API client used when reading remote config", async (t) => {
content: Buffer.from(inputFileContents).toString("base64"),
}
};
let ok = new octokit.Octokit({
userAgent: "CodeQL Action",
});
const repos = ok.repos;
const spyGetContents = sinon_1.default.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
ok.repos = repos;
sinon_1.default.stub(api, "client").value(ok);
let client = new github.GitHub('123');
const spyGetContents = sinon_1.default.stub(client.repos, "getContents").resolves(Promise.resolve(dummyResponse));
sinon_1.default.stub(api, "getApiClient").value(() => client);
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
await configUtils.loadConfig();
t.assert(spyGetContents.called);
sinon_1.default.restore();
});
});
ava_1.default("Remote config handles the case where a directory is provided", async (t) => {
@ -171,13 +166,9 @@ ava_1.default("Remote config handles the case where a directory is provided", as
const dummyResponse = {
data: [],
};
let ok = new octokit.Octokit({
userAgent: "CodeQL Action",
});
const repos = ok.repos;
sinon_1.default.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
ok.repos = repos;
sinon_1.default.stub(api, "client").value(ok);
let client = new github.GitHub('123');
sinon_1.default.stub(client.repos, "getContents").resolves(Promise.resolve(dummyResponse));
sinon_1.default.stub(api, "getApiClient").value(() => client);
const repoReference = 'octo-org/codeql-config/config.yaml@main';
setInput('config-file', repoReference);
try {
@ -187,7 +178,6 @@ ava_1.default("Remote config handles the case where a directory is provided", as
catch (err) {
t.deepEqual(err, new Error(configUtils.getConfigFileDirectoryGivenMessage(repoReference)));
}
sinon_1.default.restore();
});
});
ava_1.default("Invalid format of remote config handled correctly", async (t) => {
@ -199,13 +189,9 @@ ava_1.default("Invalid format of remote config handled correctly", async (t) =>
// note no "content" property here
}
};
let ok = new octokit.Octokit({
userAgent: "CodeQL Action",
});
const repos = ok.repos;
sinon_1.default.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
ok.repos = repos;
sinon_1.default.stub(api, "client").value(ok);
let client = new github.GitHub('123');
sinon_1.default.stub(client.repos, "getContents").resolves(Promise.resolve(dummyResponse));
sinon_1.default.stub(api, "getApiClient").value(() => client);
const repoReference = 'octo-org/codeql-config/config.yaml@main';
setInput('config-file', repoReference);
try {
@ -215,7 +201,6 @@ ava_1.default("Invalid format of remote config handled correctly", async (t) =>
catch (err) {
t.deepEqual(err, new Error(configUtils.getConfigFileFormatInvalidMessage(repoReference)));
}
sinon_1.default.restore();
});
});
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {