From b0be3dd365005236c596396026d8dce9378306a6 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 5 Feb 2021 20:02:14 +0800 Subject: [PATCH] feat: make --checkCI optionable for git-node-land (#528) --- components/git/land.js | 45 ++++++++++++++++++++++++------------------ components/metadata.js | 2 +- lib/landing_session.js | 3 ++- lib/pr_checker.js | 7 +++++-- lib/session.js | 4 +++- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/components/git/land.js b/components/git/land.js index 21a614be..f80cf857 100644 --- a/components/git/land.js +++ b/components/git/land.js @@ -9,7 +9,7 @@ const LandingSession = require('../../lib/landing_session'); const epilogue = require('./epilogue'); const yargs = require('yargs'); -const landOptions = { +const landActions = { apply: { describe: 'Apply a patch with the given PR id', type: 'number' @@ -31,6 +31,25 @@ const landOptions = { describe: 'Abort the current landing session', type: 'boolean' }, + backport: { + describe: 'Land a backport PR onto a staging branch', + default: false, + type: 'boolean' + }, + autorebase: { + describe: 'Automatically rebase branches with multiple commits', + default: false, + type: 'boolean' + }, + fixupAll: { + describe: 'Automatically fixup all commits to the first one dismissing ' + + 'other commit messages', + default: false, + type: 'boolean' + } +}; + +const landOptions = { yes: { type: 'boolean', default: false, @@ -38,11 +57,6 @@ const landOptions = { 'non-interactively. If an undesirable situation occurs, such as a pull ' + 'request or commit check fails, then git node land will abort.' }, - backport: { - describe: 'Land a backport PR onto a staging branch', - default: false, - type: 'boolean' - }, skipRefs: { describe: 'Prevent adding Fixes and Refs information to commit metadata', default: false, @@ -53,22 +67,17 @@ const landOptions = { default: false, type: 'boolean' }, - autorebase: { - describe: 'Automatically rebase branches with multiple commits', - default: false, - type: 'boolean' - }, - fixupAll: { - describe: 'Automatically fixup all commits to the first one dismissing ' + - 'other commit messages', - default: false, + checkCI: { + describe: 'Query Jenkins CI results when checking the PR', + default: true, type: 'boolean' } }; function builder(yargs) { return yargs - .options(landOptions).positional('prid', { + .options(Object.assign({}, landOptions, landActions)) + .positional('prid', { describe: 'ID or URL of the Pull Request' }) .epilogue(epilogue) @@ -109,9 +118,7 @@ function handler(argv) { } const provided = []; - for (const type of Object.keys(landOptions)) { - // Those are not actions. - if (['yes', 'skipRefs', 'lint'].includes(type)) continue; + for (const type of Object.keys(landActions)) { if (argv[type]) { provided.push(type); } diff --git a/components/metadata.js b/components/metadata.js index bce11044..122f6750 100644 --- a/components/metadata.js +++ b/components/metadata.js @@ -40,7 +40,7 @@ async function getMetadata(argv, skipRefs, cli) { cli.separator(); const checker = new PRChecker(cli, data, request, argv); - const status = await checker.checkAll(argv.checkComments); + const status = await checker.checkAll(argv.checkComments, argv.checkCI); return { status, request, diff --git a/lib/landing_session.js b/lib/landing_session.js index 31be0c1c..88d4c7fe 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -23,7 +23,7 @@ const LINT_RESULTS = { class LandingSession extends Session { constructor(cli, req, dir, - { prid, backport, lint, autorebase, fixupAll } = {}) { + { prid, backport, lint, autorebase, fixupAll, checkCI } = {}) { super(cli, dir, prid); this.req = req; this.backport = backport; @@ -31,6 +31,7 @@ class LandingSession extends Session { this.autorebase = autorebase; this.fixupAll = fixupAll; this.expectedCommitShas = []; + this.checkCI = !!checkCI; } get argv() { diff --git a/lib/pr_checker.js b/lib/pr_checker.js index c76265f5..5aceb94d 100644 --- a/lib/pr_checker.js +++ b/lib/pr_checker.js @@ -68,16 +68,19 @@ class PRChecker { return this.argv.waitTimeMultiApproval; } - async checkAll(checkComments = false) { + async checkAll(checkComments = false, checkCI = true) { const status = [ this.checkCommitsAfterReview(), - await this.checkCI(), this.checkReviewsAndWait(new Date(), checkComments), this.checkMergeableState(), this.checkPRState(), this.checkGitConfig() ]; + if (checkCI) { + status.push(await this.checkCI()); + } + if (this.data.authorIsNew()) { status.push(this.checkAuthor()); } diff --git a/lib/session.js b/lib/session.js index aa138738..ba271e22 100644 --- a/lib/session.js +++ b/lib/session.js @@ -52,6 +52,7 @@ class Session { } get argv() { + // TODO(joyeecheung): remove this and make argv an object return { owner: this.owner, repo: this.repo, @@ -62,7 +63,8 @@ class Session { waitTimeMultiApproval: this.waitTimeMultiApproval, updateDeprecations: this.updateDeprecations, ciType: this.ciType, - prid: this.prid + prid: this.prid, + checkCI: this.checkCI }; }