875 lines
23 KiB
Go
875 lines
23 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', stage = '', 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, stage, 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
|
|
`
|
|
|
|
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.Stage,
|
|
&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,
|
|
)
|
|
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, stage, 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
|
|
`
|
|
|
|
// 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.Stage,
|
|
&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,
|
|
)
|
|
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)
|
|
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'
|
|
)
|
|
)
|
|
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, stage, 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
|
|
`
|
|
|
|
type InsertChatTaskParams struct {
|
|
Owner string
|
|
Repo string
|
|
FallbackIssueNumber int64
|
|
Title string
|
|
Body string
|
|
Workflow string
|
|
Identity 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.
|
|
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,
|
|
)
|
|
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.Stage,
|
|
&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,
|
|
)
|
|
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, stage,
|
|
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
|
|
Stage 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.Stage,
|
|
&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 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,
|
|
stage = '', 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,
|
|
stage = '', 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, inputs = $4 WHERE id = $1
|
|
`
|
|
|
|
type StampTaskBindingParams struct {
|
|
ID int64
|
|
BindingID string
|
|
BindingVersion int64
|
|
Inputs string
|
|
}
|
|
|
|
func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingParams) error {
|
|
_, err := q.db.Exec(ctx, stampTaskBinding,
|
|
arg.ID,
|
|
arg.BindingID,
|
|
arg.BindingVersion,
|
|
arg.Inputs,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const taskByID = `-- name: TaskByID :one
|
|
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, 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 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.Stage,
|
|
&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,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const taskByIssue = `-- name: TaskByIssue :one
|
|
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, 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 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.Stage,
|
|
&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,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const taskByPR = `-- name: TaskByPR :one
|
|
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, stage, 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 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.Stage,
|
|
&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,
|
|
)
|
|
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, stage = $3, branch = $4, plan = $5, notes = $6,
|
|
pr_number = $7, tokens_used = $8, iterations = $9, park_reason = $10,
|
|
watch_comment_id = $11, retry_count = $12, remediation_rounds = $13,
|
|
review_payload = $14, workflow_definition_version = $15,
|
|
workflow_definition_digest = $16, workflow_definition_yaml = $17,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateTaskParams struct {
|
|
ID int64
|
|
Workflow string
|
|
Stage 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.Stage,
|
|
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
|
|
}
|