v0.17.0 ab8e178

pullrequest.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain
4
5import (
6	"strconv"
7	"strings"
8	"time"
9)
10
11// A merge request is a "pull request" for the workflows that run on it (CI-3,
12// D5): ermite keeps two refs per request, as GitHub does.
13//
14//	refs/pull/<n>/head   the head of the source branch
15//	refs/pull/<n>/merge  a test merge of the head into the target, when it merges cleanly
16//
17// They are written by ermite only: a push to them is refused (see IsPullRef),
18// and they are not branches nor tags, so no listing shows them. Git serves them
19// to fetch like any ref.
20
21// PullRefPrefix starts the refs of the merge requests.
22const PullRefPrefix = "refs/pull/"
23
24// PullHeadRef is the ref that holds the head of merge request number.
25func PullHeadRef(number int64) string { return PullRefPrefix + strconv.FormatInt(number, 10) + "/head" }
26
27// PullMergeRef is the ref that holds the test merge of merge request number.
28func PullMergeRef(number int64) string {
29	return PullRefPrefix + strconv.FormatInt(number, 10) + "/merge"
30}
31
32// IsPullRefName reports whether ref is under refs/pull/, whatever follows.
33// Pushes are refused on all of that namespace.
34func IsPullRefName(ref string) bool { return strings.HasPrefix(ref, PullRefPrefix) }
35
36// IsPullRef reports whether ref is exactly refs/pull/<n>/head or
37// refs/pull/<n>/merge, the two refs ermite maintains.
38func IsPullRef(ref string) bool {
39	rest, ok := strings.CutPrefix(ref, PullRefPrefix)
40	if !ok {
41		return false
42	}
43	num, kind, ok := strings.Cut(rest, "/")
44	if !ok || (kind != "head" && kind != "merge") {
45		return false
46	}
47	n, err := strconv.ParseInt(num, 10, 64)
48	return err == nil && n > 0 && strconv.FormatInt(n, 10) == num
49}
50
51// PullRequestActions are the activity types of the pull_request event that
52// ermite can produce. A merge request cannot be reopened yet, so "reopened"
53// never occurs, but a workflow may list it.
54const (
55	PullOpened      = "opened"
56	PullSynchronize = "synchronize"
57	PullReopened    = "reopened"
58	PullClosed      = "closed"
59)
60
61// DefaultPullRequestTypes are the types of a pull_request that lists none.
62var DefaultPullRequestTypes = []string{PullOpened, PullSynchronize, PullReopened}
63
64// TestMergeCommit returns the text of the commit that tests the merge of head
65// into base: the tree the merge produced, parents base then head, and GitHub's
66// message. It is not signed.
67func TestMergeCommit(tree, base, head ObjectID, who Identity, at time.Time) []byte {
68	sig := signatureLine(Signature{Name: who.Name, Email: who.Email, Time: at.UTC()})
69	var b strings.Builder
70	b.WriteString("tree " + tree.String() + "\n")
71	b.WriteString("parent " + base.String() + "\n")
72	b.WriteString("parent " + head.String() + "\n")
73	b.WriteString("author " + sig + "\n")
74	b.WriteString("committer " + sig + "\n")
75	b.WriteString("\nMerge " + head.String() + " into " + base.String() + "\n")
76	return []byte(b.String())
77}

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 44

↑↓ moveenter openesc close