diff --git a/components/git/land.js b/components/git/land.js index ba23de66..6633c0a3 100644 --- a/components/git/land.js +++ b/components/git/land.js @@ -141,8 +141,7 @@ async function main(state, argv, cli, req, dir) { return; } session = new LandingSession(cli, req, dir, argv.prid); - const { repo, owner, prid } = session; - const metadata = await getMetadata({ repo, owner, prid }, cli); + const metadata = await getMetadata(session.argv, cli); return session.start(metadata); } else if (state === APPLY) { return session.apply(); diff --git a/components/git/metadata.js b/components/git/metadata.js index 24267f29..726fd401 100644 --- a/components/git/metadata.js +++ b/components/git/metadata.js @@ -5,6 +5,7 @@ const yargs = require('yargs'); const getMetadata = require('../metadata'); const CLI = require('../../lib/cli'); const config = require('../../lib/config').getMergedConfig(); +const { runPromise, IGNORE } = require('../../lib/run'); const options = { owner: { @@ -86,19 +87,13 @@ function handler(argv) { const logStream = process.stdout.isTTY ? process.stdout : process.stderr; const cli = new CLI(logStream); - return getMetadata(Object.assign({}, config, argv, parsed), cli) + const merged = Object.assign({}, argv, parsed, config); + return runPromise(getMetadata(merged, cli) .then(({status}) => { if (status === false) { - throw new Error('PR checks failed'); + throw new Error(IGNORE); } - }) - .catch((err) => { - if (cli.spinner.enabled) { - cli.spinner.fail(); - } - cli.error(err); - process.exit(1); - }); + })); } module.exports = { diff --git a/lib/cli.js b/lib/cli.js index 59bcd5f8..a8dd185d 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -4,6 +4,7 @@ const ora = require('ora'); const { EOL } = require('os'); const chalk = require('chalk'); const read = require('read'); +const { IGNORE } = require('./run'); const { warning, error, info, success } = require('./figures'); @@ -35,11 +36,11 @@ class CLI { read({prompt: promptText}, (err, answer) => { if (err) { this.log(`\nCanceled: ${err.message}`); - reject(new Error('__ignore__')); + reject(new Error(IGNORE)); return; } if (answer === undefined || answer === null) { - reject(new Error('__ignore__')); + reject(new Error(IGNORE)); return; } const trimmed = answer.toLowerCase().trim(); diff --git a/lib/pr_data.js b/lib/pr_data.js index a1ff1626..23dc1732 100644 --- a/lib/pr_data.js +++ b/lib/pr_data.js @@ -70,7 +70,14 @@ class PRData { const url = `https://raw.githubusercontent.com/${owner}/${repo}/master/README.md`; readme = await request.text(url); } - this.collaborators = getCollaborators(readme, cli, owner, repo); + try { + this.collaborators = getCollaborators(readme, cli, owner, repo); + } catch (err) { + const readme = argv.readme || `${owner}/${repo}/README.md`; + cli.stopSpinner(`Failed to get collaborator info from ${readme}`, + cli.SPINNER_STATUS.FAILED); + throw err; + } } async getPR() { diff --git a/lib/run.js b/lib/run.js index d09181e9..fac94f48 100644 --- a/lib/run.js +++ b/lib/run.js @@ -66,3 +66,5 @@ exports.runSync = function(cmd, args, options) { exports.exit = function() { process.exit(1); }; + +exports.IGNORE = IGNORE; diff --git a/lib/session.js b/lib/session.js index e42d7dbe..c74bc1fc 100644 --- a/lib/session.js +++ b/lib/session.js @@ -28,6 +28,17 @@ class Session { return getNcuDir(this.dir); } + get argv() { + return { + owner: this.owner, + repo: this.repo, + upstream: this.upstream, + branch: this.branch, + readme: this.readme, + prid: this.prid + }; + } + get sessionPath() { return path.join(this.ncuDir, 'land'); } @@ -48,6 +59,10 @@ class Session { return this.config.branch; } + get readme() { + return this.config.readme; + } + get pullName() { return `${this.owner}/${this.repo}/pulls/${this.prid}`; }