Skip to content

🧹 [Code Health] Extract GraphQL fragment for contributionsCollection - #560

Closed
is0692vs wants to merge 1 commit into
mainfrom
jules-11168113056124209276-e39adfdd
Closed

🧹 [Code Health] Extract GraphQL fragment for contributionsCollection#560
is0692vs wants to merge 1 commit into
mainfrom
jules-11168113056124209276-e39adfdd

Conversation

@is0692vs

@is0692vs is0692vs commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🎯 What: Extracted the GraphQL fields for contributionsCollection into a reusable fragment CONTRIBUTIONS_COLLECTION_FRAGMENT in src/lib/github.ts and shared it with src/lib/githubYearInReview.ts. Additionally, extracted the duplicated data types into a shared ContributionsCollectionData type.

💡 Why: Both github.ts and githubYearInReview.ts contained large, duplicate sections of GraphQL queries asking for exactly the same contribution data (totalCommitContributions, contributionCalendar, etc.). Sharing fragments prevents errors and drifting definitions across different parts of the application, thereby improving code maintainability.

Verification:

  • Ran the type-checker and linters to ensure ContributionsCollectionData was applied perfectly in both queries and response shapes.
  • Ran the full test suite via npm run test which confirmed all functionality remains intact (0 regressions).
  • Ensured a successful production build via npm run build.

Result: A more maintainable and DRY codebase without any duplicated boilerplate for the contributionsCollection fetch logic.


PR created automatically by Jules for task 11168113056124209276 started by @is0692vs

Greptile Summary

contributionsCollection の共通 GraphQL フィールドとレスポンス型を github.ts に集約し、通常のコントリビューション取得と Year in Review の両方で再利用するリファクタリングです。

  • 共通の CONTRIBUTIONS_COLLECTION_FRAGMENT を追加
  • 共通の ContributionsCollectionData 型を追加
  • 既存の2つの GraphQL クエリとレスポンス型から重複定義を削除

Confidence Score: 5/5

このPRは安全にマージできると判断します。

共通化後も両クエリの選択フィールド、Year in Review 固有フィールド、およびレスポンス型の構造が維持されており、具体的な実行時・ビルド時の不具合は確認されませんでした。

Important Files Changed

Filename Overview
src/lib/github.ts 共通 GraphQL フラグメントとレスポンス型を定義し、既存のコントリビューション取得クエリへ適用しています。取得フィールドと返却処理の契約は維持されています。
src/lib/githubYearInReview.ts 共通フラグメントと型を再利用しつつ、Year in Review 固有のリポジトリ別フィールドを従来どおり追加しています。動作上の問題は確認されませんでした。

Reviews (1): Last reviewed commit: "🧹 Extract and share GraphQL fragment fo..." | Re-trigger Greptile

Context used (3)

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
github-user-summary Ignored Ignored Aug 7, 2026 6:57am

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@is0692vs, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 67476cf6-a741-4523-adb2-2d9e926ef500

📥 Commits

Reviewing files that changed from the base of the PR and between eb95c48 and c2e5b9b.

📒 Files selected for processing (2)
  • src/lib/github.ts
  • src/lib/githubYearInReview.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Extract shared GraphQL fragment + type for contributionsCollection queries

✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Extract contributionsCollection fields into a reusable GraphQL fragment to eliminate query
 duplication.
• Introduce a shared ContributionsCollectionData TypeScript type for consistent response typing.
• Reuse the fragment/type across github.ts and githubYearInReview.ts to prevent drift.
Diagram

graph TD
  A["src/lib/github.ts"] --> B["CONTRIBUTIONS_COLLECTION_FRAGMENT"] --> C["fetchContributions() query"] --> E{{"GitHub GraphQL API"}}
  A --> D["ContributionsCollectionData type"]
  B --> F["src/lib/githubYearInReview.ts query"] --> E
  D --> C
  D --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Adopt GraphQL code generation (operations + fragments)
  • ➕ Generates strongly-typed query results automatically, reducing manual TS maintenance
  • ➕ Centralizes fragments/operations and prevents drift across modules by design
  • ➖ Adds tooling/config overhead (schema fetching, codegen pipeline)
  • ➖ May be heavier than needed for a small number of queries
