-
Notifications
You must be signed in to change notification settings - Fork 14
131 lines (105 loc) · 4.86 KB
/
collaborator-check.yml
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Collaborator Check
on:
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const ORGANIZATION = "Magisk-Modules-Alt-Repo";
const EXCLUDED_USERS = ["Atrate", "DerGoogler", "Fox2Code", "HuskyDG", "tytydraco"];
const EXCLUDED_REPOS = ["HuskyDG_BootloopSaver", "vintf-bypass", "mkshrc", "node", "xhhttp"];
const EXCLUDED_TOPIC_KEYWORD = "non-module";
async function fetchAllRepositories(org) {
const repos = [];
let page = 1;
while (true) {
const { data } = await github.rest.repos.listForOrg({
org,
type: "all",
per_page: 100,
page,
});
if (data.length === 0) break;
repos.push(...data);
page++;
}
return repos;
}
async function fetchRepositoryTopics(org, repo) {
try {
const { data } = await github.rest.repos.getAllTopics({
owner: org,
repo,
});
return data.names || [];
} catch (error) {
console.error(`Error fetching topics for ${repo}: ${error.message}`);
return [];
}
}
async function fetchCollaborators(org, repo) {
try {
const { data } = await github.rest.repos.listCollaborators({
owner: org,
repo,
affiliation: "all",
});
return data.map(user => user.login);
} catch (error) {
if (error.status === 404) {
console.error(`Repository "${repo}" is not accessible.`);
return [];
}
console.error(`Error fetching collaborators for ${repo}: ${error.message}`);
return [];
}
}
async function processRepositories(org) {
const allRepos = await fetchAllRepositories(org);
if (allRepos.length === 0) {
console.log(`No repositories found for organization "${org}".`);
return;
}
console.log(`Found ${allRepos.length} repositories. Filtering excluded repositories...`);
const filteredRepos = [];
for (const repo of allRepos) {
const { name } = repo;
if (EXCLUDED_REPOS.includes(name)) {
console.log(`Excluding repository "${name}" (explicit exclusion).`);
continue;
}
const topics = await fetchRepositoryTopics(org, name);
if (topics.includes(EXCLUDED_TOPIC_KEYWORD)) {
console.log(`Excluding repository "${name}" (topic "${EXCLUDED_TOPIC_KEYWORD}" found).`);
continue;
}
filteredRepos.push(name);
}
if (filteredRepos.length === 0) {
console.log(`No repositories to process after exclusions.`);
return;
}
console.log(`Processing ${filteredRepos.length} repositories after exclusions...`);
let unmaintainedCount = 0;
for (const repo of filteredRepos) {
const collaborators = await fetchCollaborators(org, repo);
const filteredCollaborators = collaborators.filter(user => !EXCLUDED_USERS.includes(user));
if (filteredCollaborators.length > 0) {
console.log(`Collaborators for repository "${repo}":`);
filteredCollaborators.forEach(user => console.log(`- ${user}`));
} else {
console.log(`No collaborators found (after exclusions) for repository "${repo}".`);
unmaintainedCount++;
}
}
const totalRepos = filteredRepos.length;
const unmaintainedPercentage = ((unmaintainedCount / totalRepos) * 100).toFixed(2);
console.log(`\nSummary:`);
console.log(`- Total repositories processed: ${totalRepos}`);
console.log(`- Unmaintained repositories (no collaborators): ${unmaintainedCount}`);
console.log(`- Percentage of unmaintained repositories: ${unmaintainedPercentage}%`);
}
processRepositories(ORGANIZATION);