Download this file
| 1 | package chat |
| 2 | |
| 3 | import "encoding/json" |
| 4 | |
| 5 | // Read at dispatch, so a queued reply carries the current report facts. |
| 6 | func (t *txn) reportPrefix(id, text string) (string, error) { |
| 7 | k, err := t.loadTask(id) |
| 8 | if err != nil { |
| 9 | return "", err |
| 10 | } |
| 11 | v, err := t.taskView(k) |
| 12 | if err != nil { |
| 13 | return "", err |
| 14 | } |
| 15 | facts := map[string]any{"moving": v.Moving, "stopping": v.Stopping, "preparing_project": v.PreparingProject, "task_id": v.ID, "title": v.Title, "project": v.Project, "project_id": v.ProjectID, "stage": v.Stage, "needs_you": v.NeedsYou, "checks": v.Checks, "checks_reason": v.ChecksReason, "verdict": v.Verdict, "branch": v.Branch, "candidate_sha": v.CandidateSHA} |
| 16 | if n := len(v.Findings); n > 0 { |
| 17 | facts["latest_finding"] = v.Findings[n-1] |
| 18 | } |
| 19 | if n := len(v.Steps); n > 0 { |
| 20 | s := v.Steps[n-1] |
| 21 | facts["latest_step"] = map[string]any{"specialist": s.Specialist, "state": s.State, "summary": s.Summary, "reason": s.Reason} |
| 22 | } |
| 23 | raw, err := json.Marshal(facts) |
| 24 | if err != nil { |
| 25 | return "", err |
| 26 | } |
| 27 | return "(Discussing this task report: " + string(raw) + ") " + text, nil |
| 28 | } |
| 29 | |