mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-05 21:38:13 +02:00
fix(pulls): report stack merge API permission errors
Assisted-by: Codet:GPT-5-Codex
This commit is contained in:
@@ -120,7 +120,7 @@ func AddPullStackEntry(ctx stdctx.Context, login *config.Login, owner, repo stri
|
|||||||
return &s, nil
|
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 {
|
func RestackPullStack(ctx stdctx.Context, login *config.Login, owner, repo string, id int64) error {
|
||||||
client := api.NewClient(login)
|
client := api.NewClient(login)
|
||||||
resp, err := client.DoContext(ctx, http.MethodPost, fmt.Sprintf("/repos/%s/%s/stacks/%d/restack", owner, repo, id), nil, nil)
|
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 {
|
if resp.StatusCode == http.StatusAccepted {
|
||||||
return nil, true, nil
|
return nil, true, nil
|
||||||
}
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusConflict {
|
||||||
|
return nil, false, stackAPIError(resp)
|
||||||
|
}
|
||||||
|
|
||||||
var body stack.MergeResult
|
var body stack.MergeResult
|
||||||
if decodeErr := json.NewDecoder(resp.Body).Decode(&body); decodeErr != nil {
|
if decodeErr := json.NewDecoder(resp.Body).Decode(&body); decodeErr != nil {
|
||||||
return nil, false, fmt.Errorf("%s: failed to decode response: %w", resp.Status, decodeErr)
|
return nil, false, fmt.Errorf("%s: failed to decode response: %w", resp.Status, decodeErr)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
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, fmt.Errorf("%s", body.Error)
|
||||||
}
|
}
|
||||||
return &body, false, nil
|
return &body, false, nil
|
||||||
|
|||||||
@@ -227,3 +227,17 @@ func TestMergePullStackPartialFailure(t *testing.T) {
|
|||||||
require.NotNil(t, result)
|
require.NotNil(t, result)
|
||||||
assert.Equal(t, int64(1), result.Merged)
|
assert.Equal(t, int64(1), result.Merged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMergePullStackPermissionDenied(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusForbidden)
|
||||||
|
_, _ = w.Write([]byte(`{"message":"merge not permitted"}`))
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
result, queued, err := MergePullStack(t.Context(), &config.Login{
|
||||||
|
Name: "test", URL: server.URL, Token: "secret-token",
|
||||||
|
}, "owner", "repo", 6, "merge", false)
|
||||||
|
require.ErrorContains(t, err, "merge not permitted")
|
||||||
|
assert.False(t, queued)
|
||||||
|
assert.Nil(t, result)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user