Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-core-utils

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-core-utils - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

.git/COMMIT_EDITMSG

70

bin/metadata.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc