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