From eaa3b6f1b1672362e2ab343ce33ce95cb43fe11c Mon Sep 17 00:00:00 2001 From: Steve Mao Date: Mon, 18 Apr 2016 23:00:51 +1000 Subject: [PATCH] fix(unknownHost): default context.repository `context.repository` should only fallback to `browse` if `context.host`, `context.owner` and `context.repository` do not exist. --- lib/merge-config.js | 6 +++++- test/fixtures/{_unknown-host.json => _host-only.json} | 2 +- test/test.js | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) rename test/fixtures/{_unknown-host.json => _host-only.json} (61%) diff --git a/lib/merge-config.js b/lib/merge-config.js index b6f0bd5..0abcc2c 100644 --- a/lib/merge-config.js +++ b/lib/merge-config.js @@ -138,7 +138,11 @@ function mergeConfig(options, context, gitRawCommitsOpts, parserOpts, writerOpts var parsedBrowse = url.parse(browse); context.host = context.host || (repo.domain ? (parsedBrowse.protocol + (parsedBrowse.slashes ? '//' : '') + repo.domain) : null); context.owner = context.owner || repo.user || ''; - context.repository = context.repository || repo.project || browse; + context.repository = context.repository || repo.project; + + if (!context.host && !context.owner && !context.repository) { + context.repository = browse; + } } context.packageData = pkg; diff --git a/test/fixtures/_unknown-host.json b/test/fixtures/_host-only.json similarity index 61% rename from test/fixtures/_unknown-host.json rename to test/fixtures/_host-only.json index d7247bd..4630342 100644 --- a/test/fixtures/_unknown-host.json +++ b/test/fixtures/_host-only.json @@ -2,6 +2,6 @@ "version": "0.0.17", "repository": { "type": "git", - "url": "https://unknown-host/a/b.git" + "url": "https://unknown-host/.git" } } diff --git a/test/test.js b/test/test.js index d4a1470..bbbcbf4 100644 --- a/test/test.js +++ b/test/test.js @@ -177,18 +177,18 @@ describe('conventionalChangelogCore', function() { })); }); - it('should fallback to use the url if repo is unknown', function(done) { + it('should only print the host', function(done) { conventionalChangelogCore({ pkg: { - path: __dirname + '/fixtures/_unknown-host.json' + path: __dirname + '/fixtures/_host-only.json' } }, { linkReferences: true }).pipe(through(function(chunk) { chunk = chunk.toString(); - expect(chunk).to.include('](https://unknown-host/a/b/commits/'); - expect(chunk).to.include('closes [#1](https://unknown-host/a/b/issues/1)'); + expect(chunk).to.include('](https://unknown-host/commits/'); + expect(chunk).to.include('closes [#1](https://unknown-host/issues/1)'); done(); }));