Skip to content

Commit

Permalink
fix: remove dependency to git-url-parse
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Oct 27, 2018
1 parent 5c3c9b5 commit 7243769
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const url = require('url');
const {find} = require('lodash');
const {parse, format} = require('url');
const {trimEnd, find} = require('lodash');
const getStream = require('get-stream');
const intoStream = require('into-stream');
const gitUrlParse = require('git-url-parse');
const parser = require('conventional-commits-parser').sync;
const writer = require('conventional-changelog-writer');
const filter = require('conventional-commits-filter');
Expand Down Expand Up @@ -35,8 +34,12 @@ async function generateNotes(pluginConfig, context) {
} = context;
const {parserOpts, writerOpts} = await loadChangelogConfig(pluginConfig, context);

const {resource: hostname, port, name: repository, owner, protocols} = gitUrlParse(repositoryUrl);
const protocol = protocols.includes('https') ? 'https' : protocols.includes('http') ? 'http' : 'https';
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(.*)@)?(.*?):(.*)$/.exec(trimEnd(repositoryUrl, '.git')) || [];
let {hostname, port, pathname, protocol} = parse(
match ? `ssh://${auth ? `${auth}@` : ''}${host}/${path}` : repositoryUrl
);
protocol = protocol && /http[^s]/.test(protocol) ? 'http' : 'https';
const [, owner, repository] = /^\/([^/]+)?\/?(.+)?$/.exec(pathname);

const {issue, commit, referenceActions, issuePrefixes} =
find(HOSTS_CONFIG, conf => conf.hostname === hostname) || HOSTS_CONFIG.default;
Expand All @@ -50,7 +53,7 @@ async function generateNotes(pluginConfig, context) {
const currentTag = nextRelease.gitTag || nextRelease.gitHead;
const changelogContext = {
version: nextRelease.version,
host: url.format({protocol, hostname, port}),
host: format({protocol, hostname, port}),
owner,
repository,
previousTag,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"conventional-commits-parser": "^3.0.0",
"debug": "^4.0.0",
"get-stream": "^4.0.0",
"git-url-parse": "^10.0.1",
"import-from": "^2.1.0",
"into-stream": "^4.0.0",
"lodash": "^4.17.4"
Expand Down
20 changes: 20 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,26 @@ test('Accept a custom repository URL with git format', async t => {
);
});

test('Accept a custom repository URL with git format without user', async t => {
const commits = [
{hash: '111', message: 'fix(scope1): First fix'},
{hash: '222', message: 'feat(scope2): Second feature'},
];
const changelog = await generateNotes(
{},
{cwd, options: {repositoryUrl: 'domain.com:owner/repo.git'}, lastRelease, nextRelease, commits}
);

t.regex(changelog, new RegExp(escape('(https://domain.com/owner/repo/compare/v1.0.0...v2.0.0)')));
t.regex(changelog, /### Bug Fixes/);
t.regex(changelog, new RegExp(escape('* **scope1:** First fix ([111](https://domain.com/owner/repo/commit/111))')));
t.regex(changelog, /### Features/);
t.regex(
changelog,
new RegExp(escape('* **scope2:** Second feature ([222](https://domain.com/owner/repo/commit/222))'))
);
});

test('Accept a custom repository URL with git+http format', async t => {
const commits = [
{hash: '111', message: 'fix(scope1): First fix'},
Expand Down

0 comments on commit 7243769

Please sign in to comment.