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

cerebro-cli

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cerebro-cli - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

src/output/websocket.js

5

package.json
{
"name": "cerebro-cli",
"version": "0.2.3",
"version": "0.3.0",
"description": "",

@@ -30,4 +30,5 @@ "main": "./src/index.js",

"nyc": "^15.1.0",
"standard": "^16.0.3"
"standard": "^16.0.3",
"ws": "^7.4.6"
}
}

4

README.md

@@ -79,3 +79,3 @@ # Cerebro (cerebro-cli)

-e LANGUAGES=c++,javascript \
aphelionz/cerebro-cli:v0.2.1
aphelionz/cerebro-cli:v0.3.0
```

@@ -88,3 +88,3 @@

cerebro:
image: aphelionz/cerebro-cli:v0.2.1
image: aphelionz/cerebro-cli:v0.3.0
environment:

@@ -91,0 +91,0 @@ GH_TOKEN: XXXXX

const metrics = require('./metrics')
const {
candidatesFound,
missIncludedLangs,
missNonHireable,
pullRequests,
uniqueEvents,
suitablePRs
} = require('./metrics').custom
const seeker = require('./seeker')
const output = require('./output')

@@ -8,6 +15,6 @@ // Initialization

const {
GH_TOKEN,
COMMENT_THRESHOLD,
SHOW_NON_HIREABLE,
CHANGESET_THRESHOLD,
GH_TOKEN = null,
COMMENT_THRESHOLD = 3,
SHOW_NON_HIREABLE = false,
CHANGESET_THRESHOLD = 5432,
LANGUAGES

@@ -21,7 +28,7 @@ } = process.env

seeker.start(
GH_TOKEN || null,
GH_TOKEN,
{
parsedThreshold: isNaN(parseInt(COMMENT_THRESHOLD)) ? parseInt(COMMENT_THRESHOLD) : 3,
showNonHireable: SHOW_NON_HIREABLE || false,
changeSetThreshold: CHANGESET_THRESHOLD || 5432,
parsedThreshold: parseInt(COMMENT_THRESHOLD, 10),
showNonHireable: SHOW_NON_HIREABLE,
changeSetThreshold: CHANGESET_THRESHOLD,
targetLanguages

@@ -31,14 +38,14 @@ }

seeker.events.on('_debug.uniqueEvents', (count) => {
metrics.custom.uniqueEventsProcessed.inc(count)
})
seeker.events.on('_debug.suitablePRs', (count) => {
metrics.custom.suitablePRs.inc(count)
})
seeker.events.on('miss-included-langs', count => missIncludedLangs.inc(count))
seeker.events.on('miss-non-hireable', count => missNonHireable.inc(count))
seeker.events.on('stats-unique-events', count => uniqueEvents.inc(count))
seeker.events.on('stats-pull-requests', count => pullRequests.inc(count))
seeker.events.on('stats-suitable-prs', count => suitablePRs.inc(count))
function outputCandidate (candidate) {
output.console(candidate)
metrics.custom.candidatesFound.labels({ lang: candidate.includedLangs[0] }).inc(1)
console.log(candidate)
candidatesFound.labels({ lang: candidate.includedLangs[0] }).inc(1)
}
seeker.events.on('candidateFound', outputCandidate)
seeker.events.on('candidate-found', outputCandidate)

@@ -55,5 +62,5 @@ // Start Prometheus metrics server on the specified port

console.log('stopping seeker...')
seeker.events.off('candidateFound', outputCandidate)
seeker.events.removeAllListeners()
seeker.stop()
process.exit()
})

@@ -10,7 +10,14 @@ const client = require('prom-client')

const uniqueEventsProcessed = new client.Counter({
const uniqueEvents = new client.Counter({
name: 'unique_events_processed',
help: 'Number of unique events processed by Cerebro'
})
register.registerMetric(uniqueEventsProcessed)
register.registerMetric(uniqueEvents)
const pullRequests = new client.Counter({
name: 'pull_requests_processed',
help: 'Count of total pull request events processed.'
})
register.registerMetric(pullRequests)
const suitablePRs = new client.Counter({

@@ -21,2 +28,15 @@ name: 'suitable_pull_requests_found',

register.registerMetric(suitablePRs)
const missIncludedLangs = new client.Counter({
name: 'miss_included_langs',
help: 'Pull request -> candidate miss based on target programming language'
})
register.registerMetric(missIncludedLangs)
const missNonHireable = new client.Counter({
name: 'miss_non_hireable',
help: 'Pull request -> candidate miss candidate.hirable value'
})
register.registerMetric(missNonHireable)
const candidatesFound = new client.Counter({

@@ -29,3 +49,3 @@ name: 'candidates_found',

function start ({ port = 9100 }) {
function start ({ port = 9100 } = {}) {
server = http.createServer(async (req, res) => {

@@ -48,3 +68,6 @@ res.setHeader('Content-Type', register.contentType)

candidatesFound,
uniqueEventsProcessed,
missIncludedLangs,
missNonHireable,
pullRequests,
uniqueEvents,
suitablePRs

@@ -51,0 +74,0 @@ },

@@ -11,13 +11,20 @@ const { Octokit } = require('@octokit/rest')

const uniqueEvents = ghEvents.filter(d => parseInt(d.id, 10) > cursor)
events.emit('_debug.uniqueEvents', uniqueEvents.length)
// Update cursor to greatest known ID
cursor = ghEvents.map(e => parseInt(e.id, 10)).sort()[ghEvents.length - 1]
events.emit('stats-unique-events', uniqueEvents.length)
return Promise.resolve(uniqueEvents)
}
function getSuitablePRs (newEvents, { commentThreshold, changeSetThreshold }) {
const suitablePRs = newEvents
function getPREvents (newEvents) {
const prEvents = newEvents
// Get merged pull requests
.filter(d => d.type === 'PullRequestEvent')
events.emit('stats-pull-requests', prEvents.length)
return Promise.resolve(prEvents)
}
function getSuitablePRs (prEvents, { commentThreshold, changeSetThreshold }) {
const suitablePRs = prEvents
.filter(p => p.payload.action === 'closed')

@@ -32,3 +39,3 @@ .map(p => p.payload.pull_request)

events.emit('_debug.suitablePRs', suitablePRs.length)
events.emit('stats-suitable-prs', suitablePRs.length)
return Promise.resolve(suitablePRs)

@@ -43,3 +50,3 @@ }

}))
events.emit('_debug.filteredEvents', formattedPRs.length)
return Promise.resolve(formattedPRs)

@@ -63,5 +70,6 @@ }

.then(getNewEvents)
.then(newEvents => getSuitablePRs(newEvents, { commentThreshold, changeSetThreshold }))
.then(getPREvents)
.then(prEvents => getSuitablePRs(prEvents, { commentThreshold, changeSetThreshold }))
.then(formatSuitablePRs)
.then((data) => secondFilter(data, { targetLanguages, showNonHireable }))
.then((data) => extractCandidate(data, { targetLanguages, showNonHireable }))
.catch(console.error)

@@ -73,5 +81,8 @@

function stop () { clearInterval(seekInterval) }
function stop () {
clearInterval(seekInterval)
cursor = 0
}
async function secondFilter (results, { targetLanguages, showNonHireable }) {
async function extractCandidate (results, { targetLanguages, showNonHireable }) {
for (let i = 0; i < results.length; i++) {

@@ -82,3 +93,5 @@ const { languagesUrl, prHtmlUrl, username } = results[i]

const repoLanguages = Object.keys(repoRequest.data).map(l => l.toLowerCase())
// TODO: Introduce Set
const includedLangs = []
for (const lang of targetLanguages) {

@@ -89,12 +102,19 @@ // The dominant language in the repo should be first or second in the list

}
if (includedLangs.length === 0) continue
if (includedLangs.length === 0) {
events.emit('miss-included-langs', 1)
continue
}
const candidate = (await octokit.users.getByUsername({ username })).data
if (candidate.hireable || showNonHireable) {
events.emit('candidateFound', {
includedLangs,
prHtmlUrl,
...candidate
})
if (!candidate.hireable && !showNonHireable) {
events.emit('miss-non-hireable', 1)
continue
}
events.emit('candidate-found', {
includedLangs,
prHtmlUrl,
...candidate
})
}

@@ -101,0 +121,0 @@ }

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