Skip to content

Commit

Permalink
feat: make --checkCI optionable for git-node-land (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Feb 5, 2021
1 parent 9006b30 commit b0be3dd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
45 changes: 26 additions & 19 deletions components/git/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -31,18 +31,32 @@ 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,
describe: 'Assume "yes" as answer to all prompts and run ' +
'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,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion components/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/landing_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ 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;
this.lint = lint;
this.autorebase = autorebase;
this.fixupAll = fixupAll;
this.expectedCommitShas = [];
this.checkCI = !!checkCI;
}

get argv() {
Expand Down
7 changes: 5 additions & 2 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 3 additions & 1 deletion lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Session {
}

get argv() {
// TODO(joyeecheung): remove this and make argv an object
return {
owner: this.owner,
repo: this.repo,
Expand All @@ -62,7 +63,8 @@ class Session {
waitTimeMultiApproval: this.waitTimeMultiApproval,
updateDeprecations: this.updateDeprecations,
ciType: this.ciType,
prid: this.prid
prid: this.prid,
checkCI: this.checkCI
};
}

Expand Down

0 comments on commit b0be3dd

Please sign in to comment.