Skip to content

Commit

Permalink
Add comparison link under commits (#292)
Browse files Browse the repository at this point in the history
Fixes #283
  • Loading branch information
killynathan authored and sindresorhus committed Nov 29, 2018
1 parent d8dcc67 commit 3b0ed9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/ui.js
Expand Up @@ -35,20 +35,26 @@ function printCommitLog(repositoryUrl) {
if (!result) {
return false;
}
return execa.stdout('git', ['describe', '--abbrev=0'])
.then(tagName => {
const history = result.split('\n')
.map(commit => {
const splitIndex = commit.lastIndexOf(' ');
const commitMessage = util.linkifyIssues(repositoryUrl, commit.substring(0, splitIndex));
const commitId = util.linkifyCommit(repositoryUrl, commit.substring(splitIndex + 1));

const history = result.split('\n')
.map(commit => {
const splitIndex = commit.lastIndexOf(' ');
const commitMessage = util.linkifyIssues(repositoryUrl, commit.substring(0, splitIndex));
const commitId = util.linkifyCommit(repositoryUrl, commit.substring(splitIndex + 1));
return `- ${commitMessage} ${commitId}`;
})
.join('\n');

return `- ${commitMessage} ${commitId}`;
})
.join('\n');
console.log(`${chalk.bold('Commits:')}\n${history}\n`);

const commitRange = util.linkifyCommitRange(repositoryUrl, `${tagName}...master`);

console.log(`${chalk.bold('Commits:')}\n${history}\n`);
console.log(`${chalk.bold('Commit Range:')}\n${commitRange}\n`);

return true;
return true;
});
});
}

Expand Down
8 changes: 8 additions & 0 deletions lib/util.js
Expand Up @@ -36,3 +36,11 @@ exports.linkifyCommit = (url, commit) => {

return terminalLink(commit, `${url}/commit/${commit}`);
};

exports.linkifyCommitRange = (url, commitRange) => {
if (!(url && terminalLink.isSupported)) {
return commitRange;
}

return terminalLink(commitRange, `${url}/compare/${commitRange}`);
};

0 comments on commit 3b0ed9a

Please sign in to comment.