Commit ac8d910ff3
Verified · cmc ci/build: success ci/quality: success ci/test: failure
Changed files (27)
- .gitbay/wiki/Parity.org +3 −1
- .gitbay/wiki/Users.org +1
- cmd/gitbay/summaries_gen.go +1 −1
- internal/control/commitfile.go +1 −1
- internal/control/query.go +11 −40
- internal/control/query_test.go +10
- internal/control/register.go +4 −5
- internal/control/signupverify_test.go added +48
- internal/gitutil/commitfile_test.go +45
- internal/gitutil/endofoptions_test.go +1
- internal/gitutil/merge.go +24 −4
- internal/gitutil/messages.go +20
- internal/httpd/mrcommitview_test.go added +55
- internal/httpd/queries.go +13 −7
- internal/httpd/searchweb.go +12 −1
- internal/httpd/web.go +47 −13
- internal/store/fork_test.go +22
- internal/store/repos.go +9
- internal/web/static/app.js +62 −19
- internal/web/static/style.css +18 −18
- internal/web/templates/build.html +1 −1
- internal/web/templates/layout.html +4 −4
- internal/web/templates/mr.html +3 −1
- internal/web/templates/queries.html +1 −1
- internal/web/templates/settings.html +8 −8
- internal/web/web.go +3 −6
- internal/web/web_test.go +8 −10
.gitbay/wiki/Parity.org +3 −1 · view
| @@ -371,7 +371,9 @@ every repository the caller can read (#292): =query save <name> | |||
| 371 | <query>= (=--force= replaces), =query list=, =query show= with its | 371 | <query>= (=--force= replaces), =query list=, =query show= with its |
| 372 | count, =query run= for the rows, =query remove=, =query pin= and | 372 | count, =query run= for the rows, =query remove=, =query pin= and |
| 373 | =unpin=. =issue list --query <name>= and =mr list --query <name>= run | 373 | =unpin=. =issue list --query <name>= and =mr list --query <name>= run |
| 374 | one narrowed to their kind, and =--q '<query>'= takes one written out. | 374 | one 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 | ||
| 376 | unsaved query on =/<owner>/-/queries?q== dispatches. | ||
| 375 | Results are newest first, always paged with ={items, next}= and fifty | 377 | Results are newest first, always paged with ={items, next}= and fifty |
| 376 | rows by default, each naming its repository. Readability is the | 378 | rows by default, each naming its repository. Readability is the |
| 377 | search rule, decided in the SQL, so a private repository someone else | 379 | search 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 | |||
| 595 | gitbay query save v2 owner:krz label:bug 'label:needs review' milestone:v2 | 595 | gitbay query save v2 owner:krz label:bug 'label:needs review' milestone:v2 |
| 596 | gitbay query list / show mine / remove mine | 596 | gitbay query list / show mine / remove mine |
| 597 | gitbay query run mine [--limit 20] [--cursor <c>] # issues and MRs | 597 | gitbay query run mine [--limit 20] [--cursor <c>] # issues and MRs |
| 598 | gitbay query run --q 'is:open assignee:@me' # unsaved, issues and MRs | ||
| 598 | gitbay issue list --query mine # only the issues | 599 | gitbay issue list --query mine # only the issues |
| 599 | gitbay mr list --q 'owner:krz is:open author:@me' # a query written out | 600 | gitbay mr list --q 'owner:krz is:open author:@me' # a query written out |
| 600 | gitbay query pin mine # on the dashboard; unpin | 601 | gitbay query pin mine # on the dashboard; unpin |
cmd/gitbay/summaries_gen.go +1 −1 · view
| @@ -135,7 +135,7 @@ var summaries = map[string]string{ | |||
| 135 | "query list": "list your saved queries", | 135 | "query list": "list your saved queries", |
| 136 | "query pin": "show a saved query on your dashboard", | 136 | "query pin": "show a saved query on your dashboard", |
| 137 | "query remove": "delete a saved query", | 137 | "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", |
| 139 | "query save": "save an issue and merge request query across repositories under a name", | 139 | "query save": "save an issue and merge request query across repositories under a name", |
| 140 | "query show": "show a saved query and how many rows it matches", | 140 | "query show": "show a saved query and how many rows it matches", |
| 141 | "query unpin": "take a saved query off your dashboard", | 141 | "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 { | |||
| 53 | if len(rest) != 2 || ref == "" { | 53 | if len(rest) != 2 || ref == "" { |
| 54 | return c.usage() | 54 | return c.usage() |
| 55 | } | 55 | } |
| 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 == "@" { |
| 57 | return c.fail(protocol.ExitUsage, "invalid branch name %q", ref) | 57 | return c.fail(protocol.ExitUsage, "invalid branch name %q", ref) |
| 58 | } | 58 | } |
| 59 | repo, code := resolveRepo(c, rest[0], policy.CanWrite) | 59 | repo, code := resolveRepo(c, rest[0], policy.CanWrite) |
internal/control/query.go +11 −40 · view
| @@ -37,13 +37,14 @@ func init() { | |||
| 37 | Examples: []string{"query show mine"}, | 37 | Examples: []string{"query show mine"}, |
| 38 | ReadOnly: true, Run: runQueryShow}) | 38 | ReadOnly: true, Run: runQueryShow}) |
| 39 | register(Command{Path: []string{"query", "run"}, | 39 | register(Command{Path: []string{"query", "run"}, |
| 40 | Summary: "list the issues and merge requests a saved query matches", | 40 | Summary: "list the issues and merge requests a saved query, or one given with --q, matches", |
| 41 | Usage: "query run <name> [--limit <n>] [--cursor <c>]", | 41 | Usage: "query run (<name> | --q <query>) [--limit <n>] [--cursor <c>]", |
| 42 | Flags: []Flag{ | 42 | Flags: []Flag{ |
| 43 | {"--q", "<query>", "run this query instead of a saved one", ""}, | ||
| 43 | {"--limit", "<n>", "rows per page", strconv.Itoa(queryDefaultLimit)}, | 44 | {"--limit", "<n>", "rows per page", strconv.Itoa(queryDefaultLimit)}, |
| 44 | {"--cursor", "<c>", "continue from the previous page", ""}, | 45 | {"--cursor", "<c>", "continue from the previous page", ""}, |
| 45 | }, | 46 | }, |
| 46 | Examples: []string{"query run mine --limit 20"}, | 47 | Examples: []string{"query run mine --limit 20", "query run --q 'is:open assignee:@me'"}, |
| 47 | ReadOnly: true, Run: runQueryRun}) | 48 | ReadOnly: true, Run: runQueryRun}) |
| 48 | register(Command{Path: []string{"query", "remove"}, | 49 | register(Command{Path: []string{"query", "remove"}, |
| 49 | Summary: "delete a saved query", | 50 | Summary: "delete a saved query", |
| @@ -158,43 +159,6 @@ func PinnedQueries(st *store.Store, user store.User) ([]DashboardQuery, error) { | |||
| 158 | return out, nil | 159 | return out, nil |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 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. | ||
| 163 | func 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 | |||
| 198 | func encodeItemCursor(k store.ItemCursor) string { | 162 | func encodeItemCursor(k store.ItemCursor) string { |
| 199 | return encodeCursor("query", fmt.Sprintf("%s|%d|%d", k.CreatedAt, k.Kind, k.ID)) | 163 | return encodeCursor("query", fmt.Sprintf("%s|%d|%d", k.CreatedAt, k.Kind, k.ID)) |
| 200 | } | 164 | } |
| @@ -464,6 +428,13 @@ func runQueryRun(c *Ctx, args []string) int { | |||
| 464 | if code >= 0 { | 428 | if code >= 0 { |
| 465 | return code | 429 | return code |
| 466 | } | 430 | } |
| 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 | } | ||
| 467 | if len(rest) != 1 { | 438 | if len(rest) != 1 { |
| 468 | return c.usage() | 439 | return c.usage() |
| 469 | } | 440 | } |
internal/control/query_test.go +10 · view
| @@ -150,6 +150,16 @@ func TestQueryCommands(t *testing.T) { | |||
| 150 | t.Errorf("paged run = %s", got) | 150 | t.Errorf("paged run = %s", got) |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 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 | |||
| 153 | // issue list and mr list narrow to their own kind. | 163 | // issue list and mr list narrow to their own kind. |
| 154 | code, data, msg = e.run("alice", "issue", "list", "--query", "all") | 164 | code, data, msg = e.run("alice", "issue", "list", "--query", "all") |
| 155 | var p pageOut | 165 | 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 | |||
| 340 | if username == "" || code == "" { | 340 | if username == "" || code == "" { |
| 341 | return store.User{}, "enter the verification code from your email" | 341 | return store.User{}, "enter the verification code from your email" |
| 342 | } | 342 | } |
| 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. | ||
| 343 | u, err := st.UserByUsername(username) | 345 | u, err := st.UserByUsername(username) |
| 344 | if err != nil || u.Disabled { | 346 | if err != nil || u.Disabled || !u.Pending { |
| 345 | return store.User{}, "that code is invalid, expired, or already used" | 347 | return store.User{}, "that code is invalid, expired, or already used" |
| 346 | } | 348 | } |
| 347 | address, err := st.ConsumeEmailToken(u.ID, store.HashToken(code)) | 349 | address, err := st.ConsumeEmailToken(u.ID, store.HashToken(code)) |
| @@ -351,14 +353,11 @@ func VerifyPendingSignup(cfg config.Config, st *store.Store, username, code stri | |||
| 351 | if err := st.VerifyEmail(u.ID, address, "smtp"); err != nil { | 353 | if err := st.VerifyEmail(u.ID, address, "smtp"); err != nil { |
| 352 | return store.User{}, err.Error() | 354 | return store.User{}, err.Error() |
| 353 | } | 355 | } |
| 354 | wasPending := u.Pending | ||
| 355 | if err := st.ClearPending(u.ID); err != nil { | 356 | if err := st.ClearPending(u.ID); err != nil { |
| 356 | return store.User{}, err.Error() | 357 | return store.User{}, err.Error() |
| 357 | } | 358 | } |
| 358 | u.Pending = false | 359 | u.Pending = false |
| 359 | st.Audit(u.ID, "email.signup_verified", map[string]any{"address": address}) | 360 | st.Audit(u.ID, "email.signup_verified", map[string]any{"address": address}) |
| 360 | if wasPending { | 361 | notifyAdminsOfSignup(cfg, st, u.Username, "open") |
| 361 | notifyAdminsOfSignup(cfg, st, u.Username, "open") | ||
| 362 | } | ||
| 363 | return u, "" | 362 | return u, "" |
| 364 | } | 363 | } |
internal/control/signupverify_test.go added +48 · view
| @@ -0,0 +1,48 @@ | |||
| 1 | package control | ||
| 2 | |||
| 3 | import ( | ||
| 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. | ||
| 13 | func 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) { | |||
| 36 | t.Error("committing to an unknown branch of a non-empty repository succeeded") | 36 | t.Error("committing to an unknown branch of a non-empty repository succeeded") |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
| 39 | |||
| 40 | // --from creates a branch; it never commits onto one that exists, and a | ||
| 41 | // branch created meanwhile is not overwritten. | ||
| 42 | func 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 | |||
| 66 | func 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) { | |||
| 44 | "StatPath": func() error { StatPath(dir, ref, "f.txt"); return nil }, | 44 | "StatPath": func() error { StatPath(dir, ref, "f.txt"); return nil }, |
| 45 | "LastCommitDate": func() error { LastCommitDate(dir, ref); return nil }, | 45 | "LastCommitDate": func() error { LastCommitDate(dir, ref); return nil }, |
| 46 | "Parents": func() error { Parents(dir, ref); return nil }, | 46 | "Parents": func() error { Parents(dir, ref); return nil }, |
| 47 | "FirstParents": func() error { FirstParents(dir, []string{ref}); return nil }, | ||
| 47 | "RevListAuthors": func() error { _, err := RevListAuthors(dir, "", ref, 1); return err }, | 48 | "RevListAuthors": func() error { _, err := RevListAuthors(dir, "", ref, 1); return err }, |
| 48 | "RevListMessages": func() error { _, err := RevListMessages(dir, "", ref, 1); return err }, | 49 | "RevListMessages": func() error { _, err := RevListMessages(dir, "", ref, 1); return err }, |
| 49 | "IsAncestor": func() error { _, err := IsAncestor(dir, ref, "main"); return err }, | 50 | "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 | |||
| 202 | return CommitFileFrom(dir, branch, "", path, content, name, email, message) | 202 | return CommitFileFrom(dir, branch, "", path, content, name, email, message) |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | // CommitFileFrom writes content to path on branch. When branch does not exist | 205 | // CommitFileFrom writes content to path on branch. When fromBranch is |
| 206 | // yet and fromBranch is named, the new branch starts from fromBranch's tip. | 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. | ||
| 207 | func CommitFileFrom(dir, branch, fromBranch, path string, content []byte, name, email, message string) (string, error) { | 209 | func CommitFileFrom(dir, branch, fromBranch, path string, content []byte, name, email, message string) (string, error) { |
| 208 | branchRef := "refs/heads/" + branch | 210 | branchRef := "refs/heads/" + branch |
| 209 | oldRef := "" | 211 | oldRef := "" |
| 210 | parent, err := ResolveRef(dir, branchRef) | 212 | parent, err := ResolveRef(dir, branchRef) |
| 213 | if err == nil && fromBranch != "" { | ||
| 214 | return "", fmt.Errorf("branch %s already exists; pick a new name", branch) | ||
| 215 | } | ||
| 211 | if err != nil { | 216 | if err != nil { |
| 212 | if fromBranch != "" { | 217 | if fromBranch != "" { |
| 213 | baseSHA, berr := ResolveRef(dir, "refs/heads/"+fromBranch) | 218 | baseSHA, berr := ResolveRef(dir, "refs/heads/"+fromBranch) |
| @@ -215,7 +220,6 @@ func CommitFileFrom(dir, branch, fromBranch, path string, content []byte, name, | |||
| 215 | return "", fmt.Errorf("base branch %s: %w", fromBranch, berr) | 220 | return "", fmt.Errorf("base branch %s: %w", fromBranch, berr) |
| 216 | } | 221 | } |
| 217 | parent = baseSHA | 222 | parent = baseSHA |
| 218 | oldRef = "" | ||
| 219 | } else { | 223 | } else { |
| 220 | // An unborn branch is a root commit only in a repository with no | 224 | // An unborn branch is a root commit only in a repository with no |
| 221 | // refs at all. Anywhere else an unresolvable branch is a typo, and | 225 | // 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, | |||
| 233 | if err != nil { | 237 | if err != nil { |
| 234 | return "", err | 238 | return "", err |
| 235 | } | 239 | } |
| 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 { | ||
| 237 | return "", fmt.Errorf("branch moved during edit; reload and retry: %w", err) | 248 | return "", fmt.Errorf("branch moved during edit; reload and retry: %w", err) |
| 238 | } | 249 | } |
| 239 | return sha, nil | 250 | return sha, nil |
| 240 | } | 251 | } |
| 241 | 252 | ||
| 253 | // updateRefCreate points ref at newSHA only if ref does not exist. | ||
| 254 | func 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 | |||
| 242 | // CommitWithFile writes a commit on parent ("" for a root commit) whose | 262 | // CommitWithFile writes a commit on parent ("" for a root commit) whose |
| 243 | // tree is parent's with content at path, as a file of mode (100644 or | 263 | // tree is parent's with content at path, as a file of mode (100644 or |
| 244 | // 100755), authored and committed as name <email>. No ref moves: the | 264 | // 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 { | |||
| 48 | return strings.Fields(string(out)) | 48 | return strings.Fields(string(out)) |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 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. | ||
| 53 | func 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 | |||
| 51 | // LastCommitDate returns the committer date (YYYY-MM-DD) of the ref tip, | 71 | // LastCommitDate returns the committer date (YYYY-MM-DD) of the ref tip, |
| 52 | // or "" for empty repos. | 72 | // or "" for empty repos. |
| 53 | func LastCommitDate(dir, ref string) string { | 73 | func LastCommitDate(dir, ref string) string { |
internal/httpd/mrcommitview_test.go added +55 · view
| @@ -0,0 +1,55 @@ | |||
| 1 | package httpd | ||
| 2 | |||
| 3 | import ( | ||
| 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. | ||
| 15 | func 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 | |||
| 42 | return | 42 | return |
| 43 | } | 43 | } |
| 44 | if adHoc != "" { | 44 | if adHoc != "" { |
| 45 | items, count, next, err := control.RunAdHocQuery(s.st, viewer, adHoc, r.URL.Query().Get("cursor"), queryPerPage) | 45 | argv := []string{"query", "run", "--q", adHoc, "--limit", strconv.Itoa(queryPerPage)} |
| 46 | if err != nil { | 46 | if cursor := r.URL.Query().Get("cursor"); cursor != "" { |
| 47 | data.Notice = err.Error() | 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 | ||
| 48 | } else { | 55 | } else { |
| 49 | data.Items = items | 56 | data.Items = page.Items |
| 50 | data.Count = count | 57 | if page.Next != "" { |
| 51 | if next != "" { | 58 | data.Next = "?" + url.Values{"q": {adHoc}, "cursor": {page.Next}}.Encode() |
| 52 | data.Next = "?" + url.Values{"q": {adHoc}, "cursor": {next}}.Encode() | ||
| 53 | } | 59 | } |
| 54 | } | 60 | } |
| 55 | } | 61 | } |
internal/httpd/searchweb.go +12 −1 · view
| @@ -88,6 +88,17 @@ func searchHref(h control.SearchResult) string { | |||
| 88 | // servePalette answers Cmd+K / 't' jump queries with files, symbols, issues, | 88 | // servePalette answers Cmd+K / 't' jump queries with files, symbols, issues, |
| 89 | // merge requests, and repositories the viewer can read. | 89 | // merge requests, and repositories the viewer can read. |
| 90 | func (s *Server) servePalette(w http.ResponseWriter, r *http.Request, viewer store.User) { | 90 | func (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 | } | ||
| 91 | q := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("q"))) | 102 | q := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("q"))) |
| 92 | repoPath := strings.TrimSpace(r.URL.Query().Get("repo")) | 103 | repoPath := strings.TrimSpace(r.URL.Query().Get("repo")) |
| 93 | var items []paletteEntry | 104 | var items []paletteEntry |
| @@ -116,7 +127,7 @@ func (s *Server) servePalette(w http.ResponseWriter, r *http.Request, viewer sto | |||
| 116 | items = append(items, paletteEntry{ | 127 | items = append(items, paletteEntry{ |
| 117 | Group: "File", | 128 | Group: "File", |
| 118 | Label: e.Name, | 129 | Label: e.Name, |
| 119 | Href: "/" + repo.Path() + "/blob/" + ref + "/" + e.Name, | 130 | Href: "/" + repo.Path() + "/blob/" + escapePath(ref) + "/" + escapePath(e.Name), |
| 120 | }) | 131 | }) |
| 121 | count++ | 132 | count++ |
| 122 | if count >= 40 { | 133 | 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 | |||
| 440 | } | 440 | } |
| 441 | openIssues, openMRs := s.st.OpenCounts(repo.ID) | 441 | openIssues, openMRs := s.st.OpenCounts(repo.ID) |
| 442 | bookmarksCount := s.st.BookmarkCount(repo.ID) | 442 | bookmarksCount := s.st.BookmarkCount(repo.ID) |
| 443 | forksList, _ := s.st.ListForks(repo.ID) | ||
| 444 | return repoPage{ | 443 | return repoPage{ |
| 445 | basePage: s.baseFor(viewer), | 444 | basePage: s.baseFor(viewer), |
| 446 | CanAdmin: canAdmin, | 445 | CanAdmin: canAdmin, |
| @@ -448,7 +447,7 @@ func (s *Server) repoFor(w http.ResponseWriter, r *http.Request, ref string) (re | |||
| 448 | Pinned: pinned, | 447 | Pinned: pinned, |
| 449 | Marked: marked, | 448 | Marked: marked, |
| 450 | Bookmarks: bookmarksCount, | 449 | Bookmarks: bookmarksCount, |
| 451 | Forks: len(forksList), | 450 | Forks: s.st.PublicForkCount(repo.ID), |
| 452 | Watch: watch, | 451 | Watch: watch, |
| 453 | HasWiki: s.hasWiki(repo), | 452 | HasWiki: s.hasWiki(repo), |
| 454 | Host: s.cfg.SiteHost(), | 453 | Host: s.cfg.SiteHost(), |
| @@ -1165,15 +1164,20 @@ func (s *Server) blame(w http.ResponseWriter, r *http.Request) { | |||
| 1165 | blameLexer := lexers.Match(filePath) | 1164 | blameLexer := lexers.Match(filePath) |
| 1166 | var hunks []hunkView | 1165 | var hunks []hunkView |
| 1167 | sigs := map[string]sigView{} | 1166 | 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) | ||
| 1169 | for _, h := range out.Hunks { | 1176 | for _, h := range out.Hunks { |
| 1170 | v, seen := sigs[h.SHA] | 1177 | v, seen := sigs[h.SHA] |
| 1171 | if !seen { | 1178 | if !seen { |
| 1172 | v, _ = s.sigFor(p.Repo, p.Dir, h.SHA) | 1179 | v, _ = s.sigFor(p.Repo, p.Dir, h.SHA) |
| 1173 | sigs[h.SHA] = v | 1180 | sigs[h.SHA] = v |
| 1174 | if ps := gitutil.Parents(p.Dir, h.SHA); len(ps) > 0 { | ||
| 1175 | parents[h.SHA] = ps[0] | ||
| 1176 | } | ||
| 1177 | } | 1181 | } |
| 1178 | date := h.Date | 1182 | date := h.Date |
| 1179 | if t, err := time.Parse(time.RFC3339, h.Date); err == nil { | 1183 | if t, err := time.Parse(time.RFC3339, h.Date); err == nil { |
| @@ -2329,11 +2333,10 @@ type mrRow struct { | |||
| 2329 | 2333 | ||
| 2330 | // summarizeReviews computes the aggregate non-stale review state among | 2334 | // summarizeReviews computes the aggregate non-stale review state among |
| 2331 | // reviewers who count for merge gates: "changes_requested" beats "approved". | 2335 | // reviewers who count for merge gates: "changes_requested" beats "approved". |
| 2332 | func summarizeReviews(st *store.Store, repo store.Repo, revs []store.MRReview) string { | 2336 | func summarizeReviews(revs []store.MRReview, counts map[string]bool) string { |
| 2333 | if len(revs) == 0 { | 2337 | if len(revs) == 0 { |
| 2334 | return "" | 2338 | return "" |
| 2335 | } | 2339 | } |
| 2336 | counts := control.ReviewersWhoCount(st, repo, revs) | ||
| 2337 | latest := map[string]string{} | 2340 | latest := map[string]string{} |
| 2338 | for _, rv := range revs { | 2341 | for _, rv := range revs { |
| 2339 | if rv.Stale || !counts[rv.Reviewer] { | 2342 | if rv.Stale || !counts[rv.Reviewer] { |
| @@ -2409,12 +2412,19 @@ func (s *Server) mrs(w http.ResponseWriter, r *http.Request) { | |||
| 2409 | if err != nil { | 2412 | if err != nil { |
| 2410 | labels = map[int64][]string{} | 2413 | labels = map[int64][]string{} |
| 2411 | } | 2414 | } |
| 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) | ||
| 2412 | rows := make([]mrRow, len(mrs)) | 2422 | rows := make([]mrRow, len(mrs)) |
| 2413 | for i, m := range mrs { | 2423 | for i, m := range mrs { |
| 2414 | m.Labels = labels[m.ID] | 2424 | m.Labels = labels[m.ID] |
| 2415 | rows[i] = mrRow{ | 2425 | rows[i] = mrRow{ |
| 2416 | MR: m, Check: checks[m.HeadSHA], | 2426 | MR: m, Check: checks[m.HeadSHA], |
| 2417 | Review: summarizeReviews(s.st, p.Repo, reviewsMap[m.ID]), | 2427 | Review: summarizeReviews(reviewsMap[m.ID], reviewCounts), |
| 2418 | Comments: comments[m.ID], | 2428 | Comments: comments[m.ID], |
| 2419 | } | 2429 | } |
| 2420 | } | 2430 | } |
| @@ -2498,7 +2508,9 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri | |||
| 2498 | var diffTruncated bool | 2508 | var diffTruncated bool |
| 2499 | selectedCommit := strings.TrimSpace(r.URL.Query().Get("commit")) | 2509 | selectedCommit := strings.TrimSpace(r.URL.Query().Get("commit")) |
| 2500 | if selectedCommit != "" { | 2510 | 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) { | ||
| 2502 | selectedCommit = full | 2514 | selectedCommit = full |
| 2503 | if patch, truncated, err := gitutil.ShowPatch(p.Dir, full, 4<<20); err == nil { | 2515 | if patch, truncated, err := gitutil.ShowPatch(p.Dir, full, 4<<20); err == nil { |
| 2504 | files, diffTruncated = parseDiff(patch), truncated | 2516 | files, diffTruncated = parseDiff(patch), truncated |
| @@ -2506,7 +2518,8 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri | |||
| 2506 | } else { | 2518 | } else { |
| 2507 | selectedCommit = "" | 2519 | selectedCommit = "" |
| 2508 | } | 2520 | } |
| 2509 | } else if base != "" { | 2521 | } |
| 2522 | if selectedCommit == "" && base != "" { | ||
| 2510 | if patch, truncated, err := gitutil.Diff(p.Dir, base, headRef, 4<<20); err == nil { | 2523 | if patch, truncated, err := gitutil.Diff(p.Dir, base, headRef, 4<<20); err == nil { |
| 2511 | files, diffTruncated = parseDiff(patch), truncated | 2524 | files, diffTruncated = parseDiff(patch), truncated |
| 2512 | } | 2525 | } |
| @@ -2540,10 +2553,17 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri | |||
| 2540 | fmt.Sprintf("gitbay mr apply-suggestion %s %d %d", p.Repo.Path(), m.Number, cm.ID)) | 2553 | fmt.Sprintf("gitbay mr apply-suggestion %s %d %d", p.Repo.Path(), m.Number, cm.ID)) |
| 2541 | } | 2554 | } |
| 2542 | } | 2555 | } |
| 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 | } | ||
| 2543 | var detachedThreads []diffThread | 2563 | var detachedThreads []diffThread |
| 2544 | files, detachedThreads = attachThreads(files, diffComments, m.HeadSHA, md, | 2564 | files, detachedThreads = attachThreads(files, threadComments, m.HeadSHA, md, |
| 2545 | reviewRights{Viewer: p.Viewer, MRAuthor: m.Author, Write: canWrite}, suggestions) | 2565 | reviewRights{Viewer: p.Viewer, MRAuthor: m.Author, Write: canWrite}, suggestions) |
| 2546 | if p.Viewer != "" { | 2566 | if p.Viewer != "" && selectedCommit == "" { |
| 2547 | markCompose(files, r.URL.Query()) | 2567 | markCompose(files, r.URL.Query()) |
| 2548 | } | 2568 | } |
| 2549 | layout := s.diffLayoutFor(r) | 2569 | layout := s.diffLayoutFor(r) |
| @@ -2669,6 +2689,20 @@ func (s *Server) mrPage(w http.ResponseWriter, r *http.Request, previewForm stri | |||
| 2669 | sourceGone(p, m), headMerged, headPruned, base, s.labelColors(p.Repo), allLabels, s.repoPeople(p.Repo), d, layout, selectedCommit, bars}) | 2689 | sourceGone(p, m), headMerged, headPruned, base, s.labelColors(p.Repo), allLabels, s.repoPeople(p.Repo), d, layout, selectedCommit, bars}) |
| 2670 | } | 2690 | } |
| 2671 | 2691 | ||
| 2692 | // inRange reports whether sha is one of the commits in base..head. | ||
| 2693 | func 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 | |||
| 2672 | // sourceGone reports whether an MR's source branch no longer exists: the | 2706 | // sourceGone reports whether an MR's source branch no longer exists: the |
| 2673 | // push hook marks a deleted branch on an open MR, and a merged or closed | 2707 | // push hook marks a deleted branch on an open MR, and a merged or closed |
| 2674 | // one is checked here. A fork's branch lives in another repository and | 2708 | // 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) { | |||
| 27 | t.Fatal("duplicate fork name accepted") | 27 | t.Fatal("duplicate fork name accepted") |
| 28 | } | 28 | } |
| 29 | } | 29 | } |
| 30 | |||
| 31 | // A private fork is not counted: the count is shown to anyone who can | ||
| 32 | // read the parent. | ||
| 33 | func 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) { | |||
| 474 | return queryAll(s.DB, scanRepo, repoSelect+" WHERE r.fork_of = ? ORDER BY 4, r.name", repoID) | 474 | return queryAll(s.DB, scanRepo, repoSelect+" WHERE r.fork_of = ? ORDER BY 4, r.name", repoID) |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 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. | ||
| 480 | func (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 | |||
| 477 | func (s *Store) UpdateDefaultBranch(repoID int64, branch string) error { | 486 | func (s *Store) UpdateDefaultBranch(repoID int64, branch string) error { |
| 478 | _, err := s.DB.Exec("UPDATE repos SET default_branch = ? WHERE id = ?", branch, repoID) | 487 | _, err := s.DB.Exec("UPDATE repos SET default_branch = ? WHERE id = ?", branch, repoID) |
| 479 | return err | 488 | return err |
internal/web/static/app.js +62 −19 · view
| @@ -6,7 +6,9 @@ | |||
| 6 | document.documentElement.classList.add('js'); | 6 | document.documentElement.classList.add('js'); |
| 7 | 7 | ||
| 8 | let toastTimer = 0; | 8 | 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() { | ||
| 10 | let el = document.getElementById('gb-toast'); | 12 | let el = document.getElementById('gb-toast'); |
| 11 | if (!el) { | 13 | if (!el) { |
| 12 | el = document.createElement('div'); | 14 | el = document.createElement('div'); |
| @@ -15,6 +17,10 @@ | |||
| 15 | el.setAttribute('role', 'status'); | 17 | el.setAttribute('role', 'status'); |
| 16 | document.body.appendChild(el); | 18 | document.body.appendChild(el); |
| 17 | } | 19 | } |
| 20 | return el; | ||
| 21 | } | ||
| 22 | function showToast(msg, isErr = false) { | ||
| 23 | const el = toastRegion(); | ||
| 18 | el.textContent = msg; | 24 | el.textContent = msg; |
| 19 | el.classList.toggle('toast-err', isErr); | 25 | el.classList.toggle('toast-err', isErr); |
| 20 | el.classList.add('toast-show'); | 26 | el.classList.add('toast-show'); |
| @@ -213,9 +219,13 @@ | |||
| 213 | const newPops = next.querySelectorAll('.popover'); | 219 | const newPops = next.querySelectorAll('.popover'); |
| 214 | if (newPops[keepPopoverIdx]) newPops[keepPopoverIdx].open = true; | 220 | if (newPops[keepPopoverIdx]) newPops[keepPopoverIdx].open = true; |
| 215 | } else if (foldId) { | 221 | } else if (foldId) { |
| 216 | const nextAside = doc.querySelector('.aside'); | 222 | // The pending count shows in the aside on the conversation and |
| 217 | const curAside = document.querySelector('.aside'); | 223 | // in the Review changes popover on the diff view. |
| 218 | if (nextAside && curAside) curAside.replaceWith(nextAside); | 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 | } | ||
| 219 | } else if (swapSel === '#notif-root') { | 229 | } else if (swapSel === '#notif-root') { |
| 220 | const nextBell = doc.querySelector('.rail a[href="/notifications"]'); | 230 | const nextBell = doc.querySelector('.rail a[href="/notifications"]'); |
| 221 | const curBell = document.querySelector('.rail a[href="/notifications"]'); | 231 | const curBell = document.querySelector('.rail a[href="/notifications"]'); |
| @@ -505,9 +515,12 @@ | |||
| 505 | return; | 515 | return; |
| 506 | } | 516 | } |
| 507 | if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && e.target instanceof HTMLTextAreaElement && e.target.form) { | 517 | 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; | ||
| 508 | e.preventDefault(); | 522 | e.preventDefault(); |
| 509 | const btn = e.target.form.querySelector('button[type="submit"]:not([name="preview"]), button:not([type]):not([name="preview"])'); | 523 | if (btns.length) e.target.form.requestSubmit(btns[0]); |
| 510 | if (btn) e.target.form.requestSubmit(btn); | ||
| 511 | else e.target.form.requestSubmit(); | 524 | else e.target.form.requestSubmit(); |
| 512 | return; | 525 | return; |
| 513 | } | 526 | } |
| @@ -602,7 +615,14 @@ | |||
| 602 | if (prevTheme === 'system') delete document.documentElement.dataset.theme; | 615 | if (prevTheme === 'system') delete document.documentElement.dataset.theme; |
| 603 | else document.documentElement.dataset.theme = prevTheme; | 616 | else document.documentElement.dataset.theme = prevTheme; |
| 604 | } | 617 | } |
| 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) { | ||
| 606 | const serverCtl = doc.getElementById(e.target.id); | 626 | const serverCtl = doc.getElementById(e.target.id); |
| 607 | if (serverCtl instanceof HTMLInputElement && e.target instanceof HTMLInputElement && serverCtl.type === 'checkbox') { | 627 | if (serverCtl instanceof HTMLInputElement && e.target instanceof HTMLInputElement && serverCtl.type === 'checkbox') { |
| 608 | e.target.checked = serverCtl.checked; | 628 | e.target.checked = serverCtl.checked; |
| @@ -901,15 +921,24 @@ | |||
| 901 | 921 | ||
| 902 | // Inline hunk context expansion ("↑ Expand") | 922 | // Inline hunk context expansion ("↑ Expand") |
| 903 | if (repo && head) { | 923 | if (repo && head) { |
| 904 | const hunkRe = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/; | 924 | const hunkRe = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,(\d+))? @@/; |
| 905 | for (const tr of wrap.querySelectorAll('tr.hunk[data-hunk][data-file]')) { | 925 | for (const tr of wrap.querySelectorAll('tr.hunk[data-hunk][data-file]')) { |
| 906 | if (tr.dataset.expandWired) continue; | 926 | if (tr.dataset.expandWired) continue; |
| 907 | tr.dataset.expandWired = '1'; | 927 | 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; | ||
| 908 | const m = hunkRe.exec(tr.dataset.hunk || ''); | 930 | const m = hunkRe.exec(tr.dataset.hunk || ''); |
| 909 | if (!m) continue; | 931 | if (!m) continue; |
| 910 | let curNewStart = parseInt(m[2], 10); | 932 | let curNewStart = parseInt(m[2], 10); |
| 911 | let curOldStart = parseInt(m[1], 10); | 933 | 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; | ||
| 913 | const srcTd = tr.querySelector('td.src'); | 942 | const srcTd = tr.querySelector('td.src'); |
| 914 | if (!srcTd) continue; | 943 | if (!srcTd) continue; |
| 915 | const btn = document.createElement('button'); | 944 | const btn = document.createElement('button'); |
| @@ -919,11 +948,11 @@ | |||
| 919 | btn.title = 'Load up to 20 preceding context lines'; | 948 | btn.title = 'Load up to 20 preceding context lines'; |
| 920 | btn.addEventListener('click', async () => { | 949 | btn.addEventListener('click', async () => { |
| 921 | const to = curNewStart - 1; | 950 | const to = curNewStart - 1; |
| 922 | const from = Math.max(1, to - 19); | 951 | const from = Math.max(floor, to - 19); |
| 923 | if (to < 1) { btn.remove(); return; } | 952 | if (to < floor) { btn.remove(); return; } |
| 924 | btn.disabled = true; | 953 | btn.disabled = true; |
| 925 | try { | 954 | try { |
| 926 | const fpath = tr.dataset.file; | 955 | const fpath = tr.dataset.file.split('/').map(encodeURIComponent).join('/'); |
| 927 | const res = await fetch(`/${repo}/blob/${head}/${fpath}?lines=${from}:${to}`, { credentials: 'same-origin' }); | 956 | const res = await fetch(`/${repo}/blob/${head}/${fpath}?lines=${from}:${to}`, { credentials: 'same-origin' }); |
| 928 | if (!res.ok) throw new Error('fetch'); | 957 | if (!res.ok) throw new Error('fetch'); |
| 929 | const data = await res.json(); | 958 | const data = await res.json(); |
| @@ -957,7 +986,7 @@ | |||
| 957 | inserted.reverse().forEach((n) => tr.parentNode.insertBefore(n, sib)); | 986 | inserted.reverse().forEach((n) => tr.parentNode.insertBefore(n, sib)); |
| 958 | curOldStart = Math.max(1, curOldStart - (curNewStart - from)); | 987 | curOldStart = Math.max(1, curOldStart - (curNewStart - from)); |
| 959 | curNewStart = from; | 988 | curNewStart = from; |
| 960 | if (curNewStart <= 1) btn.remove(); | 989 | if (curNewStart <= floor) btn.remove(); |
| 961 | } catch { | 990 | } catch { |
| 962 | showToast('Could not expand context', true); | 991 | showToast('Could not expand context', true); |
| 963 | } finally { | 992 | } finally { |
| @@ -1015,13 +1044,13 @@ | |||
| 1015 | const writeTab = document.createElement('button'); | 1044 | const writeTab = document.createElement('button'); |
| 1016 | writeTab.type = 'button'; | 1045 | writeTab.type = 'button'; |
| 1017 | writeTab.className = 'composer-tab'; | 1046 | writeTab.className = 'composer-tab'; |
| 1018 | writeTab.setAttribute('aria-selected', 'true'); | 1047 | writeTab.setAttribute('aria-pressed', 'true'); |
| 1019 | writeTab.textContent = 'Write'; | 1048 | writeTab.textContent = 'Write'; |
| 1020 | 1049 | ||
| 1021 | const prevTab = document.createElement('button'); | 1050 | const prevTab = document.createElement('button'); |
| 1022 | prevTab.type = 'button'; | 1051 | prevTab.type = 'button'; |
| 1023 | prevTab.className = 'composer-tab'; | 1052 | prevTab.className = 'composer-tab'; |
| 1024 | prevTab.setAttribute('aria-selected', 'false'); | 1053 | prevTab.setAttribute('aria-pressed', 'false'); |
| 1025 | prevTab.textContent = 'Preview'; | 1054 | prevTab.textContent = 'Preview'; |
| 1026 | 1055 | ||
| 1027 | const hint = document.createElement('span'); | 1056 | const hint = document.createElement('span'); |
| @@ -1039,16 +1068,16 @@ | |||
| 1039 | previewBtn.classList.add('js-hidden-preview'); | 1068 | previewBtn.classList.add('js-hidden-preview'); |
| 1040 | 1069 | ||
| 1041 | writeTab.addEventListener('click', () => { | 1070 | writeTab.addEventListener('click', () => { |
| 1042 | writeTab.setAttribute('aria-selected', 'true'); | 1071 | writeTab.setAttribute('aria-pressed', 'true'); |
| 1043 | prevTab.setAttribute('aria-selected', 'false'); | 1072 | prevTab.setAttribute('aria-pressed', 'false'); |
| 1044 | pane.hidden = true; | 1073 | pane.hidden = true; |
| 1045 | wrapTarget.hidden = false; | 1074 | wrapTarget.hidden = false; |
| 1046 | ta.focus(); | 1075 | ta.focus(); |
| 1047 | }); | 1076 | }); |
| 1048 | 1077 | ||
| 1049 | prevTab.addEventListener('click', async () => { | 1078 | prevTab.addEventListener('click', async () => { |
| 1050 | writeTab.setAttribute('aria-selected', 'false'); | 1079 | writeTab.setAttribute('aria-pressed', 'false'); |
| 1051 | prevTab.setAttribute('aria-selected', 'true'); | 1080 | prevTab.setAttribute('aria-pressed', 'true'); |
| 1052 | wrapTarget.hidden = true; | 1081 | wrapTarget.hidden = true; |
| 1053 | pane.hidden = false; | 1082 | pane.hidden = false; |
| 1054 | if (!ta.value.trim()) { | 1083 | if (!ta.value.trim()) { |
| @@ -1086,6 +1115,10 @@ | |||
| 1086 | 1115 | ||
| 1087 | function closeAutocomplete() { | 1116 | function closeAutocomplete() { |
| 1088 | if (acMenu) acMenu.hidden = true; | 1117 | if (acMenu) acMenu.hidden = true; |
| 1118 | if (acContext) { | ||
| 1119 | acContext.ta.setAttribute('aria-expanded', 'false'); | ||
| 1120 | acContext.ta.removeAttribute('aria-activedescendant'); | ||
| 1121 | } | ||
| 1089 | acItems = []; | 1122 | acItems = []; |
| 1090 | acContext = null; | 1123 | acContext = null; |
| 1091 | } | 1124 | } |
| @@ -1094,6 +1127,8 @@ | |||
| 1094 | if (acMenu) return acMenu; | 1127 | if (acMenu) return acMenu; |
| 1095 | acMenu = document.createElement('ul'); | 1128 | acMenu = document.createElement('ul'); |
| 1096 | acMenu.className = 'ac-menu'; | 1129 | acMenu.className = 'ac-menu'; |
| 1130 | acMenu.id = 'ac-menu'; | ||
| 1131 | acMenu.setAttribute('role', 'listbox'); | ||
| 1097 | acMenu.hidden = true; | 1132 | acMenu.hidden = true; |
| 1098 | document.body.appendChild(acMenu); | 1133 | document.body.appendChild(acMenu); |
| 1099 | return acMenu; | 1134 | return acMenu; |
| @@ -1122,6 +1157,9 @@ | |||
| 1122 | acItems.forEach((it, idx) => { | 1157 | acItems.forEach((it, idx) => { |
| 1123 | const li = document.createElement('li'); | 1158 | const li = document.createElement('li'); |
| 1124 | li.className = idx === acIndex ? 'ac-active' : ''; | 1159 | 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'); | ||
| 1125 | const b = document.createElement('strong'); | 1163 | const b = document.createElement('strong'); |
| 1126 | b.textContent = it.insert; | 1164 | b.textContent = it.insert; |
| 1127 | const sp = document.createElement('span'); | 1165 | const sp = document.createElement('span'); |
| @@ -1137,6 +1175,10 @@ | |||
| 1137 | menu.style.left = `${Math.max(8, rect.left + window.scrollX + 12)}px`; | 1175 | menu.style.left = `${Math.max(8, rect.left + window.scrollX + 12)}px`; |
| 1138 | menu.style.top = `${rect.top + window.scrollY + Math.min(rect.height, 42)}px`; | 1176 | menu.style.top = `${rect.top + window.scrollY + Math.min(rect.height, 42)}px`; |
| 1139 | menu.hidden = false; | 1177 | 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}`); | ||
| 1140 | } | 1182 | } |
| 1141 | 1183 | ||
| 1142 | function collectPagePeople() { | 1184 | function collectPagePeople() { |
| @@ -1221,6 +1263,7 @@ | |||
| 1221 | }, true); | 1263 | }, true); |
| 1222 | 1264 | ||
| 1223 | function bootAll() { | 1265 | function bootAll() { |
| 1266 | toastRegion(); | ||
| 1224 | initCopyButtons(); | 1267 | initCopyButtons(); |
| 1225 | initScrollSpy(); | 1268 | initScrollSpy(); |
| 1226 | initPanelTabs(); | 1269 | initPanelTabs(); |
internal/web/static/style.css +18 −18 · view
| @@ -132,6 +132,8 @@ | |||
| 132 | 132 | ||
| 133 | --r-ctl: 4px; /* controls and chips */ | 133 | --r-ctl: 4px; /* controls and chips */ |
| 134 | --r-card: 6px; /* cards, lists, code blocks */ | 134 | --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); | ||
| 135 | --shadow: 0 4px 16px rgba(0, 0, 0, 0.12); | 137 | --shadow: 0 4px 16px rgba(0, 0, 0, 0.12); |
| 136 | 138 | ||
| 137 | /* the native select arrow cannot be restyled, so draw our own; | 139 | /* the native select arrow cannot be restyled, so draw our own; |
| @@ -401,12 +403,6 @@ a.railuser { | |||
| 401 | height: var(--rail-strip-h); | 403 | height: var(--rail-strip-h); |
| 402 | } | 404 | } |
| 403 | a.railuser:hover { text-decoration: none; } | 405 | a.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); } | ||
| 410 | .raildrop { | 406 | .raildrop { |
| 411 | position: absolute; | 407 | position: absolute; |
| 412 | top: 100%; | 408 | top: 100%; |
| @@ -874,7 +870,7 @@ ul.milestonelist, .readme, .code, article.release, .blame, .teambody { | |||
| 874 | background: var(--card); | 870 | background: var(--card); |
| 875 | border: 1px solid var(--card-line); | 871 | border: 1px solid var(--card-line); |
| 876 | border-radius: var(--r-card); | 872 | border-radius: var(--r-card); |
| 877 | box-shadow: 0 1px 2px rgb(0 0 0 / 0.03); | 873 | box-shadow: var(--shadow-card); |
| 878 | overflow: hidden; | 874 | overflow: hidden; |
| 879 | } | 875 | } |
| 880 | .cardhead { | 876 | .cardhead { |
| @@ -920,7 +916,7 @@ table.tree, table.refs { | |||
| 920 | background: var(--card); | 916 | background: var(--card); |
| 921 | border: 1px solid var(--card-line); | 917 | border: 1px solid var(--card-line); |
| 922 | border-radius: var(--r-card); | 918 | border-radius: var(--r-card); |
| 923 | box-shadow: 0 1px 2px rgb(0 0 0 / 0.03); | 919 | box-shadow: var(--shadow-card); |
| 924 | /* collapsed borders defeat a radius on the table itself */ | 920 | /* collapsed borders defeat a radius on the table itself */ |
| 925 | border-collapse: separate; | 921 | border-collapse: separate; |
| 926 | border-spacing: 0; | 922 | border-spacing: 0; |
| @@ -960,9 +956,11 @@ table.keys, table.assets { background: none; border: 0; border-radius: 0; } | |||
| 960 | table.keys th, table.assets th, table.keys tr.cols th { background: transparent; padding-left: 0; } | 956 | table.keys th, table.assets th, table.keys tr.cols th { background: transparent; padding-left: 0; } |
| 961 | table.keys td { padding-left: 0; } | 957 | table.keys td { padding-left: 0; } |
| 962 | table.keys td.act, table.assets td.size { text-align: right; } | 958 | table.keys td.act, table.assets td.size { text-align: right; } |
| 963 | /* a fingerprint or an account row is read across, not down: the cells | 959 | /* an account row is read across, not down: the cells keep one line |
| 964 | keep one line each and .tablewrap scrolls what does not fit */ | 960 | each. A fingerprint, URL or id wraps instead, since .setcard |
| 961 | .tablewrap does not scroll (popovers would be clipped) */ | ||
| 965 | table.keys.nowrap th, table.keys.nowrap td { white-space: nowrap; } | 962 | table.keys.nowrap th, table.keys.nowrap td { white-space: nowrap; } |
| 963 | table.keys td.mono { white-space: normal; overflow-wrap: anywhere; } | ||
| 966 | /* The account list types a username to confirm, which is longer than | 964 | /* The account list types a username to confirm, which is longer than |
| 967 | the key prefixes the confirm field is sized for elsewhere. 14rem, not | 965 | the key prefixes the confirm field is sized for elsewhere. 14rem, not |
| 968 | 11rem, because "type <name> to confirm" was cut mid-word for a name of | 966 | 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 | |||
| 2280 | cursor: pointer; | 2278 | cursor: pointer; |
| 2281 | } | 2279 | } |
| 2282 | .cmdk-trigger:hover { color: var(--shell-fg); border-color: var(--shell-muted); filter: none; } | 2280 | .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; } |
| 2284 | dialog.cmdk { | 2282 | dialog.cmdk { |
| 2285 | padding: 0; | 2283 | padding: 0; |
| 2286 | border: 1px solid var(--faint); | 2284 | border: 1px solid var(--faint); |
| @@ -2360,7 +2358,7 @@ dialog.cmdk::backdrop { background: rgb(0 0 0 / 0.45); } | |||
| 2360 | background: var(--card); | 2358 | background: var(--card); |
| 2361 | border: 1px solid var(--card-line); | 2359 | border: 1px solid var(--card-line); |
| 2362 | border-radius: var(--r-card); | 2360 | border-radius: var(--r-card); |
| 2363 | box-shadow: 0 1px 2px rgb(0 0 0 / 0.03); | 2361 | box-shadow: var(--shadow-card); |
| 2364 | padding: var(--sp-5); | 2362 | padding: var(--sp-5); |
| 2365 | margin: 0 0 var(--sp-5); | 2363 | margin: 0 0 var(--sp-5); |
| 2366 | } | 2364 | } |
| @@ -2424,7 +2422,7 @@ html.js form.setform[data-autosave] > div:has(> button[type="submit"]) { display | |||
| 2424 | background: var(--card); | 2422 | background: var(--card); |
| 2425 | border: 1px solid var(--card-line); | 2423 | border: 1px solid var(--card-line); |
| 2426 | border-radius: var(--r-card); | 2424 | border-radius: var(--r-card); |
| 2427 | box-shadow: 0 1px 2px rgb(0 0 0 / 0.03); | 2425 | box-shadow: var(--shadow-card); |
| 2428 | padding: var(--sp-4); | 2426 | padding: var(--sp-4); |
| 2429 | } | 2427 | } |
| 2430 | .dashcard-head { | 2428 | .dashcard-head { |
| @@ -2450,7 +2448,7 @@ html.js form.setform[data-autosave] > div:has(> button[type="submit"]) { display | |||
| 2450 | background: var(--card); | 2448 | background: var(--card); |
| 2451 | border: 1px solid var(--card-line); | 2449 | border: 1px solid var(--card-line); |
| 2452 | border-radius: var(--r-card); | 2450 | border-radius: var(--r-card); |
| 2453 | box-shadow: 0 1px 2px rgb(0 0 0 / 0.03); | 2451 | box-shadow: var(--shadow-card); |
| 2454 | padding: var(--sp-5); | 2452 | padding: var(--sp-5); |
| 2455 | margin-bottom: var(--sp-4); | 2453 | margin-bottom: var(--sp-4); |
| 2456 | } | 2454 | } |
| @@ -2519,7 +2517,7 @@ ul.issuelist li.unread { | |||
| 2519 | background: var(--card); | 2517 | background: var(--card); |
| 2520 | border: 1px solid var(--card-line); | 2518 | border: 1px solid var(--card-line); |
| 2521 | border-radius: var(--r-card); | 2519 | border-radius: var(--r-card); |
| 2522 | box-shadow: 0 1px 2px rgb(0 0 0 / 0.03); | 2520 | box-shadow: var(--shadow-card); |
| 2523 | padding: var(--sp-4); | 2521 | padding: var(--sp-4); |
| 2524 | } | 2522 | } |
| 2525 | .popform-stack { | 2523 | .popform-stack { |
| @@ -2637,11 +2635,11 @@ details.difffold .tablewrap { border-radius: 0 0 var(--r-card) var(--r-card); ov | |||
| 2637 | .difftoc-list li.toc-viewed a { color: var(--muted); text-decoration: line-through; } | 2635 | .difftoc-list li.toc-viewed a { color: var(--muted); text-decoration: line-through; } |
| 2638 | .idiff-del { | 2636 | .idiff-del { |
| 2639 | background: color-mix(in srgb, var(--bad) 26%, transparent); | 2637 | background: color-mix(in srgb, var(--bad) 26%, transparent); |
| 2640 | border-radius: 2px; | 2638 | border-radius: var(--r-mark); |
| 2641 | } | 2639 | } |
| 2642 | .idiff-add { | 2640 | .idiff-add { |
| 2643 | background: color-mix(in srgb, var(--ok) 26%, transparent); | 2641 | background: color-mix(in srgb, var(--ok) 26%, transparent); |
| 2644 | border-radius: 2px; | 2642 | border-radius: var(--r-mark); |
| 2645 | } | 2643 | } |
| 2646 | .hunk-expand { | 2644 | .hunk-expand { |
| 2647 | display: inline-flex; | 2645 | display: inline-flex; |
| @@ -2743,7 +2741,7 @@ kbd { | |||
| 2743 | margin-bottom: -1px; | 2741 | margin-bottom: -1px; |
| 2744 | } | 2742 | } |
| 2745 | .composer-tab:hover { color: var(--fg); background: var(--hover); filter: none; } | 2743 | .composer-tab:hover { color: var(--fg); background: var(--hover); filter: none; } |
| 2746 | .composer-tab[aria-selected="true"] { | 2744 | .composer-tab[aria-pressed="true"] { |
| 2747 | color: var(--fg); | 2745 | color: var(--fg); |
| 2748 | font-weight: 600; | 2746 | font-weight: 600; |
| 2749 | border-bottom-color: var(--mark); | 2747 | border-bottom-color: var(--mark); |
| @@ -2764,6 +2762,8 @@ kbd { | |||
| 2764 | background: var(--inset); | 2762 | background: var(--inset); |
| 2765 | } | 2763 | } |
| 2766 | html.js button.js-hidden-preview { display: none; } | 2764 | html.js button.js-hidden-preview { display: none; } |
| 2765 | /* controls that only work through app.js */ | ||
| 2766 | html:not(.js) :is(.cmdk-trigger, .kbhelp-trigger, .quote-btn, [data-copy], [data-copy-url], [data-refresh]) { display: none; } | ||
| 2767 | .ac-menu { | 2767 | .ac-menu { |
| 2768 | position: absolute; | 2768 | position: absolute; |
| 2769 | z-index: 70; | 2769 | z-index: 70; |
internal/web/templates/build.html +1 −1 · view
| @@ -11,7 +11,7 @@ | |||
| 11 | {{if and .CanWrite (not .Live) .Build.Job (ne .Build.Status "pending") (ne .Build.Status "running")}} | 11 | {{if and .CanWrite (not .Live) .Build.Job (ne .Build.Status "pending") (ne .Build.Status "running")}} |
| 12 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/builds" class="inline"> | 12 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/builds" class="inline"> |
| 13 | <input type="hidden" name="job" value="{{.Build.Job}}"> | 13 | <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> |
| 15 | </form> | 15 | </form> |
| 16 | {{end}} | 16 | {{end}} |
| 17 | {{if and .CanWrite (or (eq .Build.Status "pending") (eq .Build.Status "running"))}} | 17 | {{if and .CanWrite (or (eq .Build.Status "pending") (eq .Build.Status "running"))}} |
internal/web/templates/layout.html +4 −4 · view
| @@ -57,10 +57,10 @@ | |||
| 57 | <a href="/{{.Viewer}}/-/bookmarks">{{template "icon" "star"}} Bookmarks</a> | 57 | <a href="/{{.Viewer}}/-/bookmarks">{{template "icon" "star"}} Bookmarks</a> |
| 58 | {{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}} | 58 | {{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}} |
| 59 | <hr class="railsep"> | 59 | <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> | 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 2}}{{if $admin.Show}}<a{{if $admin.Current}} aria-current="page"{{end}} href="{{$admin.Href}}">{{template "icon" $admin.Icon}} {{$admin.Name}}</a>{{end}} | 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}} |
| 62 | <hr class="railsep"> | 62 | <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> |
| 64 | </div> | 64 | </div> |
| 65 | </details> | 65 | </details> |
| 66 | {{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}} | 66 | {{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 @@ | |||
| 284 | <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> | 284 | <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> |
| 285 | </details>{{end}} | 285 | </details>{{end}} |
| 286 | <div class="difflist"> | 286 | <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}}> |
| 288 | <summary> | 288 | <summary> |
| 289 | <span class="fpath">{{if eq .Status "renamed"}}<span class="was">{{.OldPath}} →</span> {{end}}{{.Path}}</span> | 289 | <span class="fpath">{{if eq .Status "renamed"}}<span class="was">{{.OldPath}} →</span> {{end}}{{.Path}}</span> |
| 290 | {{if ne .Status "modified"}}<span class="chip">{{.Status}}</span>{{end}} | 290 | {{if ne .Status "modified"}}<span class="chip">{{.Status}}</span>{{end}} |
internal/web/templates/mr.html +3 −1 · view
| @@ -49,7 +49,9 @@ | |||
| 49 | {{end}} | 49 | {{end}} |
| 50 | {{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> | 50 | {{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> |
| 51 | {{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}} | 51 | {{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}}&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}} | ||
| 53 | {{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> | 55 | {{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> |
| 54 | {{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}} | 56 | {{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}} |
| 55 | 57 | ||
internal/web/templates/queries.html +1 −1 · view
| @@ -77,7 +77,7 @@ | |||
| 77 | </details> | 77 | </details> |
| 78 | </section> | 78 | </section> |
| 79 | {{if .AdHoc}} | 79 | {{if .AdHoc}} |
| 80 | <h2>Results <span class="count">{{.Count}}</span></h2> | 80 | <h2>Results</h2> |
| 81 | {{template "queryrows" .}} | 81 | {{template "queryrows" .}} |
| 82 | {{end}} | 82 | {{end}} |
| 83 | <ul class="issuelist rows" id="saved-queries"> | 83 | <ul class="issuelist rows" id="saved-queries"> |
internal/web/templates/settings.html +8 −8 · view
| @@ -60,7 +60,7 @@ | |||
| 60 | </section> | 60 | </section> |
| 61 | 61 | ||
| 62 | <section id="access" class="setcard"><h2>Access</h2> | 62 | <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"> |
| 64 | <input type="hidden" name="field" value="visibility"> | 64 | <input type="hidden" name="field" value="visibility"> |
| 65 | <div><span class="fieldname">Visibility</span></div> | 65 | <div><span class="fieldname">Visibility</span></div> |
| 66 | <div class="check"> | 66 | <div class="check"> |
| @@ -69,7 +69,7 @@ | |||
| 69 | </div> | 69 | </div> |
| 70 | <div><button type="submit" class="btn">Save</button></div> | 70 | <div><button type="submit" class="btn">Save</button></div> |
| 71 | </form> | 71 | </form> |
| 72 | <form method="post" action="{{$base}}" class="setform" data-autosave="1"> | 72 | <form method="post" action="{{$base}}" class="setform"> |
| 73 | <input type="hidden" name="field" value="git-daemon"> | 73 | <input type="hidden" name="field" value="git-daemon"> |
| 74 | <div><label for="git-daemon">Serve over git://</label><p class="hint">Public repositories only.</p></div> | 74 | <div><label for="git-daemon">Serve over git://</label><p class="hint">Public repositories only.</p></div> |
| 75 | <div class="check"><input type="checkbox" id="git-daemon" name="git-daemon" value="on"{{if .Repo.Settings.GitDaemon}} checked{{end}}></div> | 75 | <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 @@ | |||
| 144 | 144 | ||
| 145 | <section id="gates" class="setcard"><h2>Merge gates</h2> | 145 | <section id="gates" class="setcard"><h2>Merge gates</h2> |
| 146 | <p class="meta">Checked before a merge, in this order: checks, approvals, resolved threads, signatures.</p> | 146 | <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"> |
| 148 | <input type="hidden" name="field" value="require-checks"> | 148 | <input type="hidden" name="field" value="require-checks"> |
| 149 | <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> | 149 | <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> |
| 150 | <div class="check"><input type="checkbox" id="require-checks" name="require-checks" value="on"{{if .Repo.Settings.RequireChecks}} checked{{end}}></div> | 150 | <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 @@ | |||
| 162 | <div class="num"><input type="number" id="approvals" name="approvals" min="0" max="10" value="{{.Repo.Settings.RequireApprovals}}"></div> | 162 | <div class="num"><input type="number" id="approvals" name="approvals" min="0" max="10" value="{{.Repo.Settings.RequireApprovals}}"></div> |
| 163 | <div><button type="submit" class="btn">Save</button></div> | 163 | <div><button type="submit" class="btn">Save</button></div> |
| 164 | </form> | 164 | </form> |
| 165 | <form method="post" action="{{$base}}" class="setform" data-autosave="1"> | 165 | <form method="post" action="{{$base}}" class="setform"> |
| 166 | <input type="hidden" name="field" value="require-resolved"> | 166 | <input type="hidden" name="field" value="require-resolved"> |
| 167 | <div><label for="require-resolved">Review threads</label><p class="hint">Every thread on the diff must be resolved before merging.</p></div> | 167 | <div><label for="require-resolved">Review threads</label><p class="hint">Every thread on the diff must be resolved before merging.</p></div> |
| 168 | <div class="check"><input type="checkbox" id="require-resolved" name="require-resolved" value="on"{{if .Repo.Settings.RequireResolved}} checked{{end}}></div> | 168 | <div class="check"><input type="checkbox" id="require-resolved" name="require-resolved" value="on"{{if .Repo.Settings.RequireResolved}} checked{{end}}></div> |
| 169 | <div><button type="submit" class="btn">Save</button></div> | 169 | <div><button type="submit" class="btn">Save</button></div> |
| 170 | </form> | 170 | </form> |
| 171 | <form method="post" action="{{$base}}" class="setform" data-autosave="1"> | 171 | <form method="post" action="{{$base}}" class="setform"> |
| 172 | <input type="hidden" name="field" value="require-codeowners"> | 172 | <input type="hidden" name="field" value="require-codeowners"> |
| 173 | <div><label for="require-codeowners">CODEOWNERS</label><p class="hint">Code owners must approve.</p></div> | 173 | <div><label for="require-codeowners">CODEOWNERS</label><p class="hint">Code owners must approve.</p></div> |
| 174 | <div class="check"><input type="checkbox" id="require-codeowners" name="require-codeowners" value="on"{{if .Repo.Settings.RequireCodeowners}} checked{{end}}></div> | 174 | <div class="check"><input type="checkbox" id="require-codeowners" name="require-codeowners" value="on"{{if .Repo.Settings.RequireCodeowners}} checked{{end}}></div> |
| 175 | <div><button type="submit" class="btn">Save</button></div> | 175 | <div><button type="submit" class="btn">Save</button></div> |
| 176 | </form> | 176 | </form> |
| 177 | <form method="post" action="{{$base}}" class="setform" data-autosave="1"> | 177 | <form method="post" action="{{$base}}" class="setform"> |
| 178 | <input type="hidden" name="field" value="require-signed"> | 178 | <input type="hidden" name="field" value="require-signed"> |
| 179 | <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> | 179 | <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> |
| 180 | <div class="check"><input type="checkbox" id="require-signed" name="require-signed" value="on"{{if .Repo.Settings.RequireSignedCommits}} checked{{end}}></div> | 180 | <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 @@ | |||
| 245 | {{end}} | 245 | {{end}} |
| 246 | 246 | ||
| 247 | <section id="secrets" class="setcard"><h2>Secret scan</h2> | 247 | <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"> |
| 249 | <input type="hidden" name="field" value="secret-scan"> | 249 | <input type="hidden" name="field" value="secret-scan"> |
| 250 | <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> | 250 | <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> |
| 251 | <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> | 251 | <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 @@ | |||
| 277 | <div><select id="branch" name="branch">{{range .Branches}}<option value="{{.Name}}">{{.Name}}</option>{{end}}</select></div> | 277 | <div><select id="branch" name="branch">{{range .Branches}}<option value="{{.Name}}">{{.Name}}</option>{{end}}</select></div> |
| 278 | <div><button type="submit" class="btn">Protect</button></div> | 278 | <div><button type="submit" class="btn">Protect</button></div> |
| 279 | </form> | 279 | </form> |
| 280 | <form method="post" action="{{$base}}" class="setform" data-autosave="1"> | 280 | <form method="post" action="{{$base}}" class="setform"> |
| 281 | <input type="hidden" name="field" value="require-mr"> | 281 | <input type="hidden" name="field" value="require-mr"> |
| 282 | <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> | 282 | <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> |
| 283 | <div class="check"><input type="checkbox" id="require-mr" name="require-mr" value="on"{{if .Repo.Settings.RequireMR}} checked{{end}}></div> | 283 | <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 | |||
| 40 | var StyleVersion string | 40 | var StyleVersion string |
| 41 | var ScriptVersion string | 41 | var ScriptVersion string |
| 42 | 42 | ||
| 43 | // railItem is one destination the rail's icon strip and the phone | 43 | // railItem is one destination of the account menu. |
| 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). | ||
| 46 | type railItem struct { | 44 | type railItem struct { |
| 47 | Href string | 45 | Href string |
| 48 | Icon string | 46 | Icon string |
| @@ -83,8 +81,8 @@ func railBool(v any, name string) bool { | |||
| 83 | return f.IsValid() && f.Kind() == reflect.Bool && f.Bool() | 81 | return f.IsValid() && f.Kind() == reflect.Bool && f.Bool() |
| 84 | } | 82 | } |
| 85 | 83 | ||
| 86 | // railOptItems is the rail's "New repository", "Settings", "Admin" and | 84 | // railOptItems is the account menu's "Settings", "Admin" and "Log out" |
| 87 | // "Log out" destinations, in the order the rail shows them. v is the | 85 | // destinations, in the order the menu shows them. v is the |
| 88 | // page value the layout renders (any page struct that embeds | 86 | // page value the layout renders (any page struct that embeds |
| 89 | // basePage), read by field name since the layout has no single common | 87 | // basePage), read by field name since the layout has no single common |
| 90 | // type for every page. | 88 | // type for every page. |
| @@ -92,7 +90,6 @@ func railOptItems(v any) []railItem { | |||
| 92 | tab := railField(v, "Tab") | 90 | tab := railField(v, "Tab") |
| 93 | admin := railBool(v, "Admin") | 91 | admin := railBool(v, "Admin") |
| 94 | return []railItem{ | 92 | return []railItem{ |
| 95 | {Href: "/new", Icon: "plus", Name: "New repository", Show: true}, | ||
| 96 | {Href: "/settings", Icon: "gear", Name: "Settings", Current: tab == "account", Show: true}, | 93 | {Href: "/settings", Icon: "gear", Name: "Settings", Current: tab == "account", Show: true}, |
| 97 | {Href: "/admin", Icon: "shield", Name: "Admin", Current: tab == "admin", Show: admin}, | 94 | {Href: "/admin", Icon: "shield", Name: "Admin", Current: tab == "admin", Show: admin}, |
| 98 | {Href: "/logout", Icon: "signout", Name: "Log out", Show: true}, | 95 | {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) { | |||
| 243 | } | 243 | } |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | // The main rail and the phone "More" menu render New repository, | 246 | // The account menu renders Settings, Admin and Log out from one list. |
| 247 | // Settings, Admin and Log out from one list, so adding a destination in | ||
| 248 | // one place reaches both (#271). | ||
| 249 | func TestRailOptItemsDriveBothRailAndMoreMenu(t *testing.T) { | 247 | func TestRailOptItemsDriveBothRailAndMoreMenu(t *testing.T) { |
| 250 | items := railOptItems(struct { | 248 | items := railOptItems(struct { |
| 251 | Tab string | 249 | Tab string |
| 252 | Admin bool | 250 | Admin bool |
| 253 | }{Tab: "admin", Admin: true}) | 251 | }{Tab: "admin", Admin: true}) |
| 254 | if len(items) != 4 { | 252 | if len(items) != 3 { |
| 255 | t.Fatalf("got %d items, want 4 (New repository, Settings, Admin, Log out)", len(items)) | 253 | t.Fatalf("got %d items, want 3 (Settings, Admin, Log out)", len(items)) |
| 256 | } | 254 | } |
| 257 | if items[2].Name != "Admin" || !items[2].Show { | 255 | if items[1].Name != "Admin" || !items[1].Show { |
| 258 | t.Errorf("Admin item: %+v", items[2]) | 256 | t.Errorf("Admin item: %+v", items[1]) |
| 259 | } | 257 | } |
| 260 | if !items[2].Current { | 258 | if !items[1].Current { |
| 261 | t.Error("Admin item should be Current when Tab is admin") | 259 | t.Error("Admin item should be Current when Tab is admin") |
| 262 | } | 260 | } |
| 263 | 261 | ||
| @@ -265,10 +263,10 @@ func TestRailOptItemsDriveBothRailAndMoreMenu(t *testing.T) { | |||
| 265 | Tab string | 263 | Tab string |
| 266 | Admin bool | 264 | Admin bool |
| 267 | }{Tab: "account"}) | 265 | }{Tab: "account"}) |
| 268 | if nonAdmin[2].Show { | 266 | if nonAdmin[1].Show { |
| 269 | t.Error("Admin item should not Show for a non-admin viewer") | 267 | t.Error("Admin item should not Show for a non-admin viewer") |
| 270 | } | 268 | } |
| 271 | if !nonAdmin[1].Current { | 269 | if !nonAdmin[0].Current { |
| 272 | t.Error("Settings item should be Current when Tab is account") | 270 | t.Error("Settings item should be Current when Tab is account") |
| 273 | } | 271 | } |
| 274 | 272 | ||