Hide the Labels heading on issues and PRs when the repo has none

d1b9a04 · Gabriel Morell · 2026-09-09 22:42

3 files +89 -2
Message
{commit_body(@commit)}

Files changed

modified lib/git_gud_web/live/issue_live/show.ex
+1 −1
@@ -322,7 +322,7 @@ defmodule GitGudWeb.IssueLive.Show do
322 322 />
323 323 </section>
324 324
325 <section>
325 + <section :if={@all_labels != []}>
326 326 <h2 class="font-semibold mb-2">Labels</h2>
327 327 <div class="flex flex-wrap gap-1">
328 328 <button
modified lib/git_gud_web/live/pr_live/show.ex
+1 −1
@@ -636,7 +636,7 @@ defmodule GitGudWeb.PrLive.Show do
636 636 </div>
637 637 </section>
638 638
639 <section>
639 + <section :if={@all_labels != []}>
640 640 <h2 class="font-semibold mb-2">Labels</h2>
641 641 <div class="flex flex-wrap gap-1">
642 642 <button
added test/git_gud_web/live/labels_section_test.exs
+87 −0
@@ -0,0 +1,87 @@
1 +defmodule GitGudWeb.LabelsSectionTest do
2 + @moduledoc """
3 + The Labels section on issue and PR pages lists every label the repo
4 + defines, dimmed when unattachedso a repo with none defined has
5 + nothing to put under the heading.
6 + """
7 +
8 + use GitGudWeb.ConnCase, async: false
9 +
10 + import Phoenix.LiveViewTest
11 + import GitGud.ForgeFixtures
12 +
13 + alias GitGud.Repositories
14 +
15 + defp repo_path(repo) do
16 + Repositories.Storage.repo_handle(GitGud.Repo.preload(repo, [:owner, :organization]))
17 + end
18 +
19 + describe "issues" do
20 + test "no heading when the repo defines no labels", %{conn: conn} do
21 + {user, repo} = repository_fixture()
22 + issue = issue_fixture(repo, user)
23 +
24 + {:ok, _lv, html} =
25 + live(
26 + log_in_user(conn, user),
27 + ~p"/r/#{repo_path(repo)}/#{repo.name}/issues/#{issue.number}"
28 + )
29 +
30 + refute html =~ ">Labels<"
31 + end
32 +
33 + test "the heading returns once the repo has one", %{conn: conn} do
34 + {user, repo} = repository_fixture()
35 + issue = issue_fixture(repo, user)
36 + _ = label_fixture(repo, %{"name" => "bug"})
37 +
38 + {:ok, _lv, html} =
39 + live(
40 + log_in_user(conn, user),
41 + ~p"/r/#{repo_path(repo)}/#{repo.name}/issues/#{issue.number}"
42 + )
43 +
44 + assert html =~ ">Labels<"
45 + assert html =~ "bug"
46 + end
47 +
48 + test "an unattached label still shows, so it can be attached", %{conn: conn} do
49 + {user, repo} = repository_fixture()
50 + issue = issue_fixture(repo, user)
51 + _ = label_fixture(repo, %{"name" => "unattached"})
52 +
53 + {:ok, lv, html} =
54 + live(
55 + log_in_user(conn, user),
56 + ~p"/r/#{repo_path(repo)}/#{repo.name}/issues/#{issue.number}"
57 + )
58 +
59 + assert html =~ "unattached"
60 + assert has_element?(lv, "button[phx-click=toggle_label]")
61 + end
62 + end
63 +
64 + describe "pull requests" do
65 + test "no heading when the repo defines no labels", %{conn: conn} do
66 + {user, repo} = repository_fixture()
67 + pr = pr_with_branches(repo, user)
68 +
69 + {:ok, _lv, html} =
70 + live(log_in_user(conn, user), ~p"/r/#{repo_path(repo)}/#{repo.name}/pulls/#{pr.number}")
71 +
72 + refute html =~ ">Labels<"
73 + end
74 +
75 + test "the heading returns once the repo has one", %{conn: conn} do
76 + {user, repo} = repository_fixture()
77 + pr = pr_with_branches(repo, user)
78 + _ = label_fixture(repo, %{"name" => "needs-review"})
79 +
80 + {:ok, _lv, html} =
81 + live(log_in_user(conn, user), ~p"/r/#{repo_path(repo)}/#{repo.name}/pulls/#{pr.number}")
82 +
83 + assert html =~ ">Labels<"
84 + assert html =~ "needs-review"
85 + end
86 + end
87 +end

Parents: ff90733