Skip to content

Commit 5ac857e

Browse files
Merge pull request #99 from praliptarajoo/contributors-page
Contributors page
2 parents 4a58a8e + 9e51b01 commit 5ac857e

File tree

7 files changed

+181
-7
lines changed

7 files changed

+181
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
uses: actions/setup-node@v4
2222
with:
2323
node-version: 20
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2426

2527
- name: 'Install dependencies'
2628
run: npm install
@@ -32,6 +34,7 @@ jobs:
3234
run: |
3335
git restore src/app/projects/assets/upcomingProjects.json
3436
git restore src/app/projects/assets/projects.json
37+
git restore src/app/projects/assets/contributors.json
3538
3639
- name: 'Fetch branches'
3740
run: git fetch origin

src/app/contributors/page.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"use client";
2+
3+
import Link from "next/link";
4+
import React from "react";
5+
import github from "../../../public/images/social-media/github.png";
6+
import Image from "next/image";
7+
import contributorList from "../projects/assets/contributors.json";
8+
9+
const Contributors = () => {
10+
const contributorsArray = Object.values(contributorList);
11+
return (
12+
<>
13+
<section className='bg-slate-50'>
14+
<div className='container mx-auto text-center'>
15+
<h1 className='text-4xl leading-10 md:text-5xl md:!leading-[3.5rem] tracking-wide text-mindfire-text-black mt-10'>
16+
Our Contributors
17+
</h1>
18+
<p className='mt-6 text-xl text-mf-light-grey tracking-wide mb-10'>
19+
We’re a dynamic group of individuals who are passionate about what
20+
we do.
21+
</p>
22+
{contributorsArray ? (
23+
<div className='grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4'>
24+
{contributorsArray.map((contributor) => (
25+
<div
26+
key={contributor.id}
27+
className='bg-white border border-gray-200 rounded-lg shadow-lg transition-transform duration-300 transform hover:scale-105'
28+
>
29+
<div className='p-4'>
30+
<img
31+
className='w-24 h-24 mb-3 rounded-full shadow-lg mx-auto transition-transform duration-300 transform hover:scale-105'
32+
src={contributor.avatar_url}
33+
alt={`Contributor ${contributor.login}`}
34+
/>
35+
<h5 className='text-xl font-medium text-gray-900 text-center'>
36+
{contributor.login}
37+
</h5>
38+
<p className='text-sm text-gray-500 text-center'>
39+
Contributions: {contributor.contributions}
40+
</p>
41+
<div className='flex justify-center mt-4'>
42+
<Link href={contributor.html_url!} target='_blank'>
43+
<Image
44+
src={github}
45+
height={20}
46+
width={20}
47+
alt='github_img'
48+
/>
49+
</Link>
50+
</div>
51+
</div>
52+
</div>
53+
))}
54+
</div>
55+
) : (
56+
<div
57+
style={{
58+
display: "flex",
59+
justifyContent: "center",
60+
alignItems: "center",
61+
height: "50vh",
62+
}}
63+
>
64+
<p className='mt-6 text-xl text-mf-light-grey tracking-wide mb-10'>
65+
No records found!
66+
</p>
67+
</div>
68+
)}
69+
</div>
70+
</section>
71+
</>
72+
);
73+
};
74+
75+
export default Contributors;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"lakinmindfire": {
3+
"id": 80667930,
4+
"contributions": 116,
5+
"html_url": "https://github.com/lakinmindfire",
6+
"avatar_url": "https://avatars.githubusercontent.com/u/80667930?v=4",
7+
"login": "lakinmindfire"
8+
}
9+
}

