Commit ac8d910ff3

ac8d910ff31c2fadc452928e1d56c64b4af25495

parent: 6521399c1c

Verified · cmc ci/build: success ci/quality: success ci/test: failure

cmc <hello@cleberg.net> · 2026-11-25 22:54 UTC

web: fix review findings from the 2026-11-25 web commits

- register/verify signs in only a pending signup; an email-add code on
  an active account no longer opens a session
- fork badge counts public forks only (PublicForkCount)
- per-commit MR diff: commit must be in base..head; shown read-only,
  without threads, with the commit as HEAD for view/expand
- Cmd+Enter does nothing on forms with several submit buttons
- explicit Save on visibility, git://, merge gates, secret scan and
  require-mr; refused autosave rolls radios back
- build page button says it runs the job on the default branch
- commit-file --from refuses an existing branch and creates atomically;
  branch names refuse only "@{" and "@"
- hunk expand stops at the previous hunk, skips deleted files, escapes
  paths
- palette rate-limited per caller; file hrefs escaped
- query run --q; the web's unsaved query dispatches it
- JS-only controls hidden without JS; review popover count refreshed
- drop .railmore CSS and the unused rail item
- aria-pressed composer toggles, listbox autocomplete, toast region at
  boot
- --shadow-card and --r-mark tokens
- key table mono cells wrap instead of overflowing the card; cmdk badge
  without its inner box
- /mrs looks up reviewer rights once; blame reads parents in one call

Layout: unified · split

