feat(pulls): support branch-validated stack reordering

Assisted-by: Codet:GPT-5-Codex
This commit is contained in:
Lunny Xiao
2026-09-24 23:31:32 -07:00
parent f28a5e696a
commit b06d902687
5 changed files with 103 additions and 1 deletions
+13
View File
@@ -120,6 +120,19 @@ func AddPullStackEntry(ctx stdctx.Context, login *config.Login, owner, repo stri
return &s, nil
}
// ReorderPullStack records the order of PR branches that are already linked.
func ReorderPullStack(ctx stdctx.Context, login *config.Login, owner, repo string, id int64, pullIndices []int64) (*stack.Stack, error) {
var s stack.Stack
err := postStackJSON(ctx, login, fmt.Sprintf("/repos/%s/%s/stacks/%d/reorder", owner, repo, id),
struct {
PullIndices []int64 `json:"pull_indices"`
}{PullIndices: pullIndices}, http.StatusOK, &s)
if err != nil {
return nil, err
}
return &s, nil
}
// 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)
+18
View File
@@ -134,6 +134,24 @@ func TestAddPullStackEntry(t *testing.T) {
assert.Equal(t, int64(5), stack.ID)
}
func TestReorderPullStack(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)
assert.Equal(t, "/api/v1/repos/owner/repo/stacks/5/reorder", r.URL.Path)
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
assert.JSONEq(t, `{"pull_indices":[2,3]}`, string(body))
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"id":5,"repo_id":2,"owner_id":3,"title":"feat: base","base_branch":"main","state":"open","auto_restack":true,"entries":[]}`))
}))
defer server.Close()
result, err := ReorderPullStack(t.Context(), &config.Login{
Name: "test", URL: server.URL, Token: "secret-token",
}, "owner", "repo", 5, []int64{2, 3})
require.NoError(t, err)
assert.Equal(t, int64(5), result.ID)
}
func TestRestackPullStack(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method)