Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.15.6",
"@mui/material": "^5.15.6",
"@primer/octicons-react": "^19.15.5",
"@primer/octicons-react": "^19.25.0",
"@vitejs/plugin-react": "^4.3.3",
"axios": "^1.7.7",
"framer-motion": "^12.23.12",
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useGitHubAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ export const useGitHubAuth = () => {
const [error, setError] = useState('');

const octokit = useMemo(() => {
if (!username || !token) return null;
if (!username) return null;
if(token){
return new Octokit({ auth: token });
}
return new Octokit();
}, [username, token]);

const getOctokit = () => octokit;
Expand Down
19 changes: 14 additions & 5 deletions src/hooks/useGitHubData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useGitHubData = (getOctokit: () => any) => {

const octokit = getOctokit();

if (!octokit || !username || rateLimited) return;
if (!octokit || !username) return;

setLoading(true);
setError('');
Expand All @@ -45,18 +45,27 @@ export const useGitHubData = (getOctokit: () => any) => {
setPrs(prRes.items);
setTotalIssues(issueRes.total);
setTotalPrs(prRes.total);
setRateLimited(false);
} catch (err: any) {
const errorMessage = err.message?.toLowerCase() || "";
if (err.status === 403) {
setError('GitHub API rate limit exceeded. Please wait or use a token.');
setRateLimited(true); // Prevent further fetches
} else {
setError('GitHub API rate limit exceeded. Please provide a PAT to continue.');
setRateLimited(true);
} else if (errorMessage.includes("do not exist")){
setError('User not found. Please check the spelling of the GitHub username.');
} else if (err.status === 401 || errorMessage.includes("permission")){
setError('Private repository detected. Please input PAT.');
}else if(err.status===404){
setError('Resource not found.');
}
else{
setError(err.message || 'Failed to fetch data');
}
} finally {
setLoading(false);
}
},
[getOctokit, rateLimited]
[getOctokit]
);

return {
Expand Down
1 change: 0 additions & 1 deletion src/pages/Tracker/Tracker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ const Home: React.FC = () => {
value={token}
onChange={(e) => setToken(e.target.value)}
type="password"
required
sx={{ flex: 1, minWidth: 150 }}
/>
<Button type="submit" variant="contained" sx={{ minWidth: "120px" }}>
Expand Down
Loading