Blog/Components/Pages/Git/GitRefs.razor 4.3 K · 122 lines · raw · history

1 @page "/git/{Repository}/refs"
2 @inherits GitPage
3
4 <PageTitle>@Repository refs — git</PageTitle>
5
6 <GitBar Repository="@Repository" Reference="@Reference" Tab="refs"/>
7
8 <main class="git-main">
9 @if (Refs is not { } refs)
10 {
11 <section class="block">
12 <p class="empty">No repository called @Repository.</p>
13 </section>
14 }
15 else
16 {
17 <section class="block">
18 <h2 class="block-head">
19 <span>branches</span>
20 <span class="block-note">@refs.Branches.Count</span>
21 </h2>
22
23 @if (refs.Branches.Count == 0)
24 {
25 <p class="empty">No branches.</p>
26 }
27 else
28 {
29 <div class="scroll">
30 <table>
31 <thead>
32 <tr>
33 <th>name</th>
34 <th>commit</th>
35 <th class="wide">subject</th>
36 <th class="when-wide">author</th>
37 <th class="num">age</th>
38 </tr>
39 </thead>
40 <tbody>
41 @foreach (var branch in refs.Branches)
42 {
43 <tr>
44 <td><a href="@LogLink(branch.Name)">@branch.Name</a></td>
45 <td class="sha dim"><a href="@CommitLink(branch.Sha)">@Shorten(branch.Sha)</a></td>
46 <td class="wide">@branch.Tip?.Summary</td>
47 <td class="dim when-wide">@branch.Tip?.Author.Name</td>
48 <td class="num dim" title="@Exact(branch.Tip?.Committer.When)">
49 @Age(branch.Tip?.Committer.When)
50 </td>
51 </tr>
52 }
53 </tbody>
54 </table>
55 </div>
56 }
57 </section>
58
59 <section class="block">
60 <h2 class="block-head">
61 <span>tags</span>
62 <span class="block-note">@refs.Tags.Count</span>
63 </h2>
64
65 @if (refs.Tags.Count == 0)
66 {
67 <p class="empty">No tags.</p>
68 }
69 else
70 {
71 <div class="scroll">
72 <table>
73 <thead>
74 <tr>
75 <th>name</th>
76 <th>commit</th>
77 <th class="wide">message</th>
78 <th class="num">age</th>
79 </tr>
80 </thead>
81 <tbody>
82 @foreach (var tag in refs.Tags)
83 {
84 <tr>
85 <td><a href="@TreeLink("", tag.Name)">@tag.Name</a></td>
86 <td class="sha dim">
87 @if (tag.Tip is { } tip)
88 {
89 <a href="@CommitLink(tip.Sha)">@Shorten(tip.Sha)</a>
90 }
91 </td>
92 @* An annotated tag's own message, falling back to the subject of
93 what it points at — which is all a lightweight tag has. *@
94 <td class="wide">@(First(tag.Message) ?? tag.Tip?.Summary)</td>
95 <td class="num dim" title="@Exact(tag.Tip?.Committer.When)">
96 @Age(tag.Tip?.Committer.When)
97 </td>
98 </tr>
99 }
100 </tbody>
101 </table>
102 </div>
103 }
104 </section>
105 }
106 </main>
107
108 @code {
109 private GitRefsView? Refs { get; set; }
110
111 protected override void OnParametersSet()
112 {
113 Refs = Service.GetRefs(Repository);
114
115 if (Refs is null) NotFound();
116 }
117
118 private static string Shorten(string sha) => sha.Length >= 10 ? sha[..10] : sha;
119
120 private static string? First(string? message) =>
121 message?.Split('\n', 2)[0].Trim() is { Length: > 0 } line ? line : null;
122 }