Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 7, 2025

Problem

In GitHub Enterprise environments with multiple organizations, users assigned to GitHub Copilot across different organizations within the same enterprise were appearing as duplicates in the "Seat Analysis" tab. This caused inflated seat counts that didn't match the actual billing.

According to GitHub's documentation:

If a single user receives a seat from multiple organizations in the same enterprise, the enterprise will only be billed once per billing cycle for that unique user.

However, the GitHub API returns separate seat entries for each organization assignment, leading to duplicate entries in the UI while the total_seats field correctly reflects the unique user count.

Solution

Added deduplication logic to the seats API endpoint (/server/api/seats.ts) that:

  1. Removes duplicate users by GitHub ID - Uses the unique user ID to identify duplicates
  2. Preserves most recent data - When duplicates exist, keeps the seat entry with the most recent activity
  3. Maintains data integrity - Handles edge cases like null activity dates gracefully
  4. Works for all scopes - Applied to both organization and enterprise seat data
  5. Supports mock data - Deduplication also works with mocked data for testing

Key Changes

  • server/api/seats.ts: Added deduplicateSeats() function that removes duplicates by user ID
  • Comprehensive tests: Added test suites covering various deduplication scenarios
  • Mock data: Created test data with duplicates to validate the fix
  • Backward compatibility: No breaking changes to existing functionality

Visual Result

Seat Analysis After Deduplication

The "Total Assigned" count now correctly shows 1 unique user instead of showing multiple entries for the same user across different organizations. This aligns with GitHub's billing model and the total_seats value from the API.

Testing

  • ✅ All existing tests continue to pass
  • ✅ New unit tests verify deduplication logic with edge cases
  • ✅ Integration tests confirm API behavior with mock data
  • ✅ Manual testing validates UI shows correct seat counts
  • ✅ Linting passes for all modified files

Fixes #178.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.fontshare.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • api.fontsource.org
    • Triggering command: node (vitest) (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • fonts.bunny.net
    • Triggering command: node (vitest) (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • fonts.google.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: /usr/local/bin/node --enable-source-maps /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/@nuxt/cli/bin/nuxi.mjs _dev (dns block)
  • fonts.googleapis.com
    • Triggering command: node (vitest 2) (dns block)
    • Triggering command: node (vitest 3) (dns block)
    • Triggering command: node (vitest 1) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Duplicate users with Github Enterprise and multiple organizations Fix duplicate users in GitHub Enterprise with multiple organizations Jul 7, 2025
@Copilot Copilot AI requested a review from karpikpl July 7, 2025 20:25
Copilot finished work on behalf of karpikpl July 7, 2025 20:25
@karpikpl karpikpl marked this pull request as ready for review July 8, 2025 03:45
@karpikpl karpikpl merged commit eb878e5 into main Jul 8, 2025
9 checks passed
@karpikpl karpikpl deleted the copilot/fix-178 branch July 8, 2025 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate users with Github Enterprise and multiple organizations
2 participants