Add background audits of the default branch's newest commit
This commit is contained in:
+27
-8
@@ -295,8 +295,16 @@ func (s *Store) ListProjects(ctx context.Context) ([]api.Project, error) {
|
||||
}
|
||||
|
||||
func (s *Store) SetReviewWorkflow(ctx context.Context, id, workflow, actor string) (api.Project, error) {
|
||||
return s.setProjectWorkflow(ctx, "review_workflow", id, workflow, actor)
|
||||
}
|
||||
|
||||
func (s *Store) SetAuditWorkflow(ctx context.Context, id, workflow, actor string) (api.Project, error) {
|
||||
return s.setProjectWorkflow(ctx, "audit_workflow", id, workflow, actor)
|
||||
}
|
||||
|
||||
func (s *Store) setProjectWorkflow(ctx context.Context, column, id, workflow, actor string) (api.Project, error) {
|
||||
err := s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
res, err := tx.ExecContext(ctx, `UPDATE projects SET review_workflow = ? WHERE id = ?`, workflow, id)
|
||||
res, err := tx.ExecContext(ctx, `UPDATE projects SET `+column+` = ? WHERE id = ?`, workflow, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -367,6 +375,11 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, frozen *FrozenWorkfl
|
||||
if t.ParentTaskId != nil {
|
||||
parentTaskID = *t.ParentTaskId
|
||||
}
|
||||
audit := ""
|
||||
if t.Audit != nil {
|
||||
audit = *t.Audit
|
||||
t.Background = true
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
if parentTaskID != "" {
|
||||
open := false
|
||||
@@ -398,9 +411,9 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, frozen *FrozenWorkfl
|
||||
return err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `
|
||||
INSERT INTO tasks (id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, todo_item, forked_from, forked_at, workflow_name, workflow_definition, workflow_brief, workflow_title, workflow_run, workflow_stage, parent_task_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, mergeTitle, t.Branch, t.WorktreePath, t.BaseRef, t.PortBase, t.Color, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem, forkedFrom, forkedAt, workflowName, workflowDefinition, workflowBrief, workflowTitle, workflowRun, workflowStage, parentTaskID)
|
||||
INSERT INTO tasks (id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, todo_item, forked_from, forked_at, workflow_name, workflow_definition, workflow_brief, workflow_title, workflow_run, workflow_stage, parent_task_id, audit)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, mergeTitle, t.Branch, t.WorktreePath, t.BaseRef, t.PortBase, t.Color, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem, forkedFrom, forkedAt, workflowName, workflowDefinition, workflowBrief, workflowTitle, workflowRun, workflowStage, parentTaskID, audit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1682,9 +1695,11 @@ func (s *Store) ClearReviewRequests(ctx context.Context) error {
|
||||
})
|
||||
}
|
||||
|
||||
const projectColumns = `id, name, repo_path, default_branch, remote, created_by, created_at, review_workflow`
|
||||
const projectColumns = `id, name, repo_path, default_branch, remote, created_by, created_at, review_workflow, audit_workflow`
|
||||
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, closed_at, merge_commit, todo_item, forked_from, forked_at, merge_queued_at, workflow_name, workflow_run, workflow_stage, parent_task_id, parent_merge_by, merge_after_review_by != '', state, merging_by != '' OR finalizing != '', discard_state != '' AND status = 'active', (SELECT coalesce(max(seq), 0) FROM events WHERE events.task_id = tasks.id AND kind = 'turn.ended' AND json_extract(payload, '$.summary') = 1)`
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, port_base, color, status, created_by, created_at, closed_at, merge_commit, todo_item, forked_from, forked_at, merge_queued_at, workflow_name, workflow_run, workflow_stage, parent_task_id, parent_merge_by, merge_after_review_by != '', state, merging_by != '' OR finalizing != '', discard_state != '' AND status = 'active', (SELECT coalesce(max(seq), 0) FROM events WHERE events.task_id = tasks.id AND kind = 'turn.ended' AND json_extract(payload, '$.summary') = 1), audit, ` + backgroundExpr
|
||||
|
||||
const backgroundExpr = `audit != '' AND NOT EXISTS (SELECT 1 FROM events WHERE events.task_id = tasks.id AND kind IN ('inbox.created', 'task.ready', 'session.error', 'session.rate_limited'))`
|
||||
|
||||
const sessionColumns = `id, coalesce(task_id, ''), owner, vendor, model, vendor_session_id, state, role, member, created_by, created_at, forked_from, forked_at, subagents`
|
||||
|
||||
@@ -1695,7 +1710,7 @@ type scanner interface {
|
||||
func scanProject(row scanner) (api.Project, error) {
|
||||
p := api.Project{}
|
||||
createdAt := ""
|
||||
err := row.Scan(&p.Id, &p.Name, &p.RepoPath, &p.DefaultBranch, &p.Remote, &p.CreatedBy, &createdAt, &p.ReviewWorkflow)
|
||||
err := row.Scan(&p.Id, &p.Name, &p.RepoPath, &p.DefaultBranch, &p.Remote, &p.CreatedBy, &createdAt, &p.ReviewWorkflow, &p.AuditWorkflow)
|
||||
if err != nil {
|
||||
return p, err
|
||||
}
|
||||
@@ -1719,11 +1734,15 @@ func scanTask(row scanner) (api.Task, error) {
|
||||
parentTaskID := ""
|
||||
parentMergeBy := ""
|
||||
taskState := ""
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &t.PortBase, &t.Color, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem, &forkedFrom, &forkedAt, &mergeQueuedAt, &workflowName, &workflowRun, &workflowStage, &parentTaskID, &parentMergeBy, &t.MergeAfterReview, &taskState, &t.Merging, &t.Discarding, &t.SummarySeq)
|
||||
audit := ""
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &t.PortBase, &t.Color, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem, &forkedFrom, &forkedAt, &mergeQueuedAt, &workflowName, &workflowRun, &workflowStage, &parentTaskID, &parentMergeBy, &t.MergeAfterReview, &taskState, &t.Merging, &t.Discarding, &t.SummarySeq, &audit, &t.Background)
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
t.State = api.TaskState(taskState)
|
||||
if audit != "" {
|
||||
t.Audit = &audit
|
||||
}
|
||||
if parentTaskID != "" {
|
||||
t.ParentTaskId = &parentTaskID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user