Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"react-hot-toast": "^2.4.1",
"react-icons": "^5.3.0",
"react-router-dom": "^6.28.0",
"recharts": "^3.8.1",
"tailwindcss": "^3.4.14"
},
"devDependencies": {
Expand All @@ -50,8 +51,16 @@
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"express": "^5.2.1",
"express-session": "^1.18.2",
"globals": "^15.11.0",
"jasmine": "^5.9.0",
"mongoose": "^9.6.2",
"passport": "^0.7.0",
"passport-local": "^1.0.0",
"supertest": "^7.1.4",
"typescript-eslint": "^8.59.3",
"vite": "^5.4.10",
"jasmine": "^5.13.0",
Comment on lines +57 to 64
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

head -75 package.json | tail -30

Repository: GitMetricsLab/github_tracker

Length of output: 943


Fix invalid JSON and duplicate dependency keys in devDependencies.

Line 62 is missing a trailing comma after "vite": "^5.4.10", making package.json unparseable. Additionally, jasmine, passport, passport-local, supertest, and vite appear twice with conflicting or redundant versions—remove the first occurrences and keep only the second set.

Suggested cleanup
-    "jasmine": "^5.9.0",
     "mongoose": "^9.6.2",
-    "passport": "^0.7.0",
-    "passport-local": "^1.0.0",
-    "supertest": "^7.1.4",
     "typescript-eslint": "^8.59.3",
-    "vite": "^5.4.10"
+    "vite": "^5.4.10",
     "jasmine": "^5.13.0",
     "jasmine-spec-reporter": "^7.0.0",
     "jsdom": "^29.1.1",
-    "passport": "^0.7.0",
-    "passport-local": "^1.0.0",
     "supertest": "^7.2.2",
-    "vite": "^5.4.10",
     "vitest": "^4.1.6"
🧰 Tools
🪛 Biome (2.4.15)

[error] 64-64: expected , but instead found "jasmine"

(parse)


[error] 57-57: The key jasmine was already declared.

(lint/suspicious/noDuplicateObjectKeys)


[error] 59-59: The key passport was already declared.

(lint/suspicious/noDuplicateObjectKeys)


[error] 60-60: The key passport-local was already declared.

(lint/suspicious/noDuplicateObjectKeys)


[error] 61-61: The key supertest was already declared.

(lint/suspicious/noDuplicateObjectKeys)


[error] 63-63: The key vite was already declared.

(lint/suspicious/noDuplicateObjectKeys)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` around lines 57 - 64, Fix the invalid JSON and duplicate
dependency entries in devDependencies: add the missing comma after the "vite":
"^5.4.10" entry to make the object parseable, remove the earlier duplicate
entries for "jasmine", "passport", "passport-local", "supertest", and "vite" so
each package appears only once, and ensure the retained versions are the
intended ones (e.g., keep "jasmine": "^5.13.0" if that's the desired version).
Confirm the final package.json parses as valid JSON after these edits.

"jasmine-spec-reporter": "^7.0.0",
"jsdom": "^29.1.1",
Expand Down
142 changes: 142 additions & 0 deletions src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React from 'react';
import {
PieChart,
Pie,
Cell,
BarChart,
Bar,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
Legend,
ResponsiveContainer
} from 'recharts';
import { Paper, Typography, Box, Grid, Theme } from '@mui/material';

interface GitHubItem {
id: number;
title: string;
state: string;
created_at: string;
pull_request?: { merged_at: string | null };
repository_url: string;
html_url: string;
}

interface DashboardProps {
totalIssues: number;
totalPrs: number;
data: GitHubItem[];
theme: Theme;
}

const Dashboard: React.FC<DashboardProps> = ({ totalIssues, totalPrs, data, theme }) => {

// Data for Pie Chart
const pieData = [
{ name: 'Issues', value: totalIssues },
{ name: 'Pull Requests', value: totalPrs },
];

// Use theme-aware colors
const COLORS = [theme.palette.primary.main, theme.palette.secondary.main];

// Data for Bar Chart (Top 5 Repositories) - Improved safety
const repoCounts: { [key: string]: number } = {};
data.forEach(item => {
if (item?.repository_url) {
const repoName = item.repository_url
.split('/')
.filter(Boolean)
.pop();

if (repoName) {
repoCounts[repoName] = (repoCounts[repoName] || 0) + 1;
}
}
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const barData = Object.entries(repoCounts)
.map(([name, count]) => ({ name, count }))
.sort((a, b) => b.count - a.count)
.slice(0, 5);

const hasData = totalIssues > 0 || totalPrs > 0;

if (!hasData) {
return (
<Paper elevation={1} sx={{ p: 4, mb: 4, textAlign: 'center', backgroundColor: theme.palette.background.paper }}>
<Typography variant="h6" color="textSecondary">
No data available. Enter a username to view analytics.
</Typography>
</Paper>
);
}

return (
<Box sx={{ mb: 4 }}>
<Grid container spacing={3}>
{/* Pie Chart: Issues vs PRs */}
<Grid item xs={12} md={6}>
<Paper elevation={2} sx={{ p: 2, height: 350, backgroundColor: theme.palette.background.paper }}>
<Typography variant="h6" gutterBottom align="center" color="textPrimary">
Contribution Mix (Total)
</Typography>
<ResponsiveContainer width="100%" height="90%">
<PieChart>
<Pie
data={pieData}
cx="50%"
cy="50%"
innerRadius={60}
outerRadius={80}
fill={theme.palette.primary.main}
paddingAngle={5}
dataKey="value"
label
>
{pieData.map((_entry, index) => (
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
))}
</Pie>
<Tooltip
contentStyle={{ backgroundColor: theme.palette.background.paper, color: theme.palette.text.primary }}
/>
<Legend />
</PieChart>
</ResponsiveContainer>
</Paper>
</Grid>

{/* Bar Chart: Activity by Repository */}
<Grid item xs={12} md={6}>
<Paper elevation={2} sx={{ p: 2, height: 350, backgroundColor: theme.palette.background.paper }}>
<Typography variant="h6" gutterBottom align="center" color="textPrimary">
Top Repositories (Current View)
</Typography>
{barData.length > 0 ? (
<ResponsiveContainer width="100%" height="90%">
<BarChart data={barData}>
<CartesianGrid strokeDasharray="3 3" stroke={theme.palette.divider} />
<XAxis dataKey="name" stroke={theme.palette.text.secondary} />
<YAxis stroke={theme.palette.text.secondary} />
<Tooltip
contentStyle={{ backgroundColor: theme.palette.background.paper, color: theme.palette.text.primary }}
/>
<Bar dataKey="count" fill={theme.palette.primary.light} radius={[4, 4, 0, 0]} />
</BarChart>
</ResponsiveContainer>
) : (
<Box display="flex" justifyContent="center" alignItems="center" height="100%">
<Typography color="textSecondary">No repository data found in this view.</Typography>
</Box>
)}
</Paper>
</Grid>
</Grid>
</Box>
);
};

export default Dashboard;
17 changes: 17 additions & 0 deletions src/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useState, useEffect } from 'react';

export function useDebounce<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value);

useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);

return () => {
clearTimeout(handler);
};
}, [value, delay]);

return debouncedValue;
}
3 changes: 0 additions & 3 deletions src/hooks/useGitHubAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Octokit } from '@octokit/core';
export const useGitHubAuth = () => {
const [username, setUsername] = useState('');
const [token, setToken] = useState('');
const [error, setError] = useState('');

const octokit = useMemo(() => {
if (!username) return null;
Expand All @@ -21,8 +20,6 @@ export const useGitHubAuth = () => {
setUsername,
token,
setToken,
error,
setError,
getOctokit,
};
};
90 changes: 73 additions & 17 deletions src/hooks/useGitHubData.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
import { useState, useCallback } from 'react';
import { useState, useCallback, useRef } from 'react';
import { Octokit } from '@octokit/core';

export const useGitHubData = (getOctokit: () => any) => {
const [issues, setIssues] = useState([]);
const [prs, setPrs] = useState([]);
interface GitHubItem {
id: number;
title: string;
state: string;
created_at: string;
pull_request?: { merged_at: string | null };
repository_url: string;
html_url: string;
}

interface FetchFilters {
search?: string;
repo?: string;
startDate?: string;
endDate?: string;
state?: string;
}

export const useGitHubData = (getOctokit: () => Octokit | null) => {
const [issues, setIssues] = useState<GitHubItem[]>([]);
const [prs, setPrs] = useState<GitHubItem[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const [totalIssues, setTotalIssues] = useState(0);
const [totalPrs, setTotalPrs] = useState(0);
const [rateLimited, setRateLimited] = useState(false);

// Track the latest request ID to prevent stale overwrites
const lastRequestId = useRef(0);

const fetchPaginated = async (
octokit: Octokit,
username: string,
type: string,
page = 1,
per_page = 10,
filters: FetchFilters = {}
) => {
let q = `author:${username} is:${type}`;

if (filters.search) q += ` ${filters.search} in:title`;
if (filters.repo) q += ` repo:${filters.repo}`;
if (filters.startDate) q += ` created:>=${filters.startDate}`;
if (filters.endDate) q += ` created:<=${filters.endDate}`;

if (filters.state === 'open' || filters.state === 'closed') {
q += ` is:${filters.state}`;
} else if (filters.state === 'merged') {
q += ` is:merged`;
}

const fetchPaginated = async (octokit: any, username: string, type: string, page = 1, per_page = 10) => {
const q = `author:${username} is:${type}`;
const response = await octokit.request('GET /search/issues', {
q,
sort: 'created',
Expand All @@ -26,27 +67,39 @@ export const useGitHubData = (getOctokit: () => any) => {
};

const fetchData = useCallback(
async (username: string, page = 1, perPage = 10) => {

async (username: string, page = 1, perPage = 10, activeTab: 'issue' | 'pr' = 'issue', filters: FetchFilters = {}) => {
const octokit = getOctokit();
if (!octokit || !username || rateLimited) return;
Comment thread
ishwari418 marked this conversation as resolved.

if (!octokit || !username) return;

Comment on lines +72 to 75
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

cat -n src/hooks/useGitHubData.ts | head -200

Repository: GitMetricsLab/github_tracker

Length of output: 5737


Add rateLimited to the useCallback dependency array.

fetchData references rateLimited in the guard condition at line 72, but the useCallback dependency array at line 134 only includes [getOctokit]. This creates a stale closure where the callback retains the initial false value of rateLimited. When setRateLimited(true) is called during rate limiting (lines 99, 112), the callback doesn't recognize the state change and continues attempting API calls despite rate limiting.

Add rateLimited to the dependency array:

Suggested fix
   const fetchData = useCallback(
     async (...) => {
       ...
     },
-    [getOctokit]
+    [getOctokit, rateLimited]
   );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!octokit || !username || rateLimited) return;
if (!octokit || !username) return;
const fetchData = useCallback(
async (...) => {
...
},
[getOctokit, rateLimited]
);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useGitHubData.ts` around lines 72 - 75, The fetchData callback in
useGitHubData references the rateLimited state but the useCallback dependency
array only includes getOctokit, causing a stale closure; update the useCallback
dependencies for fetchData (the callback defined around line 72) to include
rateLimited in addition to getOctokit so the callback sees changes to
rateLimited and stops making API calls when setRateLimited(true).

const requestId = ++lastRequestId.current;
setLoading(true);
setError('');

try {
// We fetch BOTH even if one tab is active to keep totals synchronized as requested
const [issueRes, prRes] = await Promise.all([
fetchPaginated(octokit, username, 'issue', page, perPage),
fetchPaginated(octokit, username, 'pr', page, perPage),
fetchPaginated(octokit, username, 'issue', activeTab === 'issue' ? page : 1, perPage, filters),
fetchPaginated(octokit, username, 'pr', activeTab === 'pr' ? page : 1, perPage, filters),
]);

setIssues(issueRes.items);
setPrs(prRes.items);
setTotalIssues(issueRes.total);
setTotalPrs(prRes.total);
setRateLimited(false);
} catch (err: any) {
// Only update state if this is still the latest request
if (requestId === lastRequestId.current) {
setIssues(issueRes.items);
setTotalIssues(issueRes.total);
setPrs(prRes.items);
setTotalPrs(prRes.total);
}
} catch (err: unknown) {
if (requestId === lastRequestId.current) {
const error = err as { status?: number; message?: string };
if (error.status === 403) {
setError('GitHub API rate limit exceeded. Please wait or use a token.');
setRateLimited(true);
} else {
setError(error.message || 'Failed to fetch data');
}
const errorMessage = err.message?.toLowerCase() || "";
if (err.status === 403) {
setError('GitHub API rate limit exceeded. Please provide a PAT to continue.');
Expand All @@ -66,8 +119,11 @@ export const useGitHubData = (getOctokit: () => any) => {
'Unable to fetch GitHub data. Please verify the username, token, or network connection.'
);
}
}
} finally {
setLoading(false);
if (requestId === lastRequestId.current) {
setLoading(false);
}
}
},
[getOctokit]
Expand Down
10 changes: 8 additions & 2 deletions src/pages/ContributorProfile/ContributorProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ type PR = {
repository_url: string;
};

