Skip to content

feat: Add stacked pull request endpoints - #4436

Open
Bortlesboat wants to merge 1 commit into
google:masterfrom
Bortlesboat:4435-stacked-pull-requests
Open

feat: Add stacked pull request endpoints#4436
Bortlesboat wants to merge 1 commit into
google:masterfrom
Bortlesboat:4435-stacked-pull-requests

Conversation

@Bortlesboat

Copy link
Copy Markdown

Fixes #4435

Add typed PullRequestsService support for GitHub's five stacked pull request
REST endpoints:

  • list repository stacks, optionally filtered by pull request;
  • create and get a stack;
  • append pull requests to a stack; and
  • unstack the remaining unmerged pull requests.

The change extends the existing PullRequestStack representation, adds the
request and list-option types, handles both updated-stack and 204 No Content
unstack responses, and regenerates accessors and iterators. Request methods,
paths, query parameters, bodies, response decoding, and failure paths have
focused coverage.

API contract: https://docs.github.com/en/rest/pulls/stacks?apiVersion=2022-11-28

Validation:

  • script/fmt.sh
  • script/lint.sh across all 12 modules
  • script/test.sh -covermode atomic ./... across all 12 modules
  • git diff --check

The local Go configuration has CGO disabled, so a race build was not available;
the full non-race suite passed.

AI assistance: OpenAI Codex helped draft the API bindings, tests, generated-file
workflow, and PR description. I reviewed the rendered diff and validation
evidence, understand every submitted line, and take responsibility for the
contribution and review follow-up.

@gmlewis gmlewis changed the title github: add stacked pull request endpoints feat: Add stacked pull request endpoints Aug 6, 2026
@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Aug 6, 2026
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.56%. Comparing base (4a79475) to head (b89249d).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4436   +/-   ##
=======================================
  Coverage   97.55%   97.56%           
=======================================
  Files         194      195    +1     
  Lines       19892    19962   +70     
=======================================
+ Hits        19406    19476   +70     
  Misses        268      268           
  Partials      218      218           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, @Bortlesboat!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @alexandear - @Not-Dhananjay-Mishra

Comment thread github/pulls.go
Comment on lines 127 to +152
@@ -136,10 +136,20 @@ type PullRequestStack struct {
// Position is the one-based position of this pull request within the stack,
// where 1 is the bottom of the stack.
Position *int `json:"position,omitempty"`
// ID is the ID of the stack that this pull request belongs to.
// ID is the ID of the stack.
ID *int64 `json:"id,omitempty"`
// Number is the number of the stack that this pull request belongs to.
// Number is the number of the stack.
Number *int `json:"number,omitempty"`
// NodeID is the global node ID of the stack.
NodeID *string `json:"node_id,omitempty"`
// URL is the API URL of the stack.
URL *string `json:"url,omitempty"`
// Open reports whether the stack contains any open pull requests.
Open *bool `json:"open,omitempty"`
// CreatedAt is the time the stack was created.
CreatedAt *Timestamp `json:"created_at,omitempty"`
// PullRequests contains the pull requests in the stack, from bottom to top.
PullRequests []*PullRequest `json:"pull_requests,omitempty"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

// PullRequest represents a GitHub pull request on a repository.
type PullRequest struct {
	ID                *int64     `json:"id,omitempty"`
	Number            *int       `json:"number,omitempty"`
    ...
	Head  *PullRequestBranch `json:"head,omitempty"`
	Base  *PullRequestBranch `json:"base,omitempty"`
	Stack *PullRequestStack  `json:"stack,omitempty"`
}

PullRequestStack used with PullRequest struct, but the schema ofPullRequest.Stack(docs) differs from the schema used by the stacked pull request endpoints. I think we should introduce a new struct instead of reusing PullRequestStack.

Comment on lines +301 to +314
func TestPullRequestStack_unmarshal(t *testing.T) {
t.Parallel()
testJSONUnmarshalOnly(t, testPullRequestStack(), testPullRequestStackResponse())
}

func TestCreatePullRequestStackRequest_marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &CreatePullRequestStackRequest{PullRequests: []int{101, 102}}, `{"pull_requests":[101,102]}`)
}

func TestAddPullRequestsToStackRequest_marshal(t *testing.T) {
t.Parallel()
testJSONMarshal(t, &AddPullRequestsToStackRequest{PullRequests: []int{103}}, `{"pull_requests":[103]}`)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These test can be removed, because we only write _marshal/_unmarshal tests for structs that implement custom Marshal/Unmarshal methods.

"page": "2",
"per_page": "50",
})
fmt.Fprintf(w, "[%s]", testPullRequestStackResponse())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
fmt.Fprintf(w, "[%s]", testPullRequestStackResponse())
fmt.Fprintf(w, "[%v]", testPullRequestStackResponse())

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

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for new stacked pull requests endpoints

3 participants