Skip to content
This repository was archived by the owner on Feb 5, 2018. It is now read-only.

Commit aa765c2

Browse files
committed
feat(references): remove references that already appear in the subject
Also simplifies the regex of GitHub issue and user. Resolves conventional-changelog/standard-version#70
1 parent 7dce559 commit aa765c2

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

index.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function issueUrl() {
4343
var writerOpts = {
4444
transform: function(commit) {
4545
var discard = true;
46+
var issues = [];
4647

4748
commit.notes.forEach(function(note) {
4849
note.title = 'BREAKING CHANGES';
@@ -83,13 +84,25 @@ var writerOpts = {
8384
var url = issueUrl();
8485
if (url) {
8586
// GitHub issue URLs.
86-
commit.subject = commit.subject.replace(/( ?)#([0-9]+)(\b|^)/g, '$1[#$2](' + url + '$2)$3');
87+
commit.subject = commit.subject.replace(/#([0-9]+)/g, function(_, issue) {
88+
issues.push(issue);
89+
return '[#' + issue + '](' + url + issue + ')';
90+
});
8791
}
8892
// GitHub user URLs.
89-
commit.subject = commit.subject.replace(/( ?)@([a-zA-Z0-9_]+)(\b|^)/g, '$1[@$2](https://github.com/$2)$3');
93+
commit.subject = commit.subject.replace(/@([a-zA-Z0-9_]+)/g, '[@$1](https://github.com/$1)');
9094
commit.subject = commit.subject;
9195
}
9296

97+
// remove references that already appear in the subject
98+
commit.references = commit.references.filter(function(reference) {
99+
if (issues.indexOf(reference.issue) === -1) {
100+
return true;
101+
}
102+
103+
return false;
104+
});
105+
93106
return commit;
94107
},
95108
groupBy: 'type',

test/test.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('angular preset', function() {
2020
// fix this once https://github.com/arturadib/shelljs/issues/175 is solved
2121
child.exec('git commit -m"feat: amazing new module\n\nBREAKING CHANGE: Not backward compatible." --allow-empty', function() {
2222
gitDummyCommit(['fix(compile): avoid a bug', 'BREAKING CHANGE: The Change is huge.']);
23-
gitDummyCommit('perf(ngOptions): make it faster closes #1, #2');
23+
gitDummyCommit(['perf(ngOptions): make it faster', ' closes #1, #2']);
2424
gitDummyCommit('revert(ngOptions): bad commit');
2525
gitDummyCommit('fix(*): oops');
2626

@@ -79,6 +79,23 @@ describe('angular preset', function() {
7979
}));
8080
});
8181

82+
it('should remove the issues that already appear in the subject', function(done) {
83+
gitDummyCommit(['feat(awesome): fix #88']);
84+
85+
conventionalChangelogCore({
86+
config: preset
87+
})
88+
.on('error', function(err) {
89+
done(err);
90+
})
91+
.pipe(through(function(chunk) {
92+
chunk = chunk.toString();
93+
expect(chunk).to.include('[#88](https://github.com/conventional-changelog/conventional-changelog-angular/issues/88)');
94+
expect(chunk).to.not.include('closes [#88](https://github.com/conventional-changelog/conventional-changelog-angular/issues/88)');
95+
done();
96+
}));
97+
});
98+
8299
it('should replace @username with GitHub user URL', function(done) {
83100
gitDummyCommit(['feat(awesome): issue brought up by @bcoe! on Friday']);
84101

0 commit comments

Comments
 (0)