Skip to content

Commit

Permalink
git: support readme configuration (#223)
Browse files Browse the repository at this point in the history
Also fixes the status code handling in git-node.
  • Loading branch information
joyeecheung authored Mar 31, 2018
1 parent 598a3a2 commit 3fe2049
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
3 changes: 1 addition & 2 deletions components/git/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 5 additions & 10 deletions components/git/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 = {
Expand Down
5 changes: 3 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion lib/pr_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ exports.runSync = function(cmd, args, options) {
exports.exit = function() {
process.exit(1);
};

exports.IGNORE = IGNORE;
15 changes: 15 additions & 0 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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}`;
}
Expand Down

0 comments on commit 3fe2049

Please sign in to comment.