forked from nodejs/node-core-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.js
More file actions
95 lines (86 loc) · 2.56 KB
/
metadata.js
File metadata and controls
95 lines (86 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { parsePRFromURL } from '../../lib/links.js';
import { getMetadata } from '../metadata.js';
import CLI from '../../lib/cli.js';
import { getMergedConfig } from '../../lib/config.js';
import { runPromise, IGNORE } from '../../lib/run.js';
export const command = 'metadata <identifier>';
export const describe =
'Retrieves metadata for a PR and validates them against nodejs/node PR rules';
const config = getMergedConfig();
const options = {
owner: {
alias: 'o',
describe: 'GitHub owner of the PR repository',
default: 'nodejs',
type: 'string'
},
repo: {
default: 'node',
alias: 'r',
describe: 'GitHub repository of the PR',
type: 'string'
},
file: {
alias: 'f',
describe: 'File to write the metadata in',
type: 'string'
},
readme: {
describe: 'Path to file that contains collaborator contacts',
type: 'string'
},
'check-comments': {
describe: 'Check for \'LGTM\' in comments',
type: 'boolean'
},
'max-commits': {
describe: 'Number of commits to warn',
type: 'number',
default: 3
}
};
let yargsInstance;
export function builder(yargs) {
yargsInstance = yargs;
return yargs
.options(options)
.positional('identifier', {
type: 'string',
describe: 'ID or URL of the pull request'
})
.example('git node metadata 12344',
'Retrieve the metadata of https://github.com/nodejs/node/pull/12344 ' +
'and validate the PR')
.example('git node metadata https://github.com/nodejs/node/pull/12344',
'Retrieve the metadata of https://github.com/nodejs/node/pull/12344 ' +
'and validate it')
.example('git node metadata 167 --repo llnode --readme ../node/README.md',
'Retrieve the metadata of https://github.com/nodejs/llnode/pull/167 ' +
'and validate it using the README in ../node/README.md')
.wrap(90);
}
export function handler(argv) {
let parsed = {};
const prid = Number.parseInt(argv.identifier);
if (!Number.isNaN(prid)) {
parsed.prid = prid;
} else {
parsed = parsePRFromURL(argv.identifier);
if (!parsed) {
return yargsInstance.showHelp();
}
}
if (!Number.isInteger(argv.maxCommits) || argv.maxCommits < 0) {
return yargsInstance.showHelp();
}
const logStream = process.stdout.isTTY ? process.stdout : process.stderr;
const cli = new CLI(logStream);
const merged = Object.assign({}, argv, parsed, config);
return runPromise(getMetadata(merged, false, cli)
.then(({ status }) => {
if (status === false) {
throw new Error(IGNORE);
}
return undefined;
}));
}