Skip to content

Commit a9c0676

Browse files
authored
fix: use 12 characters for commit SHAs (#372)
GitHub already refused to generate a link with 7.
1 parent 33666e1 commit a9c0676

File tree

8 files changed

+29
-14
lines changed

8 files changed

+29
-14
lines changed

lib/ci/ci_result_parser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const {
2626
CI_TYPES
2727
} = require('./ci_type_parser');
2828
const {
29-
flatten
29+
flatten,
30+
shortSha
3031
} = require('../utils');
3132
const qs = require('querystring');
3233
const _ = require('lodash');
@@ -245,7 +246,7 @@ class TestBuild extends Job {
245246
if (!change.commitId) {
246247
return 'Unknown';
247248
}
248-
return `[${change.commitId.slice(0, 7)}] ${change.msg}`;
249+
return `[${shortSha(change.commitId)}] ${change.msg}`;
249250
}
250251

251252
get author() {

lib/landing_session.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const {
66
runAsync, runSync, forceRunAsync
77
} = require('./run');
88
const Session = require('./session');
9+
const {
10+
shortSha
11+
} = require('./utils');
912

1013
const isWindows = process.platform === 'win32';
1114

@@ -221,9 +224,9 @@ class LandingSession extends Session {
221224
cli.log(`- ${strayVerbose.join('\n- ')}`);
222225
cli.separator();
223226

224-
let willBeLanded = stray[stray.length - 1].slice(0, 7);
227+
let willBeLanded = shortSha(stray[stray.length - 1]);
225228
if (stray.length > 1) {
226-
const head = this.getUpstreamHead().slice(0, 7);
229+
const head = shortSha(this.getUpstreamHead());
227230
willBeLanded = `${head}...${willBeLanded}`;
228231
}
229232

lib/pr_checker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const {
1313
const {
1414
CONFLICTING
1515
} = require('./mergeable_state');
16+
const {
17+
shortSha
18+
} = require('./utils');
1619

1720
const {
1821
JobParser,
@@ -260,7 +263,7 @@ class PRChecker {
260263
cli.warn(`PR author is a new contributor: @${prAuthor}`);
261264
for (const c of oddCommits) {
262265
const { oid, author } = c.commit;
263-
const hash = oid.slice(0, 7);
266+
const hash = shortSha(oid);
264267
cli.warn(`- commit ${hash} is authored by ${author.email}`);
265268
}
266269
return false;

lib/session.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const { readJson, writeJson, readFile, writeFile } = require('./file');
88
const {
99
runAsync, runSync, forceRunAsync
1010
} = require('./run');
11+
const {
12+
shortSha
13+
} = require('./utils');
1114

1215
const APPLYING = 'APPLYING';
1316
const STARTED = 'STARTED';
@@ -152,7 +155,7 @@ class Session {
152155
}
153156

154157
getMessagePath(rev) {
155-
return path.join(this.pullDir, `${rev.slice(0, 7)}-message`);
158+
return path.join(this.pullDir, `${shortSha(rev)}-message`);
156159
}
157160

158161
updateSession(update) {

lib/update-v8/backport.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const inquirer = require('inquirer');
88
const Listr = require('listr');
99
const input = require('listr-input');
1010

11+
const { shortSha } = require('../utils');
12+
1113
const common = require('./common');
1214

1315
exports.checkOptions = async function checkOptions(options) {
@@ -90,10 +92,6 @@ function commitPatch(patch) {
9092
};
9193
}
9294

93-
function shortSha(sha) {
94-
return sha.substring(0, 7);
95-
}
96-
9795
function formatMessageTitle(patches) {
9896
const action =
9997
patches.some(patch => patch.hadConflicts) ? 'backport' : 'cherry-pick';

lib/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ function flatten(arr) {
2222
return result;
2323
}
2424
exports.flatten = flatten;
25+
26+
exports.shortSha = function shortSha(sha) {
27+
return sha.slice(0, 12);
28+
};

lib/wpt/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const GitHubTree = require('../github/tree');
44
const path = require('path');
55
const { writeFile, readJson, writeJson, readFile } = require('../file');
66
const _ = require('lodash');
7+
const {
8+
shortSha
9+
} = require('../utils');
710

811
class WPTUpdater {
912
constructor(path, cli, request, nodedir) {
@@ -124,7 +127,7 @@ class WPTUpdater {
124127
return true;
125128
}
126129

127-
const rev = localCommit.slice(0, 7);
130+
const rev = shortSha(localCommit);
128131
this.cli.log(`Last local update for ${key} is ${rev}`);
129132
this.cli.startSpinner('checking updates...');
130133
const lastCommit = await this.tree.getLastCommit();
@@ -136,7 +139,7 @@ class WPTUpdater {
136139
return false;
137140
}
138141

139-
const upstreamRev = lastCommit.slice(0, 7);
142+
const upstreamRev = shortSha(lastCommit);
140143
this.cli.stopSpinner(`Last update in upstream is ${upstreamRev}`);
141144
return true;
142145
}

test/unit/pr_checker.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,8 @@ describe('PRChecker', () => {
744744
const expectedLogs = {
745745
warn: [
746746
['PR author is a new contributor: @pr_author([email protected])'],
747-
['- commit e3ad7c7 is authored by [email protected]'],
748-
['- commit da39a3e is authored by [email protected]']
747+
['- commit e3ad7c72e88c is authored by [email protected]'],
748+
['- commit da39a3ee5e6b is authored by [email protected]']
749749
]
750750
};
751751

0 commit comments

Comments
 (0)