Skip to content

feat: add gh contributions to display contributions graph#13231

Open
maaslalani wants to merge 2 commits intocli:trunkfrom
maaslalani:maaslalani/contributions
Open

feat: add gh contributions to display contributions graph#13231
maaslalani wants to merge 2 commits intocli:trunkfrom
maaslalani:maaslalani/contributions

Conversation

@maaslalani
Copy link
Copy Markdown

@maaslalani maaslalani commented Apr 19, 2026

image

Adds gh contributions to display GitHub contributions graph on the terminal.

Copilot AI review requested due to automatic review settings April 19, 2026 23:41
@maaslalani maaslalani requested a review from a team as a code owner April 19, 2026 23:41
@github-actions github-actions bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Apr 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new gh contributions command to display a GitHub contributions “heatmap” graph in the terminal.

Changes:

  • Registers the new contributions command on the CLI root.
  • Implements GraphQL fetching and terminal rendering (plus JSON export support) for contribution calendar data.
  • Adds unit tests covering flag parsing, date parsing, rendering output, JSON export, and user-not-found handling.
Show a summary per file
File Description
pkg/cmd/root/root.go Wires gh contributions into the root command so it’s available to users.
pkg/cmd/contributions/http.go Implements GraphQL requests to fetch viewer/user contribution calendar data.
pkg/cmd/contributions/contributions.go Adds the command, flag handling, JSON export shaping, and terminal calendar rendering.
pkg/cmd/contributions/contributions_test.go Adds tests for command parsing and core behaviors (rendering, JSON, errors).

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

pkg/cmd/contributions/contributions.go:41

  • Now: time.Now is assigned into ContributionsOptions, but opts.Now is not used anywhere. If Now is removed (recommended), this initialization should be removed too; otherwise wire it into the logic that needs current time.
	opts := &ContributionsOptions{
		IO:         f.IOStreams,
		HttpClient: f.HttpClient,
		Now:        time.Now,
	}
  • Files reviewed: 4/4 changed files
  • Comments generated: 3

Comment thread pkg/cmd/contributions/contributions.go Outdated
HttpClient func() (*http.Client, error)
HostConfig hostConfig
IO *iostreams.IOStreams
Now func() time.Time
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

ContributionsOptions.Now is set but never read anywhere in this package. This adds unused surface area and can confuse future maintainers; either remove the field entirely or use it for default range calculations so tests can control time.

This issue also appears on line 37 of the same file.

Copilot uses AI. Check for mistakes.
Comment thread pkg/cmd/contributions/contributions.go Outdated
// exportable shapes the result for JSON output, flattening days for
// easier consumption.
func exportable(r *ContributionsResult) map[string]any {
days := make([]ContributionDay, 0)
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

days := make([]ContributionDay, 0) will reallocate as weeks are appended. Since the total number of days is bounded and known-ish (len(weeks)*7), consider preallocating capacity to avoid repeated allocations when exporting JSON.

Suggested change
days := make([]ContributionDay, 0)
days := make([]ContributionDay, 0, len(r.Calendar.Weeks)*7)

Copilot uses AI. Check for mistakes.
Comment on lines +194 to +196
assert.Contains(t, out, "M")
assert.Contains(t, out, "W")
assert.Contains(t, out, "F")
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

These assertions are very broad: "M" will match many parts of the output (e.g., "More", month names, ANSI sequences), so the test can pass even if day labels are missing. Consider asserting on something more specific (e.g., the expected day-label column pattern or a line prefix) to avoid false positives.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team needs-triage needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants