Skip to content

Commit 84d6abf

Browse files
authored
[skip ci] Update fetch-sponsors.py
1 parent 7ea55b3 commit 84d6abf

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

scripts/fetch-sponsors.py

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,30 @@
66
GRAPHQL_URL = "https://api.github.com/graphql"
77

88
GRAPHQL_QUERY = """
9-
query($org: String!) {
10-
organization(login: $org) {
11-
sponsorshipsAsMaintainer(activeOnly: false, first: 100) {
9+
query($login: String!) {
10+
user(login: $login) {
11+
sponsorshipsAsMaintainer(activeOnly: false, first: 100) {
12+
nodes {
13+
sponsorEntity {
14+
... on User {
15+
login
16+
avatarUrl
17+
url
18+
}
19+
... on Organization {
20+
login
21+
avatarUrl
22+
url
23+
}
24+
}
25+
tier {
26+
monthlyPriceInCents
27+
}
28+
}
29+
}
30+
}
31+
organization(login: $login) {
32+
sponsorshipsAsMaintainer(activeOnly: false, first: 100) {
1233
nodes {
1334
sponsorEntity {
1435
... on User {
@@ -31,15 +52,15 @@
3152
}
3253
"""
3354

34-
def fetch_sponsors(github_token, org):
55+
def fetch_sponsors(github_token, login):
3556
headers = {
3657
"Authorization": f"Bearer {github_token}",
3758
"Content-Type": "application/json"
3859
}
3960

4061
response = requests.post(
4162
GRAPHQL_URL,
42-
json={"query": GRAPHQL_QUERY, "variables": {"org": org}},
63+
json={"query": GRAPHQL_QUERY, "variables": {"login": login}},
4364
headers=headers
4465
)
4566
response.raise_for_status()
@@ -58,35 +79,38 @@ def merge_sponsors(sponsors_list):
5879
return list({"login": k, **v} for k, v in sponsors_dict.items())
5980

6081
def extract_sponsors(data):
61-
org_data = data.get("data", {}).get("organization", {})
62-
if not org_data:
63-
return []
64-
65-
sponsorships = org_data.get("sponsorshipsAsMaintainer", {})
66-
if not sponsorships:
67-
return []
68-
69-
nodes = sponsorships.get("nodes", [])
70-
return [
71-
{
72-
"login": node["sponsorEntity"]["login"],
73-
"avatarUrl": node["sponsorEntity"]["avatarUrl"],
74-
"url": node["sponsorEntity"]["url"],
75-
"amount": node["tier"]["monthlyPriceInCents"]
76-
}
77-
for node in nodes if "sponsorEntity" in node and "tier" in node
78-
]
82+
sponsors = []
83+
for key in ["user", "organization"]:
84+
entity = data.get("data", {}).get(key, {})
85+
if not entity:
86+
continue
87+
88+
sponsorships = entity.get("sponsorshipsAsMaintainer", {})
89+
if not sponsorships:
90+
continue
91+
92+
nodes = sponsorships.get("nodes", [])
93+
sponsors.extend([
94+
{
95+
"login": node["sponsorEntity"]["login"],
96+
"avatarUrl": node["sponsorEntity"]["avatarUrl"],
97+
"url": node["sponsorEntity"]["url"],
98+
"amount": node["tier"]["monthlyPriceInCents"]
99+
}
100+
for node in nodes if "sponsorEntity" in node and "tier" in node
101+
])
102+
return sponsors
79103

80104
def main():
81105
github_token = os.getenv("SPONSORS_TOKEN")
82106
if not github_token:
83107
raise ValueError("GitHub token is not set in environment variables")
84108

85-
orgs = ["MMRLApp", "DerGoogler"]
109+
logins = ["MMRLApp", "DerGoogler"]
86110
all_sponsors = []
87111

88-
for org in orgs:
89-
sponsors_data = fetch_sponsors(github_token, org)
112+
for login in logins:
113+
sponsors_data = fetch_sponsors(github_token, login)
90114
sponsors = extract_sponsors(sponsors_data)
91115
all_sponsors.extend(sponsors)
92116

0 commit comments

Comments
 (0)