-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathsync-team.js
72 lines (62 loc) · 2.17 KB
/
sync-team.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
const process = require('process');
const fs = require('fs');
const axios = require('axios');
const contributorsFile = './config/contributors.json';
const docContributorsFile = './config/doc-contributors.json';
class Contributors {
constructor(contributorsFile, docContributorsFile) {
this.contributorsFile = contributorsFile;
this.docContributorsFile = docContributorsFile;
}
async init() {
try {
console.log('start...');
await this.getAllRepoData();
} catch (err) {
console.log(err);
process.exit(1)
}
}
async getAllRepoData() {
await this.getContributors();
await this.getDocContributors();
}
async writeFile(file, data) {
try {
const jsonString = JSON.stringify(data, null, 2);
fs.writeFileSync(file, jsonString);
console.log('write success');
} catch (err) {
console.error(err)
}
}
async getContributors (page= 1, per_page= 100, extraContributors = [], list = []) {
await axios.get(`https://api.github.com/repos/apache/inlong/contributors?page=${page}&per_page=${per_page}`).then(result =>{
let data = result.data;
list.push(...data);
if(data.length === per_page) {
page++;
this.getContributors(page, per_page, extraContributors, list);
}else {
const repoContributors = [...list, ...extraContributors];
this.writeFile(this.contributorsFile, repoContributors);
console.log('writing to contributors succeeded');
}
});
}
async getDocContributors (page= 1, per_page= 100, extraContributors = [], list = []) {
await axios.get(`https://api.github.com/repos/apache/inlong-website/contributors?page=${page}&per_page=${per_page}`).then(result =>{
let data = result.data;
list.push(...data);
if(data.length === per_page) {
page++;
this.getDocContributors(page, per_page, extraContributors, list);
}else {
const repoContributors = [...list, ...extraContributors];
this.writeFile(this.docContributorsFile, repoContributors);
console.log('writing to doc contributors succeeded');
}
});
}
}
new Contributors(contributorsFile, docContributorsFile).init()