Use new API client

From https://github.com/github/codeql-action/pull/82
This commit is contained in:
Sam Partington 2020-06-26 13:51:14 +01:00
parent 9566d8c220
commit f8c87948ab
6 changed files with 25 additions and 81 deletions

View file

@ -15,6 +15,7 @@ const ava_1 = __importDefault(require("ava"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const sinon_1 = __importDefault(require("sinon"));
const api = __importStar(require("./api-client"));
const configUtils = __importStar(require("./config-utils"));
const testing_utils_1 = require("./testing-utils");
const util = __importStar(require("./util"));
@ -131,29 +132,6 @@ ava_1.default("load non-empty input", async (t) => {
t.deepEqual(actualConfig, expectedConfig);
});
});
ava_1.default("Octokit not used when reading local config", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
const sandbox = sinon_1.default.createSandbox();
const spyKit = sandbox.spy(octokit, "Octokit");
const inputFileContents = `
name: my config
disable-default-queries: true
queries:
- uses: ./
paths-ignore:
- a
- b
paths:
- c/d`;
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
setInput('config-file', 'input');
await configUtils.loadConfig();
t.false(spyKit.called);
sandbox.restore();
});
});
ava_1.default("Remote and local configuration paths correctly identified", t => {
// If the path starts with ./, look locally
t.assert(configUtils.isLocal('./file'));
@ -163,7 +141,7 @@ ava_1.default("Remote and local configuration paths correctly identified", t =>
// Otherwise look locally (this is the fallback)
t.assert(configUtils.isLocal('file'));
});
ava_1.default("Octokit used when reading remote config", async (t) => {
ava_1.default("API client used when reading remote config", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;
@ -177,19 +155,22 @@ ava_1.default("Octokit used when reading remote config", async (t) => {
- b
paths:
- c/d`;
const dummyResponse = [
{ data: inputFileContents }
];
const dummyResponse = {
data: {
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(octokit, "Octokit").resolves(ok);
sinon_1.default.stub(api, "client").value(ok);
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
await configUtils.loadConfig();
t.assert(spyGetContents.called);
sinon_1.default.restore();
});
});
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {