diff --git a/src/pages/contributor/ContributorCard.jsx b/src/pages/contributor/ContributorCard.jsx index 51930d8..1d55540 100644 --- a/src/pages/contributor/ContributorCard.jsx +++ b/src/pages/contributor/ContributorCard.jsx @@ -3,7 +3,8 @@ import { Link } from 'react-router-dom'; import "../../css/Contributor.css" function ContributorCard(props) { - const { name, img } = props; + const { name, img,contributions } = props; + return ( <> @@ -12,7 +13,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..a9f1b6b 100644 --- a/src/pages/contributor/ContributorDetail.jsx +++ b/src/pages/contributor/ContributorDetail.jsx @@ -1,10 +1,95 @@ -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); + // console.log(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')} +
+
+

Github ↗

+
+ +
+
+
+ { + 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 +

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

+

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

+
+
+ + }) + } +
+ } + { + 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
- +
}) }