From a79ea5494c63ffc0732fba7c35593e3fe2ac4a89 Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Tue, 27 Apr 2021 19:39:24 -0400 Subject: [PATCH 1/8] Add exclude and include tag pattern options --- bin/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/index.js b/bin/index.js index 1df9ad4..f97db5e 100755 --- a/bin/index.js +++ b/bin/index.js @@ -45,6 +45,8 @@ var opts = parser .option('--between-tags [range]', 'only diff between these two tags, separate by 3 dots ...') .option('--issue-body', '(DEPRECATED) include the body of the issue (--data MUST equal \'pulls\')') .option('--for-tag [tag]', 'only get changes for this tag') + .option('--exclude-tag [regex]', 'exclude changes matching these tags') + .option('--include-tag [regex]', 'include changes matching only these tags') .option('--no-merges', 'do not include merges') .option('--only-merges', 'only include merges') .option('--only-pulls', 'only include pull requests') @@ -114,6 +116,14 @@ var getTags = function(){ } } + if (opts.excludeTag) { + const regex = new RegExp(opts.excludeTag, 'g'); + tagArray = tagArray.filter(tag => !tag.name.match(regex)); + } else if (opts.includeTag) { + const regex = new RegExp(opts.includeTag, 'g'); + tagArray = tagArray.filter(tag => tag.name.match(regex)); + } + return tagArray; }) .map(function(ref){ From cab630e204c0dbda69309a6fd9ad0a81d48e86a7 Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Tue, 27 Apr 2021 20:00:37 -0400 Subject: [PATCH 2/8] Add option to hide authors --- bin/index.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/bin/index.js b/bin/index.js index f97db5e..1319d2e 100755 --- a/bin/index.js +++ b/bin/index.js @@ -54,6 +54,7 @@ var opts = parser .option('--order-semver', 'use semantic versioning for the ordering instead of the tag date') .option('--reverse-changes', 'reverse the order of changes within a release (show oldest first)') .option('--hide-tag-names', 'hide tag names in changelog') + .option('--hide-authors', 'do not include authors') .option('--timeout [milliseconds]', 'Github API timeout', 10000) .parse(process.argv); @@ -387,21 +388,25 @@ var commitFormatter = function(data) { var url = "https://"+host+"/"+opts.owner+"/"+opts.repository+"/pull/"+prNumber; output += "- [#" + prNumber + "](" + url + ") " + message; - if (authors.length) { - output += ' (' + authors.map(function(author){return '@' + author}).join(', ') + ')'; - } else if (author) { - output += " (@" + author + ")"; - } else if (authorName) { - output += " (" + authorName + ")"; + if (!opts.hideAuthors) { + if (authors.length) { + output += ' (' + authors.map(function(author){return '@' + author}).join(', ') + ')'; + } else if (author) { + output += " (@" + author + ")"; + } else if (authorName) { + output += " (" + authorName + ")"; + } } } else { //otherwise link to the commit output += "- [" + commit.sha.substr(0, 7) + "](" + commit.html_url + ") " + message; - if (authors.length) - output += ' (' + authors.map(function(author){return '@' + author}).join(', ') + ')'; - else if (commit.author && commit.author.login) - output += " (@" + commit.author.login + ")"; + if (!opts.hideAuthors) { + if (authors.length) + output += ' (' + authors.map(function(author){return '@' + author}).join(', ') + ')'; + else if (commit.author && commit.author.login) + output += " (@" + commit.author.login + ")"; + } } // output += " " + moment(commit.commit.committer.date).utc().format(opts.dateFormat); From 94e283adaea8ae1c1066b1997bbb011b442a10eb Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Tue, 27 Apr 2021 20:07:05 -0400 Subject: [PATCH 3/8] Update README --- README.md | 56 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 1881bcc..7173bc6 100644 --- a/README.md +++ b/README.md @@ -17,31 +17,37 @@ npm install -g github-changes Usage: github-changes [options] Options: - -o, --owner (required) owner of the Github repository - -r, --repository (required) name of the Github repository - -d, --data (DEPRECATED) use pull requests or commits (choices: pulls, commits) [commits] - -b, --branch name of the default branch [master] - -n, --tag-name tag name for upcoming release [upcoming] - -a, --auth prompt to auth with Github - use this for private repos and higher rate limits - -k, --token need to use this or --auth for private repos and higher rate limits - -f, --file name of the file to output the changelog to [CHANGELOG.md] - -t, --title title to appear in the top of the changelog [Change Log] - -z, --time-zone time zone [UTC] - -m, --date-format date format [(YYYY/MM/DD HH:mm Z)] - -v, --verbose output details - --host alternate host name to use with github enterprise [api.github.com] - --path-prefix path-prefix for use with github enterprise - --between-tags only diff between these two tags, separate by 3 dots ... - --for-tag only get changes for this tag - --issue-body (DEPRECATED) include the body of the issue (--data MUST equal 'pulls') - --no-merges do not include merges - --only-merges only include merges - --only-pulls only include pull requests - --use-commit-body use the commit body of a merge instead of the message - "Merge branch..." - --order-semver use semantic versioning for the ordering instead of the tag date - --reverse-changes reverse the order of changes within a release (show oldest first) - --hide-tag-names hide tag names in changelog -``` + -V, --version output the version number + -o, --owner (required) owner of the Github repository + -r, --repository (required) name of the Github repository + -d, --data [type] (DEPRECATED) use pull requests or commits (choices: pulls, commits) (default: "commits") + -b, --branch [name] name of the default branch (default: "master") + -n, --tag-name [name] tag name for upcoming release (default: "upcoming") + -a, --auth prompt to auth with Github - use this for private repos and higher rate limits + -k, --token [token] need to use this or --auth for private repos and higher rate limits + -f, --file [name] name of the file to output the changelog to (default: "CHANGELOG.md") + -t, --title [title] title to appear in the top of the changelog (default: "Change Log") + -z, --time-zone [zone] time zone (default: "UTC") + -m, --date-format [format] date format (default: "(YYYY/MM/DD HH:mm Z)") + -v, --verbose output details + --host [domain] alternate host name to use with github enterprise (default: "api.github.com") + --path-prefix [path] path-prefix for use with github enterprise + --between-tags [range] only diff between these two tags, separate by 3 dots ... + --issue-body (DEPRECATED) include the body of the issue (--data MUST equal 'pulls') + --for-tag [tag] only get changes for this tag + --exclude-tag [regex] exclude changes matching these tags + --include-tag [regex] include changes matching only these tags + --no-merges do not include merges + --only-merges only include merges + --only-pulls only include pull requests + --use-commit-body use the commit body of a merge instead of the message - "Merge branch..." + --order-semver use semantic versioning for the ordering instead of the tag date + --reverse-changes reverse the order of changes within a release (show oldest first) + --hide-tag-names hide tag names in changelog + --hide-authors do not include authors + --timeout [milliseconds] Github API timeout (default: 10000) + -h, --help display help for command + ``` ### Example usage From 06b4603e39216d73dc8bcb632cffce1a0dd975b2 Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Tue, 27 Apr 2021 20:31:45 -0400 Subject: [PATCH 4/8] Move commit link to the end of the message --- bin/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/index.js b/bin/index.js index 1319d2e..a683b95 100755 --- a/bin/index.js +++ b/bin/index.js @@ -386,7 +386,7 @@ var commitFormatter = function(data) { var host = (opts.host === 'api.github.com') ? 'github.com' : opts.host; var url = "https://"+host+"/"+opts.owner+"/"+opts.repository+"/pull/"+prNumber; - output += "- [#" + prNumber + "](" + url + ") " + message; + output += "- " + message.replace((message.match(/ \(#\d+\)/) || [''])[0], '') + " [#" + prNumber + "](" + url + ") "; if (!opts.hideAuthors) { if (authors.length) { From 970f0cd21494caf79702fff9428cc16ce0860259 Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Tue, 27 Apr 2021 20:34:38 -0400 Subject: [PATCH 5/8] Move commit link to the end of the message --- bin/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/index.js b/bin/index.js index a683b95..02d8635 100755 --- a/bin/index.js +++ b/bin/index.js @@ -399,7 +399,7 @@ var commitFormatter = function(data) { } } else { //otherwise link to the commit - output += "- [" + commit.sha.substr(0, 7) + "](" + commit.html_url + ") " + message; + output += "- " + message.replace((message.match(/ \(#\d+\)/) || [''])[0], '') + " [" + commit.sha.substr(0, 7) + "](" + commit.html_url + ") "; if (!opts.hideAuthors) { if (authors.length) From 80ef87dbc90affb13e8377526422dfbc5e81bdb7 Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Tue, 27 Apr 2021 20:47:12 -0400 Subject: [PATCH 6/8] Allow token to be set using env var --- README.md | 2 ++ bin/index.js | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7173bc6..c8383ae 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Generate a changelog based on merged pull requests or commit messages npm install -g github-changes ``` +Optionally set your GitHub token using environment variable GITHUB_CHANGES_TOKEN. + ``` Usage: github-changes [options] diff --git a/bin/index.js b/bin/index.js index 02d8635..8c0a793 100755 --- a/bin/index.js +++ b/bin/index.js @@ -82,7 +82,8 @@ var currentDate = moment(); var github = null; // github auth token -var token = null; +//var token = null; +var token = process.env.GITHUB_CHANGES_TOKEN; // ~/.config/changelog.json will store the token var authOptions = { @@ -421,6 +422,7 @@ var formatter = function(data) { }; var getGithubToken = function() { + if (token) return Promise.resolve({token}); if (opts.token) return Promise.resolve({token: opts.token}); if (opts.auth) return ghauth(authOptions); return Promise.resolve({}); From 3f9a974e7f9e1459591b35dfdcf357b0f75f4be4 Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Tue, 27 Apr 2021 21:53:17 -0400 Subject: [PATCH 7/8] Fix tag selection when commit and tag date are the same --- bin/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/index.js b/bin/index.js index 8c0a793..c236765 100755 --- a/bin/index.js +++ b/bin/index.js @@ -228,7 +228,7 @@ var tagger = function(sortedTags, data) { if (opts.data === 'commits') date = moment(data.commit.committer.date); else date = moment(data.merged_at); - var current = null; + var current = sortedTags[0] || null; for (var i=0, len=sortedTags.length; i < len; i++) { var tag = sortedTags[i]; if (tag.date < date) break; From a7d381b923196ef12d3916c85e34ba9784f2e845 Mon Sep 17 00:00:00 2001 From: Andy Phillipson Date: Thu, 17 Jun 2021 17:05:25 -0400 Subject: [PATCH 8/8] Allow compare of semver's with build numbers --- bin/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bin/index.js b/bin/index.js index c236765..0b6ace0 100755 --- a/bin/index.js +++ b/bin/index.js @@ -481,6 +481,21 @@ var task = function() { if (a.tag.name === b.tag.name) tagCompare = 0; else if (a.tag.name === opts.tagName) tagCompare = 1; else if (b.tag.name === opts.tagName) tagCompare -1; + else if ((a.tag.name.split('.')).length > 3 || (b.tag.name.split('.')).length > 3) { + let tagA = a.tag.name; + let tagB = b.tag.name; + if (tagA.split('.').length > 3) { + tagA = a.tag.name.replace(/\.(?=[^.]*$)/, "+"); + } else { + tagA += '+0'; + } + if (tagB.split('.').length > 3) { + tagB = b.tag.name.replace(/\.(?=[^.]*$)/, "+"); + } else { + tagB += '+0'; + } + tagCompare = semver.compare(tagA, tagB); + } else tagCompare = semver.compare(a.tag.name, b.tag.name); return (tagCompare) ? tagCompare : compareSign * (moment(a.commit.committer.date) - moment(b.commit.committer.date)); }).reverse();