From 05bbc260ec6b5581ab8893f81a5a4db711c70cec Mon Sep 17 00:00:00 2001 From: Alicia Lopez Date: Thu, 31 Oct 2019 10:58:50 +0100 Subject: [PATCH] fix: use 12 characters for commit SHAs (#372) GitHub already refused to generate a link with 7. --- lib/ci/ci_result_parser.js | 5 +++-- lib/landing_session.js | 7 +++++-- lib/pr_checker.js | 5 ++++- lib/session.js | 5 ++++- lib/update-v8/backport.js | 6 ++---- lib/utils.js | 4 ++++ lib/wpt/index.js | 7 +++++-- test/unit/pr_checker.test.js | 4 ++-- 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/ci/ci_result_parser.js b/lib/ci/ci_result_parser.js index f3207a0..b8eb34f 100644 --- a/lib/ci/ci_result_parser.js +++ b/lib/ci/ci_result_parser.js @@ -26,7 +26,8 @@ const { CI_TYPES } = require('./ci_type_parser'); const { - flatten + flatten, + shortSha } = require('../utils'); const qs = require('querystring'); const _ = require('lodash'); @@ -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() { diff --git a/lib/landing_session.js b/lib/landing_session.js index 7649f29..eb2315f 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -6,6 +6,9 @@ const { runAsync, runSync, forceRunAsync } = require('./run'); const Session = require('./session'); +const { + shortSha +} = require('./utils'); const isWindows = process.platform === 'win32'; @@ -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}`; } diff --git a/lib/pr_checker.js b/lib/pr_checker.js index 94b2fd0..3cdfe56 100644 --- a/lib/pr_checker.js +++ b/lib/pr_checker.js @@ -13,6 +13,9 @@ const { const { CONFLICTING } = require('./mergeable_state'); +const { + shortSha +} = require('./utils'); const { JobParser, @@ -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; diff --git a/lib/session.js b/lib/session.js index b03b526..1ff5180 100644 --- a/lib/session.js +++ b/lib/session.js @@ -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'; @@ -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) { diff --git a/lib/update-v8/backport.js b/lib/update-v8/backport.js index cc5221d..1213567 100644 --- a/lib/update-v8/backport.js +++ b/lib/update-v8/backport.js @@ -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) { @@ -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'; diff --git a/lib/utils.js b/lib/utils.js index 2be8b34..1221ba2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -22,3 +22,7 @@ function flatten(arr) { return result; } exports.flatten = flatten; + +exports.shortSha = function shortSha(sha) { + return sha.slice(0, 12); +}; diff --git a/lib/wpt/index.js b/lib/wpt/index.js index e059753..0ccc3e5 100644 --- a/lib/wpt/index.js +++ b/lib/wpt/index.js @@ -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) { @@ -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(); @@ -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; } diff --git a/test/unit/pr_checker.test.js b/test/unit/pr_checker.test.js index 0b0f617..69716b3 100644 --- a/test/unit/pr_checker.test.js +++ b/test/unit/pr_checker.test.js @@ -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'] ] };