Skip to content

Commit ce1e74f

Browse files
committed
fix: set repository authentication when repositoryUrl is set as an option
1 parent b6837a2 commit ce1e74f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/get-config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ module.exports = async (opts, logger) => {
4242
};
4343
}
4444

45-
const repositoryUrl = (await pkgRepoUrl()) || (await repoUrl());
46-
4745
// Set default options values if not defined yet
4846
options = {
4947
branch: 'master',
50-
repositoryUrl: repositoryUrl ? getGitAuthUrl(repositoryUrl) : repositoryUrl,
48+
repositoryUrl: (await pkgRepoUrl()) || (await repoUrl()),
5149
tagFormat: `v\${version}`,
5250
// Remove `null` and `undefined` options so they can be replaced with default ones
5351
...pickBy(options, option => !isUndefined(option) && !isNull(option)),
5452
};
5553

54+
options.repositoryUrl = options.repositoryUrl ? getGitAuthUrl(options.repositoryUrl) : options.repositoryUrl;
55+
5656
debug('options values: %O', options);
5757

5858
return {options, plugins: await plugins(options, pluginsPath, logger)};

test/get-config.test.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ test.afterEach.always(() => {
3131
});
3232

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

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

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

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

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

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

7477
// Verify the default options are set
7578
t.is(options.branch, 'master');
76-
t.is(options.repositoryUrl, pkg.repository);
79+
t.is(options.repositoryUrl, 'https://user:[email protected]/owner/module.git');
7780
t.is(options.tagFormat, `v\${version}`);
7881
});
7982

0 commit comments

Comments
 (0)