-
Notifications
You must be signed in to change notification settings - Fork 113
Move GitHub token server-side & add ETag conditional caching to reduce API calls #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Refactor GitHubService to support ETag conditional requests and improve caching. Removed client-side token reading and added methods for managing cached meta data.
@mukeshdhadhariya is attempting to deploy a commit to the recode Team on Vercel. A member of the Team first needs to authorize it. |
Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. The estimated time for response is 5–8 hrs. In the meantime, please provide all necessary screenshots and make sure you run - npm build run , command and provide a screenshot, a video recording, or an image of the update you made below, which helps speed up the review and assignment. If you have questions, reach out to LinkedIn. Your contributions are highly appreciated!😊 Note: I maintain the repo issue every day twice at 8:00 AM IST and 9:00 PM IST. If your PR goes stale for more than one day, you can tag and comment on this same issue by tagging @sanjay-kv. We are here to help you on this journey of open source. Consistent 20 contributions are eligible for sponsorship 💰 🎁 check our list of amazing people we sponsored so far: GitHub Sponsorship. ✨ 📚Your perks for contribution to this community 👇🏻
If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊 |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@Adez017 can you cross check this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the GitHub API service by moving authentication tokens server-side and implementing ETag-based conditional caching to reduce API calls and prevent rate limiting.
- Removes client-side token access through
window.GITHUB_TOKEN
and adds constructor/method-based token setting - Implements ETag conditional caching with
If-None-Match
headers to avoid unnecessary API calls - Enhances cache structure to store ETags and metadata alongside data
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/services/githubService.ts
Outdated
signal, | ||
}, | ||
); | ||
const url = `${this.BASE_URL}/search/issues?q=org:${this.ORG_NAME}+type:issue`; |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search query changed from repo-specific to org-wide (org:${this.ORG_NAME}
instead of repo:${this.ORG_NAME}/Support
). This will return all issues across the organization rather than discussions from a specific repository, potentially causing inaccurate discussion counts.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems a issue.
src/services/githubService.ts
Outdated
}, | ||
); | ||
// Use per_page=1 to leverage Link header for total pages, if present | ||
const url = `${this.BASE_URL}/repos/${repo.full_name}/contributors?per_page=1&anon=true`; |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding anon=true
parameter changes the API behavior to include anonymous contributors. This may affect contributor count accuracy compared to the previous implementation and should be documented or made configurable.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also this one
src/services/githubService.ts
Outdated
const response = await this.fetchWithRetry("https://api.github.com/graphql", { | ||
method: "POST", | ||
headers: { | ||
...this.getHeaders(), | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ query, variables }), | ||
body: { query, variables }, | ||
signal, | ||
}); |
Copilot
AI
Oct 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The body
should be a JSON string, but it's being passed as an object. The fetchWithRetry
method calls JSON.stringify(options.body)
only when options.body
exists, but this will result in double stringification since the body is already an object here.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mukeshdhadhariya @sanjay-kv Updation of the Readme.md file remains and it is important as we are having new contributors, rest is fine :)
Also run 'npm run build' and if, any errors try solving or you can share it here for discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reset of the things looks good.
also @mukeshdhadhariya , tag the issue number assigned to this . |
Synced data from Linked IssuesLabels:
Assignees:
Milestones:
|
@Adez017 lmk if we good to close this issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to go from my side @sanjay-kv .
what are your thoughts @iitzIrFan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we an merge this, only remains is the documentation update, rest is fine @sanjay-kv @Adez017
Summary
constructor
orsetAuthToken()
(server-side only). Update README with instantiation instructions:new GitHubService(process.env.GITHUB_TOKEN)
.If-None-Match
support and store ETags in cache meta. Conditional GET reduces API usage and avoids hitting rate limits.fetchWithRetry
now accepts custom headers and handles304 Not Modified
responses. Cache now stores{ data, etags, lastUpdated }
.Why
Exposing tokens in client-side code risks leaking credentials and causing abuse. Using conditional requests via ETag reduces bandwidth and GitHub API rate consumption.
Developer notes
const svc = new GitHubService(process.env.GITHUB_TOKEN);
window
in production.lastUpdated
for freshness checks.