v0.30.0 c899179

pullrequest_test.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain_test
4
5import (
6	"strings"
7	"testing"
8	"time"
9
10	"github.com/stretchr/testify/assert"
11	"github.com/stretchr/testify/require"
12
13	"bnema.dev/ermite/internal/domain"
14)
15
16func TestPullRefNames(t *testing.T) {
17	assert.Equal(t, "refs/pull/7/head", domain.PullHeadRef(7))
18	assert.Equal(t, "refs/pull/7/merge", domain.PullMergeRef(7))
19	for _, ok := range []string{"refs/pull/1/head", "refs/pull/12/merge"} {
20		assert.True(t, domain.IsPullRef(ok), ok)
21	}
22	for _, no := range []string{"refs/pull/0/head", "refs/pull/01/head", "refs/pull/1/other", "refs/pull/1", "refs/pull/x/head", "refs/heads/pull/1/head", "refs/pull/1/head/x", "refs/pull/-1/merge"} {
23		assert.False(t, domain.IsPullRef(no), no)
24	}
25	assert.True(t, domain.IsPullRefName("refs/pull/anything"))
26	assert.False(t, domain.IsPullRefName("refs/pullx/1/head"))
27}
28
29func TestTestMergeCommit(t *testing.T) {
30	tree := mustID(t, "1")
31	base, head := mustID(t, "2"), mustID(t, "3")
32	got := string(domain.TestMergeCommit(tree, base, head, domain.Identity{Name: "ermite", Email: "e@x"}, time.Unix(1700000000, 0)))
33	assert.Equal(t, "tree "+tree.String()+"\nparent "+base.String()+"\nparent "+head.String()+
34		"\nauthor ermite <e@x> 1700000000 +0000\ncommitter ermite <e@x> 1700000000 +0000\n\nMerge "+head.String()+" into "+base.String()+"\n", got)
35}
36
37func mustID(t *testing.T, c string) domain.ObjectID {
38	t.Helper()
39	id, err := domain.ParseObjectID(strings.Repeat(c, 40))
40	require.NoError(t, err)
41	return id
42}
43
44func TestJobPermits(t *testing.T) {
45	repo, other := mustRepo(t, "proj"), mustRepo(t, "other")
46	tok := func(perms map[string]string) domain.Principal {
47		return domain.RepoTokenPrincipal(domain.CIRepoToken{ID: "a", Repo: repo, Permissions: perms})
48	}
49	read := map[string]string{domain.PermPullRequests: domain.PermissionRead}
50	write := map[string]string{domain.PermPullRequests: domain.PermissionWrite}
51	assert.True(t, tok(read).JobPermits(domain.PermPullRequests, domain.PermissionRead, repo))
52	assert.False(t, tok(read).JobPermits(domain.PermPullRequests, domain.PermissionWrite, repo))
53	assert.True(t, tok(write).JobPermits(domain.PermPullRequests, domain.PermissionRead, repo), "write includes read")
54	assert.False(t, tok(read).JobPermits(domain.PermPullRequests, domain.PermissionRead, other), "another repository")
55	assert.False(t, tok(nil).JobPermits(domain.PermPullRequests, domain.PermissionRead, repo), "the default has no pull-requests")
56	assert.False(t, tok(map[string]string{domain.PermContents: domain.PermissionWrite}).JobPermits(domain.PermPullRequests, domain.PermissionRead, repo))
57	assert.False(t, domain.Root().JobPermits(domain.PermPullRequests, domain.PermissionRead, repo), "only job tokens")
58	assert.False(t, domain.Anonymous().JobPermits(domain.PermPullRequests, domain.PermissionRead, repo))
59}
60
61func mustRepo(t *testing.T, name string) domain.RepoName {
62	t.Helper()
63	r, err := domain.ParseRepoName(name)
64	require.NoError(t, err)
65	return r
66}

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 3

Tags 43

↑↓ moveenter openesc close