Skip to content

Conversation

@thissidemayur
Copy link
Contributor

@thissidemayur thissidemayur commented Jul 22, 2025

Related Issue: Add toast messages for GitHub token errors and fetch results


Description

This PR adds toast notifications for GitHub token validation and data fetch feedback in the useGitHubData hook.

🔐 Handles invalid/missing PAT tokens

✅ Shows success toast with number of fetched issues and PRs

⚠️ Displays toast if no data is found

🧠 Adds proper error handling with status code checks (401, 403, 422, fallback)

How Has This Been Tested?

  • Manually tested with valid, invalid, and missing PATs
  • Verified behavior using:
    • valid GitHub accounts
    • invalid usernames
    • revoked tokens

Video:

Screencast.from.22-07-25.04.35.35.PM.IST.webm

Type of Change

  • New feature

Summary by CodeRabbit

  • New Features

    • Removed the login interface and related functionality from the application.
  • Chores

    • Minor formatting updates, including adjustments to trailing newlines in configuration and source files. No impact on application behavior.

@netlify
Copy link

netlify bot commented Jul 22, 2025

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 0b980eb
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/68886d882158da0008f50708
😎 Deploy Preview https://deploy-preview-109--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@thissidemayur thissidemayur changed the title feat: add toast otifications for github token errors and fetch success feat: add toast notifications for github token errors and fetch success Jul 22, 2025
Copy link
Collaborator

@mehul-m-prajapati mehul-m-prajapati left a comment

Choose a reason for hiding this comment

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

please remove all indentation and quote changes which are coming from vscode config

// Middleware
app.use(bodyParser.json());
app.use(session({
console.log("process.env.SESSION_SECRET: ", process.env.SESSION_SECRET);
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove console.log

"scripts": {
"start": "nodemon server.js",
"start": "nodemon server.js",
"dev": "nodemon server.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove dev command

@thissidemayur
Copy link
Contributor Author

Hi @mehul-m-prajapati sir👋

I noticed that the “Auto Label PRs and Issues with gssoc2025” workflow failed on my PR due to permission issues from a forked repo (Resource not accessible by integration).

Just wanted to let you know — my PR is still functional, but the label didn’t get added automatically. You might want to check the GitHub Actions permission settings or add the label manually if needed.

Thanks!

@mehul-m-prajapati
Copy link
Collaborator

@thissidemayur : Please resolve conflicts

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes include the removal of the src/Routes/Login/Login.tsx file, minor formatting adjustments (addition or removal of trailing newlines) in several files such as .env.sample, package.json, and two hook files. No changes were made to the logic or exported entities except for the deletion of the Login component.

Changes

Cohort / File(s) Change Summary
Login Component Removal
src/Routes/Login/Login.tsx
Deleted the entire Login React component, including its logic, UI, and all related code.
Trailing Newline Adjustments
backend/.env.sample, package.json, src/hooks/useGitHubAuth.ts, src/hooks/useGitHubData.ts
Added or removed a single trailing newline at the end of each file without changing content.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Add toaster message when token invalid (#63) The Login component, which could display such messages, was deleted instead of being updated.
Add toaster message for success/failures (#63) No toaster messages were added; related UI was removed with the component deletion.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Trailing newline changes in .env.sample, package.json, src/hooks/useGitHubAuth.ts, src/hooks/useGitHubData.ts These formatting changes are unrelated to the objectives of adding toaster messages for auth.
Removal of entire Login component (src/Routes/Login/Login.tsx) The issue requires adding toaster messages, not removing the login functionality or component.

Poem

A bunny hopped to check the code,
But found the Login page off-road.
With newlines trimmed and files so neat,
The toaster’s message—still incomplete!
Next time, dear coder, don’t forget:
Bugs need fixing, not reset!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c0381c and 0b980eb.

📒 Files selected for processing (2)
  • src/hooks/useGitHubAuth.ts (1 hunks)
  • src/hooks/useGitHubData.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
src/pages/Home/Home.tsx (1)

57-57: Restore or Remove dataError to Match Updated Hook

The useGitHubData hook no longer returns an error field (it’s commented out), so dataError in Home.tsx will always be undefined. You can either re-introduce error in the hook’s return value or remove the unused destructuring in the component.

• In src/hooks/useGitHubData.ts:
– Re-add the error property to the returned object (uncomment or include error in the return { … }).
• In src/pages/Home/Home.tsx:
– Remove error: dataError from the hook call, or adjust error handling to use the hook’s new API.

Example diff if re-adding in the hook:

  return {
    issues,
    prs,
    loading,
-   // error,
+   error,
    fetchData,
  };

Example diff if removing from Home:

- const { issues, prs, loading, error: dataError, fetchData } = useGitHubData(octokit);
+ const { issues, prs, loading, fetchData } = useGitHubData(octokit);
♻️ Duplicate comments (2)
src/components/Navbar.tsx (1)

62-69: Reconsider the commented code given past feedback.

Based on the past review comments, there was specific feedback to "remove comments" which you acknowledged. Adding new commented-out code may contradict that previous guidance.

Consider either:

  1. Remove the commented code entirely if the signup feature isn't planned for the immediate future
  2. Create a separate issue/task to track the signup feature implementation
-          {/* Uncomment if Signup needed
-          <Link
-            to="/signup"
-            className="text-lg font-medium hover:text-gray-300 transition-all px-2 py-1 border border-transparent hover:border-gray-400 rounded"
-          >
-            Signup
-          </Link>
-          */}
backend/server.js (1)

1-7: Quote-style flip re-introduces inconsistency

The codebase previously standardised on single quotes for CommonJS imports (see past review comment). Converting these few lines to double quotes breaks that convention and may trigger lint-rule violations.

-const express = require("express");
-const mongoose = require("mongoose");
-const session = require("express-session");
-const passport = require("passport");
-const bodyParser = require("body-parser");
-require("dotenv").config();
-const cors = require("cors");
+const express = require('express');
+const mongoose = require('mongoose');
+const session = require('express-session');
+const passport = require('passport');
+const bodyParser = require('body-parser');
+require('dotenv').config();
+const cors = require('cors');
🧹 Nitpick comments (4)
backend/.env.sample (1)

1-3: Restore trailing newline to satisfy linter & tooling expectations

dotenv-linter is flagging the missing blank line. Re-add a newline so editors and CLI tools that rely on the POSIX convention don’t complain.

 SESSION_SECRET=your-secret-key
+
src/hooks/useGitHubAuth.ts (1)

3-3: Remove unused import.

The toast import is added but not used anywhere in this file. This creates unnecessary bundle size and may cause linting issues.

-import toast from 'react-hot-toast';
src/hooks/useGitHubData.ts (2)

50-55: Improve toast notification logic and formatting.

The success toast logic is good, but the formatting could be improved for better readability.

-      if (issuesResponse?.length || prsResponse?.length) toast.success(
-        `Fetched ${issuesResponse.length} issues and ${prsResponse.length} PRs successfully.`
-      );
-
-      else toast("⚠️ No issues or PRs found", { icon: "🕵️‍♂️" });
+      if (issuesResponse?.length || prsResponse?.length) {
+        toast.success(
+          `Fetched ${issuesResponse.length} issues and ${prsResponse.length} PRs successfully.`
+        );
+      } else {
+        toast("⚠️ No issues or PRs found", { icon: "🕵️‍♂️" });
+      }

58-66: Improve error handling structure and messages.

The error handling logic is sound, but the structure and some messages could be improved for consistency and clarity.

-    } catch (err: any) {
-      if (err.status === 401 || err.status === 403) {
-        toast.error("Please provide a valid GitHub token ");
-      }
-      else if (err.status === 422) toast.error("User not found")
-      else {
-        toast.error("something went wrong while fetching data")
-      }
+    } catch (err: any) {
+      if (err.status === 401 || err.status === 403) {
+        toast.error("Please provide a valid GitHub token");
+      } else if (err.status === 422) {
+        toast.error("User not found");
+      } else {
+        toast.error("Something went wrong while fetching data");
+      }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1eba6b9 and 2c0381c.

📒 Files selected for processing (9)
  • backend/.env.sample (1 hunks)
  • backend/package.json (1 hunks)
  • backend/server.js (1 hunks)
  • package.json (1 hunks)
  • src/Routes/Login/Login.tsx (0 hunks)
  • src/components/Navbar.tsx (3 hunks)
  • src/hooks/useGitHubAuth.ts (1 hunks)
  • src/hooks/useGitHubData.ts (4 hunks)
  • src/pages/Home/Home.tsx (6 hunks)
💤 Files with no reviewable changes (1)
  • src/Routes/Login/Login.tsx
🧰 Additional context used
🪛 dotenv-linter (3.3.0)
backend/.env.sample

[warning] 3-3: [EndingBlankLine] No blank line at the end of the file

🔇 Additional comments (11)
src/components/Navbar.tsx (2)

25-25: LGTM! Good styling improvement.

Adding items-center to the desktop links container properly centers the navigation elements vertically, improving the visual alignment.


102-102: Login route and component remain functional

I’ve verified that the Login component and its routes are still present and correctly configured:

  • src/pages/Login/Login.tsx defines the Login component
  • src/Routes/Router.tsx includes <Route path="/login" element={<Login />} />
  • Navbar links (to="/login") at lines 51 and 130 in src/components/Navbar.tsx

No further action required.

package.json (1)

52-53: Formatting-only change looks good

The addition of a trailing newline is benign and aligns with POSIX style guidelines for text files.

backend/package.json (1)

6-7: Indentation tweak is harmless

Only whitespace changed; script definition remains the same. No concerns.

src/hooks/useGitHubAuth.ts (1)

12-12: All getOctokit usages safely handle undefined

The getOctokit change to return undefined instead of null poses no risk:

  • In useGitHubData, fetchData immediately guards on !octokit (and !username) before making any requests.
  • In Home.tsx, you only invoke fetchData via form submission, and the form’s required fields ensure both username and token are present—otherwise, the hook’s guard will show an error toast.

No additional changes are needed.

src/hooks/useGitHubData.ts (1)

26-28: Fix syntax error and improve error message.

There's a syntax error on line 27 - missing semicolon before return statement. Also, the error message could be more descriptive.

-    if (!octokit || !username) {
-      toast.error("PAT not found"); return
-    }
+    if (!octokit || !username) {
+      toast.error("Please provide a valid GitHub username and Personal Access Token");
+      return;
+    }

Likely an incorrect or invalid review comment.

src/pages/Home/Home.tsx (5)

15-15: Good practice: avoiding naming conflicts.

Renaming the import to MuiLink prevents potential naming conflicts and makes the code more explicit about which Link component is being used.


81-87: Improved filter logic with explicit checks.

The change from Array.includes to explicit equality checks is more readable and potentially more performant for this specific use case.


115-120: Well-implemented helper function.

The getRepoName helper function correctly extracts the "owner/repo" format from the repository URL, which is more useful than just the repository name.


302-302: Enhanced pagination options.

Expanding the pagination options from just [5] to [10, 25, 50] provides better user experience for handling different data volumes.


273-281: Consistent use of renamed import.

Good consistency in using MuiLink throughout the component after the import rename.

Comment on lines 15 to 16
app.use(cors("*"));

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

cors("*") is an incorrect & unsafe usage

The cors middleware expects an options object or a boolean origin shortcut. Passing a raw string literally forwards "*" to origin, which disables CORS pre-flight handling and can break some browsers. Use the documented form:

-app.use(cors("*"));
+app.use(
+  cors({
+    origin: '*',            // or restrict to specific origins
+    credentials: true
+  })
+);
📝 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
app.use(cors("*"));
app.use(
cors({
origin: '*', // or restrict to specific origins
credentials: true
})
);
🤖 Prompt for AI Agents
In backend/server.js around lines 15 to 16, the usage of cors("*") is incorrect
and unsafe because it passes a raw string instead of an options object. Replace
cors("*") with cors({ origin: "*" }) to correctly configure the CORS middleware
and ensure proper pre-flight handling.

Comment on lines 37 to 44
console.log("Connected to MongoDB");
app.listen(process.env.PORT, () => {
console.log(`Server running on port ${process.env.PORT}`);
console.log(`Server running on port ${process.env.PORT}`);
});
}).catch((err) => {
console.log('MongoDB connection error:', err);
});
})
.catch((err) => {
console.log("MongoDB connection error:", err);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace ad-hoc console.log with structured logging

These logs were previously requested to be removed. Re-introducing them makes debugging easier during development but pollutes stdout in production. Prefer a logger (winston / pino) or at least guard them behind NODE_ENV !== 'production'.

-    console.log("Connected to MongoDB");
+    if (process.env.NODE_ENV !== 'production')
+      console.info('Connected to MongoDB');
@@
-      console.log(`Server running on port ${process.env.PORT}`);
+      console.info(`Server running on port ${process.env.PORT}`);
@@
-    console.log("MongoDB connection error:", err);
+    console.error('MongoDB connection error:', err);
📝 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
console.log("Connected to MongoDB");
app.listen(process.env.PORT, () => {
console.log(`Server running on port ${process.env.PORT}`);
console.log(`Server running on port ${process.env.PORT}`);
});
}).catch((err) => {
console.log('MongoDB connection error:', err);
});
})
.catch((err) => {
console.log("MongoDB connection error:", err);
});
if (process.env.NODE_ENV !== 'production')
console.info('Connected to MongoDB');
app.listen(process.env.PORT, () => {
console.info(`Server running on port ${process.env.PORT}`);
});
})
.catch((err) => {
console.error('MongoDB connection error:', err);
});
🤖 Prompt for AI Agents
In backend/server.js around lines 37 to 44, replace the ad-hoc console.log
statements with structured logging using a logger like winston or pino.
Alternatively, wrap the console.log calls inside a condition that checks if
NODE_ENV is not 'production' to avoid polluting stdout in production
environments. This ensures logs are more manageable and appropriate for
different deployment stages.

@mehul-m-prajapati mehul-m-prajapati merged commit 2b701c9 into GitMetricsLab:main Jul 29, 2025
5 of 6 checks passed
@github-actions
Copy link

🎉🎉 Thank you for your contribution! Your PR #109 has been merged! 🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Add toaster message when token invalid

2 participants