From a2e396c1c7cbbdb71799023d98b28ff8f262096c Mon Sep 17 00:00:00 2001 From: Mayuri Gade Date: Mon, 1 Jun 2026 11:42:13 +0530 Subject: [PATCH] fix(contributor): show repository-specific pull requests --- .../ContributorProfile/ContributorProfile.tsx | 56 ++++++++++++++++--- src/utils/constants.ts | 3 + 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/pages/ContributorProfile/ContributorProfile.tsx b/src/pages/ContributorProfile/ContributorProfile.tsx index ed1b714d..4c3676c1 100644 --- a/src/pages/ContributorProfile/ContributorProfile.tsx +++ b/src/pages/ContributorProfile/ContributorProfile.tsx @@ -1,6 +1,8 @@ import { useParams } from "react-router-dom"; import { useEffect, useState } from "react"; import toast from "react-hot-toast"; +// --- FIX: Import the repo constant --- +import { GITHUB_REPO } from "@/utils/constants"; type PR = { title: string; @@ -14,27 +16,54 @@ type Profile = { bio: string; }; +type ErrorType = "not_found" | "api_error" | null; + export default function ContributorProfile() { const { username } = useParams(); const [profile, setProfile] = useState(null); const [prs, setPRs] = useState([]); const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); useEffect(() => { async function fetchData() { if (!username) return; + setError(null); + try { const userRes = await fetch(`https://api.github.com/users/${username}`); + + if (!userRes.ok) { + if (userRes.status === 404) { + setError("not_found"); + } else { + setError("api_error"); + } + setProfile(null); + setPRs([]); + return; + } + const userData = await userRes.json(); - setProfile(userData); + setProfile(userData as Profile); + // --- FIX: Scoped to this repo only using GITHUB_REPO constant --- const prsRes = await fetch( - `https://api.github.com/search/issues?q=author:${username}+type:pr` + `https://api.github.com/search/issues?q=repo:${GITHUB_REPO}+author:${username}+type:pr` ); - const prsData = await prsRes.json(); - setPRs(prsData.items); + + if (!prsRes.ok) { + setPRs([]); + toast.error("Failed to load pull requests."); + } else { + const prsData = await prsRes.json(); + setPRs(prsData.items ?? []); + } } catch { + setError("api_error"); + setProfile(null); + setPRs([]); toast.error("Failed to fetch user data."); } finally { setLoading(false); @@ -51,10 +80,23 @@ export default function ContributorProfile() { if (loading) return
Loading...
; - if (!profile) + if (error === "not_found") { return ( -
User not found.
+
+ User not found. +
); + } + + if (error === "api_error") { + return ( +
+ Unable to load contributor profile. Please try again later. +
+ ); + } + + if (!profile) return null; return (
@@ -98,4 +140,4 @@ export default function ContributorProfile() { )}
); -} +} \ No newline at end of file diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 09717e0b..0c028bfd 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -2,3 +2,6 @@ export const GITHUB_REPO_API_BASE = "https://api.github.com/repos/GitMetricsLab/ // endpoints: export const GITHUB_REPO_CONTRIBUTORS_URL = `${GITHUB_REPO_API_BASE}/contributors`; + +// --- FIX: Repo identifier for scoped PR search queries --- +export const GITHUB_REPO = "GitMetricsLab/github_tracker"; \ No newline at end of file