Skip to content

Commit

Permalink
RCF-9 Added issue links to release notes
Browse files Browse the repository at this point in the history
  Implemented by adding a script for post-processing
  • Loading branch information
ScottKelly committed Mar 29, 2018
1 parent 46c4038 commit fd8854a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.idea
19 changes: 16 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var argv = require("optimist").usage("git-release-notes [<options>] <since>..<un
"default": "master"
})
.options("s", {
"alias": "script"
"alias": "script",
"default": "./issue-linker.js"
})
.options("o", {
"alias": "gitlog-option",
Expand All @@ -43,15 +44,27 @@ var argv = require("optimist").usage("git-release-notes [<options>] <since>..<un
})
.boolean("version")
.check(function (argv) {
if (argv._.length == 2) {
// Added template default so only one argument is required
if (argv._.length >= 1 && argv._.length <=2) {
return true;
}
throw "Invalid parameters, please specify an interval and the template";
})
.argv;

const index = require('./index');
index(argv, argv._[0], argv._[1])

// default to using the issuelink template to reduce things
// dev needs to remember
let template;
if(!argv._[1]) {
template = "issuelink-markdown"
}
else {
template = argv._[1]
}

index(argv, argv._[0], template)
.then(function (output) {
process.stdout.write(output + "\n");
})
Expand Down
29 changes: 29 additions & 0 deletions lib/issue-linker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Jira used the syntax `<project>-<issue_id>` to link PRs to the original task e.g. VP-986
* Based upon ../samples/post-processing.js
*/

const TITLE_REGEX = /^([A-Z]+-\d+) (.*)$/;
const ISSUE_TRACKER_HOST = "https://virdocs.atlassian.net/browse/";

module.exports = function (data, callback) {
const rewritten = data.commits.map((commit) => {
const matches = commit.title.match(TITLE_REGEX);
if (matches && matches.length > 2) {
// extra metadata to remember the linked tasks
commit.issue = matches[1];
commit.issueLink = ISSUE_TRACKER_HOST + commit.issue;

// remove issue from the title
commit.title = matches[2];
}

return commit;
});

callback({
commits: rewritten.filter(Boolean),
// rewrite the range because the template only cares about the newest tag
range: data.range.split('..')[1],
});
};
5 changes: 5 additions & 0 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ exports.processCommits = function processCommits(options, commits, range) {
debug("Rendering template without post processing");
return Promise.resolve({ commits: commits });
}
else if (!fs.existsSync(externalScriptPath)) {
// fallback to checking if the referenced script is packaged with this
// node package
externalScriptPath = path.resolve(__dirname, externalScriptPath)
}

return new Promise(function (resolve, reject) {
debug(`Trying to run the external script from ${externalScriptPath}`);
Expand Down
2 changes: 1 addition & 1 deletion options.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"title" : "^([a-z]+) #(\\d+) (.*)$",
"meaning" : ["type", "issue", "title"]
}
}
9 changes: 9 additions & 0 deletions templates/issuelink-markdown.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Release Notes
## <%= range %>
<% commits.forEach(function (commit) { %>
* __[<%= commit.issue %>](<%= commit.issueLink %>) <%= commit.title %>__
[<%= commit.authorName %>](mailto:<%= commit.authorEmail %>) - <%= commit.committerDate %>
<%= commit.messageLines.join("\n ") %>
<% }) %>

0 comments on commit fd8854a

Please sign in to comment.