Skip to content

Commit db8f91b

Browse files
committed
guard for edge case of deleted PR
1 parent 8bf3a9c commit db8f91b

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

cmd/push_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,17 @@ func TestPush_NoSubmitHintWhenPRsExist(t *testing.T) {
8484
defer restore()
8585

8686
cfg, _, errR := config.NewTestConfig()
87-
cfg.GitHubClientOverride = &github.MockClient{}
87+
cfg.GitHubClientOverride = &github.MockClient{
88+
FindPRByNumberFn: func(number int) (*github.PullRequest, error) {
89+
switch number {
90+
case 10:
91+
return &github.PullRequest{Number: 10, State: "OPEN", HeadRefName: "b1"}, nil
92+
case 11:
93+
return &github.PullRequest{Number: 11, State: "OPEN", HeadRefName: "b2"}, nil
94+
}
95+
return nil, nil
96+
},
97+
}
8898
cmd := PushCmd(cfg)
8999
cmd.SetOut(io.Discard)
90100
cmd.SetErr(io.Discard)

cmd/utils.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,31 @@ func syncStackPRs(cfg *config.Config, s *stack.Stack) {
269269
if b.PullRequest != nil && b.PullRequest.Number != 0 {
270270
// Tracked PR — refresh its state.
271271
pr, err := client.FindPRByNumber(b.PullRequest.Number)
272-
if err != nil || pr == nil {
273-
continue
274-
}
275-
b.PullRequest = &stack.PullRequestRef{
276-
Number: pr.Number,
277-
ID: pr.ID,
278-
URL: pr.URL,
279-
Merged: pr.Merged,
272+
if err != nil {
273+
continue // API error — keep existing tracked PR
280274
}
281-
b.Queued = pr.IsQueued()
282-
283-
// If the PR was closed (not merged), remove the association
284-
// so we fall through to the open-PR lookup below.
285-
if pr.State == "CLOSED" {
275+
if pr == nil {
276+
// PR not found — clear stale ref and fall through
277+
// to the open-PR lookup below.
286278
b.PullRequest = nil
287279
b.Queued = false
288280
} else {
289-
continue
281+
b.PullRequest = &stack.PullRequestRef{
282+
Number: pr.Number,
283+
ID: pr.ID,
284+
URL: pr.URL,
285+
Merged: pr.Merged,
286+
}
287+
b.Queued = pr.IsQueued()
288+
289+
// If the PR was closed (not merged), remove the association
290+
// so we fall through to the open-PR lookup below.
291+
if pr.State == "CLOSED" {
292+
b.PullRequest = nil
293+
b.Queued = false
294+
} else {
295+
continue
296+
}
290297
}
291298
}
292299

0 commit comments

Comments
 (0)