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

@ -4,6 +4,7 @@ import * as fs from 'fs';
import * as path from 'path';
import sinon from 'sinon';
import * as api from './api-client';
import * as configUtils from './config-utils';
import {silenceDebugOutput} from './testing-utils';
import * as util from './util';
@ -144,33 +145,6 @@ test("load non-empty input", async t => {
});
});
test("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.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();
});
});
test("Remote and local configuration paths correctly identified", t => {
// If the path starts with ./, look locally
t.assert(configUtils.isLocal('./file'));
@ -183,7 +157,7 @@ test("Remote and local configuration paths correctly identified", t => {
t.assert(configUtils.isLocal('file'));
});
test("Octokit used when reading remote config", async t => {
test("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;
@ -198,9 +172,11 @@ test("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",
@ -208,11 +184,13 @@ test("Octokit used when reading remote config", async t => {
const repos = ok.repos;
const spyGetContents = sinon.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
ok.repos = repos;
sinon.stub(octokit, "Octokit").resolves(ok);
sinon.stub(api, "client").value(ok);
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
await configUtils.loadConfig();
t.assert(spyGetContents.called);
sinon.restore();
});
});

View file

@ -1,11 +1,10 @@
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as octokit from '@octokit/rest';
import consoleLogLevel from 'console-log-level';
import * as fs from 'fs';
import * as yaml from 'js-yaml';
import * as path from 'path';
import * as api from './api-client';
import * as util from './util';
const NAME_PROPERTY = 'name';
@ -287,12 +286,7 @@ async function getRemoteConfig(configFile: string): Promise<any> {
throw new Error(getConfigFileRepoFormatInvalid(configFile));
}
let ok = new octokit.Octokit({
auth: core.getInput('token'),
userAgent: "CodeQL Action",
log: consoleLogLevel({ level: "debug" })
});
const response = await ok.repos.getContents({
const response = await api.client.repos.getContents({
owner: pieces.groups.owner,
repo: pieces.groups.repo,
path: pieces.groups.path,