2. Create a shared query builder/helper for contributionsCollection
  • ➕ Avoids interpolating raw template strings across modules
  • ➕ Can enforce consistent fragment inclusion and variable definitions
  • ➖ More custom abstraction to maintain than a plain fragment export
  • ➖ Less standard than using GraphQL-native fragments

Recommendation: The current approach (exporting a shared fragment string + shared response type) is the best incremental improvement: it removes duplication with minimal surface-area change and keeps each query readable. If GraphQL usage grows, consider GraphQL codegen as a next step to eliminate manual response typing and further reduce drift risk.

Files changed (2) +42 / -56

Refactor (2) +42 / -56
github.tsAdd reusable contributionsCollection fragment and shared response type +38/-29

Add reusable contributionsCollection fragment and shared response type

• Introduces 'CONTRIBUTIONS_COLLECTION_FRAGMENT' containing the common 'contributionsCollection' field selection. Extracts the duplicated TypeScript shape into 'ContributionsCollectionData' and updates 'fetchContributions' to spread the fragment and use the shared type in 'ContributionsResponse'.

src/lib/github.ts

githubYearInReview.tsReuse shared contributionsCollection fragment and type in year-in-review query +4/-27

Reuse shared contributionsCollection fragment and type in year-in-review query

• Imports 'CONTRIBUTIONS_COLLECTION_FRAGMENT' and 'ContributionsCollectionData' from 'github.ts'. Replaces the inlined 'contributionsCollection' field list with a fragment spread and updates the response type to compose 'ContributionsCollectionData' with repo contribution aggregates.

src/lib/githubYearInReview.ts

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. ContributionsCollectionData not in types.ts 📘 Rule violation ⌂ Architecture
Description
ContributionsCollectionData is exported from src/lib/github.ts but is imported and used by
src/lib/githubYearInReview.ts, making it a cross-module shared type that should be centralized in
src/lib/types.ts. Keeping shared types outside src/lib/types.ts increases duplication risk and
violates the project’s type-centralization rule.
Code

src/lib/github.ts[R486-490]

