From 90c4c1088a1875076c49908409adea720cd2abca Mon Sep 17 00:00:00 2001 From: eding Date: Wed, 16 Sep 2026 09:16:45 +0200 Subject: [PATCH] fix: reuse existing migration pull requests --- internal/forgejo/repo.go | 2 +- internal/forgejo/repo_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/forgejo/repo.go b/internal/forgejo/repo.go index 15f1355..ad9cd88 100644 --- a/internal/forgejo/repo.go +++ b/internal/forgejo/repo.go @@ -419,7 +419,7 @@ func (rm *RepoManager) CreatePullRequest(repo, title, head, base string) error { if err != nil { return err } - if status != http.StatusCreated && status != http.StatusUnprocessableEntity { + if status != http.StatusCreated && status != http.StatusUnprocessableEntity && status != http.StatusConflict { return fmt.Errorf("unexpected Forgejo pull request status %d", status) } return nil diff --git a/internal/forgejo/repo_test.go b/internal/forgejo/repo_test.go index 7fd3da8..cf6e77d 100644 --- a/internal/forgejo/repo_test.go +++ b/internal/forgejo/repo_test.go @@ -426,6 +426,21 @@ func TestMergePullRequest(t *testing.T) { } } +func TestCreatePullRequestAcceptsExistingConflict(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { + if request.Method != http.MethodPost || request.URL.Path != "/api/v1/repos/owner/cluster/pulls" { + t.Fatalf("unexpected pull request request: %s %s", request.Method, request.URL.Path) + } + writer.WriteHeader(http.StatusConflict) + })) + defer server.Close() + manager := NewRepoManager(server.URL, "token", "owner", "user", "manifests", "cluster", "main", "maidn/bootstrap-test") + manager.HTTPClient = server.Client() + if err := manager.CreatePullRequest("cluster", "title", "maidn/bootstrap-test", "main"); err != nil { + t.Fatal(err) + } +} + func TestEnsurePullRequestChecksExactOpenBranchBeforeCreating(t *testing.T) { requests := 0 server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { -- 2.43.7