-
Notifications
You must be signed in to change notification settings - Fork 4
/
members.js
57 lines (49 loc) · 1.41 KB
/
members.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
// USAGE:
// Set environment var GH_TOKEN
// node members.js organization
var pumpify = require('pumpify')
var requestStream = require('requesturl-stream')
var ts = require('tool-stream')
var through = require('through2')
var request = require('request')
var parseLinkHeader = require('parse-link-header')
var TOKEN = process.env.GH_TOKEN
var APIROOT = 'https://api.github.com/'
var organization = process.argv[2]
var membersURL = APIROOT + 'orgs/' + organization + '/teams'
var requestOptions = {
json: true,
headers: {
'Authorization': 'token ' + TOKEN,
'User-Agent': 'request'
}
}
var replaceStream = function (fromString, toString) {
return through.obj(function (inputText, enc, next) {
this.push(inputText.replace(fromString, toString))
next()
})
}
var paginateRequest = through.obj(function (obj, enc, next) {
requestOptions.url = obj
request(requestOptions, (err, res, json) => {
if (err) { console.log(err) }
this.push(json)
var pages = parseLinkHeader(res.headers.link)
if (pages && pages.next) {
paginateRequest.write(pages.next.url)
}
next()
})
})
var pipeline = pumpify.obj(
requestStream(requestOptions),
ts.arraySplit(), // 3 objects (i.e. 3 teams: Contributors, Core, GSoC16)
ts.extractProperty('members_url'),
replaceStream('{/member}', ''),
paginateRequest,
ts.JSONToBuffer(),
process.stdout
)
pipeline.write(membersURL)