@@ -3,7 +3,9 @@ |
| 3 | 3 | package repo |
| 4 | 4 | |
| 5 | 5 | import ( |
| 6 | + "encoding/json" |
| 6 | 7 | "errors" |
| 8 | + "html/template" |
| 7 | 9 | "net/http" |
| 8 | 10 | "strconv" |
| 9 | 11 | "strings" |
@@ -13,11 +15,13 @@ import ( |
| 13 | 15 | "github.com/jackc/pgx/v5/pgtype" |
| 14 | 16 | |
| 15 | 17 | "github.com/tenseleyFlow/shithub/internal/auth/policy" |
| 18 | + checksdb "github.com/tenseleyFlow/shithub/internal/checks/sqlc" |
| 16 | 19 | "github.com/tenseleyFlow/shithub/internal/issues" |
| 17 | 20 | issuesdb "github.com/tenseleyFlow/shithub/internal/issues/sqlc" |
| 18 | 21 | "github.com/tenseleyFlow/shithub/internal/pulls" |
| 19 | 22 | pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc" |
| 20 | 23 | repogit "github.com/tenseleyFlow/shithub/internal/repos/git" |
| 24 | + mdrender "github.com/tenseleyFlow/shithub/internal/repos/markdown" |
| 21 | 25 | reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc" |
| 22 | 26 | "github.com/tenseleyFlow/shithub/internal/web/middleware" |
| 23 | 27 | "github.com/tenseleyFlow/shithub/internal/worker" |
@@ -411,10 +415,65 @@ func (h *Handlers) pullFiles(w http.ResponseWriter, r *http.Request) { |
| 411 | 415 | }) |
| 412 | 416 | } |
| 413 | 417 | |
| 414 | | -// pullChecks renders the Checks tab. v1 ships the visual scaffold; |
| 415 | | -// the data wires in at S24. |
| 418 | +// pullChecks renders the Checks tab. Loads suites + runs grouped by |
| 419 | +// suite for the PR's head_oid, plus the markdown-rendered output.summary |
| 420 | +// for each run. |
| 416 | 421 | func (h *Handlers) pullChecks(w http.ResponseWriter, r *http.Request) { |
| 417 | | - h.renderPullPage(w, r, "checks", nil) |
| 422 | + row, _, ok := h.loadRepoAndAuthorize(w, r, policy.ActionPullRead) |
| 423 | + if !ok { |
| 424 | + return |
| 425 | + } |
| 426 | + pr, ok := h.loadPullByNumber(w, r, row.ID) |
| 427 | + if !ok { |
| 428 | + return |
| 429 | + } |
| 430 | + type runRow struct { |
| 431 | + R checksdb.CheckRun |
| 432 | + SummaryHTML template.HTML |
| 433 | + AppSlug string |
| 434 | + } |
| 435 | + type suiteGroup struct { |
| 436 | + Suite checksdb.CheckSuite |
| 437 | + Runs []runRow |
| 438 | + } |
| 439 | + groups := []suiteGroup{} |
| 440 | + if pr.HeadOid != "" { |
| 441 | + suites, _ := h.cq.ListCheckSuitesForCommit(r.Context(), h.d.Pool, checksdb.ListCheckSuitesForCommitParams{ |
| 442 | + RepoID: row.ID, HeadSha: pr.HeadOid, |
| 443 | + }) |
| 444 | + for _, s := range suites { |
| 445 | + runs, _ := h.cq.ListCheckRunsBySuite(r.Context(), h.d.Pool, s.ID) |
| 446 | + rs := make([]runRow, 0, len(runs)) |
| 447 | + for _, run := range runs { |
| 448 | + rs = append(rs, runRow{ |
| 449 | + R: run, |
| 450 | + SummaryHTML: renderCheckSummary(run.Output), |
| 451 | + AppSlug: s.AppSlug, |
| 452 | + }) |
| 453 | + } |
| 454 | + groups = append(groups, suiteGroup{Suite: s, Runs: rs}) |
| 455 | + } |
| 456 | + } |
| 457 | + h.renderPullPage(w, r, "checks", map[string]any{ |
| 458 | + "CheckGroups": groups, |
| 459 | + }) |
| 460 | +} |
| 461 | + |
| 462 | +// renderCheckSummary parses the JSON `output` blob and renders the |
| 463 | +// `summary` field as Markdown via the existing pipeline. Returns empty |
| 464 | +// HTML on any error so a malformed payload doesn't break the page. |
| 465 | +func renderCheckSummary(raw []byte) template.HTML { |
| 466 | + if len(raw) == 0 { |
| 467 | + return "" |
| 468 | + } |
| 469 | + var o struct { |
| 470 | + Summary string `json:"summary"` |
| 471 | + } |
| 472 | + if err := json.Unmarshal(raw, &o); err != nil || o.Summary == "" { |
| 473 | + return "" |
| 474 | + } |
| 475 | + html, _ := mdrender.RenderHTML([]byte(o.Summary)) |
| 476 | + return template.HTML(html) //nolint:gosec // sanitized by bluemonday UGCPolicy |
| 418 | 477 | } |
| 419 | 478 | |
| 420 | 479 | // pullEdit handles POST .../edit |