review_pr self-omitted since d73e0748 deleted the synchronous reviewer it
called. It is rebuilt on the task enqueue path everything else uses: the
tool resolves the identity's configured repo, then queues a pr-review task
naming the pull request through the workflow's declared pr_number input,
which is the same generic input mechanism a watched-repos binding uses.
That input has to reach the store with the task, so
EnqueueChatTaskRequest gains inputs_json and the tasks insert writes the
inputs column directly. StampTaskBinding no longer writes it: the insert is
now the column's only writer, and a chat task must not acquire binding
provenance just to carry an input.
ChatPRReviewer, its result shape and the reviewer wiring are deleted with
the path they served.
891 lines
24 KiB
Go
891 lines
24 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: tasks.sql
|
|
|
|
package postgresdb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const archiveTaskDelete = `-- name: ArchiveTaskDelete :execrows
|
|
DELETE FROM tasks WHERE id = $1 AND status = $2
|
|
`
|
|
|
|
type ArchiveTaskDeleteParams struct {
|
|
ID int64
|
|
Status string
|
|
}
|
|
|
|
func (q *Queries) ArchiveTaskDelete(ctx context.Context, arg ArchiveTaskDeleteParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, archiveTaskDelete, arg.ID, arg.Status)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const beginRemediationTask = `-- name: BeginRemediationTask :execrows
|
|
UPDATE tasks SET status = 'queued', workflow = 'remediate', park_reason = '', park_class = 'needs_human', review_payload = $2, updated_at = now()
|
|
WHERE id = $1 AND status = 'pr_open'
|
|
`
|
|
|
|
type BeginRemediationTaskParams struct {
|
|
ID int64
|
|
ReviewPayload string
|
|
}
|
|
|
|
func (q *Queries) BeginRemediationTask(ctx context.Context, arg BeginRemediationTaskParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, beginRemediationTask, arg.ID, arg.ReviewPayload)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const claimByIssue = `-- name: ClaimByIssue :one
|
|
UPDATE tasks SET status = 'running', attempt = attempt + 1, updated_at = now()
|
|
WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
|
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
|
`
|
|
|
|
type ClaimByIssueParams struct {
|
|
Owner string
|
|
Repo string
|
|
IssueNumber int64
|
|
}
|
|
|
|
func (q *Queries) ClaimByIssue(ctx context.Context, arg ClaimByIssueParams) (Task, error) {
|
|
row := q.db.QueryRow(ctx, claimByIssue, arg.Owner, arg.Repo, arg.IssueNumber)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.Title,
|
|
&i.Body,
|
|
&i.Labels,
|
|
&i.Status,
|
|
&i.Workflow,
|
|
&i.Branch,
|
|
&i.Plan,
|
|
&i.Notes,
|
|
&i.PrNumber,
|
|
&i.TokensUsed,
|
|
&i.Iterations,
|
|
&i.Attempt,
|
|
&i.ParkReason,
|
|
&i.WatchCommentID,
|
|
&i.ParkClass,
|
|
&i.RemediationRounds,
|
|
&i.RetryCount,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.BindingID,
|
|
&i.BindingVersion,
|
|
&i.ReviewPayload,
|
|
&i.WorkflowDefinitionVersion,
|
|
&i.WorkflowDefinitionDigest,
|
|
&i.WorkflowDefinitionYaml,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ReviewCursor,
|
|
&i.Inputs,
|
|
&i.OrgID,
|
|
&i.WorkspaceID,
|
|
&i.CallParentTaskID,
|
|
&i.CallDepth,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const claimNextTask = `-- name: ClaimNextTask :one
|
|
UPDATE tasks
|
|
SET status = 'running', attempt = attempt + 1, updated_at = now()
|
|
WHERE id = (
|
|
SELECT id FROM tasks
|
|
WHERE status = 'queued'
|
|
ORDER BY id
|
|
FOR UPDATE SKIP LOCKED
|
|
LIMIT 1
|
|
)
|
|
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
|
`
|
|
|
|
// FOR UPDATE SKIP LOCKED replaces the SQLite single-writer assumption: two
|
|
// claimers running at once take different rows instead of blocking, so the
|
|
// daemon no longer depends on holding the only connection to the file.
|
|
func (q *Queries) ClaimNextTask(ctx context.Context) (Task, error) {
|
|
row := q.db.QueryRow(ctx, claimNextTask)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.Title,
|
|
&i.Body,
|
|
&i.Labels,
|
|
&i.Status,
|
|
&i.Workflow,
|
|
&i.Branch,
|
|
&i.Plan,
|
|
&i.Notes,
|
|
&i.PrNumber,
|
|
&i.TokensUsed,
|
|
&i.Iterations,
|
|
&i.Attempt,
|
|
&i.ParkReason,
|
|
&i.WatchCommentID,
|
|
&i.ParkClass,
|
|
&i.RemediationRounds,
|
|
&i.RetryCount,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.BindingID,
|
|
&i.BindingVersion,
|
|
&i.ReviewPayload,
|
|
&i.WorkflowDefinitionVersion,
|
|
&i.WorkflowDefinitionDigest,
|
|
&i.WorkflowDefinitionYaml,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ReviewCursor,
|
|
&i.Inputs,
|
|
&i.OrgID,
|
|
&i.WorkspaceID,
|
|
&i.CallParentTaskID,
|
|
&i.CallDepth,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const clearTerminalTasks = `-- name: ClearTerminalTasks :execrows
|
|
DELETE FROM tasks
|
|
WHERE status IN ('merged', 'rejected', 'dead', 'closed_wont_do', 'completed')
|
|
`
|
|
|
|
func (q *Queries) ClearTerminalTasks(ctx context.Context) (int64, error) {
|
|
result, err := q.db.Exec(ctx, clearTerminalTasks)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const countTasksByStatus = `-- name: CountTasksByStatus :many
|
|
SELECT status, count(*)::int AS count FROM tasks GROUP BY status
|
|
`
|
|
|
|
type CountTasksByStatusRow struct {
|
|
Status string
|
|
Count int32
|
|
}
|
|
|
|
func (q *Queries) CountTasksByStatus(ctx context.Context) ([]CountTasksByStatusRow, error) {
|
|
rows, err := q.db.Query(ctx, countTasksByStatus)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []CountTasksByStatusRow
|
|
for rows.Next() {
|
|
var i CountTasksByStatusRow
|
|
if err := rows.Scan(&i.Status, &i.Count); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const enqueueIssue = `-- name: EnqueueIssue :execrows
|
|
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, identity, org_id, workspace_id)
|
|
VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7,
|
|
COALESCE(
|
|
(SELECT a.org_id FROM org_agents a WHERE a.identity_id = $7),
|
|
(SELECT m.org_id FROM memberships m WHERE m.identity_id = $7
|
|
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
|
|
'default'
|
|
),
|
|
'default'
|
|
)
|
|
ON CONFLICT (org_id, identity, owner, repo, issue_number) DO NOTHING
|
|
`
|
|
|
|
type EnqueueIssueParams struct {
|
|
Owner string
|
|
Repo string
|
|
IssueNumber int64
|
|
Title string
|
|
Body string
|
|
Labels string
|
|
Identity string
|
|
}
|
|
|
|
// The org is derived from the identity at the one place a task row is
|
|
// written (an agent's assignment, else a membership, else the default org);
|
|
// uniqueness follows the record's identity: two orgs may work the same
|
|
// issue under their own identities, one may not work it twice.
|
|
func (q *Queries) EnqueueIssue(ctx context.Context, arg EnqueueIssueParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, enqueueIssue,
|
|
arg.Owner,
|
|
arg.Repo,
|
|
arg.IssueNumber,
|
|
arg.Title,
|
|
arg.Body,
|
|
arg.Labels,
|
|
arg.Identity,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const insertChatTask = `-- name: InsertChatTask :one
|
|
INSERT INTO tasks (owner, repo, issue_number, title, body, labels, workflow, source, identity, org_id, inputs)
|
|
VALUES (
|
|
$1, $2,
|
|
COALESCE((
|
|
SELECT MAX(existing.issue_number) FROM tasks existing
|
|
WHERE existing.owner = $1
|
|
AND existing.repo = $2
|
|
AND existing.source = 'chat'
|
|
), $3) + 1,
|
|
$4, $5, 'chat', $6, 'chat', $7,
|
|
COALESCE(
|
|
(SELECT a.org_id FROM org_agents a WHERE a.identity_id = $7),
|
|
(SELECT m.org_id FROM memberships m WHERE m.identity_id = $7
|
|
ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1),
|
|
'default'
|
|
),
|
|
$8
|
|
)
|
|
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth
|
|
`
|
|
|
|
type InsertChatTaskParams struct {
|
|
Owner string
|
|
Repo string
|
|
FallbackIssueNumber int64
|
|
Title string
|
|
Body string
|
|
Workflow string
|
|
Identity string
|
|
Inputs string
|
|
}
|
|
|
|
// The synthetic issue number keeps chat-sourced tasks off the forge's real
|
|
// issue numbers; this allocator is the single source of truth for it.
|
|
// fallback_issue_number is only the seed for a repo's first chat task -- the
|
|
// passed value is not the issue number that lands.
|
|
// inputs is the chat task's own workflow inputs; a binding dispatch passes
|
|
// its inputs here too, so this insert is the single writer of the column and
|
|
// StampTaskBinding adds only the provenance.
|
|
func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams) (Task, error) {
|
|
row := q.db.QueryRow(ctx, insertChatTask,
|
|
arg.Owner,
|
|
arg.Repo,
|
|
arg.FallbackIssueNumber,
|
|
arg.Title,
|
|
arg.Body,
|
|
arg.Workflow,
|
|
arg.Identity,
|
|
arg.Inputs,
|
|
)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.Title,
|
|
&i.Body,
|
|
&i.Labels,
|
|
&i.Status,
|
|
&i.Workflow,
|
|
&i.Branch,
|
|
&i.Plan,
|
|
&i.Notes,
|
|
&i.PrNumber,
|
|
&i.TokensUsed,
|
|
&i.Iterations,
|
|
&i.Attempt,
|
|
&i.ParkReason,
|
|
&i.WatchCommentID,
|
|
&i.ParkClass,
|
|
&i.RemediationRounds,
|
|
&i.RetryCount,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.BindingID,
|
|
&i.BindingVersion,
|
|
&i.ReviewPayload,
|
|
&i.WorkflowDefinitionVersion,
|
|
&i.WorkflowDefinitionDigest,
|
|
&i.WorkflowDefinitionYaml,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ReviewCursor,
|
|
&i.Inputs,
|
|
&i.OrgID,
|
|
&i.WorkspaceID,
|
|
&i.CallParentTaskID,
|
|
&i.CallDepth,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const insertTransition = `-- name: InsertTransition :exec
|
|
INSERT INTO transitions (task_id, from_status, to_status, detail)
|
|
VALUES ($1, $2, $3, $4)
|
|
`
|
|
|
|
type InsertTransitionParams struct {
|
|
TaskID int64
|
|
FromStatus string
|
|
ToStatus string
|
|
Detail string
|
|
}
|
|
|
|
func (q *Queries) InsertTransition(ctx context.Context, arg InsertTransitionParams) error {
|
|
_, err := q.db.Exec(ctx, insertTransition,
|
|
arg.TaskID,
|
|
arg.FromStatus,
|
|
arg.ToStatus,
|
|
arg.Detail,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const listOpenPRs = `-- name: ListOpenPRs :many
|
|
SELECT id, owner, repo, issue_number, pr_number, status, source, identity, attempt, review_cursor, watch_comment_id
|
|
FROM tasks WHERE status = 'pr_open'
|
|
`
|
|
|
|
type ListOpenPRsRow struct {
|
|
ID int64
|
|
Owner string
|
|
Repo string
|
|
IssueNumber int64
|
|
PrNumber int64
|
|
Status string
|
|
Source string
|
|
Identity string
|
|
Attempt int64
|
|
ReviewCursor int64
|
|
WatchCommentID int64
|
|
}
|
|
|
|
func (q *Queries) ListOpenPRs(ctx context.Context) ([]ListOpenPRsRow, error) {
|
|
rows, err := q.db.Query(ctx, listOpenPRs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListOpenPRsRow
|
|
for rows.Next() {
|
|
var i ListOpenPRsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.PrNumber,
|
|
&i.Status,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.Attempt,
|
|
&i.ReviewCursor,
|
|
&i.WatchCommentID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listTaskSummaries = `-- name: ListTaskSummaries :many
|
|
SELECT id, owner, repo, issue_number, title, status, workflow,
|
|
pr_number, tokens_used, iterations, attempt, park_reason, retry_count,
|
|
created_at, updated_at, plan, source, identity, binding_id, binding_version
|
|
FROM tasks ORDER BY updated_at DESC LIMIT $1
|
|
`
|
|
|
|
type ListTaskSummariesRow struct {
|
|
ID int64
|
|
Owner string
|
|
Repo string
|
|
IssueNumber int64
|
|
Title string
|
|
Status string
|
|
Workflow string
|
|
PrNumber int64
|
|
TokensUsed int64
|
|
Iterations int64
|
|
Attempt int64
|
|
ParkReason string
|
|
RetryCount int64
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Plan string
|
|
Source string
|
|
Identity string
|
|
BindingID string
|
|
BindingVersion int64
|
|
}
|
|
|
|
// The dashboard's list. This projection is deliberately narrow: Plan gates
|
|
// the "Decision required" panel and Source labels the row, and widening it
|
|
// back would send rows without them.
|
|
func (q *Queries) ListTaskSummaries(ctx context.Context, limit int32) ([]ListTaskSummariesRow, error) {
|
|
rows, err := q.db.Query(ctx, listTaskSummaries, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListTaskSummariesRow
|
|
for rows.Next() {
|
|
var i ListTaskSummariesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.Title,
|
|
&i.Status,
|
|
&i.Workflow,
|
|
&i.PrNumber,
|
|
&i.TokensUsed,
|
|
&i.Iterations,
|
|
&i.Attempt,
|
|
&i.ParkReason,
|
|
&i.RetryCount,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Plan,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.BindingID,
|
|
&i.BindingVersion,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const lockTaskStatus = `-- name: LockTaskStatus :one
|
|
SELECT status FROM tasks WHERE id = $1 FOR UPDATE
|
|
`
|
|
|
|
// Locks the task's row and returns its current status, so the staleness and
|
|
// transition-table checks that decide a guarded write hold against a
|
|
// concurrent claim or transition until the update in the same transaction.
|
|
func (q *Queries) LockTaskStatus(ctx context.Context, id int64) (string, error) {
|
|
row := q.db.QueryRow(ctx, lockTaskStatus, id)
|
|
var status string
|
|
err := row.Scan(&status)
|
|
return status, err
|
|
}
|
|
|
|
const parkTask = `-- name: ParkTask :execrows
|
|
UPDATE tasks
|
|
SET status = 'parked', park_reason = $2, park_class = $3, updated_at = now()
|
|
WHERE id = $1 AND status = $4
|
|
`
|
|
|
|
type ParkTaskParams struct {
|
|
ID int64
|
|
ParkReason string
|
|
ParkClass string
|
|
Status string
|
|
}
|
|
|
|
func (q *Queries) ParkTask(ctx context.Context, arg ParkTaskParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, parkTask,
|
|
arg.ID,
|
|
arg.ParkReason,
|
|
arg.ParkClass,
|
|
arg.Status,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const recoverStaleTasks = `-- name: RecoverStaleTasks :execrows
|
|
UPDATE tasks SET status = 'queued', updated_at = now() WHERE status = 'running'
|
|
`
|
|
|
|
func (q *Queries) RecoverStaleTasks(ctx context.Context) (int64, error) {
|
|
result, err := q.db.Exec(ctx, recoverStaleTasks)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const requeueTask = `-- name: RequeueTask :execrows
|
|
UPDATE tasks SET status = 'queued',
|
|
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
|
park_reason = '', park_class = 'needs_human', updated_at = now()
|
|
WHERE id = $2 AND status = $3
|
|
`
|
|
|
|
type RequeueTaskParams struct {
|
|
Workflow string
|
|
ID int64
|
|
FromStatus string
|
|
}
|
|
|
|
func (q *Queries) RequeueTask(ctx context.Context, arg RequeueTaskParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, requeueTask, arg.Workflow, arg.ID, arg.FromStatus)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const retryTask = `-- name: RetryTask :execrows
|
|
UPDATE tasks SET status = 'queued', retry_count = retry_count + 1,
|
|
workflow = CASE WHEN $1::text = '' THEN workflow ELSE $1::text END,
|
|
park_reason = '', park_class = 'needs_human', updated_at = now()
|
|
WHERE id = $2 AND status = $3
|
|
`
|
|
|
|
type RetryTaskParams struct {
|
|
Workflow string
|
|
ID int64
|
|
FromStatus string
|
|
}
|
|
|
|
func (q *Queries) RetryTask(ctx context.Context, arg RetryTaskParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, retryTask, arg.Workflow, arg.ID, arg.FromStatus)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const setReviewCursors = `-- name: SetReviewCursors :execrows
|
|
UPDATE tasks SET review_cursor = $2, watch_comment_id = $3, updated_at = now()
|
|
WHERE id = $1 AND status = 'pr_open'
|
|
`
|
|
|
|
type SetReviewCursorsParams struct {
|
|
ID int64
|
|
ReviewCursor int64
|
|
WatchCommentID int64
|
|
}
|
|
|
|
func (q *Queries) SetReviewCursors(ctx context.Context, arg SetReviewCursorsParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, setReviewCursors, arg.ID, arg.ReviewCursor, arg.WatchCommentID)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const stampTaskBinding = `-- name: StampTaskBinding :exec
|
|
UPDATE tasks SET binding_id = $2, binding_version = $3 WHERE id = $1
|
|
`
|
|
|
|
type StampTaskBindingParams struct {
|
|
ID int64
|
|
BindingID string
|
|
BindingVersion int64
|
|
}
|
|
|
|
func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingParams) error {
|
|
_, err := q.db.Exec(ctx, stampTaskBinding, arg.ID, arg.BindingID, arg.BindingVersion)
|
|
return err
|
|
}
|
|
|
|
const taskByID = `-- name: TaskByID :one
|
|
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) TaskByID(ctx context.Context, id int64) (Task, error) {
|
|
row := q.db.QueryRow(ctx, taskByID, id)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.Title,
|
|
&i.Body,
|
|
&i.Labels,
|
|
&i.Status,
|
|
&i.Workflow,
|
|
&i.Branch,
|
|
&i.Plan,
|
|
&i.Notes,
|
|
&i.PrNumber,
|
|
&i.TokensUsed,
|
|
&i.Iterations,
|
|
&i.Attempt,
|
|
&i.ParkReason,
|
|
&i.WatchCommentID,
|
|
&i.ParkClass,
|
|
&i.RemediationRounds,
|
|
&i.RetryCount,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.BindingID,
|
|
&i.BindingVersion,
|
|
&i.ReviewPayload,
|
|
&i.WorkflowDefinitionVersion,
|
|
&i.WorkflowDefinitionDigest,
|
|
&i.WorkflowDefinitionYaml,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ReviewCursor,
|
|
&i.Inputs,
|
|
&i.OrgID,
|
|
&i.WorkspaceID,
|
|
&i.CallParentTaskID,
|
|
&i.CallDepth,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const taskByIssue = `-- name: TaskByIssue :one
|
|
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
|
|
`
|
|
|
|
type TaskByIssueParams struct {
|
|
Owner string
|
|
Repo string
|
|
IssueNumber int64
|
|
}
|
|
|
|
func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task, error) {
|
|
row := q.db.QueryRow(ctx, taskByIssue, arg.Owner, arg.Repo, arg.IssueNumber)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.Title,
|
|
&i.Body,
|
|
&i.Labels,
|
|
&i.Status,
|
|
&i.Workflow,
|
|
&i.Branch,
|
|
&i.Plan,
|
|
&i.Notes,
|
|
&i.PrNumber,
|
|
&i.TokensUsed,
|
|
&i.Iterations,
|
|
&i.Attempt,
|
|
&i.ParkReason,
|
|
&i.WatchCommentID,
|
|
&i.ParkClass,
|
|
&i.RemediationRounds,
|
|
&i.RetryCount,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.BindingID,
|
|
&i.BindingVersion,
|
|
&i.ReviewPayload,
|
|
&i.WorkflowDefinitionVersion,
|
|
&i.WorkflowDefinitionDigest,
|
|
&i.WorkflowDefinitionYaml,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ReviewCursor,
|
|
&i.Inputs,
|
|
&i.OrgID,
|
|
&i.WorkspaceID,
|
|
&i.CallParentTaskID,
|
|
&i.CallDepth,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const taskByPR = `-- name: TaskByPR :one
|
|
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
|
|
`
|
|
|
|
type TaskByPRParams struct {
|
|
Owner string
|
|
Repo string
|
|
PrNumber int64
|
|
Status string
|
|
}
|
|
|
|
// OpenTaskByPR is the live-task lookup: it only resolves a PR the task is
|
|
// currently tracking as open, so a merged or rejected task does not read as
|
|
// the owner of a PR number it no longer holds.
|
|
func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error) {
|
|
row := q.db.QueryRow(ctx, taskByPR,
|
|
arg.Owner,
|
|
arg.Repo,
|
|
arg.PrNumber,
|
|
arg.Status,
|
|
)
|
|
var i Task
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Owner,
|
|
&i.Repo,
|
|
&i.IssueNumber,
|
|
&i.Title,
|
|
&i.Body,
|
|
&i.Labels,
|
|
&i.Status,
|
|
&i.Workflow,
|
|
&i.Branch,
|
|
&i.Plan,
|
|
&i.Notes,
|
|
&i.PrNumber,
|
|
&i.TokensUsed,
|
|
&i.Iterations,
|
|
&i.Attempt,
|
|
&i.ParkReason,
|
|
&i.WatchCommentID,
|
|
&i.ParkClass,
|
|
&i.RemediationRounds,
|
|
&i.RetryCount,
|
|
&i.Source,
|
|
&i.Identity,
|
|
&i.BindingID,
|
|
&i.BindingVersion,
|
|
&i.ReviewPayload,
|
|
&i.WorkflowDefinitionVersion,
|
|
&i.WorkflowDefinitionDigest,
|
|
&i.WorkflowDefinitionYaml,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ReviewCursor,
|
|
&i.Inputs,
|
|
&i.OrgID,
|
|
&i.WorkspaceID,
|
|
&i.CallParentTaskID,
|
|
&i.CallDepth,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const transitionTask = `-- name: TransitionTask :execrows
|
|
UPDATE tasks
|
|
SET status = $2,
|
|
park_reason = CASE WHEN $2 = 'parked' THEN $3 ELSE park_reason END,
|
|
park_class = CASE WHEN $2 = 'parked' THEN $4 ELSE park_class END,
|
|
updated_at = now()
|
|
WHERE id = $1 AND status = $5
|
|
`
|
|
|
|
type TransitionTaskParams struct {
|
|
ID int64
|
|
Status string
|
|
ParkReason string
|
|
ParkClass string
|
|
Status_2 string
|
|
}
|
|
|
|
// Arriving at 'parked' also records why. The class is normalized by the
|
|
// caller, so an unknown value persists as needs_human rather than as itself.
|
|
func (q *Queries) TransitionTask(ctx context.Context, arg TransitionTaskParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, transitionTask,
|
|
arg.ID,
|
|
arg.Status,
|
|
arg.ParkReason,
|
|
arg.ParkClass,
|
|
arg.Status_2,
|
|
)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const updateReviewPayloadTask = `-- name: UpdateReviewPayloadTask :execrows
|
|
UPDATE tasks SET review_payload = $2, updated_at = now()
|
|
WHERE id = $1 AND status = 'queued' AND workflow = 'remediate'
|
|
`
|
|
|
|
type UpdateReviewPayloadTaskParams struct {
|
|
ID int64
|
|
ReviewPayload string
|
|
}
|
|
|
|
func (q *Queries) UpdateReviewPayloadTask(ctx context.Context, arg UpdateReviewPayloadTaskParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, updateReviewPayloadTask, arg.ID, arg.ReviewPayload)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const updateTask = `-- name: UpdateTask :exec
|
|
UPDATE tasks SET workflow = $2, branch = $3, plan = $4, notes = $5,
|
|
pr_number = $6, tokens_used = $7, iterations = $8, park_reason = $9,
|
|
watch_comment_id = $10, retry_count = $11, remediation_rounds = $12,
|
|
review_payload = $13, workflow_definition_version = $14,
|
|
workflow_definition_digest = $15, workflow_definition_yaml = $16,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateTaskParams struct {
|
|
ID int64
|
|
Workflow string
|
|
Branch string
|
|
Plan string
|
|
Notes string
|
|
PrNumber int64
|
|
TokensUsed int64
|
|
Iterations int64
|
|
ParkReason string
|
|
WatchCommentID int64
|
|
RetryCount int64
|
|
RemediationRounds int64
|
|
ReviewPayload string
|
|
WorkflowDefinitionVersion int64
|
|
WorkflowDefinitionDigest string
|
|
WorkflowDefinitionYaml string
|
|
}
|
|
|
|
func (q *Queries) UpdateTask(ctx context.Context, arg UpdateTaskParams) error {
|
|
_, err := q.db.Exec(ctx, updateTask,
|
|
arg.ID,
|
|
arg.Workflow,
|
|
arg.Branch,
|
|
arg.Plan,
|
|
arg.Notes,
|
|
arg.PrNumber,
|
|
arg.TokensUsed,
|
|
arg.Iterations,
|
|
arg.ParkReason,
|
|
arg.WatchCommentID,
|
|
arg.RetryCount,
|
|
arg.RemediationRounds,
|
|
arg.ReviewPayload,
|
|
arg.WorkflowDefinitionVersion,
|
|
arg.WorkflowDefinitionDigest,
|
|
arg.WorkflowDefinitionYaml,
|
|
)
|
|
return err
|
|
}
|