Skip to content

Commit

Permalink
fix: use 12 characters for commit SHAs (#372)
Browse files Browse the repository at this point in the history
GitHub already refused to generate a link with 7.
  • Loading branch information
Alicia Lopez committed Oct 31, 2019
1 parent 705d983 commit 05bbc26
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
5 changes: 3 additions & 2 deletions lib/ci/ci_result_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const {
CI_TYPES
} = require('./ci_type_parser');
const {
flatten
flatten,
shortSha
} = require('../utils');
const qs = require('querystring');
const _ = require('lodash');
Expand Down Expand Up @@ -245,7 +246,7 @@ class TestBuild extends Job {
if (!change.commitId) {
return 'Unknown';
}
return `[${change.commitId.slice(0, 7)}] ${change.msg}`;
return `[${shortSha(change.commitId)}] ${change.msg}`;
}

get author() {
Expand Down
7 changes: 5 additions & 2 deletions lib/landing_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const {
runAsync, runSync, forceRunAsync
} = require('./run');
const Session = require('./session');
const {
shortSha
} = require('./utils');

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

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

let willBeLanded = stray[stray.length - 1].slice(0, 7);
let willBeLanded = shortSha(stray[stray.length - 1]);
if (stray.length > 1) {
const head = this.getUpstreamHead().slice(0, 7);
const head = shortSha(this.getUpstreamHead());
willBeLanded = `${head}...${willBeLanded}`;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const {
const {
CONFLICTING
} = require('./mergeable_state');
const {
shortSha
} = require('./utils');

const {
JobParser,
Expand Down Expand Up @@ -260,7 +263,7 @@ class PRChecker {
cli.warn(`PR author is a new contributor: @${prAuthor}`);
for (const c of oddCommits) {
const { oid, author } = c.commit;
const hash = oid.slice(0, 7);
const hash = shortSha(oid);
cli.warn(`- commit ${hash} is authored by ${author.email}`);
}
return false;
Expand Down
5 changes: 4 additions & 1 deletion lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const { readJson, writeJson, readFile, writeFile } = require('./file');
const {
runAsync, runSync, forceRunAsync
} = require('./run');
const {
shortSha
} = require('./utils');

const APPLYING = 'APPLYING';
const STARTED = 'STARTED';
Expand Down Expand Up @@ -152,7 +155,7 @@ class Session {
}

getMessagePath(rev) {
return path.join(this.pullDir, `${rev.slice(0, 7)}-message`);
return path.join(this.pullDir, `${shortSha(rev)}-message`);
}

updateSession(update) {
Expand Down
6 changes: 2 additions & 4 deletions lib/update-v8/backport.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const inquirer = require('inquirer');
const Listr = require('listr');
const input = require('listr-input');

const { shortSha } = require('../utils');

const common = require('./common');

exports.checkOptions = async function checkOptions(options) {
Expand Down Expand Up @@ -90,10 +92,6 @@ function commitPatch(patch) {
};
}

function shortSha(sha) {
return sha.substring(0, 7);
}

function formatMessageTitle(patches) {
const action =
patches.some(patch => patch.hadConflicts) ? 'backport' : 'cherry-pick';
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ function flatten(arr) {
return result;
}
exports.flatten = flatten;

exports.shortSha = function shortSha(sha) {
return sha.slice(0, 12);
};
7 changes: 5 additions & 2 deletions lib/wpt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const GitHubTree = require('../github/tree');
const path = require('path');
const { writeFile, readJson, writeJson, readFile } = require('../file');
const _ = require('lodash');
const {
shortSha
} = require('../utils');

class WPTUpdater {
constructor(path, cli, request, nodedir) {
Expand Down Expand Up @@ -124,7 +127,7 @@ class WPTUpdater {
return true;
}

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

const upstreamRev = lastCommit.slice(0, 7);
const upstreamRev = shortSha(lastCommit);
this.cli.stopSpinner(`Last update in upstream is ${upstreamRev}`);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,8 @@ describe('PRChecker', () => {
const expectedLogs = {
warn: [
['PR author is a new contributor: @pr_author(pr_author@example.com)'],
['- commit e3ad7c7 is authored by test@example.com'],
['- commit da39a3e is authored by test@example.com']
['- commit e3ad7c72e88c is authored by test@example.com'],
['- commit da39a3ee5e6b is authored by test@example.com']
]
};

Expand Down

0 comments on commit 05bbc26

Please sign in to comment.