Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: include links to commits on GitHub in changelogs #32

Merged
merged 1 commit into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions lib/release-ops.js
Original file line number Diff line number Diff line change
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
Loading