node-core-utils
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -20,2 +20,4 @@ #!/usr/bin/env node | ||
const { ascending } = require('../lib/comp'); | ||
const LinkParser = require('../lib/links'); | ||
const { | ||
@@ -25,6 +27,2 @@ PENDING, COMMENTED, APPROVED, CHANGES_REQUESTED, DISMISSED | ||
const FIXES_RE = /Fixes: (\S+)/mg; | ||
const FIX_RE = /Fixes: (\S+)/; | ||
const REFS_RE = /Refs?: (\S+)/mg; | ||
const REF_RE = /Refs?: (\S+)/; | ||
const LGTM_RE = /(\W|^)lgtm(\W|$)/i; | ||
@@ -118,12 +116,12 @@ | ||
const reviewers = updateMapByRawReviews(ghReviews, comments, collaborators); | ||
const result = []; | ||
const result = { | ||
approved: [], | ||
rejected: [] | ||
}; | ||
for (const [ login, review ] of reviewers) { | ||
if (review.state !== APPROVED) { | ||
logger.warn(`${login}: ${review.state} ${review.ref}`); | ||
} else { | ||
const data = collaborators.get(login); | ||
result.push({ | ||
name: data.name, | ||
email: data.email | ||
}); | ||
const reviwer = collaborators.get(login); | ||
if (review.state === APPROVED) { | ||
result.approved.push(Object.assign({ review }, reviwer)); | ||
} else if (review.state === CHANGES_REQUESTED) { | ||
result.rejected.push(Object.assign({ review }, reviwer)); | ||
} | ||
@@ -134,12 +132,4 @@ } | ||
async function getFixes(pr) { | ||
return []; // TODO | ||
} | ||
async function getRefs(pr) { | ||
return []; // TODO | ||
} | ||
async function main(prid, owner, repo) { | ||
logger.info(`Requesting ${owner}/${repo}/pull/${prid}`); | ||
logger.trace(`Getting PR from ${owner}/${repo}/pull/${prid}`); | ||
const prData = await request(PR_QUERY, { prid, owner, repo }); | ||
@@ -150,7 +140,7 @@ const pr = prData.repository.pullRequest; | ||
const vars = { prid, owner, repo }; | ||
logger.info(`Requesting ${owner}/${repo}/pull/${prid}/reviews`); | ||
logger.trace(`Getting reviews from ${owner}/${repo}/pull/${prid}`); | ||
const reviews = await requestAll(REVIEWS_QUERY, vars, [ | ||
'repository', 'pullRequest', 'reviews' | ||
]); | ||
logger.info(`Requesting ${owner}/${repo}/pull/${prid}/comments`); | ||
logger.trace(`Getting comments from ${owner}/${repo}/pull/${prid}`); | ||
const comments = await requestAll(COMMENTS_QUERY, vars, [ | ||
@@ -163,3 +153,3 @@ 'repository', 'pullRequest', 'comments' | ||
// TODO: maybe invalidate review after new commits? | ||
// logger.info(`Requesting ${owner}/${repo}/pull/${prid}/commits`); | ||
// logger.trace(`Getting commits from ${owner}/${repo}/pull/${prid}`); | ||
// const commits = await requestAll(COMMITS_QUERY, vars, [ | ||
@@ -169,6 +159,17 @@ // 'repository', 'pullRequest', 'commits' | ||
const reviewedBy = await getReviewers(reviews, comments, collaborators); | ||
const fixes = await getFixes(reviews, comments); | ||
const refs = await getRefs(reviews, comments); | ||
const reviewers = await getReviewers(reviews, comments, collaborators); | ||
if (reviewers.rejected.length > 0) { | ||
for (const { name, login, review } of reviewers.rejected) { | ||
logger.warn(`${name}(${login}) rejected in ${review.ref}`); | ||
} | ||
} | ||
if (reviewers.approved.length === 0) { | ||
logger.warn('This PR has not been approved yet'); | ||
} | ||
const reviewedBy = reviewers.approved; | ||
const parser = new LinkParser(repo, pr.bodyHTML); | ||
const fixes = parser.getFixes(); | ||
const refs = parser.getRefs(); | ||
const output = { | ||
@@ -190,4 +191,13 @@ prUrl, reviewedBy, fixes, refs | ||
); | ||
logger.info({ raw: meta.join('\n') }, `Generated metadta:`); | ||
logger.info({ raw: meta.join('\n') }, 'Generated metadta:'); | ||
if (reviewers.rejected.length === 0) { | ||
logger.info(`Rejections: 0`); | ||
} else { | ||
logger.warn(`Rejections: ${reviewers.rejected.length}`); | ||
} | ||
if (reviewers.approved.length === 0) { | ||
logger.warn(`Approvals: 0`); | ||
} else { | ||
logger.info(`Approvals: ${reviewers.approved.length}`); | ||
} | ||
} | ||
@@ -194,0 +204,0 @@ |
'use strict'; | ||
const pino = require('pino'); | ||
const chalk = require('chalk'); | ||
function paint(level) { | ||
switch (level) { | ||
case 'ERROR': | ||
case 'FATAL': | ||
return chalk.red(`[${level}]`); | ||
case 'WARN': | ||
return chalk.yellow(`[${level}]`); | ||
case 'INFO': | ||
return chalk.blue(`[${level}]`); | ||
default: | ||
return chalk.green(`[${level}]`); | ||
} | ||
} | ||
const LEVELS = new Map(Object.keys(pino.levels.values) | ||
@@ -15,17 +31,20 @@ .map((key) => [pino.levels.values[key], key.toUpperCase()])); | ||
if (level === 'ERROR') { | ||
return `[${level}] ${timestamp}${obj.type} ${obj.msg}\n` + | ||
return `${paint(level)} ${timestamp}${obj.type} ${obj.msg}\n` + | ||
`[STACK] ${obj.stack}\n` + | ||
`[DATA] ${JSON.stringify(obj.data, null, 2)}\n`; | ||
} else if (level === 'INFO' && obj.raw) { | ||
return `[${level}] ${timestamp}${obj.msg || ''}\n ${obj.raw}`; | ||
return `${paint(level)} ${timestamp}${obj.msg || ''}\n${obj.raw}`; | ||
} else { | ||
return `[${level}] ${timestamp}${obj.msg}`; | ||
return `${paint(level)} ${timestamp}${obj.msg}`; | ||
} | ||
} | ||
}); | ||
pretty.pipe(process.stdout); | ||
const logger = pino({ | ||
name: 'node-core-utils', | ||
safe: true | ||
safe: true, | ||
level: 'trace' | ||
}, pretty); | ||
module.exports = logger; |
{ | ||
"name": "node-core-utils", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -15,2 +15,4 @@ "main": "./bin/metadata.js", | ||
"dependencies": { | ||
"chalk": "^2.2.0", | ||
"jsdom": "^11.3.0", | ||
"pino": "^4.8.0", | ||
@@ -17,0 +19,0 @@ "request": "^2.83.0", |
@@ -17,7 +17,26 @@ # Node.js Core Utilities | ||
Install and link (): | ||
``` | ||
git clone git@github.com:joyeecheung/node-core-utils.git | ||
cd node-core-utils | ||
npm install | ||
npm link | ||
get-metadata 14782 | ||
``` | ||
## `get-metadata` | ||
This one is inspired by Evan Lucas's [node-review](https://github.com/evanlucas/node-review) | ||
, although it is a CLI implemented with the Github GraphQL API. | ||
### TODO | ||
- [x] Generate `PR-URL` | ||
- [x] Generate `Reviewed-By` | ||
- [ ] Generate `Fixes` | ||
- [ ] Generate `Refs` | ||
- [ ] Check for CI runs | ||
- [ ] Check if commiters match authors | ||
- [ ] Check 48-hour wait | ||
- [ ] Check two TSC approval for semver-major | ||
- [ ] Check number of files changed (request pre-backport) |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 77 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
136
42
189448
5
415
78
+ Addedchalk@^2.2.0
+ Addedjsdom@^11.3.0
+ Addedabab@2.0.6(transitive)
+ Addedacorn@5.7.46.4.2(transitive)
+ Addedacorn-globals@4.3.4(transitive)
+ Addedacorn-walk@6.2.0(transitive)
+ Addedarray-equal@1.0.2(transitive)
+ Addedasync-limiter@1.0.1(transitive)
+ Addedbrowser-process-hrtime@1.0.0(transitive)
+ Addedcssom@0.3.8(transitive)
+ Addedcssstyle@1.4.0(transitive)
+ Addeddata-urls@1.1.0(transitive)
+ Addeddeep-is@0.1.4(transitive)
+ Addeddomexception@1.0.1(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedhtml-encoding-sniffer@1.0.2(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedjsdom@11.12.0(transitive)
+ Addedleft-pad@1.3.0(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedlodash.sortby@4.7.0(transitive)
+ Addednwsapi@2.2.16(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedparse5@4.0.0(transitive)
+ Addedpn@1.1.0(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsymbol-tree@3.2.4(transitive)
+ Addedtr46@1.0.1(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedw3c-hr-time@1.0.2(transitive)
+ Addedwebidl-conversions@4.0.2(transitive)
+ Addedwhatwg-encoding@1.0.5(transitive)
+ Addedwhatwg-mimetype@2.3.0(transitive)
+ Addedwhatwg-url@6.5.07.1.0(transitive)
+ Addedword-wrap@1.2.5(transitive)
+ Addedws@5.2.4(transitive)
+ Addedxml-name-validator@3.0.0(transitive)