Skip to content

Commit 800317e

Browse files
committed
refactor: Update
1 parent 11f5042 commit 800317e

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Update organization profile README
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
organization: read
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.12"
21+
22+
- name: Install dependencies
23+
run: |
24+
pip install requests
25+
26+
- name: Update README
27+
env:
28+
ORG: DarkbordermanModding
29+
TOKEN: ${{ secrets.ORG_TOKEN || github.token }}
30+
run: |
31+
python scripts/update_profile_readme.py
32+
33+
- name: Commit changes
34+
run: |
35+
git config user.name "github-actions"
36+
git config user.email "github-actions@github.com"
37+
git add .profile/README.md
38+
git commit -m "Update repository list" || exit 0
39+
git push

scripts/update_readme.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import os
2+
import requests
3+
from pathlib import Path
4+
5+
ORG = os.environ["ORG"]
6+
TOKEN = os.environ["TOKEN"]
7+
8+
API_URL = f"https://api.github.com/orgs/{ORG}/repos"
9+
HEADERS = {
10+
"Authorization": f"Bearer {TOKEN}",
11+
"Accept": "application/vnd.github+json",
12+
}
13+
14+
def fetch_repositories():
15+
repos = []
16+
page = 1
17+
18+
while True:
19+
resp = requests.get(
20+
API_URL,
21+
headers=HEADERS,
22+
params={"per_page": 100, "page": page},
23+
timeout=30,
24+
)
25+
resp.raise_for_status()
26+
data = resp.json()
27+
28+
if not data:
29+
break
30+
31+
repos.extend(data)
32+
page += 1
33+
34+
return repos
35+
36+
def generate_markdown(repos):
37+
lines = ["## Repositories", ""]
38+
for repo in sorted(repos, key=lambda r: r["name"].lower()):
39+
lines.append(
40+
f'* {repo["name"]} ([source]({repo["html_url"]}))'
41+
)
42+
return "\n".join(lines) + "\n"
43+
44+
def main():
45+
repos = fetch_repositories()
46+
content = generate_markdown(repos)
47+
48+
readme_path = Path(".profile/README.md")
49+
readme_path.parent.mkdir(parents=True, exist_ok=True)
50+
readme_path.write_text(content, encoding="utf-8")
51+
52+
if __name__ == "__main__":
53+
main()

0 commit comments

Comments
 (0)