Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
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, i.requester_user_id, i.description_revision
`
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,
&i.RequesterUserID,
&i.DescriptionRevision,
)
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
}