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
61
lib/config-utils.js
generated
61
lib/config-utils.js
generated
|
|
@ -292,34 +292,25 @@ exports.getUnknownLanguagesError = getUnknownLanguagesError;
|
|||
/**
|
||||
* Gets the set of languages in the current repository
|
||||
*/
|
||||
async function getLanguagesInRepo(githubAuth, githubUrl, logger) {
|
||||
var _a;
|
||||
let repo_nwo = (_a = process.env['GITHUB_REPOSITORY']) === null || _a === void 0 ? void 0 : _a.split("/");
|
||||
if (repo_nwo) {
|
||||
let owner = repo_nwo[0];
|
||||
let repo = repo_nwo[1];
|
||||
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));
|
||||
// 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 = new Set();
|
||||
for (let lang of Object.keys(response.data)) {
|
||||
let parsedLang = languages_1.parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
languages.add(parsedLang);
|
||||
}
|
||||
async function getLanguagesInRepo(repository, githubAuth, githubUrl, logger) {
|
||||
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("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 = new Set();
|
||||
for (let lang of Object.keys(response.data)) {
|
||||
let parsedLang = languages_1.parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
languages.add(parsedLang);
|
||||
}
|
||||
return [...languages];
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
return [...languages];
|
||||
}
|
||||
/**
|
||||
* Get the languages to analyse.
|
||||
|
|
@ -331,7 +322,7 @@ async function getLanguagesInRepo(githubAuth, githubUrl, logger) {
|
|||
* If no languages could be detected from either the workflow or the repository
|
||||
* then throw an error.
|
||||
*/
|
||||
async function getLanguages(languagesInput, githubAuth, githubUrl, logger) {
|
||||
async function getLanguages(languagesInput, repository, githubAuth, githubUrl, logger) {
|
||||
// Obtain from action input 'languages' if set
|
||||
let languages = (languagesInput || "")
|
||||
.split(',')
|
||||
|
|
@ -340,7 +331,7 @@ async function getLanguages(languagesInput, githubAuth, githubUrl, logger) {
|
|||
logger.info("Languages from configuration: " + JSON.stringify(languages));
|
||||
if (languages.length === 0) {
|
||||
// Obtain languages as all languages in the repo that can be analysed
|
||||
languages = await getLanguagesInRepo(githubAuth, githubUrl, logger);
|
||||
languages = await getLanguagesInRepo(repository, githubAuth, githubUrl, logger);
|
||||
logger.info("Automatically detected languages: " + JSON.stringify(languages));
|
||||
}
|
||||
// If the languages parameter was not given and no languages were
|
||||
|
|
@ -377,8 +368,8 @@ async function addQueriesFromWorkflow(codeQL, queriesInput, languages, resultMap
|
|||
/**
|
||||
* Get the default config for when the user has not supplied one.
|
||||
*/
|
||||
async function getDefaultConfig(languagesInput, queriesInput, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
const languages = await getLanguages(languagesInput, githubAuth, githubUrl, logger);
|
||||
async function getDefaultConfig(languagesInput, queriesInput, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
const languages = await getLanguages(languagesInput, repository, githubAuth, githubUrl, logger);
|
||||
const queries = {};
|
||||
await addDefaultQueries(codeQL, languages, queries);
|
||||
if (queriesInput) {
|
||||
|
|
@ -399,7 +390,7 @@ exports.getDefaultConfig = getDefaultConfig;
|
|||
/**
|
||||
* Load the config from the given file.
|
||||
*/
|
||||
async function loadConfig(languagesInput, queriesInput, configFile, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
async function loadConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
let parsedYAML;
|
||||
if (isLocal(configFile)) {
|
||||
// Treat the config file as relative to the workspace
|
||||
|
|
@ -419,7 +410,7 @@ async function loadConfig(languagesInput, queriesInput, configFile, tempDir, too
|
|||
throw new Error(getNameInvalid(configFile));
|
||||
}
|
||||
}
|
||||
const languages = await getLanguages(languagesInput, githubAuth, githubUrl, logger);
|
||||
const languages = await getLanguages(languagesInput, repository, githubAuth, githubUrl, logger);
|
||||
const queries = {};
|
||||
const pathsIgnore = [];
|
||||
const paths = [];
|
||||
|
|
@ -496,15 +487,15 @@ async function loadConfig(languagesInput, queriesInput, configFile, tempDir, too
|
|||
* This will parse the config from the user input if present, or generate
|
||||
* a default config. The parsed config is then stored to a known location.
|
||||
*/
|
||||
async function initConfig(languagesInput, queriesInput, configFile, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
async function initConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
let config;
|
||||
// If no config file was provided create an empty one
|
||||
if (!configFile) {
|
||||
logger.debug('No configuration file was provided');
|
||||
config = await getDefaultConfig(languagesInput, queriesInput, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger);
|
||||
config = await getDefaultConfig(languagesInput, queriesInput, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger);
|
||||
}
|
||||
else {
|
||||
config = await loadConfig(languagesInput, queriesInput, configFile, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger);
|
||||
config = await loadConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger);
|
||||
}
|
||||
// Save the config so we can easily access it again in the future
|
||||
await saveConfig(config, logger);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue