-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathgithubGetAllContributors.js
92 lines (79 loc) · 2.6 KB
/
githubGetAllContributors.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const fs = require('fs')
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
async function getUrl(url) {
var params = {
method: 'GET'
}
const request = await fetch(`https://api.github.com/${url}`, params);
return request.json();
}
async function getAllRepositories(orgName) {
const allProjects = await getUrl(`orgs/${orgName}/repos`);
return allProjects;
}
async function getAllRepositoryContributors(repositoryFullName) {
const allContributors = await getUrl(`repos/${repositoryFullName}/contributors`);
return allContributors;
}
function mapAllContributors(contributors) {
return contributors.map(({
login,
html_url,
avatar_url
}) => {
return {
login,
html_url,
avatar_url
}
})
}
async function getAllRepositoriesContributors(repositories) {
let contributors = []
await Promise.all(repositories.map(async (repository) => {
const contributorsByProject = await getAllRepositoryContributors(repository);
contributors.push(...mapAllContributors(contributorsByProject))
}))
return contributors
}
function filterUniqueContributors(contributors) {
return contributors.filter((v, i, a) => a.findIndex(t => (t.login === v.login)) === i);
}
function filterLoginBlackList(contributors) {
const blacklist = [
'alavortx',
'dependabot[bot]',
'mellogabvortx',
'pafonso-magit',
'semantic-release-bot',
'juliadibo',
'BrsPontes-Vortx',
'anahelenamagit',
'gmo-vortx',
'DanielRSous',
'jhomarolo-vortx',
'm7vicente-vortx',
'maikvortx',
'eduardo-vortx',
'vma-vortx',
'vxksf',
'dlojudice-vortx',
'cpp-vortx',
'isabelaalonsovortx'
]
return contributors.filter(contributor => !blacklist.includes(contributor.login))
}
function orderContributors(contributors) {
return contributors.sort((a, b) => a.login.localeCompare(b.login))
}
const GetAllContributors = async () => {
const repositories = await getAllRepositories('herbsjs')
const repositoriesFullName = repositories.map(project => project.full_name)
const allRepositoriesContributors = await getAllRepositoriesContributors(repositoriesFullName)
return filterLoginBlackList(filterUniqueContributors(orderContributors(allRepositoriesContributors)));
}
try {
GetAllContributors().then(contributors => fs.writeFileSync('./static/contributors.json', JSON.stringify(contributors)))
} catch (err) {
console.error(err)
}