Skip to content

Commit 3fe2049

Browse files
authored
git: support readme configuration (#223)
Also fixes the status code handling in git-node.
1 parent 598a3a2 commit 3fe2049

File tree

6 files changed

+34
-15
lines changed

6 files changed

+34
-15
lines changed

components/git/land.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ async function main(state, argv, cli, req, dir) {
141141
return;
142142
}
143143
session = new LandingSession(cli, req, dir, argv.prid);
144-
const { repo, owner, prid } = session;
145-
const metadata = await getMetadata({ repo, owner, prid }, cli);
144+
const metadata = await getMetadata(session.argv, cli);
146145
return session.start(metadata);
147146
} else if (state === APPLY) {
148147
return session.apply();

components/git/metadata.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const yargs = require('yargs');
55
const getMetadata = require('../metadata');
66
const CLI = require('../../lib/cli');
77
const config = require('../../lib/config').getMergedConfig();
8+
const { runPromise, IGNORE } = require('../../lib/run');
89

910
const options = {
1011
owner: {
@@ -86,19 +87,13 @@ function handler(argv) {
8687
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
8788
const cli = new CLI(logStream);
8889

89-
return getMetadata(Object.assign({}, config, argv, parsed), cli)
90+
const merged = Object.assign({}, argv, parsed, config);
91+
return runPromise(getMetadata(merged, cli)
9092
.then(({status}) => {
9193
if (status === false) {
92-
throw new Error('PR checks failed');
94+
throw new Error(IGNORE);
9395
}
94-
})
95-
.catch((err) => {
96-
if (cli.spinner.enabled) {
97-
cli.spinner.fail();
98-
}
99-
cli.error(err);
100-
process.exit(1);
101-
});
96+
}));
10297
}
10398

10499
module.exports = {

lib/cli.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const ora = require('ora');
44
const { EOL } = require('os');
55
const chalk = require('chalk');
66
const read = require('read');
7+
const { IGNORE } = require('./run');
78

89
const { warning, error, info, success } = require('./figures');
910

@@ -35,11 +36,11 @@ class CLI {
3536
read({prompt: promptText}, (err, answer) => {
3637
if (err) {
3738
this.log(`\nCanceled: ${err.message}`);
38-
reject(new Error('__ignore__'));
39+
reject(new Error(IGNORE));
3940
return;
4041
}
4142
if (answer === undefined || answer === null) {
42-
reject(new Error('__ignore__'));
43+
reject(new Error(IGNORE));
4344
return;
4445
}
4546
const trimmed = answer.toLowerCase().trim();

lib/pr_data.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ class PRData {
7070
const url = `https://raw.githubusercontent.com/${owner}/${repo}/master/README.md`;
7171
readme = await request.text(url);
7272
}
73-
this.collaborators = getCollaborators(readme, cli, owner, repo);
73+
try {
74+
this.collaborators = getCollaborators(readme, cli, owner, repo);
75+
} catch (err) {
76+
const readme = argv.readme || `${owner}/${repo}/README.md`;
77+
cli.stopSpinner(`Failed to get collaborator info from ${readme}`,
78+
cli.SPINNER_STATUS.FAILED);
79+
throw err;
80+
}
7481
}
7582

7683
async getPR() {

lib/run.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ exports.runSync = function(cmd, args, options) {
6666
exports.exit = function() {
6767
process.exit(1);
6868
};
69+
70+
exports.IGNORE = IGNORE;

lib/session.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ class Session {
2828
return getNcuDir(this.dir);
2929
}
3030

31+
get argv() {
32+
return {
33+
owner: this.owner,
34+
repo: this.repo,
35+
upstream: this.upstream,
36+
branch: this.branch,
37+
readme: this.readme,
38+
prid: this.prid
39+
};
40+
}
41+
3142
get sessionPath() {
3243
return path.join(this.ncuDir, 'land');
3344
}
@@ -48,6 +59,10 @@ class Session {
4859
return this.config.branch;
4960
}
5061

62+
get readme() {
63+
return this.config.readme;
64+
}
65+
5166
get pullName() {
5267
return `${this.owner}/${this.repo}/pulls/${this.prid}`;
5368
}

0 commit comments

Comments
 (0)