generated from darsan-in/Template-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_repo.js
51 lines (38 loc) · 1.09 KB
/
list_repo.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
function _makeGroupByOwner(data) {
const result = {};
data.forEach((repo) => {
const owner = repo.owner.login;
if (result[owner] === undefined) {
result[owner] = [];
}
result[owner].push(repo.name);
});
return result;
}
async function listRepoRemote() {
const { Octokit } = await import("@octokit/rest");
const octakit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const {
repos: { listForAuthenticatedUser },
} = octakit.rest;
const { data } = await listForAuthenticatedUser({
username: "iamspdarsan",
type: "all",
per_page: 100,
});
return _makeGroupByOwner(data);
}
function listRepoLocal() {
const { data } = JSON.parse(readFileSync("out.json", { encoding: "utf8" }));
return _makeGroupByOwner(data);
}
function dumpToLocal() {
listRepoRemote()
.then((content) => {
writeFileSync("out.json", JSON.stringify(content, null, 2), {
encoding: "utf8",
});
})
.catch(console.error);
}
module.exports = { listRepoRemote, listRepoLocal, dumpToLocal };