Move the licence into the shared stats tab strip

1003c50 · Gabriel Morell · 2026-09-22 13:56

10 files +78 -56
Message
{commit_body(@commit)}

Files changed

modified lib/git_gud_web/live/repo_live/languages.ex
+5 −39
@@ -67,14 +67,11 @@ defmodule GitGudWeb.RepoLive.Languages do
67 67 <h1 class="text-xl font-semibold">Stats</h1>
68 68 </header>
69 69
70 − <div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-2">
71 − <GitGudWeb.RepoLive.StatsTabs.tabs
72 − active={:languages}
73 − handle={@handle}
74 − repo={@repo}
75 − />
76 − <.license repo={@repo} handle={@handle} />
77 − </div>
70 + <GitGudWeb.RepoLive.StatsTabs.tabs
71 + active={:languages}
72 + handle={@handle}
73 + repo={@repo}
74 + />
78 75
79 76 <p class="text-xs opacity-60 font-mono">
80 77 on {@current_ref}
@@ -139,37 +136,6 @@ defmodule GitGudWeb.RepoLive.Languages do
139 136 """
140 137 end
141 138
142 − attr :repo, :map, required: true
143 − attr :handle, :string, required: true
144 −
145 − # Detected from the licence file at the default branch's tip, so it is
146 − # labelled with that branch rather than with whichever ref the stats
147 − # on this page are for — the two can differ, and quietly showing one
148 − # branch's licence under another's name would be a lie.
149 − defp license(assigns) do
150 − ~H"""
151 − <p class="text-sm flex items-center gap-2">
152 − <%= if @repo.license do %>
153 − <span class="badge badge-sm badge-outline">{@repo.license}</span>
154 − <.link
155 − :if={@repo.license_file}
156 − navigate={
157 − ~p"/r/#{@handle}/#{@repo.name}/blob/#{@repo.default_branch}/#{@repo.license_file}"
158 − }
159 − class="link link-hover text-xs opacity-70 font-mono"
160 − >
161 − {@repo.license_file}
162 − </.link>
163 − <span class="text-xs opacity-50">on {@repo.default_branch}</span>
164 − <% else %>
165 − <span class="text-xs opacity-60">
166 − No licence detected on {@repo.default_branch}.
167 − </span>
168 − <% end %>
169 − </p>
170 − """
171 − end
172 −
173 139 attr :stats, :map, required: true
174 140
175 141 defp bar(assigns) do
modified lib/git_gud_web/live/repo_live/stats_tabs.ex
+56 −16
@@ -1,6 +1,11 @@
1 1 defmodule GitGudWeb.RepoLive.StatsTabs do
2 2 @moduledoc """
3 − Shared tab strip for the `/r/:owner/:name/stats/*` sub-pages.
3 + Shared tab strip for the `/r/:owner/:name/stats/*` sub-pages, and the
4 + repository's detected licence beside it.
5 +
6 + The licence lives here rather than on one of the pages because it is
7 + a property of the repository the tabs belong to, not of the tab that
8 + happens to be open.
4 9 """
5 10
6 11 use Phoenix.Component
@@ -15,22 +20,57 @@ defmodule GitGudWeb.RepoLive.StatsTabs do
15 20
16 21 def tabs(assigns) do
17 22 ~H"""
18 − <div role="tablist" class="tabs tabs-bordered">
19 − <.link
20 − navigate={~p"/r/#{@handle}/#{@repo.name}/stats/languages"}
21 − role="tab"
22 − class={["tab", @active == :languages && "tab-active"]}
23 − >
24 − Languages
25 − </.link>
26 − <.link
27 − navigate={~p"/r/#{@handle}/#{@repo.name}/stats/committers"}
28 − role="tab"
29 − class={["tab", @active == :committers && "tab-active"]}
30 − >
31 − Committers
32 − </.link>
23 + <div class="flex flex-wrap items-center justify-between gap-x-4 gap-y-2">
24 + <div role="tablist" class="tabs tabs-bordered">
25 + <.link
26 + navigate={~p"/r/#{@handle}/#{@repo.name}/stats/languages"}
27 + role="tab"
28 + class={["tab", @active == :languages && "tab-active"]}
29 + >
30 + Languages
31 + </.link>
32 + <.link
33 + navigate={~p"/r/#{@handle}/#{@repo.name}/stats/committers"}
34 + role="tab"
35 + class={["tab", @active == :committers && "tab-active"]}
36 + >
37 + Committers
38 + </.link>
39 + </div>
40 +
41 + <.license repo={@repo} handle={@handle} />
33 42 </div>
34 43 """
35 44 end
45 +
46 + attr :repo, :map, required: true
47 + attr :handle, :string, required: true
48 +
49 + # Detected from the licence file at the default branch's tip, so it is
50 + # labelled with that branch rather than with whichever ref a page is
51 + # showing — the two can differ, and quietly showing one branch's
52 + # licence under another's name would be a lie.
53 + defp license(assigns) do
54 + ~H"""
55 + <p class="text-sm flex items-center gap-2">
56 + <%= if @repo.license do %>
57 + <span class="badge badge-sm badge-outline">{@repo.license}</span>
58 + <.link
59 + :if={@repo.license_file}
60 + navigate={
61 + ~p"/r/#{@handle}/#{@repo.name}/blob/#{@repo.default_branch}/#{@repo.license_file}"
62 + }
63 + class="link link-hover text-xs opacity-70 font-mono"
64 + >
65 + {@repo.license_file}
66 + </.link>
67 + <span class="text-xs opacity-50">on {@repo.default_branch}</span>
68 + <% else %>
69 + <span class="text-xs opacity-60">
70 + No licence detected on {@repo.default_branch}.
71 + </span>
72 + <% end %>
73 + </p>
74 + """
75 + end
36 76 end
modified test/git_gud_web/live/stats_license_test.exs
+17 −1
@@ -1,6 +1,7 @@
1 1 defmodule GitGudWeb.StatsLicenseTest do
2 2 @moduledoc """
3 − The detected licence on `/r/:owner/:name/stats/languages`.
3 + The detected licence beside the stats tab strip, on every page that
4 + carries it.
4 5
5 6 It is labelled with the default branch rather than with whichever ref
6 7 the stats are for: detection follows the default branch's tip, and
@@ -37,6 +38,21 @@ defmodule GitGudWeb.StatsLicenseTest do
37 38 assert html =~ "/r/#{handle}/#{repo.name}/blob/main/LICENSE.md"
38 39 end
39 40
41 + test "shows on the committers tab too, being the repository's", %{
42 + conn: conn,
43 + user: user,
44 + repo: repo,
45 + handle: handle
46 + } do
47 + sha = seed_file(repo, "main", "LICENSE.md", File.read!("LICENSE.md"), user)
48 + assert {:ok, "AGPL-3.0"} = Repositories.detect_and_store_license(repo, sha)
49 +
50 + {:ok, _view, html} = live(conn, ~p"/r/#{handle}/#{repo.name}/stats/committers")
51 +
52 + assert html =~ "AGPL-3.0"
53 + assert html =~ "/r/#{handle}/#{repo.name}/blob/main/LICENSE.md"
54 + end
55 +
40 56 test "says so when nothing was detected", %{conn: conn, repo: repo, handle: handle} do
41 57 {:ok, _view, html} = live(conn, ~p"/r/#{handle}/#{repo.name}/stats/languages")
42 58

Parents: f21859b