Remove dependence of GITHUB_REPOSITORY env var
This commit is contained in:
parent
688df282cd
commit
39b361ed69
15 changed files with 108 additions and 86 deletions
|
|
@ -59,6 +59,7 @@ test("load empty config", async t => {
|
|||
languages,
|
||||
undefined,
|
||||
undefined,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -70,6 +71,7 @@ test("load empty config", async t => {
|
|||
t.deepEqual(config, await configUtils.getDefaultConfig(
|
||||
languages,
|
||||
undefined,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -105,6 +107,7 @@ test("loading config saves config", async t => {
|
|||
'javascript,python',
|
||||
undefined,
|
||||
undefined,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -129,6 +132,7 @@ test("load input outside of workspace", async t => {
|
|||
undefined,
|
||||
undefined,
|
||||
'../input',
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
getCachedCodeQL(),
|
||||
|
|
@ -153,6 +157,7 @@ test("load non-local input with invalid repo syntax", async t => {
|
|||
undefined,
|
||||
undefined,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
getCachedCodeQL(),
|
||||
|
|
@ -178,6 +183,7 @@ test("load non-existent input", async t => {
|
|||
languages,
|
||||
undefined,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
getCachedCodeQL(),
|
||||
|
|
@ -249,6 +255,7 @@ test("load non-empty input", async t => {
|
|||
languages,
|
||||
undefined,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -303,6 +310,7 @@ test("default queries are used", async t => {
|
|||
languages,
|
||||
undefined,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -355,6 +363,7 @@ test("Queries can be specified in config file", async t => {
|
|||
languages,
|
||||
undefined,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -418,6 +427,7 @@ test("Queries from config file can be overridden in workflow file", async t => {
|
|||
languages,
|
||||
queries,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -472,6 +482,7 @@ test("Multiple queries can be specified in workflow file, no config file require
|
|||
languages,
|
||||
queries,
|
||||
undefined,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -521,6 +532,7 @@ test("Invalid queries in workflow file handled correctly", async t => {
|
|||
languages,
|
||||
queries,
|
||||
undefined,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -578,6 +590,7 @@ test("API client used when reading remote config", async t => {
|
|||
languages,
|
||||
undefined,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
@ -600,6 +613,7 @@ test("Remote config handles the case where a directory is provided", async t =>
|
|||
undefined,
|
||||
undefined,
|
||||
repoReference,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
getCachedCodeQL(),
|
||||
|
|
@ -627,6 +641,7 @@ test("Invalid format of remote config handled correctly", async t => {
|
|||
undefined,
|
||||
undefined,
|
||||
repoReference,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
getCachedCodeQL(),
|
||||
|
|
@ -650,6 +665,7 @@ test("No detected languages", async t => {
|
|||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
getCachedCodeQL(),
|
||||
|
|
@ -673,6 +689,7 @@ test("Unknown languages", async t => {
|
|||
languages,
|
||||
undefined,
|
||||
undefined,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
getCachedCodeQL(),
|
||||
|
|
@ -714,6 +731,7 @@ function doInvalidInputTest(
|
|||
languages,
|
||||
undefined,
|
||||
configFile,
|
||||
{ owner: 'github', repo: 'example '},
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
codeQL,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { CodeQL, ResolveQueriesOutput } from './codeql';
|
|||
import * as externalQueries from "./external-queries";
|
||||
import { Language, parseLanguage } from "./languages";
|
||||
import { Logger } from './logging';
|
||||
import { RepositoryNwo } from './repository';
|
||||
|
||||
// Property names from the user-supplied config file.
|
||||
const NAME_PROPERTY = 'name';
|
||||
|
|
@ -450,38 +451,31 @@ export function getUnknownLanguagesError(languages: string[]): string {
|
|||
* Gets the set of languages in the current repository
|
||||
*/
|
||||
async function getLanguagesInRepo(
|
||||
repository: RepositoryNwo,
|
||||
githubAuth: string,
|
||||
githubUrl: string,
|
||||
logger: Logger): Promise<Language[]> {
|
||||
|
||||
let repo_nwo = process.env['GITHUB_REPOSITORY']?.split("/");
|
||||
if (repo_nwo) {
|
||||
let owner = repo_nwo[0];
|
||||
let repo = repo_nwo[1];
|
||||
logger.debug(`GitHub repo ${repository.owner} ${repository.repo}`);
|
||||
const response = await api.getApiClient(githubAuth, githubUrl, true).repos.listLanguages({
|
||||
owner: repository.owner,
|
||||
repo: repository.repo
|
||||
});
|
||||
|
||||
logger.debug(`GitHub repo ${owner} ${repo}`);
|
||||
const response = await api.getApiClient(githubAuth, githubUrl, true).repos.listLanguages({
|
||||
owner,
|
||||
repo
|
||||
});
|
||||
logger.debug("Languages API response: " + JSON.stringify(response));
|
||||
|
||||
logger.debug("Languages API response: " + JSON.stringify(response));
|
||||
|
||||
// The GitHub API is going to return languages in order of popularity,
|
||||
// When we pick a language to autobuild we want to pick the most popular traced language
|
||||
// Since sets in javascript maintain insertion order, using a set here and then splatting it
|
||||
// into an array gives us an array of languages ordered by popularity
|
||||
let languages: Set<Language> = new Set();
|
||||
for (let lang of Object.keys(response.data)) {
|
||||
let parsedLang = parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
languages.add(parsedLang);
|
||||
}
|
||||
// The GitHub API is going to return languages in order of popularity,
|
||||
// When we pick a language to autobuild we want to pick the most popular traced language
|
||||
// Since sets in javascript maintain insertion order, using a set here and then splatting it
|
||||
// into an array gives us an array of languages ordered by popularity
|
||||
let languages: Set<Language> = new Set();
|
||||
for (let lang of Object.keys(response.data)) {
|
||||
let parsedLang = parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
languages.add(parsedLang);
|
||||
}
|
||||
return [...languages];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return [...languages];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -496,6 +490,7 @@ async function getLanguagesInRepo(
|
|||
*/
|
||||
async function getLanguages(
|
||||
languagesInput: string | undefined,
|
||||
repository: RepositoryNwo,
|
||||
githubAuth: string,
|
||||
githubUrl: string,
|
||||
logger: Logger): Promise<Language[]> {
|
||||
|
|
@ -510,6 +505,7 @@ async function getLanguages(
|
|||
if (languages.length === 0) {
|
||||
// Obtain languages as all languages in the repo that can be analysed
|
||||
languages = await getLanguagesInRepo(
|
||||
repository,
|
||||
githubAuth,
|
||||
githubUrl,
|
||||
logger);
|
||||
|
|
@ -564,6 +560,7 @@ async function addQueriesFromWorkflow(
|
|||
export async function getDefaultConfig(
|
||||
languagesInput: string | undefined,
|
||||
queriesInput: string | undefined,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
codeQL: CodeQL,
|
||||
|
|
@ -574,6 +571,7 @@ export async function getDefaultConfig(
|
|||
|
||||
const languages = await getLanguages(
|
||||
languagesInput,
|
||||
repository,
|
||||
githubAuth,
|
||||
githubUrl,
|
||||
logger);
|
||||
|
|
@ -602,6 +600,7 @@ async function loadConfig(
|
|||
languagesInput: string | undefined,
|
||||
queriesInput: string | undefined,
|
||||
configFile: string,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
codeQL: CodeQL,
|
||||
|
|
@ -636,6 +635,7 @@ async function loadConfig(
|
|||
|
||||
const languages = await getLanguages(
|
||||
languagesInput,
|
||||
repository,
|
||||
githubAuth,
|
||||
githubUrl,
|
||||
logger);
|
||||
|
|
@ -734,6 +734,7 @@ export async function initConfig(
|
|||
languagesInput: string | undefined,
|
||||
queriesInput: string | undefined,
|
||||
configFile: string | undefined,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
codeQL: CodeQL,
|
||||
|
|
@ -750,6 +751,7 @@ export async function initConfig(
|
|||
config = await getDefaultConfig(
|
||||
languagesInput,
|
||||
queriesInput,
|
||||
repository,
|
||||
tempDir,
|
||||
toolCacheDir,
|
||||
codeQL,
|
||||
|
|
@ -762,6 +764,7 @@ export async function initConfig(
|
|||
languagesInput,
|
||||
queriesInput,
|
||||
configFile,
|
||||
repository,
|
||||
tempDir,
|
||||
toolCacheDir,
|
||||
codeQL,
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { CodeQL } from './codeql';
|
|||
import * as configUtils from './config-utils';
|
||||
import { initCodeQL, initConfig, runInit } from './init';
|
||||
import { getActionsLogger } from './logging';
|
||||
import { parseRepositoryNwo } from './repository';
|
||||
import * as util from './util';
|
||||
|
||||
interface InitSuccessStatusReport extends util.StatusReportBase {
|
||||
|
|
@ -69,6 +70,7 @@ async function run() {
|
|||
core.getInput('languages'),
|
||||
core.getInput('queries'),
|
||||
core.getInput('config-file'),
|
||||
parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')),
|
||||
util.getRequiredEnvParam('RUNNER_TEMP'),
|
||||
util.getRequiredEnvParam('RUNNER_TOOL_CACHE'),
|
||||
codeql,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import * as analysisPaths from './analysis-paths';
|
|||
import { CodeQL, setupCodeQL } from './codeql';
|
||||
import * as configUtils from './config-utils';
|
||||
import { Logger } from './logging';
|
||||
import { RepositoryNwo } from './repository';
|
||||
import { getCombinedTracerConfig, TracerConfig } from './tracer-config';
|
||||
import * as util from './util';
|
||||
|
||||
|
|
@ -36,6 +37,7 @@ export async function initConfig(
|
|||
languagesInput: string | undefined,
|
||||
queriesInput: string | undefined,
|
||||
configFile: string | undefined,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
codeQL: CodeQL,
|
||||
|
|
@ -49,6 +51,7 @@ export async function initConfig(
|
|||
languagesInput,
|
||||
queriesInput,
|
||||
configFile,
|
||||
repository,
|
||||
tempDir,
|
||||
toolCacheDir,
|
||||
codeQL,
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ interface InitArgs {
|
|||
tempDir: string | undefined;
|
||||
toolsDir: string | undefined;
|
||||
checkoutPath: string | undefined;
|
||||
repository: string;
|
||||
githubUrl: string;
|
||||
githubAuth: string;
|
||||
}
|
||||
|
|
@ -70,6 +71,7 @@ interface InitArgs {
|
|||
program
|
||||
.command('init')
|
||||
.description('Initializes CodeQL')
|
||||
.requiredOption('--repository <repository>', 'Repository name')
|
||||
.requiredOption('--github-url <url>', 'URL of GitHub instance')
|
||||
.requiredOption('--github-auth <auth>', 'GitHub Apps token, or of the form "username:token" if using a personal access token')
|
||||
.option('--languages <languages>', 'Comma-separated list of languages to analyze. Defaults to trying to detect languages from the repo.')
|
||||
|
|
@ -106,6 +108,7 @@ program
|
|||
cmd.languages,
|
||||
cmd.queries,
|
||||
cmd.configFile,
|
||||
parseRepositoryNwo(cmd.repository),
|
||||
tempDir,
|
||||
toolsDir,
|
||||
codeql,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue