Use new API client
From https://github.com/github/codeql-action/pull/82
This commit is contained in:
parent
9566d8c220
commit
f8c87948ab
6 changed files with 25 additions and 81 deletions
13
lib/config-utils.js
generated
13
lib/config-utils.js
generated
|
|
@ -6,17 +6,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
result["default"] = mod;
|
result["default"] = mod;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const io = __importStar(require("@actions/io"));
|
const io = __importStar(require("@actions/io"));
|
||||||
const octokit = __importStar(require("@octokit/rest"));
|
|
||||||
const console_log_level_1 = __importDefault(require("console-log-level"));
|
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const yaml = __importStar(require("js-yaml"));
|
const yaml = __importStar(require("js-yaml"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
|
const api = __importStar(require("./api-client"));
|
||||||
const util = __importStar(require("./util"));
|
const util = __importStar(require("./util"));
|
||||||
const NAME_PROPERTY = 'name';
|
const NAME_PROPERTY = 'name';
|
||||||
const DISPLAY_DEFAULT_QUERIES_PROPERTY = 'disable-default-queries';
|
const DISPLAY_DEFAULT_QUERIES_PROPERTY = 'disable-default-queries';
|
||||||
|
|
@ -255,12 +251,7 @@ async function getRemoteConfig(configFile) {
|
||||||
if (pieces === null || pieces.groups === undefined || pieces.length < 5) {
|
if (pieces === null || pieces.groups === undefined || pieces.length < 5) {
|
||||||
throw new Error(getConfigFileRepoFormatInvalid(configFile));
|
throw new Error(getConfigFileRepoFormatInvalid(configFile));
|
||||||
}
|
}
|
||||||
let ok = new octokit.Octokit({
|
const response = await api.client.repos.getContents({
|
||||||
auth: core.getInput('token'),
|
|
||||||
userAgent: "CodeQL Action",
|
|
||||||
log: console_log_level_1.default({ level: "debug" })
|
|
||||||
});
|
|
||||||
const response = await ok.repos.getContents({
|
|
||||||
owner: pieces.groups.owner,
|
owner: pieces.groups.owner,
|
||||||
repo: pieces.groups.repo,
|
repo: pieces.groups.repo,
|
||||||
path: pieces.groups.path,
|
path: pieces.groups.path,
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
37
lib/config-utils.test.js
generated
37
lib/config-utils.test.js
generated
|
|
@ -15,6 +15,7 @@ const ava_1 = __importDefault(require("ava"));
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const sinon_1 = __importDefault(require("sinon"));
|
const sinon_1 = __importDefault(require("sinon"));
|
||||||
|
const api = __importStar(require("./api-client"));
|
||||||
const configUtils = __importStar(require("./config-utils"));
|
const configUtils = __importStar(require("./config-utils"));
|
||||||
const testing_utils_1 = require("./testing-utils");
|
const testing_utils_1 = require("./testing-utils");
|
||||||
const util = __importStar(require("./util"));
|
const util = __importStar(require("./util"));
|
||||||
|
|
@ -131,29 +132,6 @@ ava_1.default("load non-empty input", async (t) => {
|
||||||
t.deepEqual(actualConfig, expectedConfig);
|
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 => {
|
ava_1.default("Remote and local configuration paths correctly identified", t => {
|
||||||
// If the path starts with ./, look locally
|
// If the path starts with ./, look locally
|
||||||
t.assert(configUtils.isLocal('./file'));
|
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)
|
// Otherwise look locally (this is the fallback)
|
||||||
t.assert(configUtils.isLocal('file'));
|
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) => {
|
return await util.withTmpDir(async (tmpDir) => {
|
||||||
process.env['RUNNER_TEMP'] = tmpDir;
|
process.env['RUNNER_TEMP'] = tmpDir;
|
||||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||||
|
|
@ -177,19 +155,22 @@ ava_1.default("Octokit used when reading remote config", async (t) => {
|
||||||
- b
|
- b
|
||||||
paths:
|
paths:
|
||||||
- c/d`;
|
- c/d`;
|
||||||
const dummyResponse = [
|
const dummyResponse = {
|
||||||
{ data: inputFileContents }
|
data: {
|
||||||
];
|
content: Buffer.from(inputFileContents).toString("base64"),
|
||||||
|
}
|
||||||
|
};
|
||||||
let ok = new octokit.Octokit({
|
let ok = new octokit.Octokit({
|
||||||
userAgent: "CodeQL Action",
|
userAgent: "CodeQL Action",
|
||||||
});
|
});
|
||||||
const repos = ok.repos;
|
const repos = ok.repos;
|
||||||
const spyGetContents = sinon_1.default.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
const spyGetContents = sinon_1.default.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
||||||
ok.repos = repos;
|
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');
|
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
|
||||||
await configUtils.loadConfig();
|
await configUtils.loadConfig();
|
||||||
t.assert(spyGetContents.called);
|
t.assert(spyGetContents.called);
|
||||||
|
sinon_1.default.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -4,6 +4,7 @@ import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
|
import * as api from './api-client';
|
||||||
import * as configUtils from './config-utils';
|
import * as configUtils from './config-utils';
|
||||||
import {silenceDebugOutput} from './testing-utils';
|
import {silenceDebugOutput} from './testing-utils';
|
||||||
import * as util from './util';
|
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 => {
|
test("Remote and local configuration paths correctly identified", t => {
|
||||||
// If the path starts with ./, look locally
|
// If the path starts with ./, look locally
|
||||||
t.assert(configUtils.isLocal('./file'));
|
t.assert(configUtils.isLocal('./file'));
|
||||||
|
|
@ -183,7 +157,7 @@ test("Remote and local configuration paths correctly identified", t => {
|
||||||
t.assert(configUtils.isLocal('file'));
|
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 => {
|
return await util.withTmpDir(async tmpDir => {
|
||||||
process.env['RUNNER_TEMP'] = tmpDir;
|
process.env['RUNNER_TEMP'] = tmpDir;
|
||||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||||
|
|
@ -198,9 +172,11 @@ test("Octokit used when reading remote config", async t => {
|
||||||
- b
|
- b
|
||||||
paths:
|
paths:
|
||||||
- c/d`;
|
- c/d`;
|
||||||
const dummyResponse = [
|
const dummyResponse = {
|
||||||
{data: inputFileContents}
|
data: {
|
||||||
];
|
content: Buffer.from(inputFileContents).toString("base64"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let ok = new octokit.Octokit({
|
let ok = new octokit.Octokit({
|
||||||
userAgent: "CodeQL Action",
|
userAgent: "CodeQL Action",
|
||||||
|
|
@ -208,11 +184,13 @@ test("Octokit used when reading remote config", async t => {
|
||||||
const repos = ok.repos;
|
const repos = ok.repos;
|
||||||
const spyGetContents = sinon.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
const spyGetContents = sinon.stub(repos, "getContents").resolves(Promise.resolve(dummyResponse));
|
||||||
ok.repos = repos;
|
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');
|
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
|
||||||
await configUtils.loadConfig();
|
await configUtils.loadConfig();
|
||||||
t.assert(spyGetContents.called);
|
t.assert(spyGetContents.called);
|
||||||
|
|
||||||
|
sinon.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as io from '@actions/io';
|
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 fs from 'fs';
|
||||||
import * as yaml from 'js-yaml';
|
import * as yaml from 'js-yaml';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
import * as api from './api-client';
|
||||||
import * as util from './util';
|
import * as util from './util';
|
||||||
|
|
||||||
const NAME_PROPERTY = 'name';
|
const NAME_PROPERTY = 'name';
|
||||||
|
|
@ -287,12 +286,7 @@ async function getRemoteConfig(configFile: string): Promise<any> {
|
||||||
throw new Error(getConfigFileRepoFormatInvalid(configFile));
|
throw new Error(getConfigFileRepoFormatInvalid(configFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ok = new octokit.Octokit({
|
const response = await api.client.repos.getContents({
|
||||||
auth: core.getInput('token'),
|
|
||||||
userAgent: "CodeQL Action",
|
|
||||||
log: consoleLogLevel({ level: "debug" })
|
|
||||||
});
|
|
||||||
const response = await ok.repos.getContents({
|
|
||||||
owner: pieces.groups.owner,
|
owner: pieces.groups.owner,
|
||||||
repo: pieces.groups.repo,
|
repo: pieces.groups.repo,
|
||||||
path: pieces.groups.path,
|
path: pieces.groups.path,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue