-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathgithubFunc.js
More file actions
34 lines (30 loc) · 932 Bytes
/
githubFunc.js
File metadata and controls
34 lines (30 loc) · 932 Bytes
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
const fetch = require("node-fetch")
const githubToken = require("./token.js")
const makeRequest = async (url) => {
let res = await fetch(url,
{
headers: {
authorization: `token ${githubToken.token}`
}
}
)
return res.json()
}
const getUsers = async (user, repo) => {
let users = [], list = [], pageNO = 1;
while ((list.length > 0 || pageNO == 1) && pageNO < 10) {
list = await makeRequest(`https://api.github.com/repos/${user}/${repo}/stargazers?per_page=100&page=${pageNO}`)
// if an array is not returned
if (list.message) {
return list
}
users = [...users, ...list];
pageNO++;
}
return users;
}
const getUserData = async (username) => {
let data = await makeRequest(`https://api.github.com/users/${username}`)
return await data
}
module.exports = { getUsers, getUserData };