diff --git a/lib/github.ts b/lib/github.ts index f5bd567..4ed77d0 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -70,3 +70,25 @@ async function fetchIssues(args: { } return GitHubIssueResponseSchema.parse(await resp.json()); } + +export async function fetchGitHubMembers(token: string, organization: string) { + const response = await fetch(`https://api.github.com/orgs/${organization}/members`, { + headers: { + Authorization: `token ${token}`, + Accept: 'application/vnd.github.v3+json', + }, + }); + + + if (!response.ok) { + throw new Error(`GitHub API request failed with status ${response.status}`); + } + + const members = await response.json(); + + return members.map((member: any) => ({ + fullName: member.login, + imageUrl: member.avatar_url, + profileUrl: member.html_url, + })); +} diff --git a/routes/index.tsx b/routes/index.tsx index 1138f01..999a1b6 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -1,18 +1,23 @@ -import { assert } from "$std/_util/asserts.ts"; -import { JSX } from "preact"; +import { assert } from '$std/_util/asserts.ts' +import { JSX } from 'preact' -export default function Home() { - const ghToken = Deno.env.get("GITHUB_TOKEN"); - assert(ghToken); +import { fetchGitHubMembers } from '../lib/github.ts' + +export default async function Home() { + const ghToken = Deno.env.get('GITHUB_TOKEN') + assert(ghToken) + + const org = 'devict' + + const contributors = await fetchGitHubMembers(ghToken, org) return (

- devICT is a volunteer-run community aiming to{" "} - educate, empower and connect{" "} - software developers and technologists in the{" "} - Wichita, KS area. + devICT is a volunteer-run community aiming to{' '} + educate, empower and connect software developers and + technologists in the Wichita, KS area.


@@ -26,25 +31,23 @@ export default function Home() { {[ { title: `Build Skills`, - content: - `Working on real-world projects exposes you to new technologies and best practices.`, + content: `Working on real-world projects exposes you to new technologies and best practices.`, }, { title: `Portfolio Building`, - content: - `Your contributions get recorded on GitHub, providing tangible proof of your skills.`, + content: `Your contributions get recorded on GitHub, providing tangible proof of your skills.`, }, { title: `Learning and Networking`, - content: - `Interacting with the community offers immense learning opportunities and widens your professional network.`, + content: `Interacting with the community offers immense learning opportunities and widens your professional network.`, }, { title: `Giving Back`, - content: - `By contributing, you help grow the local tech scene and create a richer environment for everyone involved.`, + content: `By contributing, you help grow the local tech scene and create a richer environment for everyone involved.`, }, - ].map((card) => )} + ].map((card) => ( + + ))}

How You Can Contribute

@@ -54,61 +57,79 @@ export default function Home() { title: `Join the Conversation`, content: ( <> - Join us{" "} + Join us{' '} in Slack - {" "} + {' '} and jump into the conversation! Share what you're working on, asking questions, and help others. ), }, { - title: "Contribute with Code", + title: 'Contribute with Code', content: ( <> - Browse our{" "} - active projects, - find an issue that interests you, and jump right in! + Browse our{' '} + + active projects + + , find an issue that interests you, and jump right in! ), }, { - title: "Contribute without Code", + title: 'Contribute without Code', content: ( <> Help us with documentation, design, or outreach efforts. Add - clarity by asking questions on{" "} - existing issues, - or contribute your ideas by filing new ones. + clarity by asking questions on{' '} + + existing issues + + , or contribute your ideas by filing new ones. ), }, { title: `Give a Talk or Workshop`, - content: - `Share your knowledge and experience in a lightning talk or more comprehensive sessions.`, + content: `Share your knowledge and experience in a lightning talk or more comprehensive sessions.`, }, { title: `Financial Support`, - content: - `Donations help us keep the lights on and fund community events. Every bit counts!`, + content: `Donations help us keep the lights on and fund community events. Every bit counts!`, }, { title: `Unique Contributions`, - content: - `Have a unique idea or skillset? We're all ears! Reach out to propose new ways to contribute.`, + content: `Have a unique idea or skillset? We're all ears! Reach out to propose new ways to contribute.`, }, - ].map((card) => )} + ].map((card) => ( + + ))} +
+

Contributors

+ +
+ {contributors.map((contributor) => ( +
+ +
+ ))}
- ); + ) } type CardProps = { - title: string; - content: string | JSX.Element; -}; + title: string + content: string | JSX.Element +} + +type ContributorsProps = { + fullName: string + imageUrl: string + profileUrl: string +} function Card({ title, content }: CardProps) { return ( @@ -116,5 +137,20 @@ function Card({ title, content }: CardProps) {

{title}

{content}

- ); + ) +} + +function Contributor({ fullName, imageUrl, profileUrl }: ContributorsProps) { + return ( + +
+ {fullName} +

{fullName}

+
+
+ ) } -- 2.54.0 From e284f6e2d48948733ba7c5aa9695c67c4e833509 Mon Sep 17 00:00:00 2001 From: Manish Paudel Date: Mon, 23 Oct 2023 20:15:26 -0500 Subject: [PATCH 2/3] added repo contributors --- lib/github.ts | 55 +++++++++++++++++++++++++++++++++--------------- routes/index.tsx | 38 ++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/lib/github.ts b/lib/github.ts index 4ed77d0..5f13fd8 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -71,24 +71,45 @@ async function fetchIssues(args: { return GitHubIssueResponseSchema.parse(await resp.json()); } -export async function fetchGitHubMembers(token: string, organization: string) { - const response = await fetch(`https://api.github.com/orgs/${organization}/members`, { - headers: { - Authorization: `token ${token}`, - Accept: 'application/vnd.github.v3+json', - }, - }); - +interface IContributor { + login: string; + avatar_url: string; + html_url: string; +} + +export async function fetchGitHubContributors(token: string, repos: string[]) { + const allContributors: IContributor[] = []; + const contributorsMap = new Map(); + + for (const repo of repos) { + const response = await fetch(`https://api.github.com/repos/${repo}/contributors`, { + headers: { + Authorization: `token ${token}`, + Accept: 'application/vnd.github.v3+json', + }, + }); - if (!response.ok) { - throw new Error(`GitHub API request failed with status ${response.status}`); + if (!response.ok) { + throw new Error(`GitHub API request failed with status ${response.status}`); + } + + const contributors = await response.json(); + + for (const contributor of contributors) { + const contributorData: IContributor = { + login: contributor.login, + avatar_url: contributor.avatar_url, + html_url: contributor.html_url, + }; + + if (!contributorsMap.has(contributor.login)) { + contributorsMap.set(contributor.login, contributorData); + } + } } - const members = await response.json(); - return members.map((member: any) => ({ - fullName: member.login, - imageUrl: member.avatar_url, - profileUrl: member.html_url, - })); -} + allContributors.push(...contributorsMap.values()); + + return allContributors; +} \ No newline at end of file diff --git a/routes/index.tsx b/routes/index.tsx index 999a1b6..c57fada 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -1,15 +1,20 @@ import { assert } from '$std/_util/asserts.ts' import { JSX } from 'preact' +import { fetchGitHubContributors, fetchGitHubMembers } from '../lib/github.ts' -import { fetchGitHubMembers } from '../lib/github.ts' +const DEVICT_REPOS: string[] = [ + 'devict/job-board', + 'devict/devict.org', + 'devict/keeper', + 'devict/hacktoberfest', + 'devict/help', +] export default async function Home() { const ghToken = Deno.env.get('GITHUB_TOKEN') assert(ghToken) - const org = 'devict' - - const contributors = await fetchGitHubMembers(ghToken, org) + const contributors = await fetchGitHubContributors(ghToken, DEVICT_REPOS) return (
@@ -109,7 +114,7 @@ export default async function Home() {

Contributors

-
+
{contributors.map((contributor) => (
@@ -126,9 +131,9 @@ type CardProps = { } type ContributorsProps = { - fullName: string - imageUrl: string - profileUrl: string + login: string + avatar_url: string + html_url: string } function Card({ title, content }: CardProps) { @@ -140,16 +145,15 @@ function Card({ title, content }: CardProps) { ) } -function Contributor({ fullName, imageUrl, profileUrl }: ContributorsProps) { +function Contributor({ login, avatar_url, html_url }: ContributorsProps) { return ( - -
- {fullName} -

{fullName}

+
+
+ {login} +

{login}

) -- 2.54.0 From 7f9a45dc4edb8d9972e9af673a02d09275e4991a Mon Sep 17 00:00:00 2001 From: Seth Etter <655500+sethetter@users.noreply.github.com> Date: Wed, 25 Oct 2023 08:06:41 -0500 Subject: [PATCH 3/3] Update lib/github.ts --- lib/github.ts | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/github.ts b/lib/github.ts index 5f13fd8..b9734f5 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -92,19 +92,39 @@ export async function fetchGitHubContributors(token: string, repos: string[]) { if (!response.ok) { throw new Error(`GitHub API request failed with status ${response.status}`); } + let contributors = await Promise.all( + repos.map(async (repo) => { + const response = await fetch( + `https://api.github.com/repos/${repo}/contributors`, + { + headers: { + Authorization: `token ${token}`, + Accept: "application/vnd.github.v3+json", + }, + }, + ); - const contributors = await response.json(); + if (!response.ok) { + throw new Error( + `GitHub API request failed with status ${response.status}`, + ); + } - for (const contributor of contributors) { - const contributorData: IContributor = { - login: contributor.login, - avatar_url: contributor.avatar_url, - html_url: contributor.html_url, - }; + return response.json(); + }), + ); - if (!contributorsMap.has(contributor.login)) { - contributorsMap.set(contributor.login, contributorData); - } + contributors = contributors.flat(); + + for (const contributor of contributors) { + const contributorData: IContributor = { + login: contributor.login, + avatar_url: contributor.avatar_url, + html_url: contributor.html_url, + }; + + if (!contributorsMap.has(contributor.login)) { + contributorsMap.set(contributor.login, contributorData); } }