From 223af1068bd170ecc95f0cd6d8bde25055b23239 Mon Sep 17 00:00:00 2001 From: Madhav Dua Date: Sun, 30 Jun 2024 02:09:44 +0530 Subject: [PATCH 1/3] created contribution detail page --- src/pages/contributor/ContributorCard.jsx | 8 ++- src/pages/contributor/ContributorDetail.jsx | 74 +++++++++++++++++++-- src/pages/contributor/Contributors.jsx | 9 +-- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/src/pages/contributor/ContributorCard.jsx b/src/pages/contributor/ContributorCard.jsx index d60d3d0..429d999 100644 --- a/src/pages/contributor/ContributorCard.jsx +++ b/src/pages/contributor/ContributorCard.jsx @@ -2,7 +2,8 @@ import React from 'react' import { Link } from 'react-router-dom'; function ContributorCard(props) { - const { name, img } = props; + const { name, img,contributions } = props; + return ( <> @@ -11,7 +12,10 @@ function ContributorCard(props) { ...
{name}
- Get Details + { + localStorage.setItem('contributorName',name); + localStorage.setItem('contributions',contributions); + }} >Get Details
diff --git a/src/pages/contributor/ContributorDetail.jsx b/src/pages/contributor/ContributorDetail.jsx index 6ce20f5..6a70db7 100644 --- a/src/pages/contributor/ContributorDetail.jsx +++ b/src/pages/contributor/ContributorDetail.jsx @@ -1,10 +1,74 @@ -import React from 'react' +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; + +function ContributorDetail(props) { + + const contributorName=localStorage.getItem('contributorName'); + + const [mergedPRs, setMergedPRs] = useState([]); + const [error, setError] = useState(null); + + const owner = 'Avdhesh-Varshney'; // Replace with actual owner username/organization + const repo = 'chanakya-niti'; // Replace with actual repo name + const contributor_username = contributorName; // Replace with contributor username + + const fetchMergedPRs = async () => { + try { + const baseUrl = 'https://api.github.com'; + const url = `${baseUrl}/repos/${owner}/${repo}/pulls?state=closed&author=${contributor_username}`; + + const response = await axios.get(url); + let data = response.data; + const arr = await data.filter((pr) => { + return pr.user.login === `${contributorName}` && pr.merged_at != null; + + }) + setMergedPRs(arr); + } catch (error) { + setError(error); + console.error('Error fetching merged PRs:', error); + } + }; + useEffect(() => { + fetchMergedPRs(); + }, []) -function ContributorDetail() { return ( -
- Contributor Detail Page -
+ <> + {mergedPRs.length > 0 && +
+
+
+ ... +
+
{contributorName}
+
+ No of contributions : {localStorage.getItem('contributions')} +
+ + +
+
+
+
+ { + mergedPRs.map((element)=>{ + return

PR No. {element.number}

+ + }) + } +
+
+ } + { + mergedPRs.length < 1 &&
+ Sorry not merged prs available +
+ } + + ) } diff --git a/src/pages/contributor/Contributors.jsx b/src/pages/contributor/Contributors.jsx index ea71732..b0d42db 100644 --- a/src/pages/contributor/Contributors.jsx +++ b/src/pages/contributor/Contributors.jsx @@ -3,11 +3,12 @@ import { useEffect, useState } from 'react' import axios from 'axios' import ContributorCard from './ContributorCard' -const Contributors = () => { - +const Contributors = (props) => { const [data, setdata] = useState([]) useEffect(() => { getContributor(); + localStorage.setItem('contributorName',''); + localStorage.setItem('contributions',''); }, []) @@ -15,7 +16,7 @@ const Contributors = () => { await axios.get('https://api.github.com/repos/Avdhesh-Varshney/chanakya-niti/contributors') .then(function (response) { setdata(response.data); - // console.log(response.data); + // console.log(data); }) .catch(function (error) { console.log(error); @@ -33,7 +34,7 @@ const Contributors = () => { { data.map((element) => { return
- +
}) } From b3bbaf91090da4bdde4ae29a7665f18e6e6b0d2c Mon Sep 17 00:00:00 2001 From: Madhav Dua Date: Mon, 1 Jul 2024 23:15:43 +0530 Subject: [PATCH 2/3] Made changes as asked to --- src/pages/contributor/ContributorDetail.jsx | 43 +++++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/pages/contributor/ContributorDetail.jsx b/src/pages/contributor/ContributorDetail.jsx index 6a70db7..c1af882 100644 --- a/src/pages/contributor/ContributorDetail.jsx +++ b/src/pages/contributor/ContributorDetail.jsx @@ -3,7 +3,7 @@ import axios from 'axios'; function ContributorDetail(props) { - const contributorName=localStorage.getItem('contributorName'); + const contributorName = localStorage.getItem('contributorName'); const [mergedPRs, setMergedPRs] = useState([]); const [error, setError] = useState(null); @@ -24,6 +24,7 @@ function ContributorDetail(props) { }) setMergedPRs(arr); + // console.log(arr); } catch (error) { setError(error); console.error('Error fetching merged PRs:', error); @@ -36,9 +37,9 @@ function ContributorDetail(props) { return ( <> {mergedPRs.length > 0 && -
+
-
+
...
{contributorName}
@@ -46,20 +47,38 @@ function ContributorDetail(props) { No of contributions : {localStorage.getItem('contributions')}
- +
-
- { - mergedPRs.map((element)=>{ - return

PR No. {element.number}

+ { + mergedPRs.map((element) => { + return
+
+ #{element.number} +
+
+
Title: {element.title}
+
+

Labels:

+ { + element.labels.length > 0 && + element.labels.map((label) => { + return
+
*{label.name}
+ -{label.description} +
+ }) + } +
+ View PR +
+
- }) - } -
+ }) + }
} { From b73812664776f280438baced0f1c14c3cb725540 Mon Sep 17 00:00:00 2001 From: Madhav Dua Date: Mon, 1 Jul 2024 23:22:35 +0530 Subject: [PATCH 3/3] added creation and closed date of pr --- src/pages/contributor/ContributorDetail.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/contributor/ContributorDetail.jsx b/src/pages/contributor/ContributorDetail.jsx index c1af882..a9f1b6b 100644 --- a/src/pages/contributor/ContributorDetail.jsx +++ b/src/pages/contributor/ContributorDetail.jsx @@ -74,6 +74,8 @@ function ContributorDetail(props) { }
View PR +

Created at: {element.created_at.substring(0,10).split("-").reverse().join("-")}

+

Closed at: {element.closed_at.substring(0,10).split("-").reverse().join("-")}