-
Notifications
You must be signed in to change notification settings - Fork 0
/
collabcheck.js
32 lines (28 loc) · 1.02 KB
/
collabcheck.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
const request = require('request')
// With username parsed from query, check to see if @RR has read/write access
// to user's fork of Patchwork. This means they have been added as a collab.
// Pass boolean on to callback.
// Called by:
// checkCollab(username, function(err, collab) { collabStatus(r, e, collab) })
module.exports = function (username, callback) {
const options = {
url: `https://api.github.com/repos/${username}/patchwork/collaborators/lhl-reporobot/permission`,
json: true,
headers: { 'User-Agent': 'request',
'Authorization': 'token ' + process.env['REPOROBOT_TOKEN'],
'Accept': 'application/vnd.github.swamp-thing-preview+json'
}
}
let collab = false
request(options, function (err, response, body) {
if (err) return callback(err.error)
const permissions = body.permission
if (permissions === 'admin' || permissions === 'write') {
collab = true
callback(null, collab)
} else {
collab = false
callback(null, collab)
}
})
}