v0.26.0 df1db36

mr.templ RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import "strings"
6
7// MRList is the list of the merge requests of a repository: the open ones,
8// then the merged and closed ones.
9templ MRList(l Layout, p MRListPage) {
10	@Shell(l, mrListRail(p)) {
11		if p.Live {
12			@LiveSlot("mr-notice")
13		}
14		<div class="filter">
15			<label for="mr-filter" class="sr">filter</label>
16			<input
17				id="mr-filter"
18				type="search"
19				data-filter=".mrs tbody tr"
20				placeholder="Filter by title, branch, author or state…"
21				autocomplete="off"
22				hx-on:input="ermite.filter(this)"
23			/>
24		</div>
25		if p.Newest == "" {
26			<h2 class="rule-h"><span>Open</span><span class="count">{ itoa(len(p.Open)) }</span></h2>
27			@mrRows(p.Open, "Open merge requests")
28			if len(p.Open) == 0 {
29				<p class="lede dim">no open merge requests.</p>
30			}
31			if p.OpenNote != "" {
32				<p class="note">{ p.OpenNote }</p>
33			}
34		}
35		<h2 class="rule-h"><span>Merged and closed</span><span class="count">{ itoa(len(p.Done)) }</span></h2>
36		@mrRows(p.Done, "Merged and closed merge requests")
37		if len(p.Done) == 0 {
38			<p class="lede dim">nothing merged or closed yet.</p>
39		}
40		if p.Older != "" || p.Newest != "" {
41			<nav class="pager" aria-label="Pages">
42				if p.Newest != "" {
43					<a class="btn" href={ templ.SafeURL(p.Newest) }>← Newest</a>
44				} else {
45					<span class="btn" aria-disabled="true">← Newest</span>
46				}
47				if p.Older != "" {
48					<a class="btn" href={ templ.SafeURL(p.Older) } rel="next">Older →</a>
49				} else {
50					<span class="btn" aria-disabled="true">Older →</span>
51				}
52			</nav>
53		}
54	}
55}
56
57templ mrRows(rows []MRRow, label string) {
58	if len(rows) > 0 {
59		<table class="list mrs" aria-label={ label }>
60			<tbody data-rows>
61				for _, m := range rows {
62					<tr data-cursor?={ m.Cursor } data-state={ m.State }>
63						<td class="c-n mute">{ m.Number }</td>
64						<td class="c-state">{ m.State }</td>
65						<td class="c-subject"><a href={ templ.SafeURL(m.Href) }>{ m.Title }</a> <span class="mute">{ m.Branches }</span></td>
66						<td class="c-who dim">{ m.Author }</td>
67						<td class="c-when nowrap dim">
68							if m.WhenAt != "" {
69								<time datetime={ m.WhenAt } title={ m.WhenAt }>{ m.When }</time>
70							}
71						</td>
72					</tr>
73				}
74			</tbody>
75		</table>
76	}
77}
78
79templ mrListRail(p MRListPage) {
80	<section aria-labelledby="r-states">
81		<h2 id="r-states">States</h2>
82		<dl class="kv">
83			<dt>open</dt>
84			<dd>awaits review</dd>
85			<dt>merged</dt>
86			<dd>the target took the branch</dd>
87			<dt>closed</dt>
88			<dd>refused, branch kept</dd>
89		</dl>
90	</section>
91	<section aria-labelledby="r-new">
92		<h2 id="r-new">Open one</h2>
93		if len(p.Branches) > 0 {
94			<p class="dim">compare a branch with { p.Default }:</p>
95			<nav class="outline" aria-label="Branches">
96				for _, b := range p.Branches {
97					<a href={ templ.SafeURL(b.Href) }>{ b.Name }</a>
98				}
99			</nav>
100		} else {
101			<p class="dim">there is no other branch to merge yet.</p>
102		}
103		@CloneBlock(p.CLI)
104	</section>
105}
106
107// MergeRequest is a merge request: its facts, its description, the diff with
108// the notes under their lines, the general comments; and in the rail the merge
109// form, the checks, the settings, the commits and the files.
110templ MergeRequest(l Layout, p MRPage) {
111	@Shell(l, mrRail(p)) {
112		<header class="show mr-h">
113			<h1><span class="mute">{ p.Number }</span> { p.Title }</h1>
114			<dl class="kv show-kv">
115				<dt>state</dt>
116				<dd class="mr-state" data-state={ p.State }>
117					{ p.State }
118					if p.MergedShort != "" {
119						{ " · " }<a href={ templ.SafeURL(p.MergedHref) }>{ p.MergedShort }</a>{ " · " + p.MergeMode }
120					}
121				</dd>
122				<dt>branch</dt>
123				<dd>
124					@branchLink(p.Source, p.SourceHref)
125					{ " → " }
126					@branchLink(p.Target, p.TargetHref)
127				</dd>
128				<dt>opened</dt>
129				<dd>
130					{ p.Opened.Name }
131					if p.Opened.WhenAt != "" {
132						{ " · " }<time datetime={ p.Opened.WhenAt } title={ p.Opened.Abs }>{ p.Opened.When }</time>
133					}
134				</dd>
135				if p.UpdatedAt != "" {
136					<dt>updated</dt>
137					<dd><time datetime={ p.UpdatedAt }>{ p.Updated }</time></dd>
138				}
139			</dl>
140		</header>
141		@LiveSlot("mr-notice")
142		if p.Desc != "" {
143			<article class="mr-desc prose" aria-label="description" hx-ignore>
144				@templ.Raw(string(p.Desc))
145			</article>
146		}
147		if p.Since != nil {
148			<nav class="since" aria-label="Diff range">
149				<a
150					href={ templ.SafeURL(p.Since.AllHref) }
151					if !p.Since.Current {
152						aria-current="page"
153					}
154				>all changes <span class="mute">vs { p.Target }</span></a>
155				<a
156					href={ templ.SafeURL(p.Since.SinceHref) }
157					if p.Since.Current {
158						aria-current="page"
159					}
160				>since your last read <span class="mute">{ p.Since.ReadShort } → { p.Since.HeadShort }</span></a>
161			</nav>
162		}
163		if p.SinceNote != "" {
164			<p class="notice">{ p.SinceNote }</p>
165		}
166		@mrBar(p)
167		if p.Invisible {
168			<p class="notice">
169				this diff holds invisible characters (direction controls, zero-width characters). They are shown as
170				<span class="inv">&lt;U+XXXX&gt;</span> markers, never applied.
171			</p>
172		}
173		if p.Note != "" {
174			<p class="notice">{ p.Note }</p>
175		}
176		<div
177			id="diffs"
178			data-mr
179			if p.Both {
180				data-diff={ p.View }
181			} else {
182				data-view={ p.View }
183			}
184			if p.Both && !p.Pinned {
185				hx-live="this.dataset.diff = sessionStorage.getItem('diff') || this.dataset.diff"
186			}
187		>
188			for _, f := range p.Files {
189				@DiffFileView(f, p.DiffView)
190			}
191			if len(p.Files) == 0 {
192				<p class="note">no changed files.</p>
193			}
194		</div>
195		<h2 class="rule-h" id="comments"><span>Comments</span><span class="count">{ itoa(p.NUnresolved) } open / { itoa(p.NComments) }</span></h2>
196		for _, c := range p.Loose {
197			@commentView(c, "")
198		}
199		for _, c := range p.General {
200			@commentView(c, "")
201		}
202		if p.NComments == 0 {
203			<p class="dim">no comments yet.</p>
204		}
205		if p.GeneralForm != nil {
206			@commentForm(*p.GeneralForm, "")
207		}
208	}
209}
210
211templ branchLink(name, href string) {
212	if href != "" {
213		<a href={ templ.SafeURL(href) }>{ name }</a>
214	} else {
215		{ name }
216	}
217}
218
219// lineNotes are the comments under a line of the diff, and the form to write
220// one when the reader asked for it. The diff is in the page twice (unified and
221// split); the suffix keeps the ids unique, the unified table having none.
222templ lineNotes(notes []CommentView, form *CommentForm, suffix string) {
223	for _, c := range notes {
224		@commentView(c, suffix)
225	}
226	if form != nil {
227		@commentForm(*form, suffix)
228	}
229}
230
231// commentView is a note: a ruled block, under its line in the diff or in the
232// list of comments. The text is plain: escaped, its line breaks kept, its
233// http(s) addresses linked.
234templ commentView(c CommentView, suffix string) {
235	<div class="cmt" id={ "c" + c.ID + suffix } data-resolved={ boolText(c.Resolved) }>
236		<p class="c-head">
237			<span class="c-who">{ c.Author }</span>
238			if c.WhenAt != "" {
239				{ " " }<time class="mute" datetime={ c.WhenAt } title={ c.Abs }>{ c.When }</time>
240			}
241			if c.Resolved {
242				{ " " }<span class="c-state">resolved</span>
243			}
244			if c.Outdated {
245				{ " " }<span class="c-state" title="written on an earlier head; the line may have moved">outdated</span>
246			}
247			if c.Where != "" {
248				{ " " }<span class="c-where mute">{ c.Where }</span>
249			}
250		</p>
251		<p class="c-text">@userText(c.Parts)</p>
252		if c.Resolve != nil {
253			<form class="c-act" method="post" action={ templ.SafeURL(c.Resolve.Action) }>
254				<input type="hidden" name="resolved" value={ boolText(c.Resolve.Value) }/>
255				if c.Resolve.From > 0 {
256					<input type="hidden" name="from" value={ itoa(c.Resolve.From) }/>
257				}
258				<button type="submit" class="btn">{ c.Resolve.Label }</button>
259			</form>
260		}
261	</div>
262}
263
264func boolText(b bool) string {
265	if b {
266		return "true"
267	}
268	return "false"
269}
270
271// commentForm writes a comment, general or on a line.
272templ commentForm(f CommentForm, suffix string) {
273	<form class="cform" method="post" action={ templ.SafeURL(f.Action) }>
274		<label for={ f.ID + suffix }>{ f.Title }</label>
275		<textarea
276			id={ f.ID + suffix }
277			name="text"
278			rows="3"
279			maxlength="8000"
280			required
281			placeholder="plain text, 8000 characters at most"
282			if f.Focus {
283				autofocus
284			}
285		></textarea>
286		if f.Path != "" {
287			<input type="hidden" name="path" value={ f.Path }/>
288			<input type="hidden" name="line" value={ f.Line }/>
289			<input type="hidden" name="side" value={ f.Side }/>
290		}
291		if f.From > 0 {
292			<input type="hidden" name="from" value={ itoa(f.From) }/>
293		}
294		<div class="f-btns">
295			<button type="submit" class="btn primary">Comment</button>
296			if f.Cancel != "" {
297				<a class="btn" href={ templ.SafeURL(f.Cancel) }>Cancel</a>
298			}
299		</div>
300	</form>
301}
302
303templ mrRail(p MRPage) {
304	<section aria-labelledby="r-files" class="r-files">
305		<h2 id="r-files">
306			Files <span class="count">{ itoa(len(p.Files)) }</span><kbd aria-hidden="true">g f</kbd>
307			<button type="button" class="btn icon fold" data-js aria-expanded="true" title="fold the list of files" hx-on:click="ermiteMR.foldFiles()">
308				<span class="ico i-chevron" aria-hidden="true"></span><span class="sr">fold the list of files</span>
309			</button>
310		</h2>
311		@FileList(p.Files)
312	</section>
313	@MRChecks(p.Checks)
314	<section aria-labelledby="r-commits">
315		<h2 id="r-commits">Commits <span class="count">{ itoa(len(p.Commits)) }</span></h2>
316		<ul class="pcommits">
317			for _, c := range p.Commits {
318				<li data-new?={ c.New }>
319					<a href={ templ.SafeURL(c.Href) }>{ c.Short }</a>
320					<span class="s">{ c.Subject }</span>
321					if c.Sig != nil {
322						@signaturePill(c.Sig)
323					}
324					<span class="mute">
325						{ c.Author }
326						if c.WhenAt != "" {
327							{ " · " }<time datetime={ c.WhenAt }>{ c.When }</time>
328						}
329						if c.New {
330							{ " · new" }
331						}
332					</span>
333				</li>
334			}
335		</ul>
336		if len(p.Commits) == 0 {
337			<p class="dim">no commit to merge.</p>
338		}
339		if p.CommitsNote != "" {
340			<p class="note">{ p.CommitsNote }</p>
341		}
342	</section>
343	<section aria-labelledby="r-settings">
344		<h2 id="r-settings">Settings</h2>
345		<dl class="kv">
346			<dt>modes</dt>
347			<dd>{ strings.Join(p.Modes, ", ") }</dd>
348			<dt>checks</dt>
349			<dd>
350				if p.ChecksBlock {
351					failing ones block the merge
352				} else {
353					do not block the merge
354				}
355			</dd>
356		</dl>
357	</section>
358}
359
360// mrBar is the bar above the diff, which follows the review: the totals, the
361// layout of the diff, the state of the checks and, for the owner of an open
362// request, the merge menu and the other actions. Each menu is a <details>: it
363// works without scripts; with them, M and the keys of the menu drive it.
364templ mrBar(p MRPage) {
365	<div class="diff-tools mr-bar" role="group" aria-label="Diff view and merge">
366		<span class="dim">{ plural(p.NFiles, "file", "files") } · <span class="plus">+{ itoa(p.Adds) }</span> <span class="minus">-{ itoa(p.Dels) }</span></span>
367		@viewLink(p.DiffView, "unified", "Unified", "u", p.UnifiedHref)
368		@viewLink(p.DiffView, "split", "Split", "d", p.SplitHref)
369		@collapseButton()
370		<span class="grow"></span>
371		@MRChecksSum(p.ChecksSum)
372		if p.Box != nil {
373			@mergeMenu(p)
374			@moreMenu(p)
375		}
376	</div>
377}
378
379// mergeMenu is the merge of an open request, for the owner: the form (it
380// carries the head that was read), or "Ready for review" for a draft. The
381// mode and the branch deletion have keys (1-3, D) while it is open.
382templ mergeMenu(p MRPage) {
383	<details class="menu mmenu" id="merge-menu" data-state="open">
384		<summary class="btn primary" aria-keyshortcuts="Shift+M">
385			if p.Box.ReadyAction != "" {
386				Draft
387			} else {
388				Merge
389			}
390			<kbd aria-hidden="true">M</kbd>
391		</summary>
392		<div class="menu-pop" role="group" aria-label="Merge">
393			<dl class="kv">
394				<dt>head</dt>
395				<dd>
396					if p.Box.HeadGone {
397						gone: the source branch was deleted
398					} else {
399						{ p.HeadShort }
400					}
401				</dd>
402				<dt>into</dt>
403				<dd>{ p.Target }</dd>
404			</dl>
405			if p.Box.ReadyAction != "" {
406				<p class="d-draft">this is a draft: it cannot be merged until it is ready for review.</p>
407				<form class="d-btns" method="post" action={ templ.SafeURL(p.Box.ReadyAction) }>
408					<button type="submit" class="btn primary" data-default title="remove the draft prefix from the title">Ready for review</button>
409				</form>
410			} else if !p.Box.HeadGone {
411				<form class="d-acts" method="post" action={ templ.SafeURL(p.Box.MergeAction) }>
412					<input type="hidden" name="head_id" value={ p.Box.Head }/>
413					<fieldset class="d-modes">
414						<legend class="sr">merge mode</legend>
415						for i, m := range p.Box.Modes {
416							<label>
417								<input type="radio" name="mode" value={ m.Value } checked?={ i == 0 }/>
418								{ m.Label }
419								if i < 9 {
420									<kbd aria-hidden="true">{ itoa(i + 1) }</kbd>
421								}
422							</label>
423						}
424					</fieldset>
425					if p.Box.CanDeleteBranch {
426						<label class="d-check"><input type="checkbox" name="delete_branch" value="1"/> delete { p.Source } after the merge <kbd aria-hidden="true">D</kbd></label>
427					}
428					<div class="d-btns">
429						<button type="submit" class="btn primary" data-default>Merge into { p.Target }</button>
430					</div>
431				</form>
432			}
433		</div>
434	</details>
435}
436
437// moreMenu is what else the owner does with an open request: mark the head
438// read, close it, merge it from a terminal.
439templ moreMenu(p MRPage) {
440	<details class="menu omenu">
441		<summary class="btn icon" aria-label="More actions" title="more actions">⋯</summary>
442		<div class="menu-pop" role="group" aria-label="More actions">
443			if p.Box.CanMarkRead {
444				<form method="post" action={ templ.SafeURL(p.Box.ReadAction) }>
445					<input type="hidden" name="head_id" value={ p.Box.Head }/>
446					<button type="submit" title="the next visit can show only what changed after this head" class="btn" aria-keyshortcuts="Shift+R" data-read>Mark read <kbd aria-hidden="true">R</kbd></button>
447				</form>
448			}
449			<form method="post" action={ templ.SafeURL(p.Box.CloseAction) }>
450				<button type="submit" title="close without merging; the branch is kept" class="btn danger">Close</button>
451			</form>
452			if !p.Box.HeadGone && p.Box.ReadyAction == "" {
453				<details class="d-or">
454					<summary class="mute">or from a terminal</summary>
455					@CloneBlock(p.Box.CLI)
456				</details>
457			}
458		</div>
459	</details>
460}
461
462templ Compare(l Layout, p ComparePage) {
463	@Shell(l, compareRail(p)) {
464		<header class="show mr-h">
465			<h1>{ p.Source } → { p.Target }</h1>
466			<dl class="kv show-kv">
467				<dt>branch</dt>
468				<dd><a href={ templ.SafeURL(p.SourceHref) }>{ p.Source }</a></dd>
469				<dt>target</dt>
470				<dd><a href={ templ.SafeURL(p.TargetHref) }>{ p.Target }</a></dd>
471				<dt>ahead</dt>
472				<dd>{ p.AheadText }</dd>
473			</dl>
474		</header>
475		if p.Note != "" {
476			<p class="notice">{ p.Note }</p>
477		}
478		if p.Existing != nil {
479			<p class="notice">an open merge request already covers these branches: <a href={ templ.SafeURL(p.Existing.Href) }>{ p.Existing.Label }</a></p>
480		}
481		if p.Create != nil {
482			<form class="cform create" method="post" action={ templ.SafeURL(p.Create.Action) }>
483				<input type="hidden" name="source" value={ p.Create.Source }/>
484				<input type="hidden" name="target" value={ p.Create.Target }/>
485				<label for="mr-title">title</label>
486				<input id="mr-title" name="title" type="text" maxlength="120" required value={ p.Create.Title } autocomplete="off"/>
487				<label for="mr-desc">description</label>
488				<textarea id="mr-desc" name="description" rows="4" maxlength="8000" placeholder="Markdown, optional"></textarea>
489				<div class="f-btns">
490					<button type="submit" class="btn primary">Create merge request</button>
491				</div>
492			</form>
493		}
494		if p.HasDiff {
495			<div class="diff-tools" role="group" aria-label="Diff view">
496				<span class="dim">{ plural(p.NFiles, "file", "files") } · <span class="plus">+{ itoa(p.Adds) }</span> <span class="minus">-{ itoa(p.Dels) }</span></span>
497				<span class="grow"></span>
498				@viewLink(p.DiffView, "unified", "Unified", "u", p.UnifiedHref)
499				@viewLink(p.DiffView, "split", "Split", "d", p.SplitHref)
500				@collapseButton()
501			</div>
502			if p.Invisible {
503				<p class="notice">
504					this diff holds invisible characters (direction controls, zero-width characters). They are shown as
505					<span class="inv">&lt;U+XXXX&gt;</span> markers, never applied.
506				</p>
507			}
508			<div
509				id="diffs"
510				if p.Both {
511					data-diff={ p.View }
512				} else {
513					data-view={ p.View }
514				}
515				if p.Both && !p.Pinned {
516					hx-live="this.dataset.diff = sessionStorage.getItem('diff') || this.dataset.diff"
517				}
518			>
519				for _, f := range p.Files {
520					@DiffFileView(f, p.DiffView)
521				}
522			</div>
523		}
524	}
525}
526
527templ compareRail(p ComparePage) {
528	<section aria-labelledby="r-ahead">
529		<h2 id="r-ahead">Commits <span class="count">{ itoa(len(p.Ahead)) }</span></h2>
530		<ul class="pcommits">
531			for _, c := range p.Ahead {
532				<li>
533					<a href={ templ.SafeURL(c.CHref) }>{ c.Short }</a>
534					<span class="s">{ c.Subject }</span>
535					<span class="mute">
536						{ c.Author }
537						if c.WhenAt != "" {
538							{ " · " }<time datetime={ c.WhenAt }>{ c.When }</time>
539						}
540					</span>
541				</li>
542			}
543		</ul>
544		if len(p.Ahead) == 0 {
545			<p class="dim">no commit ahead of { p.Target }.</p>
546		}
547	</section>
548	if p.HasDiff {
549		<section aria-labelledby="r-files">
550			<h2 id="r-files">Files <span class="count">{ itoa(len(p.Files)) }</span></h2>
551			@FileList(p.Files)
552		</section>
553	}
554	<section aria-labelledby="r-cli">
555		<h2 id="r-cli">From a terminal</h2>
556		@CloneBlock(p.CLI)
557	</section>
558}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 2

Tags 45

↑↓ moveenter openesc close