Skip to content

Commit

Permalink
Update: include links to commits on GitHub in changelogs (#32)
Browse files Browse the repository at this point in the history
This updates the changelog generator to link to commits on GitHub when generating changelogs. This should also fix the issue where commits are ambiguous, resulting in a 404 in links from generated blogposts for ESLint.
  • Loading branch information
not-an-aardvark committed Nov 10, 2018
1 parent 00a3526 commit 73b3f38
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 101 deletions.
34 changes: 22 additions & 12 deletions lib/release-ops.js
Expand Up @@ -122,7 +122,7 @@ function getVersionTags() {
* @private
*/
function parseLogs(logs) {
var regexp = /^(?:\* )?([0-9a-f]{7,}) ((?:([a-z]+): ?)?.*) \((.*)\)/i,
var regexp = /^\* ([0-9a-f]{40}) ((?:([a-z]+): ?)?.*) \((.*)\)/i,
parsed = [];

logs.forEach(function(log) {
Expand Down Expand Up @@ -165,7 +165,7 @@ function excludeReverts(logs) {
match = log.body.match(revertRegex);

if (match) {
sha = match[1].slice(0, 7);
sha = match[1];

// only exclude this revert if we can find the commit it reverts
if (typeof shaIndexMap[sha] !== "undefined") {
Expand Down Expand Up @@ -194,14 +194,24 @@ function calculateReleaseFromGitLogs(currentVersion, logs, prereleaseId) {
logs = excludeReverts(parseLogs(logs));

var changelog = {},
releaseInfo = {
version: currentVersion,
type: "",
changelog: changelog,
rawChangelog: logs.map(function(log) {
return log.raw;
}).join("\n")
};
repository = getPackageInfo().repository;

/**
* Generates a formatted line with a link to commits on GitHub
* @param {string} log A parsed log message with a full commit hash
* @returns {string} A line for a changelog with a link to the GitHub commit
*/
function generateChangelogLine(log) {
return log.raw.replace(/^\* ([0-9a-f]{40})/, function(_, hash) {
return "* [`" + hash.slice(0, 7) + "`](https://github.com/" + repository + "/commit/" + hash + ")";
});
}
var releaseInfo = {
version: currentVersion,
type: "",
changelog: changelog,
rawChangelog: logs.map(generateChangelogLine).join("\n")
};

// arrange change types into categories
logs.forEach(function(log) {
Expand All @@ -215,7 +225,7 @@ function calculateReleaseFromGitLogs(currentVersion, logs, prereleaseId) {
changelog[log.flag] = [];
}

changelog[log.flag].push(log.raw);
changelog[log.flag].push(generateChangelogLine(log));
});

if (changelog.breaking) {
Expand Down Expand Up @@ -251,7 +261,7 @@ function calculateReleaseInfo(prereleaseId) {
commitRange = lastTag ? lastTag + "..HEAD" : "";

// get log statements
var logs = ShellOps.execSilent("git log --no-merges --pretty=format:\"* %h %s (%an)%n%b\" " + commitRange).split(/\n/g);
var logs = ShellOps.execSilent("git log --no-merges --pretty=format:\"* %H %s (%an)%n%b\" " + commitRange).split(/\n/g);
var releaseInfo = calculateReleaseFromGitLogs(pkg.version, logs, prereleaseId);
releaseInfo.repository = pkg.repository;
return releaseInfo;
Expand Down

0 comments on commit 73b3f38

Please sign in to comment.