Skip to content

Commit fd8854a

Browse files
committed
RCF-9 Added issue links to release notes
Implemented by adding a script for post-processing
1 parent 46c4038 commit fd8854a

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.idea

cli.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ var argv = require("optimist").usage("git-release-notes [<options>] <since>..<un
2222
"default": "master"
2323
})
2424
.options("s", {
25-
"alias": "script"
25+
"alias": "script",
26+
"default": "./issue-linker.js"
2627
})
2728
.options("o", {
2829
"alias": "gitlog-option",
@@ -43,15 +44,27 @@ var argv = require("optimist").usage("git-release-notes [<options>] <since>..<un
4344
})
4445
.boolean("version")
4546
.check(function (argv) {
46-
if (argv._.length == 2) {
47+
// Added template default so only one argument is required
48+
if (argv._.length >= 1 && argv._.length <=2) {
4749
return true;
4850
}
4951
throw "Invalid parameters, please specify an interval and the template";
5052
})
5153
.argv;
5254

5355
const index = require('./index');
54-
index(argv, argv._[0], argv._[1])
56+
57+
// default to using the issuelink template to reduce things
58+
// dev needs to remember
59+
let template;
60+
if(!argv._[1]) {
61+
template = "issuelink-markdown"
62+
}
63+
else {
64+
template = argv._[1]
65+
}
66+
67+
index(argv, argv._[0], template)
5568
.then(function (output) {
5669
process.stdout.write(output + "\n");
5770
})

lib/issue-linker.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Jira used the syntax `<project>-<issue_id>` to link PRs to the original task e.g. VP-986
3+
* Based upon ../samples/post-processing.js
4+
*/
5+
6+
const TITLE_REGEX = /^([A-Z]+-\d+) (.*)$/;
7+
const ISSUE_TRACKER_HOST = "https://virdocs.atlassian.net/browse/";
8+
9+
module.exports = function (data, callback) {
10+
const rewritten = data.commits.map((commit) => {
11+
const matches = commit.title.match(TITLE_REGEX);
12+
if (matches && matches.length > 2) {
13+
// extra metadata to remember the linked tasks
14+
commit.issue = matches[1];
15+
commit.issueLink = ISSUE_TRACKER_HOST + commit.issue;
16+
17+
// remove issue from the title
18+
commit.title = matches[2];
19+
}
20+
21+
return commit;
22+
});
23+
24+
callback({
25+
commits: rewritten.filter(Boolean),
26+
// rewrite the range because the template only cares about the newest tag
27+
range: data.range.split('..')[1],
28+
});
29+
};

lib/process.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ exports.processCommits = function processCommits(options, commits, range) {
1515
debug("Rendering template without post processing");
1616
return Promise.resolve({ commits: commits });
1717
}
18+
else if (!fs.existsSync(externalScriptPath)) {
19+
// fallback to checking if the referenced script is packaged with this
20+
// node package
21+
externalScriptPath = path.resolve(__dirname, externalScriptPath)
22+
}
1823

1924
return new Promise(function (resolve, reject) {
2025
debug(`Trying to run the external script from ${externalScriptPath}`);

options.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"title" : "^([a-z]+) #(\\d+) (.*)$",
33
"meaning" : ["type", "issue", "title"]
4-
}
4+
}

templates/issuelink-markdown.ejs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Release Notes
2+
## <%= range %>
3+
<% commits.forEach(function (commit) { %>
4+
* __[<%= commit.issue %>](<%= commit.issueLink %>) <%= commit.title %>__
5+
6+
[<%= commit.authorName %>](mailto:<%= commit.authorEmail %>) - <%= commit.committerDate %>
7+
8+
<%= commit.messageLines.join("\n ") %>
9+
<% }) %>

0 commit comments

Comments
 (0)