From fd8854a2b4354ce256189bc55aae1f03284ba800 Mon Sep 17 00:00:00 2001 From: Scott Date: Wed, 28 Mar 2018 17:12:09 -0500 Subject: [PATCH] RCF-9 Added issue links to release notes Implemented by adding a script for post-processing --- .gitignore | 1 + cli.js | 19 ++++++++++++++++--- lib/issue-linker.js | 29 +++++++++++++++++++++++++++++ lib/process.js | 5 +++++ options.json | 2 +- templates/issuelink-markdown.ejs | 9 +++++++++ 6 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 lib/issue-linker.js create mode 100644 templates/issuelink-markdown.ejs diff --git a/.gitignore b/.gitignore index 3c3629e..eb79dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.idea diff --git a/cli.js b/cli.js index ff7f26b..3c81c0a 100755 --- a/cli.js +++ b/cli.js @@ -22,7 +22,8 @@ var argv = require("optimist").usage("git-release-notes [] ..] ..= 1 && argv._.length <=2) { return true; } throw "Invalid parameters, please specify an interval and the template"; @@ -51,7 +53,18 @@ var argv = require("optimist").usage("git-release-notes [] ..-` 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], + }); +}; diff --git a/lib/process.js b/lib/process.js index 2f838ec..b1c758b 100644 --- a/lib/process.js +++ b/lib/process.js @@ -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}`); diff --git a/options.json b/options.json index d9c9a69..e128372 100644 --- a/options.json +++ b/options.json @@ -1,4 +1,4 @@ { "title" : "^([a-z]+) #(\\d+) (.*)$", "meaning" : ["type", "issue", "title"] -} \ No newline at end of file +} diff --git a/templates/issuelink-markdown.ejs b/templates/issuelink-markdown.ejs new file mode 100644 index 0000000..703e68c --- /dev/null +++ b/templates/issuelink-markdown.ejs @@ -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 ") %> +<% }) %>