forked from mheap/github-default-branch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-repos.js
54 lines (47 loc) · 1.23 KB
/
get-repos.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
module.exports = async function (args, octokit) {
if (args.repo) {
return [args.repo];
}
let repos = [];
if (args.org && !args.team) {
repos = await octokit.paginate(
octokit.repos.listForOrg,
{
org: args.org,
per_page: 100
},
(response) => response.data
);
}
if (args.org && args.team) {
repos = await octokit.paginate(
octokit.teams.listReposInOrg,
{
org: args.org,
team_slug: args.team,
per_page: 100
},
(response) => response.data
);
}
if (args.user) {
repos = await octokit.paginate(
octokit.repos.listForAuthenticatedUser,
{
per_page: 100
},
(response) => response.data
);
// Filter down to repos owned by the provided user
// This is different to using affiliation: owner as it allows
// the consumer to update repos that they have admin access to
// but do not own
repos = repos.filter((repo) => repo.owner.login == args.user);
}
if (args.skipForks) {
repos = repos.filter((repo) => !repo.fork);
}
// Filter out archived repos as we cannot write to them
repos = repos.filter((repo) => !repo.archived);
return repos.map((repo) => repo.full_name);
};