@@ -0,0 +1,176 @@ |
| 1 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | + |
| 3 | +package repo |
| 4 | + |
| 5 | +import ( |
| 6 | + "net/http" |
| 7 | + |
| 8 | + actionsdb "github.com/tenseleyFlow/shithub/internal/actions/sqlc" |
| 9 | + "github.com/tenseleyFlow/shithub/internal/auth/policy" |
| 10 | +) |
| 11 | + |
| 12 | +type actionsManagementPageView struct { |
| 13 | + Key string |
| 14 | + Title string |
| 15 | + Description string |
| 16 | + Icon string |
| 17 | + SearchPlaceholder string |
| 18 | + CountLabel string |
| 19 | + EmptyTitle string |
| 20 | + EmptyBody string |
| 21 | + PrimaryAction string |
| 22 | + PrimaryDisabled bool |
| 23 | + Stats []actionsManagementStatView |
| 24 | + Tabs []actionsManagementTabView |
| 25 | +} |
| 26 | + |
| 27 | +type actionsManagementStatView struct { |
| 28 | + Label string |
| 29 | + Value string |
| 30 | + Note string |
| 31 | +} |
| 32 | + |
| 33 | +type actionsManagementTabView struct { |
| 34 | + Label string |
| 35 | + Icon string |
| 36 | + Active bool |
| 37 | +} |
| 38 | + |
| 39 | +func (h *Handlers) repoActionsCaches(w http.ResponseWriter, r *http.Request) { |
| 40 | + h.repoActionsManagementPage(w, r, actionsManagementPage("caches")) |
| 41 | +} |
| 42 | + |
| 43 | +func (h *Handlers) repoActionsAttestations(w http.ResponseWriter, r *http.Request) { |
| 44 | + h.repoActionsManagementPage(w, r, actionsManagementPage("attestations")) |
| 45 | +} |
| 46 | + |
| 47 | +func (h *Handlers) repoActionsRunners(w http.ResponseWriter, r *http.Request) { |
| 48 | + h.repoActionsManagementPage(w, r, actionsManagementPage("runners")) |
| 49 | +} |
| 50 | + |
| 51 | +func (h *Handlers) repoActionsUsageMetrics(w http.ResponseWriter, r *http.Request) { |
| 52 | + h.repoActionsManagementPage(w, r, actionsManagementPage("usage")) |
| 53 | +} |
| 54 | + |
| 55 | +func (h *Handlers) repoActionsPerformanceMetrics(w http.ResponseWriter, r *http.Request) { |
| 56 | + h.repoActionsManagementPage(w, r, actionsManagementPage("performance")) |
| 57 | +} |
| 58 | + |
| 59 | +func (h *Handlers) repoActionsManagementPage(w http.ResponseWriter, r *http.Request, page actionsManagementPageView) { |
| 60 | + row, owner, ok := h.loadRepoAndAuthorize(w, r, policy.ActionRepoRead) |
| 61 | + if !ok { |
| 62 | + return |
| 63 | + } |
| 64 | + |
| 65 | + q := actionsdb.New() |
| 66 | + workflowRows, err := q.ListWorkflowRunWorkflowsForRepo(r.Context(), h.d.Pool, row.ID) |
| 67 | + if err != nil { |
| 68 | + h.d.Logger.WarnContext(r.Context(), "repo actions: list workflows for management page", "repo_id", row.ID, "page", page.Key, "error", err) |
| 69 | + h.d.Render.HTTPError(w, r, http.StatusInternalServerError, "") |
| 70 | + return |
| 71 | + } |
| 72 | + |
| 73 | + basePath := "/" + owner.Username + "/" + row.Name + "/actions" |
| 74 | + workflows, allRunCount, _ := actionsWorkflowViews(workflowRows, actionsListFilters{}, basePath) |
| 75 | + |
| 76 | + data := h.repoHeaderData(r, row, owner.Username, "actions") |
| 77 | + data["Title"] = page.Title + " · " + row.Name |
| 78 | + data["Page"] = page |
| 79 | + data["ActionsSidebar"] = actionsSidebar(basePath, workflows, allRunCount, false, page.Key) |
| 80 | + data["RunCount"] = allRunCount |
| 81 | + data["Workflows"] = workflows |
| 82 | + if err := h.d.Render.RenderPage(w, r, "repo/actions_management", data); err != nil { |
| 83 | + h.d.Logger.ErrorContext(r.Context(), "repo actions management render", "page", page.Key, "error", err) |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +func actionsManagementPage(key string) actionsManagementPageView { |
| 88 | + switch key { |
| 89 | + case "caches": |
| 90 | + return actionsManagementPageView{ |
| 91 | + Key: key, |
| 92 | + Title: "Caches", |
| 93 | + Description: "Showing caches from all workflows.", |
| 94 | + Icon: "cache", |
| 95 | + SearchPlaceholder: "Filter caches", |
| 96 | + CountLabel: "0 caches", |
| 97 | + EmptyTitle: "No caches", |
| 98 | + EmptyBody: "Nothing has been cached by workflows running in this repository.", |
| 99 | + } |
| 100 | + case "attestations": |
| 101 | + return actionsManagementPageView{ |
| 102 | + Key: key, |
| 103 | + Title: "Attestations", |
| 104 | + Description: "Build provenance and artifact attestations for this repository.", |
| 105 | + Icon: "shield-check", |
| 106 | + SearchPlaceholder: "Search or filter", |
| 107 | + CountLabel: "0 attestations", |
| 108 | + EmptyTitle: "No attestations", |
| 109 | + EmptyBody: "No workflow has published an artifact attestation for this repository yet.", |
| 110 | + } |
| 111 | + case "runners": |
| 112 | + return actionsManagementPageView{ |
| 113 | + Key: key, |
| 114 | + Title: "Runners", |
| 115 | + Description: "Runners available to this repository.", |
| 116 | + Icon: "server", |
| 117 | + SearchPlaceholder: "Filter runners", |
| 118 | + CountLabel: "Runner management", |
| 119 | + EmptyTitle: "Repository runner management is coming later", |
| 120 | + EmptyBody: "Jobs can already use the shared shithub runner pool. Repository-scoped runner registration controls will land in a later Actions slice.", |
| 121 | + PrimaryAction: "New runner", |
| 122 | + PrimaryDisabled: true, |
| 123 | + Tabs: []actionsManagementTabView{ |
| 124 | + {Label: "shithub-hosted runners", Icon: "server", Active: true}, |
| 125 | + {Label: "Self-hosted runners", Icon: "repo"}, |
| 126 | + }, |
| 127 | + } |
| 128 | + case "usage": |
| 129 | + return actionsManagementPageView{ |
| 130 | + Key: key, |
| 131 | + Title: "Actions Usage Metrics", |
| 132 | + Description: "Showing data for the current billing period.", |
| 133 | + Icon: "pulse", |
| 134 | + CountLabel: "No table data available yet", |
| 135 | + EmptyTitle: "No usage metrics available yet", |
| 136 | + EmptyBody: "Workflow minute and job-run aggregates will appear here after the Actions metering model is wired into the repository UI.", |
| 137 | + Stats: []actionsManagementStatView{ |
| 138 | + {Label: "Total minutes", Value: "0", Note: "Total minutes across all workflows in this repository."}, |
| 139 | + {Label: "Total job runs", Value: "0", Note: "Total job runs across all workflows in this repository."}, |
| 140 | + }, |
| 141 | + Tabs: metricTabs("workflows"), |
| 142 | + } |
| 143 | + case "performance": |
| 144 | + return actionsManagementPageView{ |
| 145 | + Key: key, |
| 146 | + Title: "Actions Performance Metrics", |
| 147 | + Description: "Showing data for the current month.", |
| 148 | + Icon: "stopwatch", |
| 149 | + CountLabel: "No table data available yet", |
| 150 | + EmptyTitle: "No performance metrics available yet", |
| 151 | + EmptyBody: "Average runtime, queue time, and failure-rate metrics will appear here once the insights pipeline is connected to the Actions UI.", |
| 152 | + Stats: []actionsManagementStatView{ |
| 153 | + {Label: "Avg job run time", Value: "0s", Note: "Average run time of jobs in this repository."}, |
| 154 | + {Label: "Avg job queue time", Value: "0s", Note: "Average queue time of jobs in this repository."}, |
| 155 | + {Label: "Job failure rate", Value: "0%", Note: "Failure rate across jobs in this repository."}, |
| 156 | + {Label: "Failed job usage", Value: "0", Note: "Total minutes used by failed jobs."}, |
| 157 | + }, |
| 158 | + Tabs: metricTabs("workflows"), |
| 159 | + } |
| 160 | + default: |
| 161 | + return actionsManagementPageView{Key: key, Title: "Actions", EmptyTitle: "Coming later"} |
| 162 | + } |
| 163 | +} |
| 164 | + |
| 165 | +func metricTabs(active string) []actionsManagementTabView { |
| 166 | + tabs := []actionsManagementTabView{ |
| 167 | + {Label: "Workflows", Icon: "workflow"}, |
| 168 | + {Label: "Jobs", Icon: "stopwatch"}, |
| 169 | + {Label: "Runtime OS", Icon: "server"}, |
| 170 | + {Label: "Runner type", Icon: "repo"}, |
| 171 | + } |
| 172 | + for i := range tabs { |
| 173 | + tabs[i].Active = active == "workflows" && i == 0 |
| 174 | + } |
| 175 | + return tabs |
| 176 | +} |