forked from YiyiZhang/yourfirstpr.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhumans.js
More file actions
45 lines (37 loc) · 1.09 KB
/
Copy pathhumans.js
File metadata and controls
45 lines (37 loc) · 1.09 KB
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
var fs = require('fs')
var GitHubApi = require('github')
var github = new GitHubApi({
version: '3.0.0'
})
// Delete everything in humans.txt
fs.unlink('humans.txt', function (error) {
if (error) {
return console.error(error)
}
console.info('Deleted humans.txt successfully')
})
// Get list of contributors from the Github API
github.repos.getContributors({
user: 'yourfirstpr',
repo: 'yourfirstpr.github.io'
},
function (error, response) {
if (error) {
return console.error(error)
}
var contributorList = []
// Add the name and GitHub URL of each contributor to a list
response.forEach(function (contributor) {
contributorList.push(contributor.login + ' - ' + contributor.html_url)
})
// Push contributors to humans.txt
fs.writeFile('humans.txt', 'CONTRIBUTORS\n')
contributorList.forEach(function (contributor) {
fs.appendFile('humans.txt', contributor + '\n', function (error) {
if (error) {
return console.error(error)
}
})
})
console.info('Successfully wrote contributors to humans.txt')
})