Skip to content

Commit 2a30854

Browse files
committed
feat: Generate member list (#3133)
1 parent 14aac5d commit 2a30854

File tree

5 files changed

+7
-111
lines changed

5 files changed

+7
-111
lines changed

.github/workflows/build-pr.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ jobs:
7272
continue-on-error: false
7373
privileged: ${{ fromJSON(needs.metadata.outputs.privileged) }}
7474
strict: true
75-
secrets:
76-
RO_DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
7775

7876
build_i18n:
7977
if: ${{ contains(github.event.pull_request.labels.*.name, 'ci:build i18n') }}
@@ -108,8 +106,6 @@ jobs:
108106
with:
109107
ref: ${{github.event.pull_request.head.ref}}
110108
repo: ${{github.event.pull_request.head.repo.full_name}}
111-
secrets:
112-
RO_DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
113109

114110
combine_build:
115111
needs: [build_english, build_i18n, build_blog]

.github/workflows/build-zimfile.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ on:
99
repo:
1010
required: true
1111
type: string
12-
secrets:
13-
RO_DISCOURSE_API_KEY:
14-
required: false
1512

1613
permissions:
1714
contents: read
@@ -82,8 +79,6 @@ jobs:
8279
8380
- name: Generate Donating Members List
8481
continue-on-error: true
85-
env:
86-
DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
8782
run: |
8883
pip install requests
8984
python tools/generate-members.py > includes/members.md
@@ -222,8 +217,6 @@ jobs:
222217
223218
- name: Generate Donating Members List
224219
continue-on-error: true
225-
env:
226-
DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
227220
run: |
228221
pip install requests
229222
python tools/generate-members.py > includes/members.md
@@ -471,8 +464,6 @@ jobs:
471464
472465
- name: Generate Donating Members List
473466
continue-on-error: true
474-
env:
475-
DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
476467
run: |
477468
pip install requests
478469
python tools/generate-members.py > includes/members.md

.github/workflows/build.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ on:
3030
cache:
3131
type: boolean
3232
default: true
33-
secrets:
34-
RO_DISCOURSE_API_KEY:
35-
required: false
3633

3734
permissions:
3835
contents: read
@@ -176,8 +173,6 @@ jobs:
176173
177174
- name: Generate Donating Members List
178175
continue-on-error: true
179-
env:
180-
DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
181176
run: |
182177
pip install requests
183178
python tools/generate-members.py > includes/members.md

.github/workflows/publish-release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ jobs:
6363
context: production
6464
continue-on-error: false
6565
cache: false
66-
secrets:
67-
RO_DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
6866

6967
build_blog:
7068
needs: submodule
@@ -85,8 +83,6 @@ jobs:
8583
with:
8684
repo: ${{ github.repository }}
8785
ref: ${{ github.ref }}
88-
secrets:
89-
RO_DISCOURSE_API_KEY: ${{ secrets.RO_DISCOURSE_API_KEY }}
9086

9187
release:
9288
name: Create release notes

tools/generate-members.py

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,20 @@
11
import requests
22
import os
33

4-
GITHUB_API_URL = "https://api.github.com/graphql"
5-
GITHUB_TOKEN = os.getenv("GH_TOKEN")
6-
ORG_NAME = "privacyguides"
7-
84
# Fetch members from the API
9-
members_api_url = "https://discuss.privacyguides.net/g/members/members.json?offset=0&order=added_at&asc=true"
10-
headers = {
11-
"Api-Key": os.getenv("DISCOURSE_API_KEY"),
12-
"Api-Username": "system"
13-
}
14-
members_response = requests.get(members_api_url, headers=headers)
15-
members_data = members_response.json()
16-
17-
if 'members' not in members_data:
18-
raise KeyError("Response JSON does not contain 'members' key")
5+
members_api_url = os.getenv('MEMBERS_API_URL', 'https://ghost.privacyguides.org/cache/members.json')
6+
members_response = requests.get(members_api_url)
7+
members_data = members_response.json()[0]
198

209
members = members_data['members']
21-
public_members_count = 0
22-
private_members_count = 0
2310

2411
html_output = ""
2512
for member in members:
26-
flair_name = member.get('flair_name')
27-
title = member.get('title')
28-
if flair_name == "members" or title == "Member":
29-
username = member['username']
30-
avatar_template = member['avatar_template']
31-
avatar_url = f"https://discuss.privacyguides.net{avatar_template.replace('{size}', '128')}"
32-
profile_url = f"https://discuss.privacyguides.net/u/{username}"
33-
html_output += f'<a href="{profile_url}" target="_blank" title="@{username}" class="mdx-donors__item"><img loading="lazy" src="{avatar_url}"></a>'
34-
public_members_count += 1
35-
36-
# print(html_output)
37-
38-
query = """
39-
{
40-
organization(login: "%s") {
41-
sponsorshipsAsMaintainer(first: 100) {
42-
nodes {
43-
sponsorEntity {
44-
... on User {
45-
login
46-
avatarUrl
47-
url
48-
}
49-
... on Organization {
50-
login
51-
avatarUrl
52-
url
53-
}
54-
}
55-
createdAt
56-
}
57-
}
58-
}
59-
}
60-
""" % ORG_NAME
61-
62-
headers = {
63-
"Authorization": f"Bearer {GITHUB_TOKEN}",
64-
"Content-Type": "application/json"
65-
}
66-
67-
response = requests.post(GITHUB_API_URL, json={'query': query}, headers=headers)
68-
data = response.json()
69-
70-
if 'errors' in data:
71-
raise Exception(f"GraphQL query failed with errors: {data['errors']}")
72-
if 'data' not in data:
73-
raise KeyError(f"Response JSON does not contain 'data' key: {data}")
74-
75-
sponsors = data['data']['organization']['sponsorshipsAsMaintainer']['nodes']
76-
77-
# Sort sponsors by the date they began their sponsorship
78-
sponsors.sort(key=lambda x: x['createdAt'])
79-
80-
for sponsor in sponsors:
81-
sponsor_entity = sponsor['sponsorEntity']
82-
login = sponsor_entity['login']
83-
avatar_url = sponsor_entity['avatarUrl']
84-
url = sponsor_entity['url']
85-
html_output += f'<a href="{url}" title="@{login}" rel="ugc nofollow" target="_blank" class="mdx-donors__item"><img loading="lazy" src="{avatar_url}&size=120"></a>'
86-
87-
# Fetch the number of active members from the Magic Grants API
88-
magic_grants_url = "https://donate.magicgrants.org/api/active-members?fund=privacyguides"
89-
magic_grants_response = requests.get(magic_grants_url)
90-
magic_grants_data = magic_grants_response.json()
91-
92-
if 'members_count' not in magic_grants_data:
93-
raise KeyError("Response JSON does not contain 'members_count' key")
94-
95-
private_members_count += magic_grants_data['members_count']
96-
private_members_count -= public_members_count
13+
username = member['username']
14+
html_output += f'<a href="{member['url']}" target="_blank" title="@{member['username']}" class="mdx-donors__item"><img loading="lazy" src="{member['avatar']}"></a>'
9715

9816
# Append the count of private members
99-
if private_members_count > 0:
100-
html_output += f'<a href="https://donate.magicgrants.org/privacyguides" class="mdx-donors__item mdx-donors__item--private">+{private_members_count}</a>'
17+
if members_data['unaccounted'] > 0:
18+
html_output += f'<a href="https://donate.magicgrants.org/privacyguides" class="mdx-donors__item mdx-donors__item--private">+{members_data["unaccounted"]}</a>'
10119

10220
print(html_output)

0 commit comments

Comments
 (0)