Skip to content

Commit

Permalink
fix: convert git+https URL in package.json to https
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg authored and gr2m committed Mar 13, 2018
1 parent 6f74dcb commit b0b4fc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions lib/get-config.js
Expand Up @@ -2,6 +2,7 @@ const {castArray, pickBy, isUndefined, isNull, isString, isPlainObject} = requir
const readPkgUp = require('read-pkg-up');
const cosmiconfig = require('cosmiconfig');
const resolveFrom = require('resolve-from');
const gitUrlParse = require('git-url-parse');
const debug = require('debug')('semantic-release:config');
const {repoUrl, verifyAuth} = require('./git');
const PLUGINS_DEFINITIONS = require('./definitions/plugins');
Expand Down Expand Up @@ -61,6 +62,13 @@ module.exports = async (opts, logger) => {
};

async function pkgRepoUrl() {
const {pkg} = await readPkgUp();
return pkg && pkg.repository ? pkg.repository.url : undefined;
const {pkg} = await readPkgUp({normalize: false});
const repositoryUrl = pkg && (isPlainObject(pkg.repository) ? pkg.repository.url : pkg.repository);

if (repositoryUrl) {
const {protocols} = gitUrlParse(repositoryUrl);
return `${gitUrlParse(repositoryUrl).toString(
protocols.includes('https') ? 'https' : protocols.includes('http') ? 'http' : undefined
)}${protocols.includes('https') || protocols.includes('http') ? '.git' : ''}`;
}
}
12 changes: 6 additions & 6 deletions test/integration.test.js
Expand Up @@ -604,17 +604,17 @@ test.serial('Exit with 1 if missing permission to push to the remote repository'
// Create a git repository, set the current working directory at the root of the repo
t.log('Create git repository');
await gitbox.createRepo(packageName);
await writeJson('./package.json', {
name: packageName,
version: '0.0.0-dev',
repository: {url: 'http://user:wrong_pass@localhost:2080/git/unauthorized.git'},
});
await writeJson('./package.json', {name: packageName, version: '0.0.0-dev'});

/* Initial release */
t.log('Commit a feature');
await gitCommits(['feat: Initial commit']);
t.log('$ semantic-release');
const {stdout, code} = await execa(cli, [], {env: {...env, ...{GH_TOKEN: 'user:wrong_pass'}}, reject: false});
const {stdout, code} = await execa(
cli,
['--repository-url', 'http://user:wrong_pass@localhost:2080/git/unauthorized.git'],
{env: {...env, ...{GH_TOKEN: 'user:wrong_pass'}}, reject: false}
);
// Verify the type and message are logged
t.regex(stdout, /EGITNOPERMISSION/);
t.is(code, 1);
Expand Down

0 comments on commit b0b4fc8

Please sign in to comment.