Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: set repository authentication when repositoryUrl is set as an …
…option
  • Loading branch information
pvdlg committed Feb 12, 2018
1 parent b6837a2 commit ce1e74f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/get-config.js
Expand Up @@ -42,17 +42,17 @@ module.exports = async (opts, logger) => {
};
}

const repositoryUrl = (await pkgRepoUrl()) || (await repoUrl());

// Set default options values if not defined yet
options = {
branch: 'master',
repositoryUrl: repositoryUrl ? getGitAuthUrl(repositoryUrl) : repositoryUrl,
repositoryUrl: (await pkgRepoUrl()) || (await repoUrl()),
tagFormat: `v\${version}`,
// Remove `null` and `undefined` options so they can be replaced with default ones
...pickBy(options, option => !isUndefined(option) && !isNull(option)),
};

options.repositoryUrl = options.repositoryUrl ? getGitAuthUrl(options.repositoryUrl) : options.repositoryUrl;

debug('options values: %O', options);

return {options, plugins: await plugins(options, pluginsPath, logger)};
Expand Down
13 changes: 8 additions & 5 deletions test/get-config.test.js
Expand Up @@ -31,7 +31,8 @@ test.afterEach.always(() => {
});

test.serial('Default values, reading repositoryUrl from package.json', async t => {
const pkg = {repository: 'git@package.com:owner/module.git'};
process.env.GIT_CREDENTIALS = 'user:pass';
const pkg = {repository: 'https://package.com/owner/module.git'};
// Create a git repository, set the current working directory at the root of the repo
await gitRepo();
await gitCommits(['First']);
Expand All @@ -44,25 +45,27 @@ test.serial('Default values, reading repositoryUrl from package.json', async t =

// Verify the default options are set
t.is(options.branch, 'master');
t.is(options.repositoryUrl, 'git@package.com:owner/module.git');
t.is(options.repositoryUrl, 'https://user:pass@package.com/owner/module.git');
t.is(options.tagFormat, `v\${version}`);
});

test.serial('Default values, reading repositoryUrl from repo if not set in package.json', async t => {
process.env.GIT_CREDENTIALS = 'user:pass';
// Create a git repository, set the current working directory at the root of the repo
await gitRepo();
// Add remote.origin.url config
await gitAddConfig('remote.origin.url', 'git@repo.com:owner/module.git');
await gitAddConfig('remote.origin.url', 'https://hostname.com/owner/module.git');

const {options} = await t.context.getConfig();

// Verify the default options are set
t.is(options.branch, 'master');
t.is(options.repositoryUrl, 'git@repo.com:owner/module.git');
t.is(options.repositoryUrl, 'https://user:pass@hostname.com/owner/module.git');
t.is(options.tagFormat, `v\${version}`);
});

test.serial('Default values, reading repositoryUrl (http url) from package.json if not set in repo', async t => {
process.env.GIT_CREDENTIALS = 'user:pass';
const pkg = {repository: 'https://hostname.com/owner/module.git'};
// Create a git repository, set the current working directory at the root of the repo
await gitRepo();
Expand All @@ -73,7 +76,7 @@ test.serial('Default values, reading repositoryUrl (http url) from package.json

// Verify the default options are set
t.is(options.branch, 'master');
t.is(options.repositoryUrl, pkg.repository);
t.is(options.repositoryUrl, 'https://user:pass@hostname.com/owner/module.git');
t.is(options.tagFormat, `v\${version}`);
});

Expand Down

0 comments on commit ce1e74f

Please sign in to comment.