org page: live-update repo CI badges via ci:runs topic (no refresh)
20e646b · gmorell · 2026-07-02 03:16
Files changed
modified
lib/git_gud_web/live/org_live/show.ex
+15
−0
@@ -22,6 +22,11 @@ defmodule GitGudWeb.OrgLive.Show do
| 22 | 22 | true -> |
| 23 | 23 | repos = visible_repos(org, user) |
| 24 | 24 | |
| 25 | + # Live-update the repo CI badges as runs change anywhere. | |
| 26 | + if connected?(socket) do | |
| 27 | + Phoenix.PubSub.subscribe(GitGud.PubSub, Workflows.ci_topic()) | |
| 28 | + end | |
| 29 | + | |
| 25 | 30 | {:ok, |
| 26 | 31 | socket |
| 27 | 32 | |> assign(:org, org) |
@@ -38,6 +43,16 @@ defmodule GitGudWeb.OrgLive.Show do
| 38 | 43 | end |
| 39 | 44 | end |
| 40 | 45 | |
| 46 | + @impl true | |
| 47 | + def handle_info({:ci_run_changed, _run_id}, socket) do | |
| 48 | + # A run changed somewhere (topic is global); cheaply refresh this | |
| 49 | + # org's repo badges. Non-org runs simply don't change the result. | |
| 50 | + repo_ids = Enum.map(socket.assigns.repos, & &1.id) | |
| 51 | + {:noreply, assign(socket, :ci_status, Workflows.latest_run_status_by_repo(repo_ids))} | |
| 52 | + end | |
| 53 | + | |
| 54 | + def handle_info(_msg, socket), do: {:noreply, socket} | |
| 55 | + | |
| 41 | 56 | # daisyUI badge class for a repo's latest CI status. |
| 42 | 57 | defp ci_badge("success"), do: "badge-success" |
| 43 | 58 | defp ci_badge("failure"), do: "badge-error" |
Parents: b19e499