type Profile = {
avatar_url: string;
login: string;
bio: string;
};
Comment on lines +11 to +15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In GitHub REST API users response schema, is bio nullable (string | null)?

💡 Result:

Yes, in the GitHub REST API users response schema, the bio field is defined as nullable (string | null) [1][2][3][4]. Official documentation explicitly lists bio as required and of type string or null [1][4].

Citations:


Change Profile.bio to string | null to match GitHub API contract.

The GitHub API's /users endpoint returns bio as nullable. The current type bio: string is too strict for the API response shape.

Proposed fix
 type Profile = {
   avatar_url: string;
   login: string;
-  bio: string;
+  bio: string | null;
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type Profile = {
avatar_url: string;
login: string;
bio: string;
};
type Profile = {
avatar_url: string;
login: string;
bio: string | null;
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/ContributorProfile/ContributorProfile.tsx` around lines 11 - 15,
The Profile type in ContributorProfile.tsx is too strict: change the bio
property from string to string | null to match GitHub's /users nullable bio;
locate the type alias named Profile (avatar_url, login, bio) and update the bio
declaration to accept null so downstream code that consumes Profile matches the
API shape.


export default function ContributorProfile() {
const { username } = useParams();
const [profile, setProfile] = useState<any>(null);
const [profile, setProfile] = useState<Profile | null>(null);
const [prs, setPRs] = useState<PR[]>([]);
const [loading, setLoading] = useState(true);

Expand All @@ -28,7 +34,7 @@ export default function ContributorProfile() {
);
const prsData = await prsRes.json();
setPRs(prsData.items);
} catch (error) {
} catch {
toast.error("Failed to fetch user data.");
} finally {
setLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Contributors/Contributors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ContributorsPage = () => {
withCredentials: false,
});
setContributors(response.data);
} catch (err) {
} catch {
setError("Failed to fetch contributors. Please try again later.");
} finally {
setLoading(false);
Expand Down
8 changes: 6 additions & 2 deletions src/pages/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ const Login: React.FC = () => {
if (response.data.message === 'Login successful') {
navigate("/");
}
} catch (error: any) {
setMessage(error.response?.data?.message || "Something went wrong");
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
setMessage(error.response?.data?.message || "Something went wrong");
} else {
setMessage("Something went wrong");
}
} finally {
setIsLoading(false);
}
Expand Down
Loading
Loading