src/app/projects/components/ProjectCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function ProjectCard({
3333
<div className='flex gap-4 justify-end mt-6 pt-6 border-t-2'>
3434
{githubUrl && githubUrl !== "NA" ? (
3535
<Link href={githubUrl!} target='_blank'>
36-
<Image src={github} height={20} width={20} alt='facebook_img' />
36+
<Image src={github} height={20} width={20} alt='github_img' />
3737
</Link>
3838
) : null}
3939
{documentationUrl && documentationUrl !== "NA" ? (

src/constants/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ const navigations: Navigation[] = [
2222
name: "Projects",
2323
path: ["/projects", "/current-projects", "/upcoming-projects"],
2424
},
25+
{
26+
name: "Contributors",
27+
path: ["/contributors"],
28+
},
2529
{
2630
name: "GitHub",
2731
path: ["https://github.com/mindfiredigital"],

tsconfig.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
"incremental": true,
1616
"plugins": [
1717
{
18-
"name": "next",
19-
},
18+
"name": "next"
19+
}
2020
],
2121
"paths": {
22-
"@/*": ["./src/*"],
23-
},
22+
"@/*": ["./src/*"]
23+
}
2424
},
2525
"include": [
2626
"next-env.d.ts",
2727
"**/*.ts",
2828
"**/*.tsx",
2929
".next/types/**/*.ts",
30-
"build/types/**/*.ts",
30+
"build/types/**/*.ts"
3131
],
32-
"exclude": ["node_modules"],
32+
"exclude": ["node_modules"]
3333
}

updateProject.mjs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,88 @@ async function getUpcomingProjects() {
122122
}
123123
}
124124

125+
//get list of contributors from github repo
126+
async function getContributorsList() {
127+
const githubApiUrl = "https://api.github.com/users/mindfiredigital/repos";
128+
const githubToken = process.env.GITHUB_TOKEN;
129+
130+
try {
131+
const github_response = await fetch(githubApiUrl, {
132+
method: "GET",
133+
headers: {
134+
Authorization: `token ${githubToken}`,
135+
Accept: "application/vnd.github.v3+json",
136+
},
137+
});
138+
139+
if (!github_response.ok) {
140+
throw new Error(
141+
`Failed to fetch repositories. Status: ${github_response.status}`
142+
);
143+
}
144+
const repositories = await github_response.json();
145+
const repoNames = repositories.map((repo) => repo.name);
146+
147+
const contributorsObject = {};
148+
for (const repoName of repoNames) {
149+
const repoContributorsUrl = `https://api.github.com/repos/mindfiredigital/${repoName}/contributors`;
150+
151+
const contributorsResponse = await fetch(repoContributorsUrl, {
152+
method: "GET",
153+
headers: {
154+
Authorization: `token ${githubToken}`,
155+
Accept: "application/vnd.github.v3+json",
156+
},
157+
});
158+
159+
if (!contributorsResponse.ok) {
160+
console.error(
161+
`Failed to fetch contributors for ${repoName}. Status: ${contributorsResponse.status}`
162+
);
163+
continue;
164+
}
165+
166+
const contributors = await contributorsResponse.json();
167+
contributorsObject[repoName] = contributors;
168+
}
169+
let contributionsMap = {};
170+
171+
for (let repo in contributorsObject) {
172+
contributorsObject[repo].forEach((contributor) => {
173+
const { login, contributions, id, avatar_url, html_url } = contributor;
174+
if (contributionsMap.hasOwnProperty(login)) {
175+
contributionsMap[login].contributions += contributions;
176+
} else {
177+
contributionsMap[login] = {
178+
id,
179+
contributions,
180+
html_url,
181+
avatar_url,
182+
login,
183+
};
184+
}
185+
});
186+
}
187+
let sortedContributions = Object.fromEntries(
188+
Object.entries(contributionsMap).sort(
189+
([, a], [, b]) => b.contributions - a.contributions
190+
)
191+
);
192+
193+
const projectsJsonPath = path.join(
194+
__dirname,
195+
"src/app/projects/assets/contributors.json"
196+
);
197+
198+
fs.writeFileSync(
199+
projectsJsonPath,
200+
JSON.stringify(sortedContributions, null, 2)
201+
);
202+
} catch (error) {
203+
console.log(error);
204+
}
205+
}
206+
125207
getCurrentProjects();
126208
getUpcomingProjects();
209+
getContributorsList();

0 commit comments

Comments
 (0)