-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRepos.mjs
32 lines (26 loc) · 851 Bytes
/
getRepos.mjs
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
import { Octokit } from "@octokit/rest";
const octokit = new Octokit();
async function getNumberOfRepos(username) {
const response = await octokit.users.getByUsername({ username });
return response.data.public_repos;
}
async function getReposForUser(username, number) {
const per_page = 100;
const pages = Math.ceil(number / per_page);
const values = await Promise.all(
[...Array(pages).keys()].map(async index => {
const response = await octokit.repos.listForUser({
username,
page: index + 1,
per_page
});
return response.data;
})
);
return values.reduce((a, current) => a.concat(current), []);
}
export default async function(username) {
const numberOfRepos = await getNumberOfRepos(username);
const repos = await getReposForUser(username, numberOfRepos);
return repos;
};