Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(github): skip PR merge status move when the project workflow lacks the target (#9598)

Multica Eve6388272a8a6f
diff --git a/packages/core/types/github.ts b/packages/core/types/github.ts
index 3a44d77b4c..f785009bbc 100644
--- a/packages/core/types/github.ts
+++ b/packages/core/types/github.ts
@@ -70,6 +70,7 @@ export type PRAutoCompleteState =
| "issue_disabled"
| "terminal"
| "triage"
+ | "not_in_workflow"
| "at_target"
| "waiting"
| "not_merged"
diff --git a/packages/views/issues/components/pull-request-list.test.tsx b/packages/views/issues/components/pull-request-list.test.tsx
index 5088dc5640..697fe89e07 100644
--- a/packages/views/issues/components/pull-request-list.test.tsx
+++ b/packages/views/issues/components/pull-request-list.test.tsx
@@ -448,7 +448,7 @@ describe("PullRequestList auto-complete", () => {
// The workspace chose to leave status alone: a team choice, not repeated on
// every issue. An older backend's no_close_intent says nothing either.
- it.each(["workspace_disabled", "no_close_intent", "at_target", "terminal"])("says nothing for %s", async (state) => {
+ it.each(["workspace_disabled", "no_close_intent", "not_in_workflow", "at_target", "terminal"])("says nothing for %s", async (state) => {
mockPRs = [makePR({ id: "a", number: 12, state: "merged" })];
mockAutoComplete = decision(state, [], state === "workspace_disabled" ? { workspace_enabled: false, target_status: "none" } : {});
renderList();
diff --git a/server/internal/handler/github_test.go b/server/internal/handler/github_test.go
index 7951189cda..917af991cd 100644
--- a/server/internal/handler/github_test.go
+++ b/server/internal/handler/github_test.go
@@ -1520,6 +1520,61 @@ func TestPRAutoComplete_TargetStatus(t *testing.T) {
}
}
+// TestPRAutoComplete_RespectsProjectWorkflow: a merge writes only a status the
+// issue's project workflow lists. Issues outside any project and projects on
+// Default move as before; a named workflow without the target leaves the
+// issue where it is, and the issue page says nothing about it.
+func TestPRAutoComplete_RespectsProjectWorkflow(t *testing.T) {
+ if testHandler == nil {
+ t.Skip("handler test fixture not initialized (no DB?)")
+ }
+ secret := "workflow-target-secret"
+ t.Setenv("GITHUB_WEBHOOK_SECRET", secret)
+ const installationID int64 = 30264021
+ // done is in every workflow, so the target here is one a workflow may omit.
+ setWorkspacePRMergeStatusForTest(t, "in_review")
+
+ withTarget := createTestWorkflow(t, "PR merge: lists in_review", "in_progress", "in_review")
+ withoutTarget := createTestWorkflow(t, "PR merge: no in_review", "in_progress")
+ defaultProject := createWorkflowTestProject(t, "PR merge on Default")
+ withTargetProject := createWorkflowTestProject(t, "PR merge with in_review")
+ setProjectWorkflow(t, withTargetProject, map[string]any{"workflow_id": withTarget.ID}).Want(http.StatusOK)
+ withoutTargetProject := createWorkflowTestProject(t, "PR merge without in_review")
+ setProjectWorkflow(t, withoutTargetProject, map[string]any{"workflow_id": withoutTarget.ID}).Want(http.StatusOK)
+
+ cases := []struct {
+ name string
+ projectID string
+ wantState string
+ wantAfter string
+ }{
+ {"no project", "", prAutoCompleteWaiting, "in_review"},
+ {"default workflow", defaultProject, prAutoCompleteWaiting, "in_review"},
+ {"named workflow lists the target", withTargetProject, prAutoCompleteWaiting, "in_review"},
+ {"named workflow without the target", withoutTargetProject, prAutoCompleteNotInWorkflow, "in_progress"},
+ }
+ for i, tc := range cases {
+ inst := int64(0)
+ if i == 0 {
+ inst = installationID
+ }
+ issue := prAutoCompleteTestIssue(t, "workflow target: "+tc.name, inst)
+ if tc.projectID != "" {
+ dbfx.Exec(t, `UPDATE issue SET project_id = $2 WHERE id = $1`, issue.ID, tc.projectID)
+ }
+ number := int32(100 + i)
+ branch := fmt.Sprintf("fix/workflow-%d", i)
+ firePRWebhook(t, secret, installationID, number, issue.Identifier+": fix", "", branch, "opened")
+ if got := prAutoCompleteStateForTest(t, issue.ID); got.State != tc.wantState {
+ t.Errorf("%s: before merge auto_complete = %+v, want %s", tc.name, got, tc.wantState)
+ }
+ firePRWebhook(t, secret, installationID, number, issue.Identifier+": fix", "", branch, "merged")
+ if got := issueStatusForTest(t, issue.ID); got != tc.wantAfter {
+ t.Errorf("%s: status after merge = %q, want %q", tc.name, got, tc.wantAfter)
+ }
+ }
+}
+
func TestPRMergeStatusSetting(t *testing.T) {
for _, tc := range []struct {
settings string
diff --git a/server/internal/handler/pr_auto_complete.go b/server/internal/handler/pr_auto_complete.go
index 354dd0ed20..ee9b0190b7 100644
--- a/server/internal/handler/pr_auto_complete.go
+++ b/server/internal/handler/pr_auto_complete.go
@@ -15,6 +15,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/multica-ai/multica/server/internal/issuestatus"
+ "github.com/multica-ai/multica/server/internal/issueworkflow"
"github.com/multica-ai/multica/server/internal/service"
"github.com/multica-ai/multica/server/internal/util"
db "github.com/multica-ai/multica/server/pkg/db/generated"
@@ -49,6 +50,7 @@ const (
prAutoCompleteIssueDisabled = "issue_disabled" // turned off for this issue
prAutoCompleteTerminal = "terminal" // already done / cancelled
prAutoCompleteTriage = "triage" // not accepted yet
+ prAutoCompleteNotInWorkflow = "not_in_workflow" // project workflow does not list the target
prAutoCompleteAtTarget = "at_target" // already in the target status
prAutoCompleteWaiting = "waiting" // some PRs still open / draft
prAutoCompleteNotMerged = "not_merged" // some PRs closed without merging
@@ -202,6 +204,19 @@ func (h *Handler) decidePRAutoComplete(ctx context.Context, ws db.Workspace, iss
case disabled:
d.State = prAutoCompleteIssueDisabled
return d, nil
+ }
+ // A merge writes only a status the issue's project workflow lists, the same
+ // rule a manual status change follows (applyIssueWorkflow). Default and
+ // issues outside any project accept every status. The issue page shows
+ // nothing for this state: the issue just stays where it is.
+ def, _, err := issueworkflow.ForProject(ctx, h.Queries, issue.WorkspaceID, issue.ProjectID)
+ if err != nil {
+ return prAutoCompleteDecision{}, err
+ }
+ switch {
+ case issueworkflow.CheckStatus(def, d.Target) != nil:
+ d.State = prAutoCompleteNotInWorkflow
+ return d, nil
case issue.Status == d.Target:
d.State = prAutoCompleteAtTarget
return d, nil