From b0b4fc82de6be5f274094c2b60114422ad255497 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Mon, 12 Mar 2018 16:37:58 -0400 Subject: [PATCH] fix: convert `git+https` URL in package.json to `https` --- lib/get-config.js | 12 ++++++++++-- test/integration.test.js | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/get-config.js b/lib/get-config.js index db719feb..abc4bb2a 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -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'); @@ -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' : ''}`; + } } diff --git a/test/integration.test.js b/test/integration.test.js index b3b7c560..df12853b 100644 --- a/test/integration.test.js +++ b/test/integration.test.js @@ -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);