Skip to content

🧹 Refactor: Extract GraphQL fragment for contributionsCollection - #558

Open
is0692vs wants to merge 1 commit into
mainfrom
jules-6402684108824583430-f936f2c9
Open

🧹 Refactor: Extract GraphQL fragment for contributionsCollection#558
is0692vs wants to merge 1 commit into
mainfrom
jules-6402684108824583430-f936f2c9

Conversation

@is0692vs

@is0692vs is0692vs commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🎯 What: Extracted the duplicated GraphQL query fragment for contributionsCollection into a shared configuration.
💡 Why: This improves maintainability and readability by deduplicating the query definition between fetchContributions (in src/lib/github.ts) and YEAR_IN_REVIEW_QUERY (in src/lib/githubYearInReview.ts), minimizing the risk of modifying the shape of the data in one place but forgetting the other. A shared TypeScript type BaseContributionsCollection has been introduced as well to unify the response types.
Verification: Verified by checking that npm run test, npm run build, and npm run lint pass successfully. The application logic logic remains unchanged while standardizing the query requests.
Result: Improved maintainability and DRYer codebase regarding GitHub GraphQL API usage.


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

Greptile Summary

contributionsCollection の共通フィールドを共有 GraphQL フラグメントと TypeScript 型へ抽出するリファクタリングです。既存の取得フィールドとアプリケーションロジックは維持されています。

  • CONTRIBUTIONS_COLLECTION_FRAGMENTBaseContributionsCollection を追加
  • 通常のコントリビューション取得クエリで共有フラグメントを利用
  • Year in Review クエリとレスポンス型でも同じ定義を再利用

Confidence Score: 5/5

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

生成される GraphQL クエリは従来と同じフィールドを要求し、Year in Review 固有のフィールドも保持されているため、ブロッキングとなる動作変更は確認されませんでした。

Important Files Changed

Filename Overview
src/lib/github.ts インラインのコントリビューション選択フィールドと型を共有定義へ置き換えており、取得データの形は維持されています。
src/lib/githubQueries.ts 既存の共通 GraphQL フィールドと対応する TypeScript 型を一箇所に集約しています。
src/lib/githubYearInReview.ts Year in Review 固有のリポジトリ別フィールドを残しつつ、共通フィールドと基本型を再利用しています。

Reviews (1): Last reviewed commit: "Refactor: Extract common GraphQL fragmen..." | Re-trigger Greptile

Context used:

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:56am

@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: 46 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: a82ba203-41ee-4ed0-aad8-72429e43f384

📥 Commits

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

📒 Files selected for processing (3)
  • src/lib/github.ts
  • src/lib/githubQueries.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

Refactor: Deduplicate contributionsCollection GraphQL fields via shared fragment

✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Extract shared contributionsCollection GraphQL fields into a reusable fragment
• Reuse the fragment in both fetchContributions and Year-In-Review query
• Introduce a shared TypeScript base type to keep response shapes consistent
Diagram

graph TD
  A["src/lib/github.ts"] --> B["src/lib/githubQueries.ts"] --> C{{"GitHub GraphQL API"}}
  D["src/lib/githubYearInReview.ts"] --> B

  subgraph Legend
    direction LR
    _mod[Module] ~~~ _ext{{External API}}
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Adopt GraphQL code generation (schema + operations → typed artifacts)
  • ➕ Eliminates manual TS response types and reduces drift risk further
  • ➕ Can validate queries at build time and generate fragments/types consistently
  • ➖ Adds build tooling and workflow complexity
  • ➖ Requires maintaining schema introspection and codegen configuration
2. Centralize full queries in a single module (no inline query strings)
  • ➕ Further reduces duplication beyond the fragment
  • ➕ Makes query auditing/versioning easier
  • ➖ Less local context at call sites; may reduce readability where used
  • ➖ Can become a large grab-bag module without clear ownership

Recommendation: The chosen approach (shared fragment + shared base type) is the best incremental step: it removes the current duplication with minimal tooling overhead and keeps query intent readable at call sites. If query surface area grows or type drift becomes a recurring issue, consider GraphQL codegen as a next step.

Files changed (3) +43 / -57

Refactor (3) +43 / -57
github.tsReuse shared contributions fragment and base response type +5/-29

Reuse shared contributions fragment and base response type

• Imports the shared contributions fragment and BaseContributionsCollection type. Updates fetchContributions to spread the fragment instead of duplicating fields, and simplifies the response typing accordingly.

src/lib/github.ts

githubQueries.tsAdd shared contributionsCollection fragment and BaseContributionsCollection type +33/-0

Add shared contributionsCollection fragment and BaseContributionsCollection type

• Introduces a reusable GraphQL fragment for the common contributionsCollection field set. Adds a shared TypeScript type representing the base contributionsCollection shape used by multiple queries.

src/lib/githubQueries.ts

githubYearInReview.tsDeduplicate Year-In-Review contributions fields via fragment and shared type +5/-28

Deduplicate Year-In-Review contributions fields via fragment and shared type

• Imports and uses the shared contributions fragment in YEAR_IN_REVIEW_QUERY. Refactors the YearInReviewResponse type to compose BaseContributionsCollection with additional by-repository fields.

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. BaseContributionsCollection outside types.ts 📘 Rule violation ⌂ Architecture
Description
BaseContributionsCollection is a shared exported type used by multiple modules, but it is defined
in src/lib/githubQueries.ts instead of being centralized in src/lib/types.ts. This increases the
risk of shared-type drift and violates the project’s type centralization requirement.
Code

src/lib/githubQueries.ts[R19-22]

