🧹 [Code Health] Refactor fetchContributions to reduce complexity#454
🧹 [Code Health] Refactor fetchContributions to reduce complexity#454is0692vs wants to merge 1 commit into
Conversation
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Warning Review limit reached
Next review available in: 41 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| } | ||
| }`; | ||
|
|
||
| type ContributionWeek = NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"][number]; |
There was a problem hiding this comment.
ContributionWeek 型が定義されていますが、コード内のどこからも参照されていません。processContributionsCalendar の引数型は同じ型を直接 NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"] として展開しているため、この型エイリアスは現状デッドコードになっています。削除するか、関数の引数型を ContributionWeek[] に置き換えて活用してください。
Context Used: 日本語で!!! (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/github.ts
Line: 508
Comment:
**未使用の型定義**
`ContributionWeek` 型が定義されていますが、コード内のどこからも参照されていません。`processContributionsCalendar` の引数型は同じ型を直接 `NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"]` として展開しているため、この型エイリアスは現状デッドコードになっています。削除するか、関数の引数型を `ContributionWeek[]` に置き換えて活用してください。
**Context Used:** 日本語で!!! ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0]; | ||
| const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0]; | ||
|
|
||
| const query = `query($login: String!, $from: DateTime!, $to: DateTime!) { | ||
| user(login: $login) { | ||
| contributionsCollection(from: $from, to: $to) { | ||
| totalCommitContributions | ||
| totalPullRequestContributions | ||
| totalIssueContributions | ||
| totalPullRequestReviewContributions | ||
| contributionCalendar { | ||
| totalContributions | ||
| weeks { | ||
| contributionDays { | ||
| date | ||
| contributionCount | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }`; | ||
|
|
||
| const data = await graphql<ContributionsResponse>(query, token, { | ||
|
|
||
| const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, { |
There was a problem hiding this comment.
インラインクエリを削除した後、fetchContributions 内に連続する空行が2行残っています。1行にまとめてください。
| const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0]; | |
| const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0]; | |
| const query = `query($login: String!, $from: DateTime!, $to: DateTime!) { | |
| user(login: $login) { | |
| contributionsCollection(from: $from, to: $to) { | |
| totalCommitContributions | |
| totalPullRequestContributions | |
| totalIssueContributions | |
| totalPullRequestReviewContributions | |
| contributionCalendar { | |
| totalContributions | |
| weeks { | |
| contributionDays { | |
| date | |
| contributionCount | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }`; | |
| const data = await graphql<ContributionsResponse>(query, token, { | |
| const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, { | |
| const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0]; | |
| const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0]; | |
| const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/lib/github.ts
Line: 560-565
Comment:
**余分な空行**
インラインクエリを削除した後、`fetchContributions` 内に連続する空行が2行残っています。1行にまとめてください。
```suggestion
const sevenDaysAgoStr = new Date(now.getTime() - 6 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
const thirtyDaysAgoStr = new Date(now.getTime() - 29 * 24 * 60 * 60 * 1000).toISOString().split("T")[0];
const data = await graphql<ContributionsResponse>(CONTRIBUTIONS_QUERY, token, {
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Code Review
This pull request refactors src/lib/github.ts by extracting the GraphQL query into a constant and modularizing the contribution processing logic into helper functions. The reviewer suggests improving type safety and readability by defining a ContributionDay type and ensuring explicit return types for the new helper functions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| type ContributionWeek = NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"][number]; | ||
|
|
||
| function processContributionsCalendar(weeks: NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"]) { |
There was a problem hiding this comment.
To improve readability and type safety, you can introduce a ContributionDay type and use the existing ContributionWeek type. This makes the function signature cleaner and more self-documenting.
First, define ContributionDay before this function:
type ContributionDay = { date: string; count: number };Then, you can update this function's signature. You should also update calculateRecentContributions to use ContributionDay[] for its calendar parameter. Ensure that explicit return types are maintained for type safety.
| function processContributionsCalendar(weeks: NonNullable<ContributionsResponse["user"]>["contributionsCollection"]["contributionCalendar"]["weeks"]) { | |
| function processContributionsCalendar(weeks: ContributionWeek[]): ContributionDay[] { |
References
- Maintain explicit return types for functions in TypeScript to ensure type safety and API clarity.
| return calendar; | ||
| } | ||
|
|
||
| function calculateRecentContributions(calendar: { date: string; count: number }[], sevenDaysAgoStr: string, thirtyDaysAgoStr: string) { |
There was a problem hiding this comment.
To align with the suggested change in processContributionsCalendar, you should update this function to use the new ContributionDay type for the calendar parameter. Additionally, ensure the function has an explicit return type to maintain type safety and API clarity.
| function calculateRecentContributions(calendar: { date: string; count: number }[], sevenDaysAgoStr: string, thirtyDaysAgoStr: string) { | |
| function calculateRecentContributions(calendar: ContributionDay[], sevenDaysAgoStr: string, thirtyDaysAgoStr: string): number { |
References
- Maintain explicit return types for functions in TypeScript to ensure type safety and API clarity.
🎯 What: Extracted CONTRIBUTIONS_QUERY, processContributionsCalendar, and calculateRecentContributions out of fetchContributions.
💡 Why: Improves maintainability and readability by reducing the length and complexity of fetchContributions.
✅ Verification: Ran test suite and manually verified logic.
✨ Result: fetchContributions is now shorter and more focused.
PR created automatically by Jules for task 7121083320895186331 started by @is0692vs
Greptile Summary
このPRは
fetchContributions関数のリファクタリングで、GraphQLクエリ文字列・カレンダー変換ロジック・直近コントリビューション集計をそれぞれモジュールレベルの定数・関数として切り出しています。ロジック自体に変更はなく、既存の動作は維持されています。CONTRIBUTIONS_QUERYをモジュール定数として分離し、再利用しやすくしたprocessContributionsCalendarとcalculateRecentContributionsを独立した関数として抽出し、fetchContributionsの見通しを改善ContributionWeek型が実際には参照されておらず、不要なデッドコードが残っているConfidence Score: 4/5
純粋なリファクタリングでロジック変更はなく、マージは安全。
抽出された3つの関数はオリジナルのロジックを忠実に再現しており、動作への影響はない。未使用の ContributionWeek 型と残存する空行という軽微な整理残しがあるものの、機能的な問題はない。
src/lib/github.ts の ContributionWeek 型(508行目)は定義後に参照されておらず、削除または活用が必要。
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Caller participant fetchContributions participant graphql participant processContributionsCalendar participant calculateRecentContributions participant calculateStreaks participant calculateMostActiveDay Caller->>fetchContributions: username, token fetchContributions->>graphql: CONTRIBUTIONS_QUERY, token, variables graphql-->>fetchContributions: ContributionsResponse fetchContributions->>processContributionsCalendar: cc.contributionCalendar.weeks processContributionsCalendar-->>fetchContributions: calendar (sorted) fetchContributions->>calculateRecentContributions: calendar, sevenDaysAgoStr, thirtyDaysAgoStr calculateRecentContributions-->>fetchContributions: weeklyContributions, monthlyContributions fetchContributions->>calculateStreaks: calendar calculateStreaks-->>fetchContributions: longestStreak, currentStreak fetchContributions->>calculateMostActiveDay: calendar calculateMostActiveDay-->>fetchContributions: mostActiveDay fetchContributions-->>Caller: ContributionData%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Caller participant fetchContributions participant graphql participant processContributionsCalendar participant calculateRecentContributions participant calculateStreaks participant calculateMostActiveDay Caller->>fetchContributions: username, token fetchContributions->>graphql: CONTRIBUTIONS_QUERY, token, variables graphql-->>fetchContributions: ContributionsResponse fetchContributions->>processContributionsCalendar: cc.contributionCalendar.weeks processContributionsCalendar-->>fetchContributions: calendar (sorted) fetchContributions->>calculateRecentContributions: calendar, sevenDaysAgoStr, thirtyDaysAgoStr calculateRecentContributions-->>fetchContributions: weeklyContributions, monthlyContributions fetchContributions->>calculateStreaks: calendar calculateStreaks-->>fetchContributions: longestStreak, currentStreak fetchContributions->>calculateMostActiveDay: calendar calculateMostActiveDay-->>fetchContributions: mostActiveDay fetchContributions-->>Caller: ContributionDataPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "refactor: extract helper functions in fe..." | Re-trigger Greptile
Context used: