Skip to content

[BUG] Goal sync writes GitHub's capped total_count (hard-capped at 1000) as commit progress, corrupting goals for active contributors #982

@anshul23102

Description

@anshul23102

Describe the Bug

The /api/goals/sync endpoint fetches weekly commit count from the GitHub Search API and writes ghData.total_count directly as the goal's current value.

Relevant code in src/app/api/goals/sync/route.ts:

const ghData = (await ghRes.json()) as { total_count: number };
const commitCount = ghData.total_count;

await supabaseAdmin
  .from('goals')
  .update({ current: commitCount, last_synced_at: now })
  .in('id', ids);

This has two distinct problems:

Problem 1: GitHub hard-caps total_count at 1000

The GitHub Search API documents that total_count is capped at 1000 regardless of actual results. For prolific contributors this means:

  • A user with 1200 commits this week gets current = 1000, not 1200
  • A user with a goal target of 50 commits can have current set to 1000, making the goal appear 20x over-completed

Problem 2: All commit goals receive the same aggregate count

The sync query uses a single total across all repos and all timeframes. A user with two separate goals:

  • "50 commits to frontend repo this week"
  • "20 commits to backend repo this week"

...both get overwritten with the same combined cross-repository total_count. Per-repo goal tracking is completely broken.

Steps to Reproduce

  1. Create two commit-based weekly goals targeting different values
  2. Make more than 1000 commits in a week (or observe with any active multi-repo workflow)
  3. Trigger goal sync
  4. Both goals show the same current value; goals with a target below total_count appear falsely completed

Expected Behavior

  • Commit count used for goal progress should come from paginating data.items (actual returned results) rather than trusting total_count
  • For per-repo goals, the sync query should be scoped to the goal's target repository, not a cross-all-repos aggregate

Screenshots / Logs

GitHub API response excerpt:

{
  "total_count": 1000,
  "incomplete_results": true,
  "items": [...]
}

When incomplete_results: true, the real count exceeds 1000 but total_count is capped.

Environment

  • OS: Any
  • Node version: 18+
  • Browser: Any

Additional Context

Existing issue #361 documents a similar cap problem with the contributions widget. The same root cause applies here in the goals sync path.

I am happy to work on this if it can be assigned to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions