fix(pulls): report stack merge API permission errors

Assisted-by: Codet:GPT-5-Codex
This commit is contained in:
Lunny Xiao
2026-09-24 23:27:23 -07:00
parent ba167a7352
commit f28a5e696a
2 changed files with 21 additions and 1 deletions
+7 -1
View File
@@ -120,7 +120,7 @@ func AddPullStackEntry(ctx stdctx.Context, login *config.Login, owner, repo stri
return &s, nil
}
// RestackPullStack queues a restack of every entry above the merged pull request in the stack.
// RestackPullStack queues a restack starting at the stack's base branch.
func RestackPullStack(ctx stdctx.Context, login *config.Login, owner, repo string, id int64) error {
client := api.NewClient(login)
resp, err := client.DoContext(ctx, http.MethodPost, fmt.Sprintf("/repos/%s/%s/stacks/%d/restack", owner, repo, id), nil, nil)
@@ -156,12 +156,18 @@ func MergePullStack(ctx stdctx.Context, login *config.Login, owner, repo string,
if resp.StatusCode == http.StatusAccepted {
return nil, true, nil
}
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusConflict {
return nil, false, stackAPIError(resp)
}
var body stack.MergeResult
if decodeErr := json.NewDecoder(resp.Body).Decode(&body); decodeErr != nil {
return nil, false, fmt.Errorf("%s: failed to decode response: %w", resp.Status, decodeErr)
}
if resp.StatusCode != http.StatusOK {
if body.Error == "" {
return &body, false, fmt.Errorf("%s", resp.Status)
}
return &body, false, fmt.Errorf("%s", body.Error)
}
return &body, false, nil