Skip to content
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

chore: add thanks.dev #655

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions tools/fetch-sponsors.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ function getTierSlug(monthlyDonation) {

/**
* Fetch order data from Open Collective using the GraphQL API.
* @returns {Array} An array of sponsors.
* @returns {Promise<{sponsors: Array, donations: Array}>} An promise that resolves to an object with two properties:
* - `sponsors` (Array): List of sponsors
* - `donations` (Array): List of donations
*/
async function fetchOpenCollectiveData() {
const endpoint = "https://api.opencollective.com/graphql/v2";
Expand Down Expand Up @@ -205,7 +207,9 @@ async function fetchOpenCollectiveData() {

/**
* Fetches GitHub Sponsors data using the GraphQL API.
* @returns {Array} An array of sponsors.
* @returns {Promise<{sponsors: Array, donations: Array}>} An promise that resolves to an object with two properties:
* - `sponsors` (Array): List of sponsors
* - `donations` (Array): List of donations
*/
async function fetchGitHubSponsors() {
function sponsorshipsQuery(cursor = null) {
Expand Down Expand Up @@ -387,6 +391,57 @@ async function fetchGitHubSponsors() {
};
}

/**
* Fetches thanks.dev data using the REST API.
* @returns {Promise<{sponsors: Array}>} An promise that resolves to an object with one property:
* - `sponsors` (Array): List of sponsors
*/
async function fetchThanksDevData() {
const endpoint = "https://api.thanks.dev/v1/entity/gh/eslint/donors";

const { body: result } = await request(endpoint, {
method: "GET",
headers: { "Content-Type": "application/json" },
});

const payload = await result.json();

if (process.env.DEBUG) {
await fs.writeFile(
"./debug-thanksdev-raw-response.json",
JSON.stringify(payload, null, 4),
{ encoding: "utf8" },
);
}

const sponsors = Object.values(payload.donors).reduce(
amareshsm marked this conversation as resolved.
Show resolved Hide resolved
(accumulator, { name, login, avatar, url, payments }) => {
const lastPayment = payments.at(-1);

const paymentMonth = new Date(lastPayment.month).getMonth();
const currentMonth = new Date().getMonth();
amareshsm marked this conversation as resolved.
Show resolved Hide resolved

if (paymentMonth === currentMonth) {
accumulator.push({
name: name ?? login,
url: fixUrl(url),
image: avatar,
monthlyDonation: Number(lastPayment.amount),
source: "thanksdev",
tier: getTierSlug(lastPayment.amount),
});
}

return accumulator;
},
[],
);

return {
sponsors,
};
}

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Expand All @@ -402,6 +457,7 @@ async function fetchGitHubSponsors() {
] = await Promise.all([
fetchOpenCollectiveData(),
fetchGitHubSponsors(),
fetchThanksDevData(),
amareshsm marked this conversation as resolved.
Show resolved Hide resolved
fs
.readFile(blockedSponsorsFilename, { encoding: "utf8" })
.then(data => JSON.parse(data)),
Expand Down