v0.23.0 333c710

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					<span class="mute">
322						{ c.Author }
323						if c.WhenAt != "" {
324							{ " · " }<time datetime={ c.WhenAt }>{ c.When }</time>
325						}
326						if c.New {
327							{ " · new" }
328						}
329					</span>
330				</li>
331			}
332		</ul>
333		if len(p.Commits) == 0 {
334			<p class="dim">no commit to merge.</p>
335		}
336		if p.CommitsNote != "" {
337			<p class="note">{ p.CommitsNote }</p>
338		}
339	</section>
340	<section aria-labelledby="r-settings">
341		<h2 id="r-settings">Settings</h2>
342		<dl class="kv">
343			<dt>modes</dt>
344			<dd>{ strings.Join(p.Modes, ", ") }</dd>
345			<dt>checks</dt>
346			<dd>
347				if p.ChecksBlock {
348					failing ones block the merge
349				} else {
350					do not block the merge
351				}
352			</dd>
353		</dl>
354	</section>
355}
356
357// mrBar is the bar above the diff, which follows the review: the totals, the
358// layout of the diff, the state of the checks and, for the owner of an open
359// request, the merge menu and the other actions. Each menu is a <details>: it
360// works without scripts; with them, M and the keys of the menu drive it.
361templ mrBar(p MRPage) {
362	<div class="diff-tools mr-bar" role="group" aria-label="Diff view and merge">
363		<span class="dim">{ plural(p.NFiles, "file", "files") } · <span class="plus">+{ itoa(p.Adds) }</span> <span class="minus">-{ itoa(p.Dels) }</span></span>
364		@viewLink(p.DiffView, "unified", "Unified", "u", p.UnifiedHref)
365		@viewLink(p.DiffView, "split", "Split", "d", p.SplitHref)
366		@collapseButton()
367		<span class="grow"></span>
368		@MRChecksSum(p.ChecksSum)
369		if p.Box != nil {
370			@mergeMenu(p)
371			@moreMenu(p)
372		}
373	</div>
374}
375
376// mergeMenu is the merge of an open request, for the owner: the form (it
377// carries the head that was read), or "Ready for review" for a draft. The
378// mode and the branch deletion have keys (1-3, D) while it is open.
379templ mergeMenu(p MRPage) {
380	<details class="menu mmenu" id="merge-menu" data-state="open">
381		<summary class="btn primary" aria-keyshortcuts="Shift+M">
382			if p.Box.ReadyAction != "" {
383				Draft
384			} else {
385				Merge
386			}
387			<kbd aria-hidden="true">M</kbd>
388		</summary>
389		<div class="menu-pop" role="group" aria-label="Merge">
390			<dl class="kv">
391				<dt>head</dt>
392				<dd>
393					if p.Box.HeadGone {
394						gone: the source branch was deleted
395					} else {
396						{ p.HeadShort }
397					}
398				</dd>
399				<dt>into</dt>
400				<dd>{ p.Target }</dd>
401			</dl>
402			if p.Box.ReadyAction != "" {
403				<p class="d-draft">this is a draft: it cannot be merged until it is ready for review.</p>
404				<form class="d-btns" method="post" action={ templ.SafeURL(p.Box.ReadyAction) }>
405					<button type="submit" class="btn primary" data-default title="remove the draft prefix from the title">Ready for review</button>
406				</form>
407			} else if !p.Box.HeadGone {
408				<form class="d-acts" method="post" action={ templ.SafeURL(p.Box.MergeAction) }>
409					<input type="hidden" name="head_id" value={ p.Box.Head }/>
410					<fieldset class="d-modes">
411						<legend class="sr">merge mode</legend>
412						for i, m := range p.Box.Modes {
413							<label>
414								<input type="radio" name="mode" value={ m.Value } checked?={ i == 0 }/>
415								{ m.Label }
416								if i < 9 {
417									<kbd aria-hidden="true">{ itoa(i + 1) }</kbd>
418								}
419							</label>
420						}
421					</fieldset>
422					if p.Box.CanDeleteBranch {
423						<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>
424					}
425					<div class="d-btns">
426						<button type="submit" class="btn primary" data-default>Merge into { p.Target }</button>
427					</div>
428				</form>
429			}
430		</div>
431	</details>
432}
433
434// moreMenu is what else the owner does with an open request: mark the head
435// read, close it, merge it from a terminal.
436templ moreMenu(p MRPage) {
437	<details class="menu omenu">
438		<summary class="btn icon" aria-label="More actions" title="more actions">⋯</summary>
439		<div class="menu-pop" role="group" aria-label="More actions">
440			if p.Box.CanMarkRead {
441				<form method="post" action={ templ.SafeURL(p.Box.ReadAction) }>
442					<input type="hidden" name="head_id" value={ p.Box.Head }/>
443					<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>
444				</form>
445			}
446			<form method="post" action={ templ.SafeURL(p.Box.CloseAction) }>
447				<button type="submit" title="close without merging; the branch is kept" class="btn danger">Close</button>
448			</form>
449			if !p.Box.HeadGone && p.Box.ReadyAction == "" {
450				<details class="d-or">
451					<summary class="mute">or from a terminal</summary>
452					@CloneBlock(p.Box.CLI)
453				</details>
454			}
455		</div>
456	</details>
457}
458
459templ Compare(l Layout, p ComparePage) {
460	@Shell(l, compareRail(p)) {
461		<header class="show mr-h">
462			<h1>{ p.Source } → { p.Target }</h1>
463			<dl class="kv show-kv">
464				<dt>branch</dt>
465				<dd><a href={ templ.SafeURL(p.SourceHref) }>{ p.Source }</a></dd>
466				<dt>target</dt>
467				<dd><a href={ templ.SafeURL(p.TargetHref) }>{ p.Target }</a></dd>
468				<dt>ahead</dt>
469				<dd>{ p.AheadText }</dd>
470			</dl>
471		</header>
472		if p.Note != "" {
473			<p class="notice">{ p.Note }</p>
474		}
475		if p.Existing != nil {
476			<p class="notice">an open merge request already covers these branches: <a href={ templ.SafeURL(p.Existing.Href) }>{ p.Existing.Label }</a></p>
477		}
478		if p.Create != nil {
479			<form class="cform create" method="post" action={ templ.SafeURL(p.Create.Action) }>
480				<input type="hidden" name="source" value={ p.Create.Source }/>
481				<input type="hidden" name="target" value={ p.Create.Target }/>
482				<label for="mr-title">title</label>
483				<input id="mr-title" name="title" type="text" maxlength="120" required value={ p.Create.Title } autocomplete="off"/>
484				<label for="mr-desc">description</label>
485				<textarea id="mr-desc" name="description" rows="4" maxlength="8000" placeholder="Markdown, optional"></textarea>
486				<div class="f-btns">
487					<button type="submit" class="btn primary">Create merge request</button>
488				</div>
489			</form>
490		}
491		if p.HasDiff {
492			<div class="diff-tools" role="group" aria-label="Diff view">
493				<span class="dim">{ plural(p.NFiles, "file", "files") } · <span class="plus">+{ itoa(p.Adds) }</span> <span class="minus">-{ itoa(p.Dels) }</span></span>
494				<span class="grow"></span>
495				@viewLink(p.DiffView, "unified", "Unified", "u", p.UnifiedHref)
496				@viewLink(p.DiffView, "split", "Split", "d", p.SplitHref)
497				@collapseButton()
498			</div>
499			if p.Invisible {
500				<p class="notice">
501					this diff holds invisible characters (direction controls, zero-width characters). They are shown as
502					<span class="inv">&lt;U+XXXX&gt;</span> markers, never applied.
503				</p>
504			}
505			<div
506				id="diffs"
507				if p.Both {
508					data-diff={ p.View }
509				} else {
510					data-view={ p.View }
511				}
512				if p.Both && !p.Pinned {
513					hx-live="this.dataset.diff = sessionStorage.getItem('diff') || this.dataset.diff"
514				}
515			>
516				for _, f := range p.Files {
517					@DiffFileView(f, p.DiffView)
518				}
519			</div>
520		}
521	}
522}
523
524templ compareRail(p ComparePage) {
525	<section aria-labelledby="r-ahead">
526		<h2 id="r-ahead">Commits <span class="count">{ itoa(len(p.Ahead)) }</span></h2>
527		<ul class="pcommits">
528			for _, c := range p.Ahead {
529				<li>
530					<a href={ templ.SafeURL(c.CHref) }>{ c.Short }</a>
531					<span class="s">{ c.Subject }</span>
532					<span class="mute">
533						{ c.Author }
534						if c.WhenAt != "" {
535							{ " · " }<time datetime={ c.WhenAt }>{ c.When }</time>
536						}
537					</span>
538				</li>
539			}
540		</ul>
541		if len(p.Ahead) == 0 {
542			<p class="dim">no commit ahead of { p.Target }.</p>
543		}
544	</section>
545	if p.HasDiff {
546		<section aria-labelledby="r-files">
547			<h2 id="r-files">Files <span class="count">{ itoa(len(p.Files)) }</span></h2>
548			@FileList(p.Files)
549		</section>
550	}
551	<section aria-labelledby="r-cli">
552		<h2 id="r-cli">From a terminal</h2>
553		@CloneBlock(p.CLI)
554	</section>
555}

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 4

Tags 45

↑↓ moveenter openesc close