Files
multica/server/pkg/db/generated/pr_automation.sql.go
fc4a615700 MUL-7726: let the workspace choose the status merged PRs move an issue to (#8862)
* feat(pr): move issues to a workspace-chosen status when their PRs merge (MUL-7726)

The merge automation completed an issue only when a PR said "Closes MUL-1",
so the workspace switch mostly did nothing: most PRs are linked by title or
branch and never completed anything. The workspace now picks what a merge
does, in settings.pr_merge_status: "none", or the key of a started or done
status (custom ones included, Blocked excluded). Absent means Done. When
every linked PR is merged, the issue moves to that status. A closing keyword
only links.

- Decision: terminal, triage, "none", the per-issue switch and a new
  at_target state (the issue already has the target) come before the PR
  states, so the issue page only speaks when a merge would move the issue.
  The response adds target_status.
- MoveIssueFromPullRequests replaces CompleteIssueFromPullRequests and
  writes the target status. The target is resolved through the delivery's
  shared catalog read (Resolver.WritableCategory). An archived or unknown
  choice, or a failed read, fails closed to no write.
- Close intent is no longer synced or read. The column stays.
- Migration 551 pins "none" on existing workspaces whose history shows a
  merge never moved every issue: auto-complete switched off, or a linked PR
  whose merges were not all keyword merges. Workspaces with no links, or with
  only keyword merges, keep the Done default. Replays are harmless.
- CLI: `multica issue pr-automation <id> on|off` lets an agent keep one issue
  where it is. The multica-platform skill describes the new rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>

* feat(views): choose the status merged PRs move an issue to on the GitHub page (MUL-7726)

- Settings → Integrations → GitHub → Features: "After PRs merge, move the
  issue to" picks Don't change, or a started or done status, custom ones
  included and Blocked excluded. It replaces the read-only auto-complete row.
  The self-hosted Git page shows the same setting. The statuses page drops
  its switch, and a badge on the target status now links to the setting.
- Issue sidebar: the line under the PR list names the target status ("Moves
  to In Review when #19 merges"). It says nothing when the workspace leaves
  status alone, when the issue already has the target, or on an older
  backend's no_close_intent. The per-issue switch reads "Keep status when PRs
  merge" and is hidden when it would change nothing. The menu opens the
  GitHub setting. The link hint only shows while auto-link is on.
- core: derivePRMergeStatus replaces derivePRAutoCompleteEnabled; the
  auto_complete schema adds target_status and the at_target state.
- Copy in 5 languages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>

* docs: describe the workspace-chosen status for merged PRs (MUL-7726)

GitHub integration, self-hosted Git, issues and environment variable pages
(4-5 languages) now say that the workspace picks what a merge does: Done by
default, another started or done status, or no change. They also say that a
closing keyword only links, and how to keep one issue's status. The
troubleshooting entries explain what a missing line under the PR list means.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>

* refactor(pr): keep the merge automation out of agents' instructions (MUL-7726)

Agents don't act on what a merge does to an issue, so they don't need a
command for it or a rule to learn. Drop `multica issue pr-automation`, and
cut the multica-platform skill down to how PRs get linked: no merge rule, no
auto_complete field guide, no "the server moves it to done" note. People
still keep one issue's status from its Pull requests menu, and the docs now
point there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>

* fix(pr): keep the retired auto-complete switch working for old desktop clients (MUL-7726)

Review of #8862: an admin on a desktop client from before this change can
still flip "Complete issues when their PRs merge". The client saved
pr_auto_complete_enabled = false, and the save looked successful, but the
server only read pr_merge_status, so merges kept moving issues to Done.

- Settings writes: a flip of the retired switch becomes a choice (off →
  none, on → Done). An old client that echoes a chosen target without
  flipping the switch leaves the target alone. Every write mirrors the switch
  from the effective choice (false for none, absent otherwise), so old
  clients show the right state.
- Reads: without pr_merge_status, the retired switch decides (off → none,
  else Done), on the server and in derivePRMergeStatus. This also covers
  settings written by a pod that predates the change during rollout.
- Migration 551 sets the switch off on the workspaces it pins to none.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: multica-agent <[email protected]>
2026-09-27 02:26:24 +08:00

266 lines
8.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: pr_automation.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const deletePullRequestExclusion = `-- name: DeletePullRequestExclusion :exec
DELETE FROM issue_pull_request_exclusion
WHERE issue_id = $1 AND pull_request_id = $2
`
type DeletePullRequestExclusionParams struct {
IssueID pgtype.UUID `json:"issue_id"`
PullRequestID pgtype.UUID `json:"pull_request_id"`
}
func (q *Queries) DeletePullRequestExclusion(ctx context.Context, arg DeletePullRequestExclusionParams) error {
_, err := q.db.Exec(ctx, deletePullRequestExclusion, arg.IssueID, arg.PullRequestID)
return err
}
const excludePullRequestFromIssue = `-- name: ExcludePullRequestFromIssue :exec
INSERT INTO issue_pull_request_exclusion (
issue_id, pull_request_id, workspace_id, excluded_by_type, excluded_by_id
) VALUES (
$1, $2, $3, $4, $5
)
ON CONFLICT (issue_id, pull_request_id) DO UPDATE SET
excluded_by_type = EXCLUDED.excluded_by_type,
excluded_by_id = EXCLUDED.excluded_by_id,
created_at = now()
`
type ExcludePullRequestFromIssueParams struct {
IssueID pgtype.UUID `json:"issue_id"`
PullRequestID pgtype.UUID `json:"pull_request_id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
ExcludedByType pgtype.Text `json:"excluded_by_type"`
ExcludedByID pgtype.UUID `json:"excluded_by_id"`
}
func (q *Queries) ExcludePullRequestFromIssue(ctx context.Context, arg ExcludePullRequestFromIssueParams) error {
_, err := q.db.Exec(ctx, excludePullRequestFromIssue,
arg.IssueID,
arg.PullRequestID,
arg.WorkspaceID,
arg.ExcludedByType,
arg.ExcludedByID,
)
return err
}
const getIssuePRAutoCompleteDisabled = `-- name: GetIssuePRAutoCompleteDisabled :one
SELECT EXISTS (
SELECT 1 FROM issue_pr_automation
WHERE issue_id = $1 AND auto_complete_disabled
)::boolean AS disabled
`
// =====================
// PR auto-complete (MUL-7429)
// =====================
func (q *Queries) GetIssuePRAutoCompleteDisabled(ctx context.Context, issueID pgtype.UUID) (bool, error) {
row := q.db.QueryRow(ctx, getIssuePRAutoCompleteDisabled, issueID)
var disabled bool
err := row.Scan(&disabled)
return disabled, err
}
const isPullRequestExcludedFromIssue = `-- name: IsPullRequestExcludedFromIssue :one
SELECT EXISTS (
SELECT 1 FROM issue_pull_request_exclusion
WHERE issue_id = $1 AND pull_request_id = $2
)::boolean AS excluded
`
type IsPullRequestExcludedFromIssueParams struct {
IssueID pgtype.UUID `json:"issue_id"`
PullRequestID pgtype.UUID `json:"pull_request_id"`
}
func (q *Queries) IsPullRequestExcludedFromIssue(ctx context.Context, arg IsPullRequestExcludedFromIssueParams) (bool, error) {
row := q.db.QueryRow(ctx, isPullRequestExcludedFromIssue, arg.IssueID, arg.PullRequestID)
var excluded bool
err := row.Scan(&excluded)
return excluded, err
}
const listIssueLinkedPullRequestStates = `-- name: ListIssueLinkedPullRequestStates :many
SELECT pr.id, 'github'::text AS provider, pr.pr_number, pr.state
FROM github_pull_request pr
JOIN issue_pull_request ipr ON ipr.pull_request_id = pr.id
WHERE ipr.issue_id = $1
UNION ALL
SELECT pr.id, pr.provider AS provider, pr.pr_number, pr.state
FROM vcs_pull_request pr
JOIN issue_vcs_pull_request ipr ON ipr.pull_request_id = pr.id
WHERE ipr.issue_id = $1
ORDER BY pr_number
`
type ListIssueLinkedPullRequestStatesRow struct {
ID pgtype.UUID `json:"id"`
Provider string `json:"provider"`
PrNumber int32 `json:"pr_number"`
State string `json:"state"`
}
// Every PR linked to the issue across GitHub and self-hosted providers, for
// the merge decision. Ordered by number so reasons read stably.
func (q *Queries) ListIssueLinkedPullRequestStates(ctx context.Context, issueID pgtype.UUID) ([]ListIssueLinkedPullRequestStatesRow, error) {
rows, err := q.db.Query(ctx, listIssueLinkedPullRequestStates, issueID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListIssueLinkedPullRequestStatesRow{}
for rows.Next() {
var i ListIssueLinkedPullRequestStatesRow
if err := rows.Scan(
&i.ID,
&i.Provider,
&i.PrNumber,
&i.State,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const moveIssueFromPullRequests = `-- name: MoveIssueFromPullRequests :one
UPDATE issue AS i SET
status = $3::text,
duplicate_of_issue_id = NULL,
position = (
SELECT COALESCE(MIN(target.position), 0) - 1
FROM issue AS target
WHERE target.workspace_id = i.workspace_id
AND target.status = $3::text
),
revision = i.revision + 1,
last_activity_at = GREATEST(COALESCE(i.last_activity_at, i.updated_at), now()),
updated_at = now()
WHERE i.id = $1
AND i.workspace_id = $2
AND i.status = $4::text
AND i.status <> $3::text
AND EXISTS (
SELECT 1 FROM issue_pull_request ipr WHERE ipr.issue_id = i.id
UNION ALL
SELECT 1 FROM issue_vcs_pull_request ipr WHERE ipr.issue_id = i.id
)
AND NOT EXISTS (
SELECT 1 FROM issue_pull_request ipr
JOIN github_pull_request pr ON pr.id = ipr.pull_request_id
WHERE ipr.issue_id = i.id AND pr.state <> 'merged'
)
AND NOT EXISTS (
SELECT 1 FROM issue_vcs_pull_request ipr
JOIN vcs_pull_request pr ON pr.id = ipr.pull_request_id
WHERE ipr.issue_id = i.id AND pr.state <> 'merged'
)
RETURNING i.id, i.workspace_id, i.title, i.description, i.status, i.priority, i.assignee_type, i.assignee_id, i.creator_type, i.creator_id, i.parent_issue_id, i.acceptance_criteria, i.context_refs, i.position, i.due_date, i.created_at, i.updated_at, i.number, i.project_id, i.origin_type, i.origin_id, i.first_executed_at, i.start_date, i.metadata, i.stage, i.properties, i.revision, i.last_activity_at, i.triage_state, i.duplicate_of_issue_id
`
type MoveIssueFromPullRequestsParams struct {
ID pgtype.UUID `json:"id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
TargetStatus string `json:"target_status"`
ExpectedStatus string `json:"expected_status"`
}
// Conditional status write for the PR merge automation. It lands only if the
// issue is still in the status the decision saw (two merges racing move it
// once), is not already in the target, and the linked PRs are still all merged
// when the write runs (a PR linked between the decision and this statement
// keeps the issue where it is). Repositions and clears a duplicate mark like
// UpdateIssueStatus does; the target is never cancelled.
func (q *Queries) MoveIssueFromPullRequests(ctx context.Context, arg MoveIssueFromPullRequestsParams) (Issue, error) {
row := q.db.QueryRow(ctx, moveIssueFromPullRequests,
arg.ID,
arg.WorkspaceID,
arg.TargetStatus,
arg.ExpectedStatus,
)
var i Issue
err := row.Scan(
&i.ID,
&i.WorkspaceID,
&i.Title,
&i.Description,
&i.Status,
&i.Priority,
&i.AssigneeType,
&i.AssigneeID,
&i.CreatorType,
&i.CreatorID,
&i.ParentIssueID,
&i.AcceptanceCriteria,
&i.ContextRefs,
&i.Position,
&i.DueDate,
&i.CreatedAt,
&i.UpdatedAt,
&i.Number,
&i.ProjectID,
&i.OriginType,
&i.OriginID,
&i.FirstExecutedAt,
&i.StartDate,
&i.Metadata,
&i.Stage,
&i.Properties,
&i.Revision,
&i.LastActivityAt,
&i.TriageState,
&i.DuplicateOfIssueID,
)
return i, err
}
const setIssuePRAutoCompleteDisabled = `-- name: SetIssuePRAutoCompleteDisabled :exec
INSERT INTO issue_pr_automation (
issue_id, workspace_id, auto_complete_disabled, updated_by_type, updated_by_id
) VALUES (
$1, $2, $3, $4, $5
)
ON CONFLICT (issue_id) DO UPDATE SET
auto_complete_disabled = EXCLUDED.auto_complete_disabled,
updated_by_type = EXCLUDED.updated_by_type,
updated_by_id = EXCLUDED.updated_by_id,
updated_at = now()
`
type SetIssuePRAutoCompleteDisabledParams struct {
IssueID pgtype.UUID `json:"issue_id"`
WorkspaceID pgtype.UUID `json:"workspace_id"`
AutoCompleteDisabled bool `json:"auto_complete_disabled"`
UpdatedByType pgtype.Text `json:"updated_by_type"`
UpdatedByID pgtype.UUID `json:"updated_by_id"`
}
func (q *Queries) SetIssuePRAutoCompleteDisabled(ctx context.Context, arg SetIssuePRAutoCompleteDisabledParams) error {
_, err := q.db.Exec(ctx, setIssuePRAutoCompleteDisabled,
arg.IssueID,
arg.WorkspaceID,
arg.AutoCompleteDisabled,
arg.UpdatedByType,
arg.UpdatedByID,
)
return err
}