node-core-utils
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -12,7 +12,6 @@ 'use strict'; | ||
module.exports = async function getMetadata(argv, cli) { | ||
const { prid, owner, repo } = argv; | ||
const credentials = await auth(); | ||
const request = new Request(credentials); | ||
const data = new PRData(prid, owner, repo, cli, request); | ||
const data = new PRData(argv, cli, request); | ||
await data.getAll(); | ||
@@ -19,0 +18,0 @@ |
@@ -40,2 +40,7 @@ 'use strict'; | ||
}) | ||
.option('readme', { | ||
demandOption: false, | ||
describe: 'Path to file that contains collaborator contacts', | ||
type: 'string' | ||
}) | ||
.option('check-comments', { | ||
@@ -64,5 +69,7 @@ demandOption: false, | ||
owner = 'nodejs', repo = 'node', | ||
identifier, file, checkComments, maxCommits | ||
identifier, file, checkComments, maxCommits, readme | ||
} = args; | ||
const result = { owner, repo, file, checkComments, maxCommits }; | ||
const result = { | ||
owner, repo, file, checkComments, maxCommits, readme | ||
}; | ||
if (!isNaN(identifier)) { | ||
@@ -73,3 +80,3 @@ result.prid = +identifier; | ||
if (match === null) { | ||
throw new Error(`Could not understand PR id format: ${args}`); | ||
throw new Error(`Could not understand PR id format: ${identifier}`); | ||
} | ||
@@ -76,0 +83,0 @@ Object.assign(result, { |
'use strict'; | ||
const { | ||
tick, cross, info: infoRaw, warning: warningRaw | ||
} = require('figures'); | ||
const ora = require('ora'); | ||
@@ -10,6 +7,3 @@ const { EOL } = require('os'); | ||
const warning = chalk.yellow(warningRaw); | ||
const error = chalk.red(cross); | ||
const info = chalk.blue(infoRaw); | ||
const success = chalk.green(tick); | ||
const { warning, error, info, success } = require('./figures'); | ||
@@ -22,3 +16,2 @@ const SPINNER_STATUS = { | ||
}; | ||
const { SUCCESS, FAILED, WARN, INFO } = SPINNER_STATUS; | ||
@@ -34,2 +27,3 @@ | ||
this.spinner = ora({ stream }); | ||
this.SPINNER_STATUS = SPINNER_STATUS; | ||
} | ||
@@ -116,6 +110,2 @@ | ||
CLI.SPINNER_STATUS = SPINNER_STATUS; | ||
CLI.SCISSOR_LEFT = '>8'; | ||
CLI.SCISSOR_RIGHT = '8<'; | ||
module.exports = CLI; |
@@ -44,3 +44,3 @@ 'use strict'; | ||
async function getCollaborators(readme, cli, owner, repo) { | ||
function getCollaborators(readme, cli, owner, repo) { | ||
// This is more or less taken from | ||
@@ -47,0 +47,0 @@ // https://github.com/rvagg/iojs-tools/blob/master/pr-metadata/pr-metadata.js |
@@ -48,3 +48,3 @@ 'use strict'; | ||
getRefUrlFromOP(ref) { | ||
const as = this.OP.querySelectorAll('a.issue-link'); | ||
const as = this.OP.querySelectorAll('a'); | ||
const links = Array.from(as); | ||
@@ -51,0 +51,0 @@ for (const link of links) { |
@@ -56,4 +56,4 @@ 'use strict'; | ||
this.checkCommitsAfterReview(), | ||
this.checkCI(), | ||
this.checkPRWait(new Date()), | ||
this.checkCI(), | ||
this.checkMergeableState() | ||
@@ -154,8 +154,27 @@ ]; | ||
checkPRWait(now) { | ||
const { pr } = this; | ||
const { cli } = this; | ||
const { | ||
pr, cli, reviewers, CIStatus | ||
} = this; | ||
const labels = pr.labels.nodes; | ||
const fast = labels.some((l) => l.name === 'code-and-learn') || | ||
(labels.length === 1 && labels[0].name === 'doc'); | ||
if (fast) { return true; } | ||
const fast = | ||
labels.some((l) => ['fast-track'].includes(l.name)); | ||
if (fast) { | ||
const { approved } = reviewers; | ||
if (approved.length > 1 && CIStatus) { | ||
cli.info('This PR is being fast-tracked'); | ||
return true; | ||
} else { | ||
const msg = ['This PR is being fast-tracked, but awating ']; | ||
if (approved.length < 2) msg.push('approvals of 2 contributors'); | ||
if (!CIStatus) msg.push('a CI run'); | ||
let warnMsg = msg.length === 2 | ||
? msg.join('') : `${msg[0] + msg[1]} and ${msg[2]}`; | ||
cli.warn(warnMsg); | ||
} | ||
return false; | ||
} | ||
const wait = this.getWait(now); | ||
@@ -187,2 +206,3 @@ if (wait.timeLeft > 0) { | ||
cli.error('No CI runs detected'); | ||
this.CIStatus = false; | ||
return false; | ||
@@ -237,2 +257,3 @@ } else if (!ciMap.get(FULL)) { | ||
this.CIStatus = status; | ||
return status; | ||
@@ -254,4 +275,4 @@ } | ||
const prAuthor = pr.author.login; | ||
cli.warn(`PR author is: @${prAuthor}`); | ||
const prAuthor = `${pr.author.login}(${pr.author.email})`; | ||
cli.warn(`PR author is a new contributor: @${prAuthor}`); | ||
for (const c of oddCommits) { | ||
@@ -271,2 +292,9 @@ const { oid, author } = c.commit; | ||
const { pr, collaboratorEmails } = this; | ||
// They have turned on the private email feature, can't really check | ||
// anything, GitHub should know how to link that, see nodejs/node#15489 | ||
if (!pr.author.email) { | ||
return false; | ||
} | ||
// If they have added the alternative email to their account, | ||
@@ -273,0 +301,0 @@ // commit.authoredByCommitter should be set to true by Github |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const { ReviewAnalyzer } = require('./reviews'); | ||
const fs = require('fs'); | ||
@@ -22,3 +23,4 @@ // lib/queries/*.gql file names | ||
*/ | ||
constructor(prid, owner, repo, cli, request) { | ||
constructor(argv, cli, request) { | ||
const { prid, owner, repo } = argv; | ||
this.prid = prid; | ||
@@ -28,2 +30,3 @@ this.owner = owner; | ||
this.cli = cli; | ||
this.argv = argv; | ||
this.request = request; | ||
@@ -41,3 +44,3 @@ this.prStr = `${owner}/${repo}/pull/${prid}`; | ||
async getAll() { | ||
async getAll(argv) { | ||
const { prStr } = this; | ||
@@ -62,8 +65,14 @@ this.cli.startSpinner(`Loading data for ${prStr}`); | ||
async getCollaborators() { | ||
const { owner, repo, cli, request } = this; | ||
cli.updateSpinner( | ||
`Getting collaborator contacts from README of ${owner}/${repo}`); | ||
const url = `https://raw.githubusercontent.com/${owner}/${repo}/master/README.md`; | ||
const readme = await request.promise({ url }); | ||
this.collaborators = await getCollaborators(readme, cli, owner, repo); | ||
const { owner, repo, cli, request, argv } = this; | ||
let readme; | ||
if (argv.readme) { | ||
cli.updateSpinner(`Reading collaborator contacts from ${argv.readme}`); | ||
readme = fs.readFileSync(argv.readme, 'utf8'); | ||
} else { | ||
cli.updateSpinner( | ||
`Getting collaborator contacts from README of ${owner}/${repo}`); | ||
const url = `https://raw.githubusercontent.com/${owner}/${repo}/master/README.md`; | ||
readme = await request.promise({ url }); | ||
} | ||
this.collaborators = getCollaborators(readme, cli, owner, repo); | ||
} | ||
@@ -70,0 +79,0 @@ |
@@ -47,10 +47,9 @@ 'use strict'; | ||
}; | ||
// console.log(options); | ||
const result = await rp(options); | ||
if (result.errors) { | ||
const err = new Error('GraphQL request Error'); | ||
const { type, message } = result.errors[0]; | ||
const err = new Error(`[${type}] GraphQL request Error: ${message}`); | ||
err.data = { | ||
// query: query, | ||
variables: variables, | ||
errors: result.errors | ||
variables | ||
}; | ||
@@ -57,0 +56,0 @@ throw err; |
{ | ||
"name": "node-core-utils", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "Utilities for Node.js core collaborators", | ||
@@ -5,0 +5,0 @@ "main": "./bin/metadata.js", |
@@ -85,2 +85,9 @@ # Node.js Core Utilities | ||
### Git bash for Windows | ||
If you are using `git bash` and having trouble with output use `winpty get-metadata.cmd $PRID`. | ||
current known issues with git bash: | ||
- git bash Lacks colors. | ||
- git bash output duplicates metadata. | ||
### Features | ||
@@ -87,0 +94,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47055
27
1312
112
4