-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore(website): account for thanks.dev
donors in sponsors list
#10172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoshuaKGoldberg
merged 9 commits into
typescript-eslint:main
from
abrahamguo:generate-sponsors
Nov 4, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c3b9ef
clean up
abrahamguo 0c07457
finish
abrahamguo 660d154
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into g…
abrahamguo 708610d
extract extra variables
abrahamguo 68f5238
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into g…
abrahamguo 63b052f
Merge branch 'main' of github.com:abrahamguo/typescript-eslint into g…
abrahamguo d445ff7
add knip ignore
abrahamguo acff8d6
remove unnecessary nullish coalesce
abrahamguo 5e8c27c
Update tools/scripts/generate-sponsors.mts
JoshuaKGoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
packages/website/src/components/FinancialContributors/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
export interface SponsorData { | ||
description?: string; | ||
id: string; | ||
image: string; | ||
name: string; | ||
tier?: string; | ||
totalDonations: number; | ||
website?: string; | ||
website: string; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,98 +2,155 @@ import * as fs from 'node:fs'; | |
import * as path from 'node:path'; | ||
|
||
import fetch from 'cross-fetch'; | ||
import type { SponsorData } from 'website/src/components/FinancialContributors/types.ts'; | ||
|
||
import { PACKAGES_WEBSITE } from './paths.mts'; | ||
|
||
type MemberNodes = { | ||
account: { | ||
id: string; | ||
imageUrl: string; | ||
name: string; | ||
website: string; | ||
}; | ||
totalDonations: { valueInCents: number }; | ||
}[]; | ||
|
||
const excludedNames = new Set([ | ||
'Josh Goldberg', // Team member 💖 | ||
]); | ||
|
||
const filteredTerms = ['casino', 'deepnude', 'tiktok']; | ||
|
||
const { members } = ( | ||
(await ( | ||
await fetch('https://api.opencollective.com/graphql/v2', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
query: ` | ||
{ | ||
collective(slug: "typescript-eslint") { | ||
members(limit: 1000, role: BACKER) { | ||
nodes { | ||
account { | ||
id | ||
imageUrl | ||
name | ||
website | ||
} | ||
tier { | ||
amount { | ||
valueInCents | ||
} | ||
orders(limit: 100) { | ||
nodes { | ||
amount { | ||
valueInCents | ||
} | ||
} | ||
} | ||
} | ||
totalDonations { | ||
valueInCents | ||
} | ||
updatedAt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this attribute was unused in the response |
||
} | ||
const jsonApiFetch = async <T,>( | ||
api: string, | ||
options?: RequestInit, | ||
): Promise<T> => { | ||
const url = `https://api.${api}`; | ||
const response = await fetch(url, options); | ||
if (!response.ok) { | ||
abrahamguo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.error({ | ||
url, | ||
response: { status: response.status, body: await response.text() }, | ||
}); | ||
throw new Error('API call failed.'); | ||
} | ||
return (await response.json()) as T; | ||
}; | ||
|
||
const openCollectiveSponsorsPromise = jsonApiFetch<{ | ||
data: { | ||
collective: { | ||
members: { | ||
nodes: { | ||
account: { | ||
id: string; | ||
imageUrl: string; | ||
name: string; | ||
website: string | null; | ||
}; | ||
totalDonations: { valueInCents: number }; | ||
}[]; | ||
}; | ||
}; | ||
}; | ||
}>('opencollective.com/graphql/v2', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
query: ` | ||
{ | ||
collective(slug: "typescript-eslint") { | ||
members(limit: 1000, role: BACKER) { | ||
nodes { | ||
account { | ||
id | ||
imageUrl | ||
name | ||
website | ||
} | ||
totalDonations { | ||
valueInCents | ||
} | ||
} | ||
} | ||
`, | ||
}), | ||
}) | ||
).json()) as { data: { collective: { members: { nodes: MemberNodes } } } } | ||
).data.collective; | ||
} | ||
} | ||
`, | ||
}), | ||
}).then(({ data }) => { | ||
// TODO: remove polyfill in Node 22 | ||
const groupBy = <T,>( | ||
arr: T[], | ||
fn: (item: T) => string, | ||
): Record<string, T[]> => { | ||
const grouped: Record<string, T[]> = {}; | ||
for (const item of arr) { | ||
(grouped[fn(item)] ??= []).push(item); | ||
} | ||
return grouped; | ||
}; | ||
return Object.entries( | ||
groupBy( | ||
data.collective.members.nodes, | ||
({ account }) => account.name || account.id, | ||
), | ||
).flatMap(([id, members]) => { | ||
const [ | ||
{ | ||
account: { website, ...account }, | ||
}, | ||
] = members; | ||
return website | ||
? { | ||
id, | ||
image: account.imageUrl, | ||
name: account.name, | ||
totalDonations: members.reduce( | ||
(sum, { totalDonations }) => sum + totalDonations.valueInCents, | ||
0, | ||
), | ||
website, | ||
} | ||
: []; | ||
}); | ||
}); | ||
|
||
const sponsors = Object.entries( | ||
// TODO: use Object.groupBy in Node 22 | ||
members.nodes.reduce<Record<string, MemberNodes>>((membersById, member) => { | ||
const { account } = member; | ||
(membersById[account.name || account.id] ??= []).push(member); | ||
return membersById; | ||
}, {}), | ||
const thanksDevSponsorsPromise = jsonApiFetch< | ||
Record<'dependers' | 'donors', ['gh' | 'gl', string, number][]> | ||
>('thanks.dev/v1/vip/dependee/gh/typescript-eslint').then(async ({ donors }) => | ||
( | ||
await Promise.all( | ||
donors | ||
/* GitLab does not have an API to get a user's profile. At the time of writing, only 13% of donors | ||
from thanks.dev came from GitLab rather than GitHub, and none of them met the contribution | ||
threshold. */ | ||
.filter(([site]) => site === 'gh') | ||
.map(async ([, id, totalDonations]) => { | ||
const { name, ...github } = await jsonApiFetch< | ||
Record<'avatar_url' | 'blog', string> & { | ||
name: string | null; | ||
} | ||
>(`github.com/users/${id}`); | ||
return name | ||
? { | ||
id, | ||
image: github.avatar_url, | ||
name, | ||
totalDonations, | ||
website: github.blog || `https://github.com/${id}`, | ||
} | ||
: []; | ||
}), | ||
) | ||
).flat(), | ||
); | ||
|
||
const sponsors = ( | ||
await Promise.all<SponsorData[]>([ | ||
openCollectiveSponsorsPromise, | ||
thanksDevSponsorsPromise, | ||
]) | ||
) | ||
.map(([id, members]) => { | ||
const [{ account }] = members; | ||
return { | ||
id, | ||
image: account.imageUrl, | ||
name: account.name, | ||
totalDonations: members.reduce( | ||
(sum, { totalDonations }) => sum + totalDonations.valueInCents, | ||
0, | ||
), | ||
website: account.website, | ||
}; | ||
}) | ||
.flat() | ||
.filter( | ||
({ id, name, totalDonations, website }) => | ||
({ id, name, totalDonations }) => | ||
!( | ||
filteredTerms.some(filteredTerm => | ||
name.toLowerCase().includes(filteredTerm), | ||
) || | ||
excludedNames.has(id) || | ||
totalDonations < 10000 || | ||
!website | ||
totalDonations < 10000 | ||
), | ||
) | ||
.sort((a, b) => b.totalDonations - a.totalDonations); | ||
JoshuaKGoldberg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this attribute was unused in the response