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
export async function ghOrgRepos(
owner: string,
token: string,
type: "all" | "public" | "private" | "forks" | "sources" | "member" = "all",
sort: "created" | "updated" | "pushed" | "full_name" = "created",
direction: "asc" | "desc" = "desc",
): Promise<{
name: string;
full_name: string;
description: string;
html_url: string;
private: boolean;
fork: boolean;
archived: boolean;
}[]> {
const { Octokit } = await import("npm:@octokit/core");
const { paginateRest } = await import("npm:@octokit/plugin-paginate-rest");
const PaginatedOctokit = Octokit.plugin(paginateRest);
const gh = new PaginatedOctokit({ auth: token });
const parameters = {
type,
sort,
direction,
per_page: 100,
};
let repositories = [];
try {
const repos = await gh.paginate(`GET /orgs/${owner}/repos`, parameters);
console.log(`${repos.length} repositories found for ${owner}.`);
for (const r of repos) {
repositories.push({
name: r.name,
full_name: r.full_name,
description: r.description,
html_url: r.html_url,
private: r.private,
fork: r.fork,
archived: r.archived,
});
}
return repositories;
}
catch ({ name, message }) {
if (name == "HttpError") {
console.log(`Error: ${owner} is not an organization.`);
}
else {
console.log(`${name}: ${message}`);
}
return [];
}
}