Created
September 15, 2015 19:15
-
-
Save tylerpeterson/a7c2e9faccf89fda41e8 to your computer and use it in GitHub Desktop.
Example of searching github for code hits and then contributor information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// Be sure to chmod +x this file if you want to run it by name | |
// Node requires | |
var util = require('util'); | |
// Vendor requires | |
var request = require('superagent'); | |
var debug = require('debug')('blueprint-maint'); | |
// To turn on debug statements export the proper variable in the shell | |
// $ export DEBUG=blueprint-maint | |
// Then run this script in that shell | |
// module variables | |
// Create an access token at https://github.com/settings/tokens and set it in your env | |
// $ export GITHUB_PERSONAL_ACCESS_TOKEN=1234abcd1234abcd1... etc. | |
// Run this script in the same terminal that you set the access token in. | |
var accessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN; | |
debug('accessToken', accessToken); | |
// Change the username to your github username | |
var basicToken = 'Basic ' + new Buffer('tylerpeterson:' + accessToken).toString('base64'); | |
// Change this search query to suit your needs. | |
// This query is looking in repositories owned by fs-eng for files named blueprint containing 'name' | |
var queryTemplate = 'https://api.github.com/search/code?q=name+%s+in:file+language:yaml+user:fs-eng+filename:blueprint'; | |
// These are all the values we will interpolate into the search command above. | |
blueprints = [ | |
'acceptance-test-app-pfaxiu', | |
'acceptance-test-app-pgjwrg', | |
'acceptance-test-app-pjdxjn', | |
'allredlt-node-sample-app', | |
'at-node-test', | |
'blueprint-deploy-testapp', | |
'dsw10-test', | |
'fs-sas-node', | |
'gator', | |
'jdbc-message-service', | |
'journeyman', | |
'meme-generator-example', | |
'pgs', | |
'portfolio-parser', | |
'prof-dev-family-quiz', | |
'professional-development-ramesbury', | |
'pwn', | |
'qa-test-persistence', | |
'rdc', | |
'rds-postgres-migration-test', | |
'rec-engine', | |
'slide-test-clirr-deployable-component', | |
'slide-test-datacenter-to-aws', | |
'slide-test-deployable-component', | |
'slide-test-migration', | |
'sps-cassandra-testapp', | |
'sqs-aws-prototype', | |
'sysps-bpd-testapp', | |
'test-data-service', | |
'tmi', | |
'tree-memories-integration', | |
'trk-ws', | |
'ums-log-reaper', | |
'web-service-tools', | |
'zoning-controller', | |
'zoning-filemanager', | |
'zoning-trove', | |
'zoning-zrafs' | |
]; | |
function searchForBlueprint(blueprintI) { | |
if (blueprintI === blueprints.length) { | |
debug('finished searching for blueprints'); | |
return; | |
} | |
var insights = { | |
blueprint: blueprints[blueprintI] | |
}; | |
function next() { | |
console.log(JSON.stringify(insights, null, ' ')); | |
searchForBlueprint(blueprintI + 1); | |
} | |
// Search for code matches | |
request.get(util.format(queryTemplate, insights.blueprint)) | |
.set('Authorization', basicToken) | |
.end(function (err, codeHits) { | |
var firstHit = codeHits.body.items[0]; | |
insights.codeHitCount = codeHits.body.items.length; | |
if (firstHit === undefined) { | |
return next(); | |
} | |
insights.repositoryName = firstHit.repository.name; | |
insights.repositoryHtmlUrl = firstHit.repository.html_url; | |
insights.contributorsUrl = firstHit.repository.contributors_url; | |
debug('contributors', insights.contributorsUrl); | |
// Get information about the contributors to the repo that had the match in it. | |
request.get(insights.contributorsUrl) | |
.set('Authorization', basicToken) | |
.end(function (err, contribHits) { | |
debug('Found contributors:', contribHits.body.length); | |
insights.contributors = []; | |
function readContrib(contribI) { | |
if (contribI === contribHits.body.length) { | |
return next(); | |
} | |
request.get(contribHits.body[contribI].url) | |
.set('Authorization', basicToken) | |
.end(function (err, contribDetails) { | |
debug(contribDetails.body.login + ' (' + contribDetails.body.name + ' <' + contribDetails.body.email + '>)'); | |
insights.contributors.push({ | |
login: contribDetails.body.login, | |
name: contribDetails.body.name, | |
email: contribDetails.body.email | |
}); | |
readContrib(contribI + 1); | |
}); | |
} | |
readContrib(0); | |
}); | |
}); | |
} | |
searchForBlueprint(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "blueprint-maint", | |
"version": "1.0.0", | |
"description": "Find a list of blueprint maintainers given the name of a blueprint", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Tyler Peterson <[email protected]>", | |
"license": "MIT", | |
"dependencies": { | |
"debug": "^2.2.0", | |
"superagent": "^1.3.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install node. Put these files in an empty directory. Run npm install.
Read instructions in index.js to create a personal token for use against the github api.
Run.
Tweak.
Enjoy.