-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
fetch.js
58 lines (55 loc) · 1.67 KB
/
fetch.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
const axios = require('axios');
const userInfoFetcher = (token) => {
return axios({
url: 'https://api.github.com/graphql',
method: 'post',
headers: {
Authorization: `bearer ${token}`,
},
data: {
query: `
query userInfo {
viewer {
name
login
contributionsCollection {
totalCommitContributions
}
repositoriesContributedTo(first: 1, contributionTypes: [COMMIT, ISSUE, PULL_REQUEST, REPOSITORY]) {
totalCount
}
pullRequests(first: 1) {
totalCount
}
issues(first: 1) {
totalCount
}
repositories(first: 100, ownerAffiliations: OWNER, isFork: false, orderBy: {direction: DESC, field: STARGAZERS}) {
totalCount
nodes {
stargazers {
totalCount
}
}
}
}
}`,
},
});
};
// Experimental API
const totalCommitsFetcher = async (login, token) => {
return axios({
method: 'get',
url: `https://api.github.com/search/commits?q=author:${login}`,
headers: {
'Content-Type': 'application/json',
Accept: 'application/vnd.github.cloak-preview',
Authorization: `bearer ${token}`,
},
}).then((res) => res.data.total_count);
};
module.exports = {
userInfoFetcher,
totalCommitsFetcher,
};