Skip to content

Commit 24933c5

Browse files
authored
Create empty-repos.yml
1 parent ebf444c commit 24933c5

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

.github/workflows/empty-repos.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: "Empty repo check"
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 1 * *' # 00:00 UTC on day 1 of every month
6+
workflow_dispatch: # also allow manual runs
7+
8+
permissions:
9+
contents: read
10+
issues: write
11+
12+
env:
13+
SCAN_ORG: YOUR-ORG-HERE
14+
15+
jobs:
16+
report:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Generate empty/README-only report 🕵️‍♂️
21+
uses: actions/github-script@v6
22+
with:
23+
github-token: ${{ secrets.GITHUB_TOKEN }}
24+
script: |
25+
const org = process.env.SCAN_ORG;
26+
// 1) Fetch all repos in the org
27+
const all = await github.paginate(
28+
github.rest.repos.listForOrg,
29+
{ org, per_page: 100 }
30+
);
31+
32+
const empty = [];
33+
const readmeOnly= [];
34+
35+
for (const repo of all) {
36+
let contents;
37+
try {
38+
// list root directory
39+
const res = await github.rest.repos.getContent({
40+
owner: org, repo: repo.name, path: ""
41+
});
42+
contents = Array.isArray(res.data) ? res.data : [res.data];
43+
} catch (e) {
44+
// 409 means “empty repo”
45+
if (e.status === 409) contents = [];
46+
else throw e;
47+
}
48+
49+
if (contents.length === 0) {
50+
empty.push(repo.full_name);
51+
} else {
52+
// filter-out any README* files
53+
const nonReadmes = contents.filter(f =>
54+
!/^README(\.[a-z]+)?$/i.test(f.name)
55+
);
56+
if (nonReadmes.length === 0) {
57+
readmeOnly.push(repo.full_name);
58+
}
59+
}
60+
}
61+
62+
// 2) Only create an issue if we found some
63+
if (empty.length + readmeOnly.length === 0) {
64+
console.log("✔ No empty/README-only repos found. Skipping issue.");
65+
return;
66+
}
67+
68+
// 3) Build markdown table
69+
const today = new Date().toISOString().slice(0,10);
70+
let body = `# Repo Health Report for \`${org}\` (${today})\n\n`;
71+
body += "| Repository | Status |\n| --- | --- |\n";
72+
for (const r of empty) body += `| ${r} | empty |\n`;
73+
for (const r of readmeOnly) body += `| ${r} | README-only |\n`;
74+
body += "\n_This issue is generated automatically on the 1st of each month._";
75+
76+
// 4) Open an issue in THIS repo
77+
await github.rest.issues.create({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
title: `Empty Repo Check: ${org} (${today})`,
81+
body
82+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy