|
| 1 | +--- |
| 2 | +const GITHUB_TOKEN = import.meta.env.GITHUB_TOKEN; |
| 3 | +
|
| 4 | +const gitHubQuery = `query { |
| 5 | + organization(login:"tauri-apps") { |
| 6 | + sponsors(first: 100) { |
| 7 | + nodes { |
| 8 | + ... on Actor { |
| 9 | + login, |
| 10 | + avatarUrl |
| 11 | + } |
| 12 | + } |
| 13 | + } |
| 14 | + } |
| 15 | +}`; |
| 16 | +
|
| 17 | +type Sponsor = { |
| 18 | + login: string; |
| 19 | + avatarUrl: string; |
| 20 | + amount?: number; |
| 21 | +}; |
| 22 | +
|
| 23 | +const gitHubSponsors: Sponsor[] = await fetch('https://api.github.com/graphql', { |
| 24 | + method: 'POST', |
| 25 | + body: JSON.stringify({ query: gitHubQuery }), |
| 26 | + headers: { |
| 27 | + "Authorization": `bearer ${GITHUB_TOKEN}` |
| 28 | + }, |
| 29 | +}).then(async (response) => { |
| 30 | + if (response.ok) { |
| 31 | + const data = await response.json(); |
| 32 | + return data.data.organization.sponsors.nodes; |
| 33 | + } |
| 34 | + throw Error( |
| 35 | + `There was an issue with the GitHub sponsors query: ${response.status}: ${response.statusText}` |
| 36 | + ); |
| 37 | +}); |
| 38 | +
|
| 39 | +// Documentation at https://graphql-docs-v2.opencollective.com/welcome |
| 40 | +const openCollectiveQuery = `query account { |
| 41 | + account(slug: "tauri") { |
| 42 | + transactions(kind: CONTRIBUTION) { |
| 43 | + nodes { |
| 44 | + fromAccount { |
| 45 | + name |
| 46 | + imageUrl |
| 47 | + } |
| 48 | + amount { |
| 49 | + value |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +}`; |
| 55 | +
|
| 56 | +const openCollectiveSponsors: Sponsor[] = await fetch('https://api.opencollective.com/graphql/v2', { |
| 57 | + method: 'POST', |
| 58 | + body: JSON.stringify({ query: openCollectiveQuery }), |
| 59 | + headers: { |
| 60 | + 'Content-Type': 'application/json', |
| 61 | + }, |
| 62 | +}).then(async (response) => { |
| 63 | + if (response.ok) { |
| 64 | + const data = await response.json(); |
| 65 | + return data.data.account.transactions.nodes.map( |
| 66 | + (node: any) => ({ |
| 67 | + login: node.fromAccount.name, |
| 68 | + avatarUrl: node.fromAccount.imageUrl, |
| 69 | + amount: node.amount.value |
| 70 | + }) |
| 71 | + ); |
| 72 | + } |
| 73 | + throw Error( |
| 74 | + `There was an issue with the Open Collective sponsors query: ${response.status} ${response.statusText}` |
| 75 | + ); |
| 76 | +}); |
| 77 | +
|
| 78 | +// TODO: Need to loop over the Open Collective array to merge them based on the login and sum up the amount value (then sort by amount largest to smallest) |
| 79 | +--- |
| 80 | + |
| 81 | +<h1>Sponsors</h1> |
| 82 | +<h2>Open Collective</h2> |
| 83 | +<ul> |
| 84 | + {openCollectiveSponsors.map((sponsor) => <li>{sponsor.login}</li>)} |
| 85 | +</ul> |
| 86 | +<h2>GitHub</h2> |
| 87 | +<ul> |
| 88 | + {gitHubSponsors.map((sponsor) => <li>{sponsor.login}</li>)} |
| 89 | +</ul> |
| 90 | + |
0 commit comments