+export type BaseContributionsCollection = {
+  totalCommitContributions: number;
+  totalPullRequestContributions: number;
+  totalIssueContributions: number;
Evidence
The checklist requires shared types used across multiple modules to be defined in
src/lib/types.ts. The PR adds BaseContributionsCollection as an exported type in
src/lib/githubQueries.ts, and the diff shows it being imported/used from both src/lib/github.ts
and src/lib/githubYearInReview.ts, demonstrating cross-module usage while remaining outside
types.ts.

Rule 226102: Centralize shared TypeScript types in src/lib/types.ts
src/lib/githubQueries.ts[19-33]
src/lib/github.ts[1-4]
src/lib/githubYearInReview.ts[3-8]

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 exported TypeScript type (`BaseContributionsCollection`) is defined in `src/lib/githubQueries.ts` even though it is imported by multiple modules. Per compliance, cross-module/shared types must be centralized in `src/lib/types.ts`.

## Issue Context
`BaseContributionsCollection` is imported/used by both `src/lib/github.ts` and `src/lib/githubYearInReview.ts`, so it qualifies as a shared type.

## Fix Focus Areas
- src/lib/githubQueries.ts[19-33]
- src/lib/types.ts[1-120]
- src/lib/github.ts[1-20]
- src/lib/githubYearInReview.ts[1-12]

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



Informational

2. Mixed import path styles 🐞 Bug ⚙ Maintainability
Description
The new githubQueries module is imported with two different specifiers (./githubQueries vs
@/lib/githubQueries), which reduces consistency and can make refactors/searches harder (and in
some toolchains can create duplicate module identities). Standardizing on one import style for this
module will avoid these issues.
Code

src/lib/github.ts[R1-4]

import "server-only";
import { cache } from 'react';
+import { CONTRIBUTIONS_COLLECTION_FRAGMENT, type BaseContributionsCollection } from "./githubQueries";
import { logger } from "@/lib/logger";
Evidence
The PR introduces two different import specifiers that both resolve to the newly added
src/lib/githubQueries.ts, creating an inconsistency in how the same module is referenced across
the codebase.

src/lib/github.ts[1-5]
src/lib/githubYearInReview.ts[3-28]

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/githubQueries.ts` is imported via two different module specifiers:
- relative import in `src/lib/github.ts`
- alias import in `src/lib/githubYearInReview.ts`

This inconsistency makes the codebase less uniform and may cause tooling/bundler edge-cases where the same file is treated as two separate module identities.

## Issue Context
Both imports were introduced as part of this PR when extracting the shared GraphQL fragment and base type.

## Fix Focus Areas
- src/lib/github.ts[1-4]
- src/lib/githubYearInReview.ts[3-8]

## Suggested fix
Pick one convention and apply it consistently for `githubQueries`, e.g. change `src/lib/github.ts` to:
```ts
import { CONTRIBUTIONS_COLLECTION_FRAGMENT, type BaseContributionsCollection } from "@/lib/githubQueries";
```
(or alternatively switch `githubYearInReview.ts` to a relative import).

ⓘ 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/githubQueries.ts
Comment on lines +19 to +22
export type BaseContributionsCollection = {
totalCommitContributions: number;
totalPullRequestContributions: number;
totalIssueContributions: 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. basecontributionscollection outside types.ts 📘 Rule violation ⌂ Architecture

BaseContributionsCollection is a shared exported type used by multiple modules, but it is defined
in src/lib/githubQueries.ts instead of being centralized in src/lib/types.ts. This increases the
risk of shared-type drift and violates the project’s type centralization requirement.
Agent Prompt
## Issue description
A shared exported TypeScript type (`BaseContributionsCollection`) is defined in `src/lib/githubQueries.ts` even though it is imported by multiple modules. Per compliance, cross-module/shared types must be centralized in `src/lib/types.ts`.

## Issue Context
`BaseContributionsCollection` is imported/used by both `src/lib/github.ts` and `src/lib/githubYearInReview.ts`, so it qualifies as a shared type.

## Fix Focus Areas
- src/lib/githubQueries.ts[19-33]
- src/lib/types.ts[1-120]
- src/lib/github.ts[1-20]
- src/lib/githubYearInReview.ts[1-12]

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

Comment thread src/lib/github.ts
Comment on lines 1 to 4
import "server-only";
import { cache } from 'react';
import { CONTRIBUTIONS_COLLECTION_FRAGMENT, type BaseContributionsCollection } from "./githubQueries";
import { logger } from "@/lib/logger";

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. Mixed import path styles 🐞 Bug ⚙ Maintainability

The new githubQueries module is imported with two different specifiers (./githubQueries vs
@/lib/githubQueries), which reduces consistency and can make refactors/searches harder (and in
some toolchains can create duplicate module identities). Standardizing on one import style for this
module will avoid these issues.
Agent Prompt
## Issue description
`src/lib/githubQueries.ts` is imported via two different module specifiers:
- relative import in `src/lib/github.ts`
- alias import in `src/lib/githubYearInReview.ts`

This inconsistency makes the codebase less uniform and may cause tooling/bundler edge-cases where the same file is treated as two separate module identities.

## Issue Context
Both imports were introduced as part of this PR when extracting the shared GraphQL fragment and base type.

## Fix Focus Areas
- src/lib/github.ts[1-4]
- src/lib/githubYearInReview.ts[3-8]

## Suggested fix
Pick one convention and apply it consistently for `githubQueries`, e.g. change `src/lib/github.ts` to:
```ts
import { CONTRIBUTIONS_COLLECTION_FRAGMENT, type BaseContributionsCollection } from "@/lib/githubQueries";
```
(or alternatively switch `githubYearInReview.ts` to a relative import).

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

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