Skip to content

Commit

Permalink
Merge branch 'urlfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanCarroll committed Oct 1, 2021
2 parents aba90c5 + 27953e1 commit 9b87ade
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@ async function pkgRepoUrl(options) {
return packageJson && (isPlainObject(packageJson.repository) ? packageJson.repository.url : packageJson.repository);
}

async function ciInferFromEnv(env) {
// currently, used in GitLab
if ( env["CI_REPOSITORY_URL"] ) {
return env["CI_REPOSITORY_URL"];
}
return null;
}

async function repoUrlResolve(options) {
let {cwd, env, ci} = options;
let ret;

if (ci) {
ret ||= await ciInferFromEnv(env);
}

// get from package.json
ret ||= await pkgRepoUrl({normalize: false, cwd});

// get from git
ret ||= await repoUrl({cwd, env});

debug("Resolved repoUrl to %s", ret);

return ret;
}

const DEFAULTS = {
branches: [
'+([0-9])?(.{+([0-9]),x}).x',
Expand Down Expand Up @@ -85,7 +112,6 @@ module.exports = async (context, cliOptions) => {
// Set default options values if not defined yet
options = {
...DEFAULTS,
repositoryUrl: (await pkgRepoUrl({normalize: false, cwd})) || (await repoUrl({cwd, env})),
// Remove `null` and `undefined` options so they can be replaced with default ones
...pickBy(options, (option) => !isNil(option)),
...(options.branches ? {branches: castArray(options.branches)} : {}),
Expand All @@ -104,6 +130,8 @@ module.exports = async (context, cliOptions) => {
options.noCi = !ci;
}

options["repositoryUrl"] = await repoUrlResolve({cwd, env, ci: options.ci});

debug(`Load config %O`,{filepath, 'unprocessed_config': config, 'processed_options': options});

return {options, plugins: await plugins({...context, options}, pluginsPath)};
Expand Down

0 comments on commit 9b87ade

Please sign in to comment.