Changed files (27)
.gitbay/wiki/Parity.org +3 −1 · view
@@ -371,7 +371,9 @@ every repository the caller can read (#292): =query save <name>
371371<query>= (=--force= replaces), =query list=, =query show= with its
372372count, =query run= for the rows, =query remove=, =query pin= and
373373=unpin=. =issue list --query <name>= and =mr list --query <name>= run
374one narrowed to their kind, and =--q '<query>'= takes one written out.
374one narrowed to their kind, and =--q '<query>'= takes one written out;
375=query run --q '<query>'= runs one over both, which is what the web's
376unsaved query on =/<owner>/-/queries?q== dispatches.
375377Results are newest first, always paged with ={items, next}= and fifty
376378rows by default, each naming its repository. Readability is the
377379search rule, decided in the SQL, so a private repository someone else
.gitbay/wiki/Users.org +1 · view
@@ -595,6 +595,7 @@ gitbay query save triage 'repo:krz/*' is:issue is:open no:label
595595gitbay query save v2 owner:krz label:bug 'label:needs review' milestone:v2
596596gitbay query list / show mine / remove mine
597597gitbay query run mine [--limit 20] [--cursor <c>] # issues and MRs
598gitbay query run --q 'is:open assignee:@me' # unsaved, issues and MRs
598599gitbay issue list --query mine # only the issues
599600gitbay mr list --q 'owner:krz is:open author:@me' # a query written out
600601gitbay query pin mine # on the dashboard; unpin
cmd/gitbay/summaries_gen.go +1 −1 · view
@@ -135,7 +135,7 @@ var summaries = map[string]string{
135135 "query list": "list your saved queries",
136136 "query pin": "show a saved query on your dashboard",
137137 "query remove": "delete a saved query",
138 "query run": "list the issues and merge requests a saved query matches",
138 "query run": "list the issues and merge requests a saved query, or one given with --q, matches",
139139 "query save": "save an issue and merge request query across repositories under a name",
140140 "query show": "show a saved query and how many rows it matches",
141141 "query unpin": "take a saved query off your dashboard",
internal/control/commitfile.go +1 −1 · view
@@ -53,7 +53,7 @@ func runCommitFile(c *Ctx, args []string) int {
5353 if len(rest) != 2 || ref == "" {
5454 return c.usage()
5555 }
56 if strings.HasPrefix(ref, "-") || strings.HasPrefix(ref, "/") || strings.HasSuffix(ref, "/") || strings.HasSuffix(ref, ".lock") || strings.Contains(ref, "..") || strings.Contains(ref, "//") || strings.ContainsAny(ref, " \t\r\n~^:?*[\\@{") {
56 if strings.HasPrefix(ref, "-") || strings.HasPrefix(ref, "/") || strings.HasSuffix(ref, "/") || strings.HasSuffix(ref, ".lock") || strings.Contains(ref, "..") || strings.Contains(ref, "//") || strings.ContainsAny(ref, " \t\r\n~^:?*[\\") || strings.Contains(ref, "@{") || ref == "@" {
5757 return c.fail(protocol.ExitUsage, "invalid branch name %q", ref)
5858 }
5959 repo, code := resolveRepo(c, rest[0], policy.CanWrite)
internal/control/query.go +11 −40 · view
@@ -37,13 +37,14 @@ func init() {
3737 Examples: []string{"query show mine"},
3838 ReadOnly: true, Run: runQueryShow})
3939 register(Command{Path: []string{"query", "run"},
40 Summary: "list the issues and merge requests a saved query matches",
41 Usage: "query run <name> [--limit <n>] [--cursor <c>]",
40 Summary: "list the issues and merge requests a saved query, or one given with --q, matches",
41 Usage: "query run (<name> | --q <query>) [--limit <n>] [--cursor <c>]",
4242 Flags: []Flag{
43 {"--q", "<query>", "run this query instead of a saved one", ""},
4344 {"--limit", "<n>", "rows per page", strconv.Itoa(queryDefaultLimit)},
4445 {"--cursor", "<c>", "continue from the previous page", ""},
4546 },
46 Examples: []string{"query run mine --limit 20"},
47 Examples: []string{"query run mine --limit 20", "query run --q 'is:open assignee:@me'"},
4748 ReadOnly: true, Run: runQueryRun})
4849 register(Command{Path: []string{"query", "remove"},
4950 Summary: "delete a saved query",
@@ -158,43 +159,6 @@ func PinnedQueries(st *store.Store, user store.User) ([]DashboardQuery, error) {
158159 return out, nil
159160}
160161
161// RunAdHocQuery evaluates an unsaved cross-repository query for the web
162// queries page using the same parser, visibility filter, and cursor as query run.
163func RunAdHocQuery(st *store.Store, user store.User, rawQuery, cursor string, limit int) ([]QueryItem, int, string, error) {
164 q, err := ParseItemQuery(rawQuery)
165 if err != nil {
166 return nil, 0, "", err
167 }
168 var after *store.ItemCursor
169 if cursor != "" {
170 key, err := decodeCursor("query", cursor)
171 if err != nil {
172 return nil, 0, "", errors.New("bad cursor")
173 }
174 if after, err = decodeItemCursor(key); err != nil {
175 return nil, 0, "", err
176 }
177 }
178 if limit <= 0 {
179 limit = queryDefaultLimit
180 }
181 f := q.Filter(user.Username, true, true)
182 total, err := st.CountItems(user.ID, f)
183 if err != nil {
184 return nil, 0, "", err
185 }
186 items, err := st.QueryItems(user.ID, f, after, limit+1)
187 if err != nil {
188 return nil, 0, "", err
189 }
190 next := ""
191 if len(items) > limit {
192 items = items[:limit]
193 next = encodeItemCursor(items[len(items)-1].Cursor())
194 }
195 return queryItems(items), total, next, nil
196}
197
198162func encodeItemCursor(k store.ItemCursor) string {
199163 return encodeCursor("query", fmt.Sprintf("%s|%d|%d", k.CreatedAt, k.Kind, k.ID))
200164}
@@ -464,6 +428,13 @@ func runQueryRun(c *Ctx, args []string) int {
464428 if code >= 0 {
465429 return code
466430 }
431 if len(rest) == 2 && rest[0] == "--q" {
432 q, err := ParseItemQuery(rest[1])
433 if err != nil {
434 return c.fail(protocol.ExitUsage, "%v", err)
435 }
436 return runItemQuery(c, q, true, true, p, "Results")
437 }
467438 if len(rest) != 1 {
468439 return c.usage()
469440 }
internal/control/query_test.go +10 · view
@@ -150,6 +150,16 @@ func TestQueryCommands(t *testing.T) {
150150 t.Errorf("paged run = %s", got)
151151 }
152152
153 // query run --q runs the same text unsaved, with the same visibility.
154 for user, want := range map[string]int{"alice": 3, "bob": 4} {
155 code, data, msg := e.run(user, "query", "run", "--q", "is:open", "--limit", "10")
156 var p pageOut
157 json.Unmarshal(data, &p)
158 if code != 0 || len(p.Items) != want {
159 t.Errorf("query run --q as %s: exit %d, %d items, want %d %s", user, code, len(p.Items), want, msg)
160 }
161 }
162
153163 // issue list and mr list narrow to their own kind.
154164 code, data, msg = e.run("alice", "issue", "list", "--query", "all")
155165 var p pageOut
internal/control/register.go +4 −5 · view
@@ -340,8 +340,10 @@ func VerifyPendingSignup(cfg config.Config, st *store.Store, username, code stri
340340 if username == "" || code == "" {
341341 return store.User{}, "enter the verification code from your email"
342342 }
343 // Only a pending signup signs in by code: an active account's codes
344 // come from `email add` and prove an address, not the account.
343345 u, err := st.UserByUsername(username)
344 if err != nil || u.Disabled {
346 if err != nil || u.Disabled || !u.Pending {
345347 return store.User{}, "that code is invalid, expired, or already used"
346348 }
347349 address, err := st.ConsumeEmailToken(u.ID, store.HashToken(code))
@@ -351,14 +353,11 @@ func VerifyPendingSignup(cfg config.Config, st *store.Store, username, code stri
351353 if err := st.VerifyEmail(u.ID, address, "smtp"); err != nil {
352354 return store.User{}, err.Error()
353355 }
354 wasPending := u.Pending
355356 if err := st.ClearPending(u.ID); err != nil {
356357 return store.User{}, err.Error()
357358 }
358359 u.Pending = false
359360 st.Audit(u.ID, "email.signup_verified", map[string]any{"address": address})
360 if wasPending {
361 notifyAdminsOfSignup(cfg, st, u.Username, "open")
362 }
361 notifyAdminsOfSignup(cfg, st, u.Username, "open")
363362 return u, ""
364363}
internal/control/signupverify_test.go added +48 · view
@@ -0,0 +1,48 @@
1package control
2
3import (
4 "testing"
5 "time"
6
7 "gitbay.org/gitbay/internal/config"
8 "gitbay.org/gitbay/internal/store"
9)
10
11// A code minted by `email add` on an active account does not sign in
12// through the signup screen; a pending signup's code does.
13func TestVerifyPendingSignupOnlyPending(t *testing.T) {
14 st, err := store.Open(":memory:")
15 if err != nil {
16 t.Fatal(err)
17 }
18 defer st.Close()
19 if err := st.MigrateUp(); err != nil {
20 t.Fatal(err)
21 }
22
23 active, err := st.CreateUser("alice", false)
24 if err != nil {
25 t.Fatal(err)
26 }
27 if err := st.AddEmail(active, "bob@example.test", "", false); err != nil {
28 t.Fatal(err)
29 }
30 if err := st.CreateEmailToken(active, "bob@example.test", store.HashToken("c0de"), time.Hour); err != nil {
31 t.Fatal(err)
32 }
33 if _, msg := VerifyPendingSignup(config.Config{}, st, "alice", "c0de"); msg == "" {
34 t.Fatal("active account signed in with an email-add code")
35 }
36
37 pending, err := st.RegisterOpen("carol", "carol@example.test", "SHA256:x", "ssh-ed25519", []byte("blob"))
38 if err != nil {
39 t.Fatal(err)
40 }
41 if err := st.CreateEmailToken(pending, "carol@example.test", store.HashToken("f00d"), time.Hour); err != nil {
42 t.Fatal(err)
43 }
44 u, msg := VerifyPendingSignup(config.Config{}, st, "carol", "f00d")
45 if msg != "" || u.ID != pending || u.Pending {
46 t.Fatalf("pending signup: user %+v, msg %q", u, msg)
47 }
48}
internal/gitutil/commitfile_test.go +45 · view
@@ -36,3 +36,48 @@ func TestCommitFileChangeEmptyRepo(t *testing.T) {
3636 t.Error("committing to an unknown branch of a non-empty repository succeeded")
3737 }
3838}
39
40// --from creates a branch; it never commits onto one that exists, and a
41// branch created meanwhile is not overwritten.
42func TestCommitFileFromCreatesOnly(t *testing.T) {
43 dir := t.TempDir()
44 if err := InitBare(dir, "main", ""); err != nil {
45 t.Fatal(err)
46 }
47 if _, err := CommitFileChange(dir, "main", "a.md", []byte("a\n"), "alice", "alice@example.org", "a"); err != nil {
48 t.Fatal(err)
49 }
50 if _, err := CommitFileFrom(dir, "topic", "main", "a.md", []byte("b\n"), "alice", "alice@example.org", "b"); err != nil {
51 t.Fatalf("creating topic from main: %v", err)
52 }
53 if _, err := CommitFileFrom(dir, "topic", "main", "a.md", []byte("c\n"), "alice", "alice@example.org", "c"); err == nil {
54 t.Error("--from committed onto an existing branch")
55 }
56 raw, _ := ReadBlob(dir, "topic", "a.md", 1<<20)
57 if string(raw) != "b\n" {
58 t.Errorf("topic holds %q, want %q", raw, "b\n")
59 }
60 main, _ := ResolveRef(dir, "refs/heads/main")
61 if err := updateRefCreate(dir, "refs/heads/topic", main); err == nil {
62 t.Error("updateRefCreate moved an existing ref")
63 }
64}
65
66func TestFirstParents(t *testing.T) {
67 dir := t.TempDir()
68 if err := InitBare(dir, "main", ""); err != nil {
69 t.Fatal(err)
70 }
71 a, err := CommitFileChange(dir, "main", "a.md", []byte("a\n"), "alice", "alice@example.org", "a")
72 if err != nil {
73 t.Fatal(err)
74 }
75 b, err := CommitFileChange(dir, "main", "a.md", []byte("b\n"), "alice", "alice@example.org", "b")
76 if err != nil {
77 t.Fatal(err)
78 }
79 got := FirstParents(dir, []string{b, a})
80 if got[b] != a || len(got) != 1 {
81 t.Errorf("FirstParents = %v, want {%s: %s}", got, b, a)
82 }
83}
internal/gitutil/endofoptions_test.go +1 · view
@@ -44,6 +44,7 @@ func TestRefsAreNotOptions(t *testing.T) {
4444 "StatPath": func() error { StatPath(dir, ref, "f.txt"); return nil },
4545 "LastCommitDate": func() error { LastCommitDate(dir, ref); return nil },
4646 "Parents": func() error { Parents(dir, ref); return nil },
47 "FirstParents": func() error { FirstParents(dir, []string{ref}); return nil },
4748 "RevListAuthors": func() error { _, err := RevListAuthors(dir, "", ref, 1); return err },
4849 "RevListMessages": func() error { _, err := RevListMessages(dir, "", ref, 1); return err },
4950 "IsAncestor": func() error { _, err := IsAncestor(dir, ref, "main"); return err },
internal/gitutil/merge.go +24 −4 · view
@@ -202,12 +202,17 @@ func CommitFileChange(dir, branch, path string, content []byte, name, email, mes
202202 return CommitFileFrom(dir, branch, "", path, content, name, email, message)
203203}
204204
205// CommitFileFrom writes content to path on branch. When branch does not exist
206// yet and fromBranch is named, the new branch starts from fromBranch's tip.
205// CommitFileFrom writes content to path on branch. When fromBranch is
206// named, branch is created from fromBranch's tip and must not exist yet:
207// the content was read from fromBranch, and committing it onto another
208// branch's history would undo that branch's version of the file.
207209func CommitFileFrom(dir, branch, fromBranch, path string, content []byte, name, email, message string) (string, error) {
208210 branchRef := "refs/heads/" + branch
209211 oldRef := ""
210212 parent, err := ResolveRef(dir, branchRef)
213 if err == nil && fromBranch != "" {
214 return "", fmt.Errorf("branch %s already exists; pick a new name", branch)
215 }
211216 if err != nil {
212217 if fromBranch != "" {
213218 baseSHA, berr := ResolveRef(dir, "refs/heads/"+fromBranch)
@@ -215,7 +220,6 @@ func CommitFileFrom(dir, branch, fromBranch, path string, content []byte, name,
215220 return "", fmt.Errorf("base branch %s: %w", fromBranch, berr)
216221 }
217222 parent = baseSHA
218 oldRef = ""
219223 } else {
220224 // An unborn branch is a root commit only in a repository with no
221225 // refs at all. Anywhere else an unresolvable branch is a typo, and
@@ -233,12 +237,28 @@ func CommitFileFrom(dir, branch, fromBranch, path string, content []byte, name,
233237 if err != nil {
234238 return "", err
235239 }
236 if err := UpdateRefCAS(dir, branchRef, sha, oldRef); err != nil {
240 if oldRef == "" {
241 // A new branch: the empty old value makes update-ref refuse if
242 // someone created it meanwhile.
243 err = updateRefCreate(dir, branchRef, sha)
244 } else {
245 err = UpdateRefCAS(dir, branchRef, sha, oldRef)
246 }
247 if err != nil {
237248 return "", fmt.Errorf("branch moved during edit; reload and retry: %w", err)
238249 }
239250 return sha, nil
240251}
241252
253// updateRefCreate points ref at newSHA only if ref does not exist.
254func updateRefCreate(dir, ref, newSHA string) error {
255 cmd := exec.Command(toolpath.Look("git"), "-C", dir, "update-ref", ref, newSHA, "")
256 if out, err := cmd.CombinedOutput(); err != nil {
257 return fmt.Errorf("update-ref %s: %v\n%s", ref, err, out)
258 }
259 return nil
260}
261
242262// CommitWithFile writes a commit on parent ("" for a root commit) whose
243263// tree is parent's with content at path, as a file of mode (100644 or
244264// 100755), authored and committed as name <email>. No ref moves: the
internal/gitutil/messages.go +20 · view
@@ -48,6 +48,26 @@ func Parents(dir, sha string) []string {
4848 return strings.Fields(string(out))
4949}
5050
51// FirstParents maps each of shas to its first parent, in one git call. A
52// root commit, or a sha git cannot read, has no entry.
53func FirstParents(dir string, shas []string) map[string]string {
54 out := map[string]string{}
55 if len(shas) == 0 {
56 return out
57 }
58 args := append([]string{"-C", dir, "log", "--no-walk=unsorted", "--format=%H %P", "--end-of-options"}, shas...)
59 raw, err := exec.Command(toolpath.Look("git"), args...).Output()
60 if err != nil {
61 return out
62 }
63 for _, line := range strings.Split(string(raw), "\n") {
64 if f := strings.Fields(line); len(f) >= 2 {
65 out[f[0]] = f[1]
66 }
67 }
68 return out
69}
70
5171// LastCommitDate returns the committer date (YYYY-MM-DD) of the ref tip,
5272// or "" for empty repos.
5373func LastCommitDate(dir, ref string) string {
internal/httpd/mrcommitview_test.go added +55 · view
@@ -0,0 +1,55 @@
1package httpd
2
3import (
4 "net/http/httptest"
5 "strconv"
6 "strings"
7 "testing"
8
9 "gitbay.org/gitbay/internal/control"
10)
11
12// The per-commit diff is read-only (no comment links: review comments
13// are anchored to the head diff's lines), and only a commit the merge
14// request carries is shown.
15func TestMRCommitViewReadOnlyAndInRange(t *testing.T) {
16 st, cfg, alice, _, repo, n, v1, v2, _ := rangeDiffFixture(t)
17 git := rangeDiffGitRunner(t)
18 dir := control.RepoDir(cfg.Server.Root, repo.OwnerName, repo.Name)
19 git(dir, "update-ref", "refs/merge-requests/"+strconv.FormatInt(n, 10)+"/head", v2)
20 s := New(cfg, st, nil)
21 cookie := loginCookie(t, st, alice.ID)
22
23 get := func(query string) string {
24 t.Helper()
25 req := httptest.NewRequest("GET", "/alice/secret/mrs/"+strconv.FormatInt(n, 10)+query, nil)
26 req.SetPathValue("owner", repo.OwnerName)
27 req.SetPathValue("repo", repo.Name)
28 req.SetPathValue("n", strconv.FormatInt(n, 10))
29 req.AddCookie(cookie)
30 rr := httptest.NewRecorder()
31 s.mr(rr, req)
32 if rr.Code != 200 {
33 t.Fatalf("%s: status %d", query, rr.Code)
34 }
35 return rr.Body.String()
36 }
37
38 full := get("?view=diff")
39 if !strings.Contains(full, `class="cmt"`) {
40 t.Fatal("full diff has no comment links")
41 }
42 one := get("?view=diff&commit=" + v2)
43 if strings.Contains(one, `class="cmt"`) {
44 t.Error("per-commit diff offers comment links")
45 }
46 if !strings.Contains(one, "read-only") {
47 t.Error("per-commit diff does not say it is read-only")
48 }
49 // v1 was amended away: it is in the repository's objects but not in
50 // the merge request's range, so the page falls back to the full diff.
51 stale := get("?view=diff&commit=" + v1)
52 if strings.Contains(stale, "read-only") || !strings.Contains(stale, `class="cmt"`) {
53 t.Error("a commit outside the range was shown as the selected commit")
54 }
55}
internal/httpd/queries.go +13 −7 · view
@@ -42,14 +42,20 @@ func (s *Server) queriesPage(w http.ResponseWriter, r *http.Request, viewer stor
4242 return
4343 }
4444 if adHoc != "" {
45 items, count, next, err := control.RunAdHocQuery(s.st, viewer, adHoc, r.URL.Query().Get("cursor"), queryPerPage)
46 if err != nil {
47 data.Notice = err.Error()
45 argv := []string{"query", "run", "--q", adHoc, "--limit", strconv.Itoa(queryPerPage)}
46 if cursor := r.URL.Query().Get("cursor"); cursor != "" {
47 argv = append(argv, "--cursor", cursor)
48 }
49 var page struct {
50 Items []control.QueryItem `json:"items"`
51 Next string `json:"next"`
52 }
53 if msg, ok := s.runControlInto(viewer, argv, &page); !ok {
54 data.Notice = msg
4855 } else {
49 data.Items = items
50 data.Count = count
51 if next != "" {
52 data.Next = "?" + url.Values{"q": {adHoc}, "cursor": {next}}.Encode()
56 data.Items = page.Items
57 if page.Next != "" {
58 data.Next = "?" + url.Values{"q": {adHoc}, "cursor": {page.Next}}.Encode()
5359 }
5460 }
5561 }
internal/httpd/searchweb.go +12 −1 · view
@@ -88,6 +88,17 @@ func searchHref(h control.SearchResult) string {
8888// servePalette answers Cmd+K / 't' jump queries with files, symbols, issues,
8989// merge requests, and repositories the viewer can read.
9090func (s *Server) servePalette(w http.ResponseWriter, r *http.Request, viewer store.User) {
91 // Each call can walk a whole tree, and anonymous callers reach it, so
92 // it draws on the API's per-caller read budget.
93 key := "palette:" + s.clientIP(r)
94 if viewer.ID != 0 {
95 key = "palette:" + strconv.FormatInt(viewer.ID, 10)
96 }
97 if allowed, wait := s.apiLimit.allow(key, false); !allowed {
98 w.Header().Set("Retry-After", strconv.Itoa(int(wait.Seconds())+1))
99 http.Error(w, "too many requests", http.StatusTooManyRequests)
100 return
101 }
91102 q := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("q")))
92103 repoPath := strings.TrimSpace(r.URL.Query().Get("repo"))
93104 var items []paletteEntry
@@ -116,7 +127,7 @@ func (s *Server) servePalette(w http.ResponseWriter, r *http.Request, viewer sto
116127 items = append(items, paletteEntry{
117128 Group: "File",
118129 Label: e.Name,
119 Href: "/" + repo.Path() + "/blob/" + ref + "/" + e.Name,
130 Href: "/" + repo.Path() + "/blob/" + escapePath(ref) + "/" + escapePath(e.Name),
120131 })
121132 count++
122133 if count >= 40 {
internal/httpd/web.go +47 −13 · view
@@ -440,7 +440,6 @@ func (s *Server) repoFor(w http.ResponseWriter, r *http.Request, ref string) (re
440440 }
441441 openIssues, openMRs := s.st.OpenCounts(repo.ID)
442442 bookmarksCount := s.st.BookmarkCount(repo.ID)
443 forksList, _ := s.st.ListForks(repo.ID)
444443 return repoPage{
445444 basePage: s.baseFor(viewer),
446445 CanAdmin: canAdmin,
@@ -448,7 +447,7 @@ func (s *Server) repoFor(w http.ResponseWriter, r *http.Request, ref string) (re
448447 Pinned: pinned,
449448 Marked: marked,
450449 Bookmarks: bookmarksCount,
451 Forks: len(forksList),
450 Forks: s.st.PublicForkCount(repo.ID),
452451 Watch: watch,
453452 HasWiki: s.hasWiki(repo),
454453 Host: s.cfg.SiteHost(),
@@ -1165,15 +1164,20 @@ func (s *Server) blame(w http.ResponseWriter, r *http.Request) {
11651164 blameLexer := lexers.Match(filePath)
11661165 var hunks []hunkView
11671166 sigs := map[string]sigView{}
1168 parents := map[string]string{}
1167 var blamed []string
1168 seenSHA := map[string]bool{}
1169 for _, h := range out.Hunks {
1170 if !seenSHA[h.SHA] {
1171 seenSHA[h.SHA] = true
1172 blamed = append(blamed, h.SHA)
1173 }
1174 }
1175 parents := gitutil.FirstParents(p.Dir, blamed)
11691176 for _, h := range out.Hunks {
11701177 v, seen := sigs[h.SHA]
11711178 if !seen {
11721179 v, _ = s.sigFor(p.Repo, p.Dir, h.SHA)
11731180 sigs[h.SHA] = v
1174 if ps := gitutil.Parents(p.Dir, h.SHA); len(ps) > 0 {
1175 parents[h.SHA] = ps[0]
1176 }
11771181 }
11781182 date := h.Date
11791183 if t, err := time.Parse(time.RFC3339, h.Date); err == nil {
@@ -2329,11 +2333,10 @@ type mrRow struct {
23292333
23302334// summarizeReviews computes the aggregate non-stale review state among
23312335// reviewers who count for merge gates: "changes_requested" beats "approved".
2332func summarizeReviews(st *store.Store, repo store.Repo, revs []store.MRReview) string {
2336func summarizeReviews(revs []store.MRReview, counts map[string]bool) string {
23332337 if len(revs) == 0 {
23342338 return ""
23352339 }
2336 counts := control.ReviewersWhoCount(st, repo, revs)
23372340 latest := map[string]string{}
23382341 for _, rv := range revs {
23392342 if rv.Stale || !counts[rv.Reviewer] {
@@ -2409,12 +2412,19 @@ func (s *Server) mrs(w http.ResponseWriter, r *http.Request) {
24092412 if err != nil {
24102413 labels = map[int64][]string{}
24112414 }
2415 // Whose review counts is a per-reviewer lookup; one pass over every
2416 // row's reviews rather than one per row.
2417 var allReviews []store.MRReview
2418 for _, revs := range reviewsMap {
2419 allReviews = append(allReviews, revs...)
2420 }
2421 reviewCounts := control.ReviewersWhoCount(s.st, p.Repo, allReviews)
24122422 rows := make([]mrRow, len(mrs))
24132423 for i, m := range mrs {
24142424 m.Labels = labels[m.ID]
24152425 rows[i] = mrRow{
24162426 MR: m, Check: checks[m.HeadSHA],
2417 Review: summarizeReviews(s.st, p.Repo, reviewsMap[m.ID]),
2427 Review: summarizeReviews(reviewsMap[m.ID], reviewCounts),
24182428 Comments: comments[m.ID],
24192429 }
24202430 }
@@ -2498,7 +2508,9 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri
24982508 var diffTruncated bool
24992509 selectedCommit := strings.TrimSpace(r.URL.Query().Get("commit"))
25002510 if selectedCommit != "" {
2501 if full, err := gitutil.ResolveRef(p.Dir, selectedCommit); err == nil {
2511 // Only a commit this merge request carries; any other revision in
2512 // the repository is not part of what is under review.
2513 if full, err := gitutil.ResolveRef(p.Dir, selectedCommit); err == nil && base != "" && inRange(p.Dir, base, headRef, full) {
25022514 selectedCommit = full
25032515 if patch, truncated, err := gitutil.ShowPatch(p.Dir, full, 4<<20); err == nil {
25042516 files, diffTruncated = parseDiff(patch), truncated
@@ -2506,7 +2518,8 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri
25062518 } else {
25072519 selectedCommit = ""
25082520 }
2509 } else if base != "" {
2521 }
2522 if selectedCommit == "" && base != "" {
25102523 if patch, truncated, err := gitutil.Diff(p.Dir, base, headRef, 4<<20); err == nil {
25112524 files, diffTruncated = parseDiff(patch), truncated
25122525 }
@@ -2540,10 +2553,17 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri
25402553 fmt.Sprintf("gitbay mr apply-suggestion %s %d %d", p.Repo.Path(), m.Number, cm.ID))
25412554 }
25422555 }
2556 // Review comments are anchored to lines of the head diff. One
2557 // commit's diff has other line numbers, so it is shown read-only and
2558 // without the threads.
2559 threadComments := diffComments
2560 if selectedCommit != "" {
2561 threadComments = nil
2562 }
25432563 var detachedThreads []diffThread
2544 files, detachedThreads = attachThreads(files, diffComments, m.HeadSHA, md,
2564 files, detachedThreads = attachThreads(files, threadComments, m.HeadSHA, md,
25452565 reviewRights{Viewer: p.Viewer, MRAuthor: m.Author, Write: canWrite}, suggestions)
2546 if p.Viewer != "" {
2566 if p.Viewer != "" && selectedCommit == "" {
25472567 markCompose(files, r.URL.Query())
25482568 }
25492569 layout := s.diffLayoutFor(r)
@@ -2669,6 +2689,20 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri
26692689 sourceGone(p, m), headMerged, headPruned, base, s.labelColors(p.Repo), allLabels, s.repoPeople(p.Repo), d, layout, selectedCommit, bars})
26702690}
26712691
2692// inRange reports whether sha is one of the commits in base..head.
2693func inRange(dir, base, head, sha string) bool {
2694 shas, err := gitutil.RevListRange(dir, base, head)
2695 if err != nil {
2696 return false
2697 }
2698 for _, c := range shas {
2699 if c == sha {
2700 return true
2701 }
2702 }
2703 return false
2704}
2705
26722706// sourceGone reports whether an MR's source branch no longer exists: the
26732707// push hook marks a deleted branch on an open MR, and a merged or closed
26742708// one is checked here. A fork's branch lives in another repository and
internal/store/fork_test.go +22 · view
@@ -27,3 +27,25 @@ func TestCreateForkSetsParent(t *testing.T) {
2727 t.Fatal("duplicate fork name accepted")
2828 }
2929}
30
31// A private fork is not counted: the count is shown to anyone who can
32// read the parent.
33func TestPublicForkCountSkipsPrivate(t *testing.T) {
34 s := open(t)
35 if err := s.MigrateUp(); err != nil {
36 t.Fatal(err)
37 }
38 uid, _ := s.CreateUser("alice", false)
39 bob, _ := s.CreateUser("bob", false)
40 carol, _ := s.CreateUser("carol", false)
41 parent, _ := s.CreateRepo("user", uid, "app", "public")
42 if _, err := s.CreateFork("user", bob, "app", "public", parent); err != nil {
43 t.Fatal(err)
44 }
45 if _, err := s.CreateFork("user", carol, "app", "private", parent); err != nil {
46 t.Fatal(err)
47 }
48 if n := s.PublicForkCount(parent); n != 1 {
49 t.Fatalf("PublicForkCount = %d, want 1", n)
50 }
51}
internal/store/repos.go +9 · view
@@ -474,6 +474,15 @@ func (s *Store) ListForks(repoID int64) ([]Repo, error) {
474474 return queryAll(s.DB, scanRepo, repoSelect+" WHERE r.fork_of = ? ORDER BY 4, r.name", repoID)
475475}
476476
477// PublicForkCount counts a repository's public forks: a private fork
478// is not counted, since the count is shown to anyone who can read the
479// parent.
480func (s *Store) PublicForkCount(repoID int64) int {
481 var n int
482 s.DB.QueryRow("SELECT COUNT(*) FROM repos WHERE fork_of = ? AND visibility = 'public'", repoID).Scan(&n)
483 return n
484}
485
477486func (s *Store) UpdateDefaultBranch(repoID int64, branch string) error {
478487 _, err := s.DB.Exec("UPDATE repos SET default_branch = ? WHERE id = ?", branch, repoID)
479488 return err
internal/web/static/app.js +62 −19 · view
@@ -6,7 +6,9 @@
66 document.documentElement.classList.add('js');
77
88 let toastTimer = 0;
9 function showToast(msg, isErr = false) {
9 // The live region exists from boot: assistive tech often does not
10 // announce a region that appears together with its first message.
11 function toastRegion() {
1012 let el = document.getElementById('gb-toast');
1113 if (!el) {
1214 el = document.createElement('div');
@@ -15,6 +17,10 @@
1517 el.setAttribute('role', 'status');
1618 document.body.appendChild(el);
1719 }
20 return el;
21 }
22 function showToast(msg, isErr = false) {
23 const el = toastRegion();
1824 el.textContent = msg;
1925 el.classList.toggle('toast-err', isErr);
2026 el.classList.add('toast-show');
@@ -213,9 +219,13 @@
213219 const newPops = next.querySelectorAll('.popover');
214220 if (newPops[keepPopoverIdx]) newPops[keepPopoverIdx].open = true;
215221 } else if (foldId) {
216 const nextAside = doc.querySelector('.aside');
217 const curAside = document.querySelector('.aside');
218 if (nextAside && curAside) curAside.replaceWith(nextAside);
222 // The pending count shows in the aside on the conversation and
223 // in the Review changes popover on the diff view.
224 for (const sel of ['.aside', '.finish-review']) {
225 const nextEl = doc.querySelector(sel);
226 const curEl = document.querySelector(sel);
227 if (nextEl && curEl) curEl.replaceWith(nextEl);
228 }
219229 } else if (swapSel === '#notif-root') {
220230 const nextBell = doc.querySelector('.rail a[href="/notifications"]');
221231 const curBell = document.querySelector('.rail a[href="/notifications"]');
@@ -505,9 +515,12 @@
505515 return;
506516 }
507517 if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && e.target instanceof HTMLTextAreaElement && e.target.form) {
518 // Only a form with one way to submit: on a review form the buttons
519 // are verdicts, and the first of them is Approve.
520 const btns = e.target.form.querySelectorAll('button[type="submit"]:not([name="preview"]), button:not([type]):not([name="preview"])');
521 if (btns.length > 1) return;
508522 e.preventDefault();
509 const btn = e.target.form.querySelector('button[type="submit"]:not([name="preview"]), button:not([type]):not([name="preview"])');
510 if (btn) e.target.form.requestSubmit(btn);
523 if (btns.length) e.target.form.requestSubmit(btns[0]);
511524 else e.target.form.requestSubmit();
512525 return;
513526 }
@@ -602,7 +615,14 @@
602615 if (prevTheme === 'system') delete document.documentElement.dataset.theme;
603616 else document.documentElement.dataset.theme = prevTheme;
604617 }
605 if (e.target.id) {
618 // Put the control back to what the server holds. Radios have no
619 // id, so they are matched by name and value.
620 if (e.target instanceof HTMLInputElement && e.target.type === 'radio') {
621 for (const r of form.querySelectorAll('input[type="radio"]')) {
622 const sv = doc.querySelector(`input[type="radio"][name="${CSS.escape(r.name)}"][value="${CSS.escape(r.value)}"]`);
623 if (sv instanceof HTMLInputElement) r.checked = sv.checked;
624 }
625 } else if (e.target.id) {
606626 const serverCtl = doc.getElementById(e.target.id);
607627 if (serverCtl instanceof HTMLInputElement && e.target instanceof HTMLInputElement && serverCtl.type === 'checkbox') {
608628 e.target.checked = serverCtl.checked;
@@ -901,15 +921,24 @@
901921
902922 // Inline hunk context expansion ("↑ Expand")
903923 if (repo && head) {
904 const hunkRe = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
924 const hunkRe = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
905925 for (const tr of wrap.querySelectorAll('tr.hunk[data-hunk][data-file]')) {
906926 if (tr.dataset.expandWired) continue;
907927 tr.dataset.expandWired = '1';
928 // A deleted file has no head blob to read context from.
929 if (tr.closest('details.difffold')?.dataset.status === 'deleted') continue;
908930 const m = hunkRe.exec(tr.dataset.hunk || '');
909931 if (!m) continue;
910932 let curNewStart = parseInt(m[2], 10);
911933 let curOldStart = parseInt(m[1], 10);
912 if (curNewStart <= 1) continue;
934 // Context stops at the previous hunk's last new-side line, which
935 // that hunk already shows.
936 let floor = 1;
937 const hunks = Array.from(tr.closest('table')?.querySelectorAll('tr.hunk[data-hunk]') || []);
938 const prev = hunks[hunks.indexOf(tr) - 1];
939 const pm = prev && hunkRe.exec(prev.dataset.hunk || '');
940 if (pm) floor = parseInt(pm[2], 10) + (pm[3] === undefined ? 1 : parseInt(pm[3], 10));
941 if (curNewStart <= floor) continue;
913942 const srcTd = tr.querySelector('td.src');
914943 if (!srcTd) continue;
915944 const btn = document.createElement('button');
@@ -919,11 +948,11 @@
919948 btn.title = 'Load up to 20 preceding context lines';
920949 btn.addEventListener('click', async () => {
921950 const to = curNewStart - 1;
922 const from = Math.max(1, to - 19);
923 if (to < 1) { btn.remove(); return; }
951 const from = Math.max(floor, to - 19);
952 if (to < floor) { btn.remove(); return; }
924953 btn.disabled = true;
925954 try {
926 const fpath = tr.dataset.file;
955 const fpath = tr.dataset.file.split('/').map(encodeURIComponent).join('/');
927956 const res = await fetch(`/${repo}/blob/${head}/${fpath}?lines=${from}:${to}`, { credentials: 'same-origin' });
928957 if (!res.ok) throw new Error('fetch');
929958 const data = await res.json();
@@ -957,7 +986,7 @@
957986 inserted.reverse().forEach((n) => tr.parentNode.insertBefore(n, sib));
958987 curOldStart = Math.max(1, curOldStart - (curNewStart - from));
959988 curNewStart = from;
960 if (curNewStart <= 1) btn.remove();
989 if (curNewStart <= floor) btn.remove();
961990 } catch {
962991 showToast('Could not expand context', true);
963992 } finally {
@@ -1015,13 +1044,13 @@
10151044 const writeTab = document.createElement('button');
10161045 writeTab.type = 'button';
10171046 writeTab.className = 'composer-tab';
1018 writeTab.setAttribute('aria-selected', 'true');
1047 writeTab.setAttribute('aria-pressed', 'true');
10191048 writeTab.textContent = 'Write';
10201049
10211050 const prevTab = document.createElement('button');
10221051 prevTab.type = 'button';
10231052 prevTab.className = 'composer-tab';
1024 prevTab.setAttribute('aria-selected', 'false');
1053 prevTab.setAttribute('aria-pressed', 'false');
10251054 prevTab.textContent = 'Preview';
10261055
10271056 const hint = document.createElement('span');
@@ -1039,16 +1068,16 @@
10391068 previewBtn.classList.add('js-hidden-preview');
10401069
10411070 writeTab.addEventListener('click', () => {
1042 writeTab.setAttribute('aria-selected', 'true');
1043 prevTab.setAttribute('aria-selected', 'false');
1071 writeTab.setAttribute('aria-pressed', 'true');
1072 prevTab.setAttribute('aria-pressed', 'false');
10441073 pane.hidden = true;
10451074 wrapTarget.hidden = false;
10461075 ta.focus();
10471076 });
10481077
10491078 prevTab.addEventListener('click', async () => {
1050 writeTab.setAttribute('aria-selected', 'false');
1051 prevTab.setAttribute('aria-selected', 'true');
1079 writeTab.setAttribute('aria-pressed', 'false');
1080 prevTab.setAttribute('aria-pressed', 'true');
10521081 wrapTarget.hidden = true;
10531082 pane.hidden = false;
10541083 if (!ta.value.trim()) {
@@ -1086,6 +1115,10 @@
10861115
10871116 function closeAutocomplete() {
10881117 if (acMenu) acMenu.hidden = true;
1118 if (acContext) {
1119 acContext.ta.setAttribute('aria-expanded', 'false');
1120 acContext.ta.removeAttribute('aria-activedescendant');
1121 }
10891122 acItems = [];
10901123 acContext = null;
10911124 }
@@ -1094,6 +1127,8 @@
10941127 if (acMenu) return acMenu;
10951128 acMenu = document.createElement('ul');
10961129 acMenu.className = 'ac-menu';
1130 acMenu.id = 'ac-menu';
1131 acMenu.setAttribute('role', 'listbox');
10971132 acMenu.hidden = true;
10981133 document.body.appendChild(acMenu);
10991134 return acMenu;
@@ -1122,6 +1157,9 @@
11221157 acItems.forEach((it, idx) => {
11231158 const li = document.createElement('li');
11241159 li.className = idx === acIndex ? 'ac-active' : '';
1160 li.id = `ac-opt-${idx}`;
1161 li.setAttribute('role', 'option');
1162 li.setAttribute('aria-selected', idx === acIndex ? 'true' : 'false');
11251163 const b = document.createElement('strong');
11261164 b.textContent = it.insert;
11271165 const sp = document.createElement('span');
@@ -1137,6 +1175,10 @@
11371175 menu.style.left = `${Math.max(8, rect.left + window.scrollX + 12)}px`;
11381176 menu.style.top = `${rect.top + window.scrollY + Math.min(rect.height, 42)}px`;
11391177 menu.hidden = false;
1178 ta.setAttribute('aria-autocomplete', 'list');
1179 ta.setAttribute('aria-controls', menu.id);
1180 ta.setAttribute('aria-expanded', 'true');
1181 ta.setAttribute('aria-activedescendant', `ac-opt-${acIndex}`);
11401182 }
11411183
11421184 function collectPagePeople() {
@@ -1221,6 +1263,7 @@
12211263 }, true);
12221264
12231265 function bootAll() {
1266 toastRegion();
12241267 initCopyButtons();
12251268 initScrollSpy();
12261269 initPanelTabs();
internal/web/static/style.css +18 −18 · view
@@ -132,6 +132,8 @@
132132
133133 --r-ctl: 4px; /* controls and chips */
134134 --r-card: 6px; /* cards, lists, code blocks */
135 --r-mark: 2px; /* inline highlights inside a line of code */
136 --shadow-card: 0 1px 2px rgb(0 0 0 / 0.03);
135137 --shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
136138
137139 /* the native select arrow cannot be restyled, so draw our own;
@@ -401,12 +403,6 @@ a.railuser {
401403 height: var(--rail-strip-h);
402404}
403405a.railuser:hover { text-decoration: none; }
404/* the phone rail's overflow: every square .railopt hides, and log out,
405 as a labelled list under the rail. Shown only below 34rem. */
406.railmore { display: none; position: relative; }
407.railmore > summary { list-style: none; cursor: pointer; }
408.railmore > summary::-webkit-details-marker { display: none; }
409.railmore[open] > summary { background: var(--shell-hover); }
410406.raildrop {
411407 position: absolute;
412408 top: 100%;
@@ -874,7 +870,7 @@ ul.milestonelist, .readme, .code, article.release, .blame, .teambody {
874870 background: var(--card);
875871 border: 1px solid var(--card-line);
876872 border-radius: var(--r-card);
877 box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
873 box-shadow: var(--shadow-card);
878874 overflow: hidden;
879875}
880876.cardhead {
@@ -920,7 +916,7 @@ table.tree, table.refs {
920916 background: var(--card);
921917 border: 1px solid var(--card-line);
922918 border-radius: var(--r-card);
923 box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
919 box-shadow: var(--shadow-card);
924920 /* collapsed borders defeat a radius on the table itself */
925921 border-collapse: separate;
926922 border-spacing: 0;
@@ -960,9 +956,11 @@ table.keys, table.assets { background: none; border: 0; border-radius: 0; }
960956table.keys th, table.assets th, table.keys tr.cols th { background: transparent; padding-left: 0; }
961957table.keys td { padding-left: 0; }
962958table.keys td.act, table.assets td.size { text-align: right; }
963/* a fingerprint or an account row is read across, not down: the cells
964 keep one line each and .tablewrap scrolls what does not fit */
959/* an account row is read across, not down: the cells keep one line
960 each. A fingerprint, URL or id wraps instead, since .setcard
961 .tablewrap does not scroll (popovers would be clipped) */
965962table.keys.nowrap th, table.keys.nowrap td { white-space: nowrap; }
963table.keys td.mono { white-space: normal; overflow-wrap: anywhere; }
966964/* The account list types a username to confirm, which is longer than
967965 the key prefixes the confirm field is sized for elsewhere. 14rem, not
968966 11rem, because "type <name> to confirm" was cut mid-word for a name of
@@ -2280,7 +2278,7 @@ button.react.mine { border-color: var(--link); background: var(--surface); color
22802278 cursor: pointer;
22812279}
22822280.cmdk-trigger:hover { color: var(--shell-fg); border-color: var(--shell-muted); filter: none; }
2283.cmdk-trigger kbd { font-family: var(--mono); font-size: var(--fs-0); color: inherit; }
2281.cmdk-trigger kbd { padding: 0; border: 0; background: none; font-family: var(--mono); font-size: var(--fs-0); color: inherit; }
22842282dialog.cmdk {
22852283 padding: 0;
22862284 border: 1px solid var(--faint);
@@ -2360,7 +2358,7 @@ dialog.cmdk::backdrop { background: rgb(0 0 0 / 0.45); }
23602358 background: var(--card);
23612359 border: 1px solid var(--card-line);
23622360 border-radius: var(--r-card);
2363 box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
2361 box-shadow: var(--shadow-card);
23642362 padding: var(--sp-5);
23652363 margin: 0 0 var(--sp-5);
23662364}
@@ -2424,7 +2422,7 @@ html.js form.setform[data-autosave] > div:has(> button[type="submit"]) { display
24242422 background: var(--card);
24252423 border: 1px solid var(--card-line);
24262424 border-radius: var(--r-card);
2427 box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
2425 box-shadow: var(--shadow-card);
24282426 padding: var(--sp-4);
24292427}
24302428.dashcard-head {
@@ -2450,7 +2448,7 @@ html.js form.setform[data-autosave] > div:has(> button[type="submit"]) { display
24502448 background: var(--card);
24512449 border: 1px solid var(--card-line);
24522450 border-radius: var(--r-card);
2453 box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
2451 box-shadow: var(--shadow-card);
24542452 padding: var(--sp-5);
24552453 margin-bottom: var(--sp-4);
24562454}
@@ -2519,7 +2517,7 @@ ul.issuelist li.unread {
25192517 background: var(--card);
25202518 border: 1px solid var(--card-line);
25212519 border-radius: var(--r-card);
2522 box-shadow: 0 1px 2px rgb(0 0 0 / 0.03);
2520 box-shadow: var(--shadow-card);
25232521 padding: var(--sp-4);
25242522}
25252523.popform-stack {
@@ -2637,11 +2635,11 @@ details.difffold .tablewrap { border-radius: 0 0 var(--r-card) var(--r-card); ov
26372635.difftoc-list li.toc-viewed a { color: var(--muted); text-decoration: line-through; }
26382636.idiff-del {
26392637 background: color-mix(in srgb, var(--bad) 26%, transparent);
2640 border-radius: 2px;
2638 border-radius: var(--r-mark);
26412639}
26422640.idiff-add {
26432641 background: color-mix(in srgb, var(--ok) 26%, transparent);
2644 border-radius: 2px;
2642 border-radius: var(--r-mark);
26452643}
26462644.hunk-expand {
26472645 display: inline-flex;
@@ -2743,7 +2741,7 @@ kbd {
27432741 margin-bottom: -1px;
27442742}
27452743.composer-tab:hover { color: var(--fg); background: var(--hover); filter: none; }
2746.composer-tab[aria-selected="true"] {
2744.composer-tab[aria-pressed="true"] {
27472745 color: var(--fg);
27482746 font-weight: 600;
27492747 border-bottom-color: var(--mark);
@@ -2764,6 +2762,8 @@ kbd {
27642762 background: var(--inset);
27652763}
27662764html.js button.js-hidden-preview { display: none; }
2765/* controls that only work through app.js */
2766html:not(.js) :is(.cmdk-trigger, .kbhelp-trigger, .quote-btn, [data-copy], [data-copy-url], [data-refresh]) { display: none; }
27672767.ac-menu {
27682768 position: absolute;
27692769 z-index: 70;
internal/web/templates/build.html +1 −1 · view
@@ -11,7 +11,7 @@
1111{{if and .CanWrite (not .Live) .Build.Job (ne .Build.Status "pending") (ne .Build.Status "running")}}
1212<form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/builds" class="inline">
1313 <input type="hidden" name="job" value="{{.Build.Job}}">
14 <button type="submit" class="btn">Re-run {{.Build.Job}}</button>
14 <button type="submit" class="btn">Run {{.Build.Job}} on {{.Repo.DefaultBranch}}</button>
1515</form>
1616{{end}}
1717{{if and .CanWrite (or (eq .Build.Status "pending") (eq .Build.Status "running"))}}
internal/web/templates/layout.html +4 −4 · view
@@ -57,10 +57,10 @@
5757 <a href="/{{.Viewer}}/-/bookmarks">{{template "icon" "star"}} Bookmarks</a>
5858 {{if .Rail.Pins}}<div class="railpins-mob"><hr class="railsep">{{range .Rail.Pins}}<a href="/{{.Owner}}/{{.Name}}">{{template "icon" "pin"}} {{.Owner}}/{{.Name}}</a>{{end}}</div>{{end}}
5959 <hr class="railsep">
60 {{$settings := index $items 1}}<a{{if $settings.Current}} aria-current="page"{{end}} href="{{$settings.Href}}">{{template "icon" $settings.Icon}} {{$settings.Name}}</a>
61 {{$admin := index $items 2}}{{if $admin.Show}}<a{{if $admin.Current}} aria-current="page"{{end}} href="{{$admin.Href}}">{{template "icon" $admin.Icon}} {{$admin.Name}}</a>{{end}}
60 {{$settings := index $items 0}}<a{{if $settings.Current}} aria-current="page"{{end}} href="{{$settings.Href}}">{{template "icon" $settings.Icon}} {{$settings.Name}}</a>
61 {{$admin := index $items 1}}{{if $admin.Show}}<a{{if $admin.Current}} aria-current="page"{{end}} href="{{$admin.Href}}">{{template "icon" $admin.Icon}} {{$admin.Name}}</a>{{end}}
6262 <hr class="railsep">
63 {{$logout := index $items 3}}<a href="{{$logout.Href}}">{{template "icon" $logout.Icon}} {{$logout.Name}}</a>
63 {{$logout := index $items 2}}<a href="{{$logout.Href}}">{{template "icon" $logout.Icon}} {{$logout.Name}}</a>
6464 </div>
6565 </details>
6666 {{else}}<a class="railicon" href="/login" aria-label="Sign in" title="Sign in">{{template "icon" "person"}}<span class="raillabel" aria-hidden="true">Sign in</span><span class="vh">Sign in</span></a>{{end}}
@@ -284,7 +284,7 @@
284284 <ul class="difftoc-list">{{range $fi, $f := .Files}}<li data-toc-path="{{.Path}}"><a href="#f{{$fi}}">{{.Path}}</a>{{if ne .Status "modified"}} <span class="chip">{{.Status}}</span>{{end}}{{if .Threads}} <span class="chip chip-neutral" title="{{.Threads}} thread{{if ne .Threads 1}}s{{end}}">💬 {{.Threads}}</span>{{end}} <span class="fstat">{{if .Adds}}<span class="add">+{{.Adds}}</span>{{end}}{{if .Dels}} <span class="del">−{{.Dels}}</span>{{end}}</span></li>{{end}}</ul>
285285</details>{{end}}
286286<div class="difflist">
287{{range $fi, $f := .Files}}<details class="difffold" id="f{{$fi}}" data-file-path="{{.Path}}"{{if .Open}} open{{end}}>
287{{range $fi, $f := .Files}}<details class="difffold" id="f{{$fi}}" data-file-path="{{.Path}}" data-status="{{.Status}}"{{if .Open}} open{{end}}>
288288 <summary>
289289 <span class="fpath">{{if eq .Status "renamed"}}<span class="was">{{.OldPath}} →</span> {{end}}{{.Path}}</span>
290290 {{if ne .Status "modified"}}<span class="chip">{{.Status}}</span>{{end}}
internal/web/templates/mr.html +3 −1 · view
@@ -49,7 +49,9 @@
4949{{end}}
5050{{if .DiffFiles}}<p class="diffstat">{{.Stat.Files}} file{{if ne .Stat.Files 1}}s{{end}} changed, <span class="add">+{{.Stat.Adds}}</span> <span class="del">−{{.Stat.Dels}}</span>{{if .DiffTruncated}} · shown up to 4 MiB; the counts and the last file are partial{{end}}</p>
5151{{if .DiffTruncated}}<p class="error" role="alert">This diff is larger than 4 MiB and is cut off below. Fetch the branch to see all of it.</p>{{end}}
52{{template "difffiles" dict "Files" .DiffFiles "Base" $base "Viewer" .Viewer "L" .Layout "RepoPath" .Repo.Path "HeadSHA" .MR.HeadSHA}}
52{{if $sel}}<p class="meta">One commit's changes, read-only. Review comments go on <a href="{{$base}}?view=diff{{if .Layout.Carry}}&amp;layout={{.Layout.Carry}}{{end}}">all commits</a>.</p>
53{{template "difffiles" dict "Files" .DiffFiles "Base" "" "Viewer" "" "L" .Layout "RepoPath" .Repo.Path "HeadSHA" $sel}}
54{{else}}{{template "difffiles" dict "Files" .DiffFiles "Base" $base "Viewer" .Viewer "L" .Layout "RepoPath" .Repo.Path "HeadSHA" .MR.HeadSHA}}{{end}}
5355{{else if .HeadPruned}}<p class="empty-note">The head of this merge request is no longer in the repository; its diff is not available.</p>
5456{{else}}<p class="empty-note">No changes between the source and target.{{if .HeadMerged}} The source branch was already merged or fast-forwarded into <code>{{.MR.TargetRef}}</code>.{{end}}</p>{{end}}
5557
internal/web/templates/queries.html +1 −1 · view
@@ -77,7 +77,7 @@
7777</details>
7878</section>
7979{{if .AdHoc}}
80<h2>Results <span class="count">{{.Count}}</span></h2>
80<h2>Results</h2>
8181{{template "queryrows" .}}
8282{{end}}
8383<ul class="issuelist rows" id="saved-queries">
internal/web/templates/settings.html +8 −8 · view
@@ -60,7 +60,7 @@
6060</section>
6161
6262<section id="access" class="setcard"><h2>Access</h2>
63<form method="post" action="{{$base}}" class="setform" data-autosave="1">
63<form method="post" action="{{$base}}" class="setform">
6464 <input type="hidden" name="field" value="visibility">
6565 <div><span class="fieldname">Visibility</span></div>
6666 <div class="check">
@@ -69,7 +69,7 @@
6969 </div>
7070 <div><button type="submit" class="btn">Save</button></div>
7171</form>
72<form method="post" action="{{$base}}" class="setform" data-autosave="1">
72<form method="post" action="{{$base}}" class="setform">
7373 <input type="hidden" name="field" value="git-daemon">
7474 <div><label for="git-daemon">Serve over git://</label><p class="hint">Public repositories only.</p></div>
7575 <div class="check"><input type="checkbox" id="git-daemon" name="git-daemon" value="on"{{if .Repo.Settings.GitDaemon}} checked{{end}}></div>
@@ -144,7 +144,7 @@
144144
145145<section id="gates" class="setcard"><h2>Merge gates</h2>
146146<p class="meta">Checked before a merge, in this order: checks, approvals, resolved threads, signatures.</p>
147<form method="post" action="{{$base}}" class="setform" data-autosave="1">
147<form method="post" action="{{$base}}" class="setform">
148148 <input type="hidden" name="field" value="require-checks">
149149 <div><label for="require-checks">Required checks</label><p class="hint">Requires CI to succeed.{{with .Repo.Settings.RequiredContexts}} Also waits for {{range $i, $c := .}}{{if $i}}, {{end}}<code>{{$c}}</code>{{end}} until they report{{if not $.Repo.Settings.RequireChecks}}, once this is on{{end}}.{{end}}</p></div>
150150 <div class="check"><input type="checkbox" id="require-checks" name="require-checks" value="on"{{if .Repo.Settings.RequireChecks}} checked{{end}}></div>
@@ -162,19 +162,19 @@
162162 <div class="num"><input type="number" id="approvals" name="approvals" min="0" max="10" value="{{.Repo.Settings.RequireApprovals}}"></div>
163163 <div><button type="submit" class="btn">Save</button></div>
164164</form>
165<form method="post" action="{{$base}}" class="setform" data-autosave="1">
165<form method="post" action="{{$base}}" class="setform">
166166 <input type="hidden" name="field" value="require-resolved">
167167 <div><label for="require-resolved">Review threads</label><p class="hint">Every thread on the diff must be resolved before merging.</p></div>
168168 <div class="check"><input type="checkbox" id="require-resolved" name="require-resolved" value="on"{{if .Repo.Settings.RequireResolved}} checked{{end}}></div>
169169 <div><button type="submit" class="btn">Save</button></div>
170170</form>
171<form method="post" action="{{$base}}" class="setform" data-autosave="1">
171<form method="post" action="{{$base}}" class="setform">
172172 <input type="hidden" name="field" value="require-codeowners">
173173 <div><label for="require-codeowners">CODEOWNERS</label><p class="hint">Code owners must approve.</p></div>
174174 <div class="check"><input type="checkbox" id="require-codeowners" name="require-codeowners" value="on"{{if .Repo.Settings.RequireCodeowners}} checked{{end}}></div>
175175 <div><button type="submit" class="btn">Save</button></div>
176176</form>
177<form method="post" action="{{$base}}" class="setform" data-autosave="1">
177<form method="post" action="{{$base}}" class="setform">
178178 <input type="hidden" name="field" value="require-signed">
179179 <div><label for="require-signed">Signed commits</label><p class="hint">Every commit in the request must carry a verified signature. Squash and merge strategies are refused, since both mint an unsigned commit.</p></div>
180180 <div class="check"><input type="checkbox" id="require-signed" name="require-signed" value="on"{{if .Repo.Settings.RequireSignedCommits}} checked{{end}}></div>
@@ -245,7 +245,7 @@
245245{{end}}
246246
247247<section id="secrets" class="setcard"><h2>Secret scan</h2>
248<form method="post" action="{{$base}}" class="setform" data-autosave="1">
248<form method="post" action="{{$base}}" class="setform">
249249 <input type="hidden" name="field" value="secret-scan">
250250 <div><label for="secret-scan">Pushes</label><p class="hint">Each push's new files are checked for credentials in known formats. Warn accepts the push and tells the pusher where; block refuses it. Only the path, line and kind of credential are reported, never the value.</p></div>
251251 <div><select id="secret-scan" name="secret-scan">{{$mode := or .Repo.Settings.SecretScan "warn"}}<option value="off"{{if eq $mode "off"}} selected{{end}}>off</option><option value="warn"{{if eq $mode "warn"}} selected{{end}}>warn</option><option value="block"{{if eq $mode "block"}} selected{{end}}>block</option></select></div>
@@ -277,7 +277,7 @@
277277 <div><select id="branch" name="branch">{{range .Branches}}<option value="{{.Name}}">{{.Name}}</option>{{end}}</select></div>
278278 <div><button type="submit" class="btn">Protect</button></div>
279279</form>
280<form method="post" action="{{$base}}" class="setform" data-autosave="1">
280<form method="post" action="{{$base}}" class="setform">
281281 <input type="hidden" name="field" value="require-mr">
282282 <div><label for="require-mr">Require merge requests</label><p class="hint">Every protected branch changes through a merge request. A direct push is refused in pre-receive.</p></div>
283283 <div class="check"><input type="checkbox" id="require-mr" name="require-mr" value="on"{{if .Repo.Settings.RequireMR}} checked{{end}}></div>
internal/web/web.go +3 −6 · view
@@ -40,9 +40,7 @@ var ImageFS embed.FS
4040var StyleVersion string
4141var ScriptVersion string
4242
43// railItem is one destination the rail's icon strip and the phone
44// "More" menu both render — from this one list, so a destination added
45// here reaches both instead of the two being hand-kept in step (#271).
43// railItem is one destination of the account menu.
4644type railItem struct {
4745 Href string
4846 Icon string
@@ -83,8 +81,8 @@ func railBool(v any, name string) bool {
8381 return f.IsValid() && f.Kind() == reflect.Bool && f.Bool()
8482}
8583
86// railOptItems is the rail's "New repository", "Settings", "Admin" and
87// "Log out" destinations, in the order the rail shows them. v is the
84// railOptItems is the account menu's "Settings", "Admin" and "Log out"
85// destinations, in the order the menu shows them. v is the
8886// page value the layout renders (any page struct that embeds
8987// basePage), read by field name since the layout has no single common
9088// type for every page.
@@ -92,7 +90,6 @@ func railOptItems(v any) []railItem {
9290 tab := railField(v, "Tab")
9391 admin := railBool(v, "Admin")
9492 return []railItem{
95 {Href: "/new", Icon: "plus", Name: "New repository", Show: true},
9693 {Href: "/settings", Icon: "gear", Name: "Settings", Current: tab == "account", Show: true},
9794 {Href: "/admin", Icon: "shield", Name: "Admin", Current: tab == "admin", Show: admin},
9895 {Href: "/logout", Icon: "signout", Name: "Log out", Show: true},
internal/web/web_test.go +8 −10 · view
@@ -243,21 +243,19 @@ func TestMixedTextLinksAreUnderlined(t *testing.T) {
243243 }
244244}
245245
246// The main rail and the phone "More" menu render New repository,
247// Settings, Admin and Log out from one list, so adding a destination in
248// one place reaches both (#271).
246// The account menu renders Settings, Admin and Log out from one list.
249247func TestRailOptItemsDriveBothRailAndMoreMenu(t *testing.T) {
250248 items := railOptItems(struct {
251249 Tab string
252250 Admin bool
253251 }{Tab: "admin", Admin: true})
254 if len(items) != 4 {
255 t.Fatalf("got %d items, want 4 (New repository, Settings, Admin, Log out)", len(items))
252 if len(items) != 3 {
253 t.Fatalf("got %d items, want 3 (Settings, Admin, Log out)", len(items))
256254 }
257 if items[2].Name != "Admin" || !items[2].Show {
258 t.Errorf("Admin item: %+v", items[2])
255 if items[1].Name != "Admin" || !items[1].Show {
256 t.Errorf("Admin item: %+v", items[1])
259257 }
260 if !items[2].Current {
258 if !items[1].Current {
261259 t.Error("Admin item should be Current when Tab is admin")
262260 }
263261
@@ -265,10 +263,10 @@ func TestRailOptItemsDriveBothRailAndMoreMenu(t *testing.T) {
265263 Tab string
266264 Admin bool
267265 }{Tab: "account"})
268 if nonAdmin[2].Show {
266 if nonAdmin[1].Show {
269267 t.Error("Admin item should not Show for a non-admin viewer")
270268 }
271 if !nonAdmin[1].Current {
269 if !nonAdmin[0].Current {
272270 t.Error("Settings item should be Current when Tab is account")
273271 }
274272
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form