Last active
February 4, 2016 17:39
-
-
Save ryands/a6b8e86656fe4e0f1f8c to your computer and use it in GitHub Desktop.
Bitbar pull request monitoring
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/local/bin/node | |
// node.js BitBar plugin for pull-request tracking. | |
var https = require('https'); | |
function pull_requests(options, cb) { | |
var repo = options.repo, | |
token = options.token; | |
https.get({ | |
protocol: 'https:', | |
host: 'api.github.com', | |
path: `/repos/${repo}/pulls`, | |
headers: { | |
'Accept': 'application/vnd.github.v3+json', | |
'Content-type': 'application/json', | |
'Authorization': `token ${token}`, | |
'User-Agent': 'ryands/bitbar-pr (v0.1; nodejs v5.x)' | |
} | |
}, (res) => { | |
var data = ''; | |
res.on('data', (chunk) => { | |
data += chunk; | |
}); | |
res.on('end', () => { | |
cb.call(this, JSON.parse(data), options); | |
}); | |
}); | |
} | |
pull_requests({ | |
repo: '<some/repo>', | |
token: '<create a github personal token w/ repo permissions>', | |
user: '<github username>' | |
}, (data, options) => { | |
var open = data.length, | |
user = options.user; | |
mine = [], | |
assigned_me = [], | |
unassigned = []; | |
data.forEach((pr) => { | |
if (pr.assignee && pr.assignee.login == user) { | |
assigned_me.push(pr); | |
} else if (!pr.assignee) { | |
unassigned.push(pr); | |
} | |
if (pr.user.login == user) { | |
mine.push(pr); | |
} | |
}); | |
console.log(`pr:${assigned_me.length} u:${unassigned.length}`); | |
console.log('---'); | |
console.log('Assigned Me: | color=green'); | |
assigned_me.forEach((pr) => { | |
console.log(` #${pr.number}: ${pr.title} | href=${pr.html_url}`); | |
}); | |
console.log('---'); | |
console.log('Unassigned: | color=red'); | |
unassigned.forEach((pr) => { | |
console.log(` #${pr.number}: ${pr.title} (${pr.user.login}) | href=${pr.html_url}`); | |
}); | |
console.log('---'); | |
console.log('Mine: | color=green'); | |
mine.forEach((pr) => { | |
var assigned = pr.asignee ? pr.assignee.login : 'unassigned'; | |
console.log(` #${pr.number}: ${pr.title} (${assigned}) | href=${pr.html_url}`); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment