Skip to content

Commit e41621e

Browse files
authored
tests
1 parent 37ca2b0 commit e41621e

File tree

8 files changed

+127
-2
lines changed

8 files changed

+127
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Fetch GitHub Sponsors
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
fetch-sponsors:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.x'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install requests
25+
26+
- name: Fetch GitHub Sponsors
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.SPONSORS_TOKEN }}
29+
run: python scripts/fetch-sponsors.py
30+
31+
- name: Configure Git
32+
run: |
33+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
34+
git config --local user.name "github-actions[bot]"
35+
36+
- name: Commit and Push Sponsors JSON
37+
run: |
38+
git add json/sponsors.json
39+
git commit -m "Update Sponsors" || true
40+
git push || true

docs/.vitepress/config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ export default defineConfig( {
55
title: 'MMRL',
66
locales: locales.locales,
77
sitemap: {
8-
hostname: 'https://mmrlapp.github.io'
8+
hostname: 'https://mmrl.dev'
99
},
10+
head: [
11+
[
12+
'script',
13+
{
14+
async: 'async',
15+
src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5042729416879007',
16+
crossorigin: 'anonymous',
17+
}
18+
],
19+
],
1020
})

docs/guide/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
:::warning
2+
The new website is still a work-in-progress!
3+
:::
4+
15
_Nothing to see here bro 🤓_

docs/home/repositories.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Some repositories don't use the MMRL Repo format. Those repositories may lack of
55
:::
66

77
<script setup>
8-
import data from '../repos.json'
8+
import data from '../public/repositories.json'
99
</script>
1010

1111
<table>

docs/public/Ads.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google.com, pub-5042729416879007, DIRECT, f08c47fec0942fa0

docs/public/api/sponsors.json

Whitespace-only changes.

scripts/fetch-sponsors.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import requests
2+
import json
3+
import os
4+
5+
GRAPHQL_URL = "https://api.github.com/graphql"
6+
7+
GRAPHQL_QUERY = """
8+
query {
9+
user(login: "DerGoogler") {
10+
sponsorshipsAsMaintainer(activeOnly: false, first: 100) {
11+
nodes {
12+
sponsorEntity {
13+
... on User {
14+
login
15+
avatarUrl
16+
url
17+
}
18+
... on Organization {
19+
login
20+
avatarUrl
21+
url
22+
}
23+
}
24+
tier {
25+
monthlyPriceInCents
26+
}
27+
}
28+
}
29+
}
30+
}
31+
"""
32+
33+
def fetch_sponsors(github_token):
34+
headers = {
35+
"Authorization": f"Bearer {github_token}",
36+
"Content-Type": "application/json"
37+
}
38+
39+
response = requests.post(GRAPHQL_URL, json={"query": GRAPHQL_QUERY}, headers=headers)
40+
response.raise_for_status()
41+
42+
return response.json()
43+
44+
def save_sponsors_to_file(sponsors_data, filename="json/sponsors.json"):
45+
print(sponsors_data)
46+
47+
sponsors = [
48+
{
49+
"login": node["sponsorEntity"]["login"],
50+
"avatarUrl": node["sponsorEntity"]["avatarUrl"],
51+
"url": node["sponsorEntity"]["url"],
52+
"amount": node["tier"]["monthlyPriceInCents"]
53+
}
54+
for node in sponsors_data["data"]["user"]["sponsorshipsAsMaintainer"]["nodes"]
55+
]
56+
57+
os.makedirs(os.path.dirname(filename), exist_ok=True)
58+
with open(filename, "w") as f:
59+
json.dump(sponsors, f, indent=2)
60+
61+
def main():
62+
github_token = os.getenv("GITHUB_TOKEN")
63+
if not github_token:
64+
raise ValueError("GitHub token is not set in environment variables")
65+
66+
sponsors_data = fetch_sponsors(github_token)
67+
save_sponsors_to_file(sponsors_data)
68+
69+
if __name__ == "__main__":
70+
main()

0 commit comments

Comments
 (0)