Skip to content

Commit

Permalink
feat(#53): created github:getUserSponsorList query
Browse files Browse the repository at this point in the history
  • Loading branch information
sametcodes committed Apr 7, 2023
1 parent 9ccabd3 commit b08caea
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 1 deletion.
40 changes: 40 additions & 0 deletions platforms/github/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,43 @@ export const getContributors: QueryService = async (connection, config) => {
const response = await request(query, connection);
return response;
};

/**
* @name getUserSponsorList
* @title Get list of sponsors of a user
* @query_type Public
* @cache_time 3600
* @description Get the list of contributors of a repository. Only the most contributed 100 contributors are returned.
*/
export const getUserSponsorList: QueryService = async (connection, config) => {
const { queryConfig } = config as any;
const { username } = queryConfig as { username: string };

const query = `{
user(login: "${username}") {
sponsorshipsAsMaintainer(first: 100) {
totalCount
nodes {
sponsorEntity {
... on User {
login
name
avatarUrl
}
... on Organization {
login
name
avatarUrl
}
}
}
}
}
}`;

const response = await request(query, connection);
if (response.data.user.sponsorshipsAsMaintainer.totalCount === 0) {
throw new Error("You must have at least one sponsor to use this query.");
}
return response;
};
10 changes: 10 additions & 0 deletions platforms/github/query/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ export const getContributors = object({
})
.required()
.noUnknown(true);

export const getUserSponsorList = object({
username: string().required().meta({
label: "Username",
placeholder: "Username",
description: "The username of the profile, do not include the @ symbol.",
}),
})
.required()
.noUnknown(true);
44 changes: 44 additions & 0 deletions platforms/github/view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,47 @@ export const getContributors: ViewComponent = async (result, config) => {
/>
);
};

export const getUserSponsorList: ViewComponent = async (result, config) => {
const { title, subtitle, items_per_row } = config.viewConfig as any;

const { nodes: sponsors } = result.data.user.sponsorshipsAsMaintainer;

const promise_thumbnails: IFlock["members"] = sponsors.map(
async (sponsor: any, key: number) => {
const url = new URL(sponsor.sponsorEntity.avatarUrl);
let params = qs.parse(url.search, { ignoreQueryPrefix: true });
url.search = qs.stringify({ ...params, s: "128" });

const response = await fetch(url.toString());
const arrayBuffer = await response.arrayBuffer();

const buffer = Buffer.from(arrayBuffer);
const imageData = getImageSize(buffer);

return {
value: buffer.toString("base64"),
width: imageData.width,
height: imageData.height,
};
}
);

const thumbnails = await Promise.all(promise_thumbnails);

const members: IFlock["members"] = sponsors.map(
(sponsor: any, key: number) => ({
image: thumbnails[key],
caption: sponsor.sponsorEntity.login,
})
);

return (
<Flock
title={title}
subtitle={subtitle}
items_per_row={items_per_row}
members={members}
/>
);
};
63 changes: 62 additions & 1 deletion platforms/github/view/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,68 @@ export const getContributors = {
config: {
viewConfig: {
title: "Our contributors",
subtitle: "We are grateful to all of our contributors",
subtitle: "We are grateful.",
items_per_row: 20,
},
},
};

export const getUserSponsorList = {
result: {
data: {
user: {
sponsorshipsAsMaintainer: {
totalCount: 5,
nodes: [
{
sponsorEntity: {
login: "eserozvataf",
name: "Eser Ozvataf",
avatarUrl:
"https://avatars.githubusercontent.com/u/866558?u=b22a39f91f830670029edf4a75a4917d167e3477&v=4",
},
},
{
sponsorEntity: {
login: "MrPeker",
name: "Mehmet Ali Peker",
avatarUrl:
"https://avatars.githubusercontent.com/u/23459375?u=a134e27718baa73c41da5534b6d02b10bc88065a&v=4",
},
},
{
sponsorEntity: {
login: "ImYrS",
name: "秋酿",
avatarUrl:
"https://avatars.githubusercontent.com/u/44287632?u=9685045ebfa4354c434053ee5e527b106ee59d34&v=4",
},
},
{
sponsorEntity: {
login: "LydiaMorris",
name: "XavierMTest",
avatarUrl:
"https://avatars.githubusercontent.com/u/50951276?v=4",
},
},
{
sponsorEntity: {
login: "frankenslime",
name: "Garret",
avatarUrl:
"https://avatars.githubusercontent.com/u/124593259?v=4",
},
},
],
},
},
},
},
config: {
viewConfig: {
title: "Sponsors",
subtitle: "Thank you for sponsoring me.",
items_per_row: 20,
},
},
Expand Down
20 changes: 20 additions & 0 deletions platforms/github/view/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,23 @@ export const getContributors = object({
})
.required()
.noUnknown(true);

export const getUserSponsorList = object({
title: string().meta({
label: "Title",
placeholder: "Title",
description: "Title of the widget",
}),
subtitle: string().meta({
label: "Subtitle",
placeholder: "Subtitle",
description: "Subtitle of the widget",
}),
items_per_row: number().min(5).max(25).default(20).meta({
label: "Items per row",
placeholder: "Items per row",
description: "Number of items per row. Default is 20.",
}),
})
.required()
.noUnknown(true);

0 comments on commit b08caea

Please sign in to comment.