From 96c219f560f4a0202ba13108c69bd76c8ce013ea Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Wed, 9 Jul 2025 18:14:51 +0100 Subject: [PATCH] appview: add CI status component to pulls view Change-Id: qrxlommzxxwmmkqptrqxqnrrxkqvpwtp Signed-off-by: oppiliappan --- appview/db/pipeline.go | 7 ++-- appview/pages/pages.go | 1 + .../repo/pipelines/fragments/logBlock.html | 7 ++-- .../repo/pipelines/fragments/logLine.html | 4 +- .../templates/repo/pipelines/pipelines.html | 21 ++++++---- appview/pages/templates/repo/pulls/pull.html | 41 ++++++++++++++++++- appview/pulls/pulls.go | 28 ++++++++++++- 7 files changed, 89 insertions(+), 20 deletions(-) diff --git a/appview/db/pipeline.go b/appview/db/pipeline.go index 142af30..b13647f 100644 --- a/appview/db/pipeline.go +++ b/appview/db/pipeline.go @@ -9,6 +9,7 @@ import ( "github.com/bluesky-social/indigo/atproto/syntax" "github.com/go-git/go-git/v5/plumbing" spindle "tangled.sh/tangled.sh/core/spindle/models" + "tangled.sh/tangled.sh/core/workflow" ) type Pipeline struct { @@ -85,7 +86,7 @@ func (p Pipeline) IsResponding() bool { type Trigger struct { Id int - Kind string + Kind workflow.TriggerKind // push trigger fields PushRef *string @@ -100,11 +101,11 @@ type Trigger struct { } func (t *Trigger) IsPush() bool { - return t != nil && t.Kind == "push" + return t != nil && t.Kind == workflow.TriggerKindPush } func (t *Trigger) IsPullRequest() bool { - return t != nil && t.Kind == "pull_request" + return t != nil && t.Kind == workflow.TriggerKindPullRequest } func (t *Trigger) TargetRef() string { diff --git a/appview/pages/pages.go b/appview/pages/pages.go index d9d4b73..a7e7398 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -797,6 +797,7 @@ type RepoSinglePullParams struct { AbandonedPulls []*db.Pull MergeCheck types.MergeCheckResponse ResubmitCheck ResubmitResult + Pipelines map[string]db.Pipeline } func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error { diff --git a/appview/pages/templates/repo/pipelines/fragments/logBlock.html b/appview/pages/templates/repo/pipelines/fragments/logBlock.html index 42a175b..49464fc 100644 --- a/appview/pages/templates/repo/pipelines/fragments/logBlock.html +++ b/appview/pages/templates/repo/pipelines/fragments/logBlock.html @@ -1,7 +1,7 @@ {{ define "repo/pipelines/fragments/logBlock" }}
-
- +
+
{{ i "chevron-right" "w-4 h-4" }} {{ .Name }}
@@ -9,8 +9,7 @@ {{ i "chevron-down" "w-4 h-4" }} {{ .Name }}
-
{{ .Command }}
-
+
{{ .Command }}
{{ end }} diff --git a/appview/pages/templates/repo/pipelines/fragments/logLine.html b/appview/pages/templates/repo/pipelines/fragments/logLine.html index 65055d0..c1f3e1c 100644 --- a/appview/pages/templates/repo/pipelines/fragments/logLine.html +++ b/appview/pages/templates/repo/pipelines/fragments/logLine.html @@ -1,6 +1,4 @@ {{ define "repo/pipelines/fragments/logLine" }} -
-

{{ .Content }}

-
+

{{ .Content }}

{{ end }} diff --git a/appview/pages/templates/repo/pipelines/pipelines.html b/appview/pages/templates/repo/pipelines/pipelines.html index 40ab6df..0d06538 100644 --- a/appview/pages/templates/repo/pipelines/pipelines.html +++ b/appview/pages/templates/repo/pipelines/pipelines.html @@ -34,7 +34,11 @@ {{ $p := index . 1 }} {{ with $p }}
-
+
+ {{ .Trigger.Kind.String }} +
+ +
{{ $target := .Trigger.TargetRef }} {{ $workflows := .Workflows }} {{ $link := "" }} @@ -43,7 +47,6 @@ {{ end }} {{ if .Trigger.IsPush }} {{ $target }} - push {{ else if .Trigger.IsPullRequest }} - - pull request - - {{ $target }} - {{ i "arrow-left" "size-4" }} - {{ .Trigger.PRSourceBranch }} + {{ $sha := deref .Trigger.PRSourceSha }} + + {{ $target }} + {{ i "arrow-left" "size-4" }} + {{ .Trigger.PRSourceBranch }} + + @ + {{ slice $sha 0 8 }} {{ end }} diff --git a/appview/pages/templates/repo/pulls/pull.html b/appview/pages/templates/repo/pulls/pull.html index 40f3725..16d1084 100644 --- a/appview/pages/templates/repo/pulls/pull.html +++ b/appview/pages/templates/repo/pulls/pull.html @@ -162,6 +162,8 @@
{{ end }} + {{ block "pipelineStatus" (list $ .) }} {{ end }} + {{ if eq $lastIdx .RoundNumber }} {{ block "mergeStatus" $ }} {{ end }} {{ block "resubmitStatus" $ }} {{ end }} @@ -260,5 +262,42 @@ {{ end }} {{ end }} -{{ define "commits" }} +{{ define "pipelineStatus" }} + {{ $root := index . 0 }} + {{ $submission := index . 1 }} + {{ $pipeline := index $root.Pipelines $submission.SourceRev }} + {{ with $pipeline }} + {{ $id := .Id }} + {{ if .Statuses }} + + {{ end }} + {{ end }} {{ end }} diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index a587560..d05facf 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -167,15 +167,41 @@ func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) { resubmitResult = s.resubmitCheck(f, pull, stack) } + repoInfo := f.RepoInfo(user) + + m := make(map[string]db.Pipeline) + + var shas []string + for _, s := range pull.Submissions { + shas = append(shas, s.SourceRev) + } + + ps, err := db.GetPipelineStatuses( + s.db, + db.FilterEq("repo_owner", repoInfo.OwnerDid), + db.FilterEq("repo_name", repoInfo.Name), + db.FilterEq("knot", repoInfo.Knot), + db.FilterIn("sha", shas), + ) + if err != nil { + log.Printf("failed to fetch pipeline statuses: %s", err) + // non-fatal + } + + for _, p := range ps { + m[p.Sha] = p + } + s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{ LoggedInUser: user, - RepoInfo: f.RepoInfo(user), + RepoInfo: repoInfo, DidHandleMap: didHandleMap, Pull: pull, Stack: stack, AbandonedPulls: abandonedPulls, MergeCheck: mergeCheckResponse, ResubmitCheck: resubmitResult, + Pipelines: m, }) } -- 2.43.0