-
-
Notifications
You must be signed in to change notification settings - Fork 302
/
Copy pathutil.js
38 lines (29 loc) · 868 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
const readPkgUp = require('read-pkg-up');
const issueRegex = require('issue-regex');
const terminalLink = require('terminal-link');
exports.readPkg = () => {
const {pkg} = readPkgUp.sync();
if (!pkg) {
throw new Error(`No package.json found. Make sure you're in the correct project.`);
}
return pkg;
};
exports.linkifyIssues = (url, message) => {
if (!(url && terminalLink.isSupported)) {
return message;
}
return message.replace(issueRegex(), issue => {
const issuePart = issue.replace('#', '/issues/');
if (issue.startsWith('#')) {
return terminalLink(issue, `${url}${issuePart}`);
}
return terminalLink(issue, `https://github.com/${issuePart}`);
});
};
exports.linkifyCommit = (url, commit) => {
if (!(url && terminalLink.isSupported)) {
return commit;
}
return terminalLink(commit, `${url}/commit/${commit}`);
};