Skip to content

feat: add --org flag to filter contributions by organization - #108

Open
omercnet wants to merge 2 commits into
github:mainfrom
omercnet:feature/org-filter
Open

feat: add --org flag to filter contributions by organization#108
omercnet wants to merge 2 commits into
github:mainfrom
omercnet:feature/org-filter

Conversation

@omercnet

@omercnetomercnet commented Dec 29, 2025

Copy link
Copy Markdown

Summary

Add support for generating skylines scoped to a specific GitHub organization. This is useful for teams who want to visualize contributions to their org's repos specifically, rather than a user's entire GitHub activity.

 ┌─────────────────────────────────────────────────────────────┐
│ │
│ 🏢 ORG-SCOPED SKYLINES │
│ │
│ gh skyline --user employee --org mycompany --year 2024 │
│ │
└─────────────────────────────────────────────────────────────┘

Usage

# Generate skyline for contributions to a specific org
gh skyline --user octocat --org github --year 2024
# Works with year ranges too
gh skyline --user octocat --org github --year 2020-2024

Implementation Details

  • New --org flag accepts organization login name
  • Uses contributionsByRepository GraphQL queries to get commits, PRs, issues, and reviews grouped by repository
  • Quarterly queries to work around GitHub's 100 repo limit per request (supports up to 400 repos/year)
  • Client-side filtering by repository owner to isolate org contributions
  • Aggregates into standard contribution grid format for seamless STL generation

Why quarterly queries?

GitHub's GraphQL API limits contributionsByRepository to 100 repositories per request with no pagination cursor. By querying each quarter separately, we can capture contributions across up to 400 repos per year, which covers virtually all real-world usage patterns.

// Query each quarter separately to work around the 100 repo limit per query.// Each query can return up to 100 unique repos, so quarterly queries give us up to 400 repos/year.quarters:= []struct{ start, endstring }{
{"2024-01-01", "2024-03-31"},
{"2024-04-01", "2024-06-30"},
{"2024-07-01", "2024-09-30"},
{"2024-10-01", "2024-12-31"},
}

Example Output

=== ORG ONLY 2024 ===
╻ ┃ ▓ ░ ▓ ░ ╻ ╻ ╻╻ ░ ╻ ╻ ╻┃ ╽▒╻ ╻ ░╻ ░ ▒░ ╻╻ ▒ ░╻╻ ╻░ ░ ▓ ░░▓░░▒░░░ ▒ ▒░ ▒ ░░▒▒▓ ░░░░░░ ▒░░▒░ ░░░▒░
=== ALL CONTRIBUTIONS 2024 ===
╻ ╻ ╻ ╻╻ ╻ ╻╻ ╻ ░ ╻░ ░ ╻ ░░ ╻╻ ╻╻╻░╻ ╻░░ ╻ ╻ ╻ ░╻╻ ░╻░░╻╻░╻╻╻╻╻░╻ ░░╻╻ ░░╻ ░░░░░╻╻░▒░ ░ ░ ░ ▒▓░ ╻░░░░░░░░░░░▒░░ ╻ ░░░░╻░░░ ░░░░░░░░▒░╻▒╻░ ╻╻░╻ ░░░ ░░░░░░░░░░░░░░░╻ ░ ░░░░░░░░╻░░░░░░░░▒░░░░░╻░░░░╻░░░╻
░░░░░░░░░░░░▒░░░╻░╻╻░▒░░░░░░░░░░░░░░░░▒▒░░░░░░░░░░░░░
░░░░░░░░░▒░░░░░░░▒░░░░░░░░░░░░░░░▒░░░░░░▒░░░░░░░░░░▒░

Tests Added

  • TestFetchOrgContributions - validation and error handling for the new client method
  • TestGenerateSkylineWithOrg - integration tests with org flag
  • TestBuildContributionGrid - unit tests for the contribution grid builder
  • TestFetchOrgContributionDataFiltering - verifies org filtering excludes non-org repos

Files Changed

FileChange
cmd/root.goAdded --org flag
internal/types/types.goAdded OrgContributionsResponse type
internal/github/client.goAdded FetchOrgContributions with quarterly queries
cmd/skyline/skyline.goAdded org-filtering logic + buildContributionGrid
internal/testutil/mocks/github.goExtended mock for org contributions
cmd/skyline/skyline_test.goAdded comprehensive tests
internal/github/client_test.goAdded tests for FetchOrgContributions

Add support for generating skylines scoped to a specific GitHub organization.
This is useful for teams who want to visualize contributions to their org's
repos specifically, rather than a user's entire GitHub activity.
Implementation details:
- New --org flag accepts organization login name
- Uses contributionsByRepository GraphQL queries (commits, PRs, issues, reviews)
- Queries each quarter separately to work around GitHub's 100 repo limit
- Filters results client-side by repository owner
- Aggregates into the same contribution grid format for STL generation
Example usage:
gh skyline --user employee --org mycompany --year 2024

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for filtering GitHub contributions by organization through a new --org flag. Users can now generate skyline visualizations scoped to contributions made to a specific organization's repositories, rather than all their GitHub activity.

Key changes:

  • Adds --org flag to filter contributions by organization
  • Implements quarterly GraphQL queries to work around GitHub's 100 repository per request limit
  • Introduces client-side filtering logic to aggregate organization-specific contributions into the standard contribution grid format

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.

Show a summary per file
FileDescription
cmd/root.goAdds the --org flag and passes it to the skyline generation function
internal/types/types.goDefines OrgContributionsResponse struct for repository-grouped contribution data from GraphQL API
internal/github/client.goImplements FetchOrgContributions method with quarterly queries to fetch contribution data by repository
cmd/skyline/skyline.goAdds org filtering logic in fetchOrgContributionData and buildContributionGrid helper function
internal/testutil/mocks/github.goExtends mock client to support org contribution testing with GenerateOrgContributionsResponse
cmd/skyline/skyline_test.goAdds comprehensive test coverage for org filtering functionality
internal/github/client_test.goAdds unit tests for FetchOrgContributions validation and error handling

Comment threadcmd/skyline/skyline.go Outdated
Comment threadcmd/skyline/skyline.go Outdated
Comment threadcmd/skyline/skyline.go Outdated
Comment threadcmd/skyline/skyline.go Outdated
Comment threadcmd/skyline/skyline.go Outdated
Comment threadcmd/skyline/skyline.go Outdated
Comment threadinternal/testutil/mocks/github.go
Comment threadcmd/skyline/skyline.go Outdated
Comment threadcmd/skyline/skyline.go
- Replace unsafe string slice with proper time.Parse for RFC3339 timestamps
- Fix potential infinite loop in buildContributionGrid with cleaner termination
- Simplify complex year condition to straightforward date comparison
- Extract addContributionDate helper to reduce code duplication
- Add GoDoc comment to GenerateOrgContributionsResponse
@omercnet

Copy link
Copy Markdown
Author

Review Comments Addressed ✅

All 9 review comments from Copilot have been addressed in commit 9022747:

Critical Fixes

  1. Infinite loop (line 186) - Refactored buildContributionGrid with proper loop termination. Loop now only iterates until endDate, with partial week handling moved outside the loop.

  2. Unsafe string slice (lines 142, 150, 158, 166) - Replaced node.OccurredAt[:10] with proper time.Parse(time.RFC3339, timestamp) in new addContributionDate helper. Silently skips malformed timestamps for robustness.

  3. Complex year condition (line 190) - Simplified to straightforward !d.After(endDate) check. Previous year days are naturally included via Sunday-aligned startDate.

Code Quality

  1. Code duplication - Extracted addContributionDate(timestamp, counts) helper used by all 4 contribution type loops.

  2. Missing GoDoc - Added GoDoc comment to GenerateOrgContributionsResponse.

All threads resolved via GraphQL API.

@Shakacro

Copy link
Copy Markdown

Thank you all. He deserved. 👍

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

Labels

None yet

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

3 participants

@omercnet@Shakacro