Add background audits of the default branch's newest commit
This commit is contained in:
@@ -15,6 +15,7 @@ type FrozenWorkflow struct {
|
||||
Definition api.WorkflowDefinition
|
||||
Brief string
|
||||
Title string
|
||||
Audit string
|
||||
}
|
||||
|
||||
func (s *Store) ListWorkflows(ctx context.Context) ([]api.WorkflowSummary, error) {
|
||||
@@ -81,7 +82,7 @@ func (s *Store) PutWorkflow(ctx context.Context, name, from string, def api.Work
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = repointReviews(ctx, tx, emit, from, name, actor)
|
||||
err = repointProjects(ctx, tx, emit, from, name, actor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -99,8 +100,13 @@ func (s *Store) PutWorkflow(ctx context.Context, name, from string, def api.Work
|
||||
})
|
||||
}
|
||||
|
||||
func repointReviews(ctx context.Context, tx *sql.Tx, emit emitFunc, from, to, actor string) error {
|
||||
rows, err := tx.QueryContext(ctx, `UPDATE projects SET review_workflow = ? WHERE review_workflow = ? RETURNING `+projectColumns, to, from)
|
||||
func repointProjects(ctx context.Context, tx *sql.Tx, emit emitFunc, from, to, actor string) error {
|
||||
rows, err := tx.QueryContext(ctx, `
|
||||
UPDATE projects SET
|
||||
review_workflow = CASE WHEN review_workflow = ?1 THEN ?2 ELSE review_workflow END,
|
||||
audit_workflow = CASE WHEN audit_workflow = ?1 THEN ?2 ELSE audit_workflow END
|
||||
WHERE review_workflow = ?1 OR audit_workflow = ?1
|
||||
RETURNING `+projectColumns, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -139,7 +145,7 @@ func (s *Store) DeleteWorkflow(ctx context.Context, name, actor string) error {
|
||||
if n == 0 {
|
||||
return fmt.Errorf("%w: no workflow %q", ErrNotFound, name)
|
||||
}
|
||||
err = repointReviews(ctx, tx, emit, name, "", actor)
|
||||
err = repointProjects(ctx, tx, emit, name, "", actor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -158,7 +164,7 @@ func (s *Store) FreezeWorkflow(ctx context.Context, name string) (FrozenWorkflow
|
||||
func (s *Store) TaskWorkflow(ctx context.Context, taskID string) (FrozenWorkflow, error) {
|
||||
f := FrozenWorkflow{}
|
||||
def := ""
|
||||
err := s.db.QueryRowContext(ctx, `SELECT workflow_name, workflow_definition, workflow_brief, workflow_title FROM tasks WHERE id = ?`, taskID).Scan(&f.Name, &def, &f.Brief, &f.Title)
|
||||
err := s.db.QueryRowContext(ctx, `SELECT workflow_name, workflow_definition, workflow_brief, workflow_title, audit FROM tasks WHERE id = ?`, taskID).Scan(&f.Name, &def, &f.Brief, &f.Title, &f.Audit)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return FrozenWorkflow{}, fmt.Errorf("%w: no task %s", ErrNotFound, taskID)
|
||||
}
|
||||
@@ -172,6 +178,17 @@ func (s *Store) TaskWorkflow(ctx context.Context, taskID string) (FrozenWorkflow
|
||||
return f, err
|
||||
}
|
||||
|
||||
func (s *Store) LastAudit(ctx context.Context, projectID string) (string, bool, error) {
|
||||
commit := ""
|
||||
active := false
|
||||
err := s.db.QueryRowContext(ctx, `
|
||||
SELECT
|
||||
coalesce((SELECT audit FROM tasks WHERE project_id = ?1 AND audit != '' ORDER BY rowid DESC LIMIT 1), ''),
|
||||
EXISTS (SELECT 1 FROM tasks WHERE project_id = ?1 AND audit != '' AND status = ?2)
|
||||
`, projectID, string(api.TaskStatusActive)).Scan(&commit, &active)
|
||||
return commit, active, err
|
||||
}
|
||||
|
||||
func (s *Store) RunTasks(ctx context.Context, run string) ([]api.Task, error) {
|
||||
return s.queryTasks(ctx, `SELECT `+taskColumns+` FROM tasks WHERE workflow_run = ? ORDER BY created_at`, run)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user