+export type ContributionsCollectionData = {
+  totalCommitContributions: number;
+  totalPullRequestContributions: number;
+  totalIssueContributions: number;
+  totalPullRequestReviewContributions: number;
Evidence
PR Compliance ID 226102 requires shared, cross-module types to be defined in src/lib/types.ts. The
PR introduces ContributionsCollectionData in src/lib/github.ts and then imports/uses it in
src/lib/githubYearInReview.ts, demonstrating it is shared across modules but not centralized.

Rule 226102: Centralize shared TypeScript types in src/lib/types.ts
src/lib/github.ts[486-500]
src/lib/githubYearInReview.ts[7-56]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A shared TypeScript type (`ContributionsCollectionData`) is defined/exported from `src/lib/github.ts` but is consumed by multiple modules, so it should live in `src/lib/types.ts` per the compliance rule.

## Issue Context
`src/lib/types.ts` is already the central location for shared types and is already imported by `src/lib/githubYearInReview.ts`.

## Fix Focus Areas
- src/lib/github.ts[486-500]
- src/lib/githubYearInReview.ts[1-57]
- src/lib/types.ts[1-120]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

2. Duplicate github imports 🐞 Bug ⚙ Maintainability
Description
src/lib/githubYearInReview.ts now imports from "@/lib/github" twice, which adds noise and
complicates future import refactors. Also, ContributionsCollectionData is only used in a type
position and should be imported with type for clarity/consistency.
Code

src/lib/githubYearInReview.ts[7]

+import { CONTRIBUTIONS_COLLECTION_FRAGMENT, ContributionsCollectionData } from "@/lib/github";
Evidence
The file now contains two imports from the same module, and the newly imported
ContributionsCollectionData is only referenced inside a type definition (no runtime usage).

src/lib/githubYearInReview.ts[3-8]
src/lib/githubYearInReview.ts[48-57]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`src/lib/githubYearInReview.ts` has two separate import statements from `@/lib/github`, and `ContributionsCollectionData` is only used as a TypeScript type. This is unnecessary duplication and makes the import section harder to maintain.

### Issue Context
- There is already an existing import from `@/lib/github` for `headers` and `handleRateLimit`.
- The PR adds a second import from the same module for `CONTRIBUTIONS_COLLECTION_FRAGMENT` and `ContributionsCollectionData`.
- `ContributionsCollectionData` is used only in the `YearInReviewResponse` type.

### Fix
Merge the imports into a single statement and import the type using `type`:

```ts
import {
 headers,
 handleRateLimit,
 CONTRIBUTIONS_COLLECTION_FRAGMENT,
 type ContributionsCollectionData,
} from "@/lib/github";
```

### Fix Focus Areas
- src/lib/githubYearInReview.ts[4-8]
- src/lib/githubYearInReview.ts[48-57]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context used
✅ Compliance rules (platform): 30 rules

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

Comment thread src/lib/github.ts
Comment on lines +486 to +490
export type ContributionsCollectionData = {
totalCommitContributions: number;
totalPullRequestContributions: number;
totalIssueContributions: number;
totalPullRequestReviewContributions: number;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. contributionscollectiondata not in types.ts 📘 Rule violation ⌂ Architecture

ContributionsCollectionData is exported from src/lib/github.ts but is imported and used by
src/lib/githubYearInReview.ts, making it a cross-module shared type that should be centralized in
src/lib/types.ts. Keeping shared types outside src/lib/types.ts increases duplication risk and
violates the project’s type-centralization rule.
Agent Prompt
## Issue description
A shared TypeScript type (`ContributionsCollectionData`) is defined/exported from `src/lib/github.ts` but is consumed by multiple modules, so it should live in `src/lib/types.ts` per the compliance rule.

## Issue Context
`src/lib/types.ts` is already the central location for shared types and is already imported by `src/lib/githubYearInReview.ts`.

## Fix Focus Areas
- src/lib/github.ts[486-500]
- src/lib/githubYearInReview.ts[1-57]
- src/lib/types.ts[1-120]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

import { headers, handleRateLimit } from "@/lib/github";
import { buildHourlyHeatmapFromCommitDates, getMostActiveDayFromCalendar, getMostActiveHour } from "@/lib/yearInReviewUtils";
import { logger } from "@/lib/logger";
import { CONTRIBUTIONS_COLLECTION_FRAGMENT, ContributionsCollectionData } from "@/lib/github";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Informational

2. Duplicate github imports 🐞 Bug ⚙ Maintainability

src/lib/githubYearInReview.ts now imports from "@/lib/github" twice, which adds noise and
complicates future import refactors. Also, ContributionsCollectionData is only used in a type
position and should be imported with type for clarity/consistency.
Agent Prompt
### Issue description
`src/lib/githubYearInReview.ts` has two separate import statements from `@/lib/github`, and `ContributionsCollectionData` is only used as a TypeScript type. This is unnecessary duplication and makes the import section harder to maintain.

### Issue Context
- There is already an existing import from `@/lib/github` for `headers` and `handleRateLimit`.
- The PR adds a second import from the same module for `CONTRIBUTIONS_COLLECTION_FRAGMENT` and `ContributionsCollectionData`.
- `ContributionsCollectionData` is used only in the `YearInReviewResponse` type.

### Fix
Merge the imports into a single statement and import the type using `type`:

```ts
import {
  headers,
  handleRateLimit,
  CONTRIBUTIONS_COLLECTION_FRAGMENT,
  type ContributionsCollectionData,
} from "@/lib/github";
```

### Fix Focus Areas
- src/lib/githubYearInReview.ts[4-8]
- src/lib/githubYearInReview.ts[48-57]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@is0692vs

is0692vs commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #558; both extract the contributionsCollection GraphQL fragment, while #558 centralizes it in githubQueries for reuse.

@is0692vs is0692vs closed this Aug 9, 2026
@is0692vs
is0692vs deleted the jules-11168113056124209276-e39adfdd branch August 9, 2026 13:44
@google-labs-jules

Copy link
Copy Markdown
Contributor

Closing as a duplicate of #558; both extract the contributionsCollection GraphQL fragment, while #558 centralizes it in githubQueries for reuse.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant