-
Notifications
You must be signed in to change notification settings - Fork 53
/
clearuser.js
59 lines (55 loc) · 1.81 KB
/
clearuser.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
58
59
// After Reporobot does everything with a sucessful user, it deltes the file
// they added because turns out lots of people are doing this and the repo
// gets bulky quickly. This file is called from buildpage.js
var request = require('request')
var baseURL = 'https://api.github.com/repos/jlord/patchwork/contents/contributors'
var headers = {
'User-Agent': 'request',
'Authorization': 'token ' + process.env['REPOROBOT_TOKEN']
}
module.exports = function deleteFile (username, callback) {
var options = {
url: baseURL,
json: true,
headers: headers
}
// First get info on the file
request(options, function (err, response, body) {
if (err) return callback(err, 'Did not get file info')
console.log(new Date(), 'Files in contributors: ' + body.length)
loop()
function loop () {
if (!body.length) return callback(null)
var file = body.shift()
if (file.path.match('add-jlord.txt')) return loop()
deleteFile(file, function (err) {
if (err) return callback(err, 'Error deleting file')
setTimeout(loop, 5000)
})
}
})
function deleteFile (file, callback) {
var options = {
url: baseURL + '/' + file.name,
json: true,
headers: headers,
body: {
'message': 'Clearing directory',
'committer': {
'name': 'reporobot',
'email': '[email protected]'
},
'sha': file.sha,
'path': file.path
}
}
request.del(options, function (err, response, body) {
if (err) return callback(err, 'Error with delete request')
if (response.statusCode != 200) {
return callback(null, 'Non 200 for delete: ' + response.statusCode + ' ' + response.body.message)
}
console.log(new Date(), 'Deleted ' + file.name)
callback(null)
})
}
}