BlueGit

timfa bluegit

fix: toon mergeblokkades en markeer een al gepushte merge

De mergeknop legt uit waarom samenvoegen niet mag. Een beheerder kan
toch mergen, met bevestiging en een regel in de activiteit. Een push
waarin de bron-head al in de doelbranch zit zet de merge request op
merged. De branchpagina houdt acties op één rij, vult de MR-kolom en
toont een korte relatieve tijd.

Co-authored-by: tim <tim@timfalken.com>

timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa

Authored 2026-10-22 · 3 weeks ago

Hash
81edde89328af4b716df3cc53746e065ee094236
Parent
4bb9fce0
19 files changed +729 −37
internal/gitrepo/ancestor.go added +50 −0
@@ -0,0 +1,50 @@
1 package gitrepo
2
3 import (
4 "bytes"
5 "context"
6 "errors"
7 "fmt"
8 "os/exec"
9 "strings"
10 )
11
12 // IsAncestor zegt of ancestor een voorouder is van descendant, inclusief
13 // het geval dat beide dezelfde commit zijn.
14 func IsAncestor(ctx context.Context, gitBin, dir, ancestor, descendant string) bool {
15 if ancestor == "" || descendant == "" {
16 return false
17 }
18 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "merge-base", "--is-ancestor", ancestor, descendant)
19 return cmd.Run() == nil
20 }
21
22 // Conflicts zegt of ours en theirs niet schoon samen te voegen zijn.
23 // ours is de doelbranch, theirs de bron. Een ontbrekende revisie is een fout.
24 func Conflicts(ctx context.Context, gitBin, dir, ours, theirs string) (bool, error) {
25 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "merge-tree", "--write-tree", ours, theirs)
26 out, err := cmd.CombinedOutput()
27 if err == nil {
28 return false, nil
29 }
30 var exit *exec.ExitError
31 if errors.As(err, &exit) && exit.ExitCode() == 1 {
32 return true, nil
33 }
34 if errors.As(err, &exit) && exit.ExitCode() == 129 || bytes.Contains(out, []byte("unknown option")) {
35 return conflictsLegacy(ctx, gitBin, dir, ours, theirs)
36 }
37 return false, fmt.Errorf("merge-tree: %w (%s)", err, strings.TrimSpace(string(out)))
38 }
39
40 func conflictsLegacy(ctx context.Context, gitBin, dir, ours, theirs string) (bool, error) {
41 base, err := run(ctx, gitBin, nil, "-C", dir, "merge-base", ours, theirs)
42 if err != nil {
43 return false, err
44 }
45 out, err := run(ctx, gitBin, nil, "-C", dir, "merge-tree", strings.TrimSpace(base), ours, theirs)
46 if err != nil {
47 return false, err
48 }
49 return strings.Contains(out, "changed in both") || strings.Contains(out, "CONFLICT"), nil
50 }
@@ -0,0 +1,50 @@
1package gitrepo
2
3import (
4 "bytes"
5 "context"
6 "errors"
7 "fmt"
8 "os/exec"
9 "strings"
10)
11
12// IsAncestor zegt of ancestor een voorouder is van descendant, inclusief
13// het geval dat beide dezelfde commit zijn.
14func IsAncestor(ctx context.Context, gitBin, dir, ancestor, descendant string) bool {
15 if ancestor == "" || descendant == "" {
16 return false
17 }
18 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "merge-base", "--is-ancestor", ancestor, descendant)
19 return cmd.Run() == nil
20}
21
22// Conflicts zegt of ours en theirs niet schoon samen te voegen zijn.
23// ours is de doelbranch, theirs de bron. Een ontbrekende revisie is een fout.
24func Conflicts(ctx context.Context, gitBin, dir, ours, theirs string) (bool, error) {
25 cmd := exec.CommandContext(ctx, gitBin, "-C", dir, "merge-tree", "--write-tree", ours, theirs)
26 out, err := cmd.CombinedOutput()
27 if err == nil {
28 return false, nil
29 }
30 var exit *exec.ExitError
31 if errors.As(err, &exit) && exit.ExitCode() == 1 {
32 return true, nil
33 }
34 if errors.As(err, &exit) && exit.ExitCode() == 129 || bytes.Contains(out, []byte("unknown option")) {
35 return conflictsLegacy(ctx, gitBin, dir, ours, theirs)
36 }
37 return false, fmt.Errorf("merge-tree: %w (%s)", err, strings.TrimSpace(string(out)))
38}
39
40func conflictsLegacy(ctx context.Context, gitBin, dir, ours, theirs string) (bool, error) {
41 base, err := run(ctx, gitBin, nil, "-C", dir, "merge-base", ours, theirs)
42 if err != nil {
43 return false, err
44 }
45 out, err := run(ctx, gitBin, nil, "-C", dir, "merge-tree", strings.TrimSpace(base), ours, theirs)
46 if err != nil {
47 return false, err
48 }
49 return strings.Contains(out, "changed in both") || strings.Contains(out, "CONFLICT"), nil
50}
internal/gitrepo/ancestor_test.go added +88 −0
@@ -0,0 +1,88 @@
1 package gitrepo
2
3 import (
4 "context"
5 "os"
6 "os/exec"
7 "path/filepath"
8 "testing"
9 )
10
11 func TestAncestorAndConflict(t *testing.T) {
12 if _, err := exec.LookPath("git"); err != nil {
13 t.Skip("git ontbreekt")
14 }
15 dir := t.TempDir()
16 git := func(args ...string) {
17 t.Helper()
18 cmd := exec.Command("git", args...)
19 cmd.Dir = dir
20 cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@example.com", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.com")
21 if out, err := cmd.CombinedOutput(); err != nil {
22 t.Fatalf("git %v: %v\n%s", args, err, out)
23 }
24 }
25 git("init", "-b", "master")
26 git("config", "user.email", "t@example.com")
27 git("config", "user.name", "t")
28 if err := os.WriteFile(filepath.Join(dir, "a.txt"), []byte("a\n"), 0o644); err != nil {
29 t.Fatal(err)
30 }
31 git("add", "a.txt")
32 git("commit", "-m", "start")
33 git("checkout", "-b", "topic")
34 if err := os.WriteFile(filepath.Join(dir, "b.txt"), []byte("b\n"), 0o644); err != nil {
35 t.Fatal(err)
36 }
37 git("add", "b.txt")
38 git("commit", "-m", "topic")
39 ctx := context.Background()
40 if !IsAncestor(ctx, "git", dir, "master", "topic") {
41 t.Fatal("master hoort in topic te zitten")
42 }
43 if IsAncestor(ctx, "git", dir, "topic", "master") {
44 t.Fatal("topic zit nog niet in master")
45 }
46 conflict, err := Conflicts(ctx, "git", dir, "master", "topic")
47 if err != nil || conflict {
48 t.Fatalf("schone merge: %v %v", conflict, err)
49 }
50 git("checkout", "master")
51 git("merge", "--no-edit", "topic")
52 if !IsAncestor(ctx, "git", dir, "topic", "master") {
53 t.Fatal("na de merge hoort topic in master te zitten")
54 }
55
56 other := t.TempDir()
57 gitc := func(args ...string) {
58 t.Helper()
59 cmd := exec.Command("git", args...)
60 cmd.Dir = other
61 cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@example.com", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.com")
62 if out, err := cmd.CombinedOutput(); err != nil {
63 t.Fatalf("git %v: %v\n%s", args, err, out)
64 }
65 }
66 gitc("init", "-b", "master")
67 gitc("config", "user.email", "t@example.com")
68 gitc("config", "user.name", "t")
69 if err := os.WriteFile(filepath.Join(other, "a.txt"), []byte("a\n"), 0o644); err != nil {
70 t.Fatal(err)
71 }
72 gitc("add", "a.txt")
73 gitc("commit", "-m", "start")
74 gitc("checkout", "-b", "topic")
75 if err := os.WriteFile(filepath.Join(other, "a.txt"), []byte("links\n"), 0o644); err != nil {
76 t.Fatal(err)
77 }
78 gitc("commit", "-am", "links")
79 gitc("checkout", "master")
80 if err := os.WriteFile(filepath.Join(other, "a.txt"), []byte("rechts\n"), 0o644); err != nil {
81 t.Fatal(err)
82 }
83 gitc("commit", "-am", "rechts")
84 conflict, err = Conflicts(ctx, "git", other, "master", "topic")
85 if err != nil || !conflict {
86 t.Fatalf("conflict verwacht: %v %v", conflict, err)
87 }
88 }
@@ -0,0 +1,88 @@
1package gitrepo
2
3import (
4 "context"
5 "os"
6 "os/exec"
7 "path/filepath"
8 "testing"
9)
10
11func TestAncestorAndConflict(t *testing.T) {
12 if _, err := exec.LookPath("git"); err != nil {
13 t.Skip("git ontbreekt")
14 }
15 dir := t.TempDir()
16 git := func(args ...string) {
17 t.Helper()
18 cmd := exec.Command("git", args...)
19 cmd.Dir = dir
20 cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@example.com", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.com")
21 if out, err := cmd.CombinedOutput(); err != nil {
22 t.Fatalf("git %v: %v\n%s", args, err, out)
23 }
24 }
25 git("init", "-b", "master")
26 git("config", "user.email", "t@example.com")
27 git("config", "user.name", "t")
28 if err := os.WriteFile(filepath.Join(dir, "a.txt"), []byte("a\n"), 0o644); err != nil {
29 t.Fatal(err)
30 }
31 git("add", "a.txt")
32 git("commit", "-m", "start")
33 git("checkout", "-b", "topic")
34 if err := os.WriteFile(filepath.Join(dir, "b.txt"), []byte("b\n"), 0o644); err != nil {
35 t.Fatal(err)
36 }
37 git("add", "b.txt")
38 git("commit", "-m", "topic")
39 ctx := context.Background()
40 if !IsAncestor(ctx, "git", dir, "master", "topic") {
41 t.Fatal("master hoort in topic te zitten")
42 }
43 if IsAncestor(ctx, "git", dir, "topic", "master") {
44 t.Fatal("topic zit nog niet in master")
45 }
46 conflict, err := Conflicts(ctx, "git", dir, "master", "topic")
47 if err != nil || conflict {
48 t.Fatalf("schone merge: %v %v", conflict, err)
49 }
50 git("checkout", "master")
51 git("merge", "--no-edit", "topic")
52 if !IsAncestor(ctx, "git", dir, "topic", "master") {
53 t.Fatal("na de merge hoort topic in master te zitten")
54 }
55
56 other := t.TempDir()
57 gitc := func(args ...string) {
58 t.Helper()
59 cmd := exec.Command("git", args...)
60 cmd.Dir = other
61 cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@example.com", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.com")
62 if out, err := cmd.CombinedOutput(); err != nil {
63 t.Fatalf("git %v: %v\n%s", args, err, out)
64 }
65 }
66 gitc("init", "-b", "master")
67 gitc("config", "user.email", "t@example.com")
68 gitc("config", "user.name", "t")
69 if err := os.WriteFile(filepath.Join(other, "a.txt"), []byte("a\n"), 0o644); err != nil {
70 t.Fatal(err)
71 }
72 gitc("add", "a.txt")
73 gitc("commit", "-m", "start")
74 gitc("checkout", "-b", "topic")
75 if err := os.WriteFile(filepath.Join(other, "a.txt"), []byte("links\n"), 0o644); err != nil {
76 t.Fatal(err)
77 }
78 gitc("commit", "-am", "links")
79 gitc("checkout", "master")
80 if err := os.WriteFile(filepath.Join(other, "a.txt"), []byte("rechts\n"), 0o644); err != nil {
81 t.Fatal(err)
82 }
83 gitc("commit", "-am", "rechts")
84 conflict, err = Conflicts(ctx, "git", other, "master", "topic")
85 if err != nil || !conflict {
86 t.Fatalf("conflict verwacht: %v %v", conflict, err)
87 }
88}
internal/gitrepo/branch.go +1 −1
@@ -13,7 +13,7 @@ type BranchTip struct {
13 13
14 14 // BranchTips geeft elke lokale branch met zijn laatste commit.
15 15 func BranchTips(ctx context.Context, gitBin, dir string) ([]BranchTip, error) {
16 const format = "%(refname:short)%00%(objectname)%00%(subject)%00%(creatordate:short)"
16 const format = "%(refname:short)%00%(objectname)%00%(subject)%00%(creatordate:unix)"
17 17 out, err := run(ctx, gitBin, nil, "-C", dir, "for-each-ref", "--format="+format, "refs/heads")
18 18 if err != nil {
19 19 return nil, err
@@ -13,7 +13,7 @@ type BranchTip struct {
13
13
14// BranchTips geeft elke lokale branch met zijn laatste commit.
14// BranchTips geeft elke lokale branch met zijn laatste commit.
15func BranchTips(ctx context.Context, gitBin, dir string) ([]BranchTip, error) {
15func BranchTips(ctx context.Context, gitBin, dir string) ([]BranchTip, error) {
16 const format = "%(refname:short)%00%(objectname)%00%(subject)%00%(creatordate:short)"
16 const format = "%(refname:short)%00%(objectname)%00%(subject)%00%(creatordate:unix)"
17 out, err := run(ctx, gitBin, nil, "-C", dir, "for-each-ref", "--format="+format, "refs/heads")
17 out, err := run(ctx, gitBin, nil, "-C", dir, "for-each-ref", "--format="+format, "refs/heads")
18 if err != nil {
18 if err != nil {
19 return nil, err
19 return nil, err
internal/i18n/catalog_mrfix.go added +108 −0
@@ -0,0 +1,108 @@
1 package i18n
2
3 func init() {
4 addCatalog(en, mrfixEN)
5 addCatalog(nl, mrfixNL)
6 addCatalog(de, mrfixDE)
7 addCatalog(fr, mrfixFR)
8 }
9
10 var mrfixEN = map[string]string{
11 "mr.block.why": "This merge request cannot be merged yet.",
12 "mr.block.conflict": "The branches conflict.",
13 "mr.force": "Merge anyway",
14 "mr.force.warn": "Merging anyway skips the checks above. This is recorded in the activity.",
15 "mr.force.confirm": "I understand and want to merge anyway",
16 "mr.force.need": "Confirm that you want to merge anyway.",
17 "mr.forcedEvent": "merged anyway",
18 "branch.mrShort": "MR",
19 "branch.more": "More actions",
20 "ago.short.just": "now",
21 "ago.short.minute": "1m",
22 "ago.short.minutes": "%dm",
23 "ago.short.hour": "1h",
24 "ago.short.hours": "%dh",
25 "ago.short.day": "1d",
26 "ago.short.days": "%dd",
27 "ago.short.week": "1w",
28 "ago.short.weeks": "%dw",
29 "ago.short.month": "1mo",
30 "ago.short.months": "%dmo",
31 "ago.short.year": "1y",
32 "ago.short.years": "%dy",
33 }
34
35 var mrfixNL = map[string]string{
36 "mr.block.why": "Deze merge request kan nog niet samengevoegd worden.",
37 "mr.block.conflict": "De branches conflicteren.",
38 "mr.force": "Toch mergen",
39 "mr.force.warn": "Toch mergen slaat de controles hierboven over. Dit komt in de activiteit.",
40 "mr.force.confirm": "Ik begrijp het en wil toch mergen",
41 "mr.force.need": "Bevestig dat je toch wilt mergen.",
42 "mr.forcedEvent": "merge toch, ondanks de controles",
43 "branch.mrShort": "MR",
44 "branch.more": "Meer acties",
45 "ago.short.just": "nu",
46 "ago.short.minute": "1m",
47 "ago.short.minutes": "%dm",
48 "ago.short.hour": "1u",
49 "ago.short.hours": "%du",
50 "ago.short.day": "1d",
51 "ago.short.days": "%dd",
52 "ago.short.week": "1w",
53 "ago.short.weeks": "%dw",
54 "ago.short.month": "1mnd",
55 "ago.short.months": "%dmnd",
56 "ago.short.year": "1j",
57 "ago.short.years": "%dj",
58 }
59
60 var mrfixDE = map[string]string{
61 "mr.block.why": "Dieser Merge Request kann noch nicht zusammengeführt werden.",
62 "mr.block.conflict": "Die Branches haben einen Konflikt.",
63 "mr.force": "Trotzdem mergen",
64 "mr.force.warn": "Trotzdem mergen überspringt die Prüfungen oben. Das steht in der Aktivität.",
65 "mr.force.confirm": "Ich verstehe es und will trotzdem mergen",
66 "mr.force.need": "Bestätige, dass du trotzdem mergen willst.",
67 "mr.forcedEvent": "hat trotzdem gemergt",
68 "branch.mrShort": "MR",
69 "branch.more": "Weitere Aktionen",
70 "ago.short.just": "jetzt",
71 "ago.short.minute": "1m",
72 "ago.short.minutes": "%dm",
73 "ago.short.hour": "1h",
74 "ago.short.hours": "%dh",
75 "ago.short.day": "1d",
76 "ago.short.days": "%dd",
77 "ago.short.week": "1w",
78 "ago.short.weeks": "%dw",
79 "ago.short.month": "1mo",
80 "ago.short.months": "%dmo",
81 "ago.short.year": "1y",
82 "ago.short.years": "%dy",
83 }
84
85 var mrfixFR = map[string]string{
86 "mr.block.why": "Cette merge request ne peut pas encore être fusionnée.",
87 "mr.block.conflict": "Les branches sont en conflit.",
88 "mr.force": "Fusionner quand même",
89 "mr.force.warn": "Fusionner quand même ignore les contrôles ci-dessus. Cela est noté dans l activité.",
90 "mr.force.confirm": "Je comprends et je veux fusionner quand même",
91 "mr.force.need": "Confirmez que vous voulez fusionner quand même.",
92 "mr.forcedEvent": "a fusionné quand même",
93 "branch.mrShort": "MR",
94 "branch.more": "Autres actions",
95 "ago.short.just": "maintenant",
96 "ago.short.minute": "1m",
97 "ago.short.minutes": "%dm",
98 "ago.short.hour": "1h",
99 "ago.short.hours": "%dh",
100 "ago.short.day": "1j",
101 "ago.short.days": "%dj",
102 "ago.short.week": "1sem",
103 "ago.short.weeks": "%dsem",
104 "ago.short.month": "1mo",
105 "ago.short.months": "%dmo",
106 "ago.short.year": "1a",
107 "ago.short.years": "%da",
108 }
@@ -0,0 +1,108 @@
1package i18n
2
3func init() {
4 addCatalog(en, mrfixEN)
5 addCatalog(nl, mrfixNL)
6 addCatalog(de, mrfixDE)
7 addCatalog(fr, mrfixFR)
8}
9
10var mrfixEN = map[string]string{
11 "mr.block.why": "This merge request cannot be merged yet.",
12 "mr.block.conflict": "The branches conflict.",
13 "mr.force": "Merge anyway",
14 "mr.force.warn": "Merging anyway skips the checks above. This is recorded in the activity.",
15 "mr.force.confirm": "I understand and want to merge anyway",
16 "mr.force.need": "Confirm that you want to merge anyway.",
17 "mr.forcedEvent": "merged anyway",
18 "branch.mrShort": "MR",
19 "branch.more": "More actions",
20 "ago.short.just": "now",
21 "ago.short.minute": "1m",
22 "ago.short.minutes": "%dm",
23 "ago.short.hour": "1h",
24 "ago.short.hours": "%dh",
25 "ago.short.day": "1d",
26 "ago.short.days": "%dd",
27 "ago.short.week": "1w",
28 "ago.short.weeks": "%dw",
29 "ago.short.month": "1mo",
30 "ago.short.months": "%dmo",
31 "ago.short.year": "1y",
32 "ago.short.years": "%dy",
33}
34
35var mrfixNL = map[string]string{
36 "mr.block.why": "Deze merge request kan nog niet samengevoegd worden.",
37 "mr.block.conflict": "De branches conflicteren.",
38 "mr.force": "Toch mergen",
39 "mr.force.warn": "Toch mergen slaat de controles hierboven over. Dit komt in de activiteit.",
40 "mr.force.confirm": "Ik begrijp het en wil toch mergen",
41 "mr.force.need": "Bevestig dat je toch wilt mergen.",
42 "mr.forcedEvent": "merge toch, ondanks de controles",
43 "branch.mrShort": "MR",
44 "branch.more": "Meer acties",
45 "ago.short.just": "nu",
46 "ago.short.minute": "1m",
47 "ago.short.minutes": "%dm",
48 "ago.short.hour": "1u",
49 "ago.short.hours": "%du",
50 "ago.short.day": "1d",
51 "ago.short.days": "%dd",
52 "ago.short.week": "1w",
53 "ago.short.weeks": "%dw",
54 "ago.short.month": "1mnd",
55 "ago.short.months": "%dmnd",
56 "ago.short.year": "1j",
57 "ago.short.years": "%dj",
58}
59
60var mrfixDE = map[string]string{
61 "mr.block.why": "Dieser Merge Request kann noch nicht zusammengeführt werden.",
62 "mr.block.conflict": "Die Branches haben einen Konflikt.",
63 "mr.force": "Trotzdem mergen",
64 "mr.force.warn": "Trotzdem mergen überspringt die Prüfungen oben. Das steht in der Aktivität.",
65 "mr.force.confirm": "Ich verstehe es und will trotzdem mergen",
66 "mr.force.need": "Bestätige, dass du trotzdem mergen willst.",
67 "mr.forcedEvent": "hat trotzdem gemergt",
68 "branch.mrShort": "MR",
69 "branch.more": "Weitere Aktionen",
70 "ago.short.just": "jetzt",
71 "ago.short.minute": "1m",
72 "ago.short.minutes": "%dm",
73 "ago.short.hour": "1h",
74 "ago.short.hours": "%dh",
75 "ago.short.day": "1d",
76 "ago.short.days": "%dd",
77 "ago.short.week": "1w",
78 "ago.short.weeks": "%dw",
79 "ago.short.month": "1mo",
80 "ago.short.months": "%dmo",
81 "ago.short.year": "1y",
82 "ago.short.years": "%dy",
83}
84
85var mrfixFR = map[string]string{
86 "mr.block.why": "Cette merge request ne peut pas encore être fusionnée.",
87 "mr.block.conflict": "Les branches sont en conflit.",
88 "mr.force": "Fusionner quand même",
89 "mr.force.warn": "Fusionner quand même ignore les contrôles ci-dessus. Cela est noté dans l activité.",
90 "mr.force.confirm": "Je comprends et je veux fusionner quand même",
91 "mr.force.need": "Confirmez que vous voulez fusionner quand même.",
92 "mr.forcedEvent": "a fusionné quand même",
93 "branch.mrShort": "MR",
94 "branch.more": "Autres actions",
95 "ago.short.just": "maintenant",
96 "ago.short.minute": "1m",
97 "ago.short.minutes": "%dm",
98 "ago.short.hour": "1h",
99 "ago.short.hours": "%dh",
100 "ago.short.day": "1j",
101 "ago.short.days": "%dj",
102 "ago.short.week": "1sem",
103 "ago.short.weeks": "%dsem",
104 "ago.short.month": "1mo",
105 "ago.short.months": "%dmo",
106 "ago.short.year": "1a",
107 "ago.short.years": "%da",
108}
internal/i18n/i18n.go +69 −0
@@ -189,6 +189,75 @@ func Ago(lang Lang, unix int64) string {
189 189 return T(lang, "ago.years", n)
190 190 }
191 191
192 // ShortAgo is the compact relative time used in tables, such as "3d".
193 func ShortAgo(lang Lang, unix int64) string {
194 if unix <= 0 {
195 return ""
196 }
197 d := time.Since(time.Unix(unix, 0))
198 if d < time.Minute {
199 return T(lang, "ago.short.just")
200 }
201 if d < time.Hour {
202 n := int(d.Minutes())
203 if n < 1 {
204 n = 1
205 }
206 if n == 1 {
207 return T(lang, "ago.short.minute")
208 }
209 return T(lang, "ago.short.minutes", n)
210 }
211 if d < 24*time.Hour {
212 n := int(d.Hours())
213 if n < 1 {
214 n = 1
215 }
216 if n == 1 {
217 return T(lang, "ago.short.hour")
218 }
219 return T(lang, "ago.short.hours", n)
220 }
221 days := int(d.Hours() / 24)
222 if days < 1 {
223 days = 1
224 }
225 if days == 1 {
226 return T(lang, "ago.short.day")
227 }
228 if days < 14 {
229 return T(lang, "ago.short.days", days)
230 }
231 if days < 60 {
232 n := days / 7
233 if n < 1 {
234 n = 1
235 }
236 if n == 1 {
237 return T(lang, "ago.short.week")
238 }
239 return T(lang, "ago.short.weeks", n)
240 }
241 if days < 365 {
242 n := days / 30
243 if n < 1 {
244 n = 1
245 }
246 if n == 1 {
247 return T(lang, "ago.short.month")
248 }
249 return T(lang, "ago.short.months", n)
250 }
251 n := days / 365
252 if n < 1 {
253 n = 1
254 }
255 if n == 1 {
256 return T(lang, "ago.short.year")
257 }
258 return T(lang, "ago.short.years", n)
259 }
260
192 261 // Contrib is the heatmap sentence. year is the twelve-month total;
193 262 // otherwise date is the long date of one cell.
194 263 func Contrib(lang Lang, n int, date string, year bool) string {
@@ -189,6 +189,75 @@ func Ago(lang Lang, unix int64) string {
189 return T(lang, "ago.years", n)
189 return T(lang, "ago.years", n)
190}
190}
191
191
192// ShortAgo is the compact relative time used in tables, such as "3d".
193func ShortAgo(lang Lang, unix int64) string {
194 if unix <= 0 {
195 return ""
196 }
197 d := time.Since(time.Unix(unix, 0))
198 if d < time.Minute {
199 return T(lang, "ago.short.just")
200 }
201 if d < time.Hour {
202 n := int(d.Minutes())
203 if n < 1 {
204 n = 1
205 }
206 if n == 1 {
207 return T(lang, "ago.short.minute")
208 }
209 return T(lang, "ago.short.minutes", n)
210 }
211 if d < 24*time.Hour {
212 n := int(d.Hours())
213 if n < 1 {
214 n = 1
215 }
216 if n == 1 {
217 return T(lang, "ago.short.hour")
218 }
219 return T(lang, "ago.short.hours", n)
220 }
221 days := int(d.Hours() / 24)
222 if days < 1 {
223 days = 1
224 }
225 if days == 1 {
226 return T(lang, "ago.short.day")
227 }
228 if days < 14 {
229 return T(lang, "ago.short.days", days)
230 }
231 if days < 60 {
232 n := days / 7
233 if n < 1 {
234 n = 1
235 }
236 if n == 1 {
237 return T(lang, "ago.short.week")
238 }
239 return T(lang, "ago.short.weeks", n)
240 }
241 if days < 365 {
242 n := days / 30
243 if n < 1 {
244 n = 1
245 }
246 if n == 1 {
247 return T(lang, "ago.short.month")
248 }
249 return T(lang, "ago.short.months", n)
250 }
251 n := days / 365
252 if n < 1 {
253 n = 1
254 }
255 if n == 1 {
256 return T(lang, "ago.short.year")
257 }
258 return T(lang, "ago.short.years", n)
259}
260
192// Contrib is the heatmap sentence. year is the twelve-month total;
261// Contrib is the heatmap sentence. year is the twelve-month total;
193// otherwise date is the long date of one cell.
262// otherwise date is the long date of one cell.
194func Contrib(lang Lang, n int, date string, year bool) string {
263func Contrib(lang Lang, n int, date string, year bool) string {
internal/server/branch_mr_test.go +6 −3
@@ -60,11 +60,14 @@ func TestBranchesAndMergeRequest(t *testing.T) {
60 60 git(t, work, "push", "-u", "origin", "topic")
61 61
62 62 page = read(t, mustGet(t, tim, ts.URL+"/tim/takken/-/branches"))
63 for _, want := range []string{"data-branch-filter", "topic", "default", "1 ahead", "master"} {
63 for _, want := range []string{"data-branch-filter", "topic", "default", "1 ahead", "master", "when-short", "rowmenu", "aria-label=\"More actions\""} {
64 64 if !strings.Contains(page, want) {
65 65 t.Fatalf("branchpagina mist %q", want)
66 66 }
67 67 }
68 if strings.Contains(page, "Create merge request") {
69 t.Fatalf("acties horen compact:\n%s", page)
70 }
68 71 page = read(t, mustPost(t, tim, ts.URL+"/tim/takken/-/branches/delete", url.Values{
69 72 "csrf": {csrfOf(t, page)}, "name": {"master"}, "confirm": {"master"},
70 73 }))
@@ -130,7 +133,7 @@ func TestBranchesAndMergeRequest(t *testing.T) {
130 133 if !strings.Contains(page, "Draft") || !strings.Contains(page, "This merge request is a draft.") || !strings.Contains(page, "<strong>vet</strong>") || strings.Contains(page, "<script>") {
131 134 t.Fatalf("concept:\n%s", page)
132 135 }
133 if !strings.Contains(page, "disabled") {
136 if !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
134 137 t.Fatalf("concept hoort mergen te blokkeren:\n%s", page)
135 138 }
136 139 if !strings.Contains(page, "mr.overview") && !strings.Contains(page, "Overview") {
@@ -141,7 +144,7 @@ func TestBranchesAndMergeRequest(t *testing.T) {
141 144 }
142 145
143 146 branches := read(t, mustGet(t, tim, ts.URL+"/tim/takken/-/branches"))
144 if !strings.Contains(branches, "/-/merge-requests/1") {
147 if !strings.Contains(branches, "/-/merge-requests/1") || !strings.Contains(branches, ">!1<") {
145 148 t.Fatalf("mr-link:\n%s", branches)
146 149 }
147 150
@@ -60,11 +60,14 @@ func TestBranchesAndMergeRequest(t *testing.T) {
60 git(t, work, "push", "-u", "origin", "topic")
60 git(t, work, "push", "-u", "origin", "topic")
61
61
62 page = read(t, mustGet(t, tim, ts.URL+"/tim/takken/-/branches"))
62 page = read(t, mustGet(t, tim, ts.URL+"/tim/takken/-/branches"))
63 for _, want := range []string{"data-branch-filter", "topic", "default", "1 ahead", "master"} {
63 for _, want := range []string{"data-branch-filter", "topic", "default", "1 ahead", "master", "when-short", "rowmenu", "aria-label=\"More actions\""} {
64 if !strings.Contains(page, want) {
64 if !strings.Contains(page, want) {
65 t.Fatalf("branchpagina mist %q", want)
65 t.Fatalf("branchpagina mist %q", want)
66 }
66 }
67 }
67 }
68 if strings.Contains(page, "Create merge request") {
69 t.Fatalf("acties horen compact:\n%s", page)
70 }
68 page = read(t, mustPost(t, tim, ts.URL+"/tim/takken/-/branches/delete", url.Values{
71 page = read(t, mustPost(t, tim, ts.URL+"/tim/takken/-/branches/delete", url.Values{
69 "csrf": {csrfOf(t, page)}, "name": {"master"}, "confirm": {"master"},
72 "csrf": {csrfOf(t, page)}, "name": {"master"}, "confirm": {"master"},
70 }))
73 }))
@@ -130,7 +133,7 @@ func TestBranchesAndMergeRequest(t *testing.T) {
130 if !strings.Contains(page, "Draft") || !strings.Contains(page, "This merge request is a draft.") || !strings.Contains(page, "<strong>vet</strong>") || strings.Contains(page, "<script>") {
133 if !strings.Contains(page, "Draft") || !strings.Contains(page, "This merge request is a draft.") || !strings.Contains(page, "<strong>vet</strong>") || strings.Contains(page, "<script>") {
131 t.Fatalf("concept:\n%s", page)
134 t.Fatalf("concept:\n%s", page)
132 }
135 }
133 if !strings.Contains(page, "disabled") {
136 if !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
134 t.Fatalf("concept hoort mergen te blokkeren:\n%s", page)
137 t.Fatalf("concept hoort mergen te blokkeren:\n%s", page)
135 }
138 }
136 if !strings.Contains(page, "mr.overview") && !strings.Contains(page, "Overview") {
139 if !strings.Contains(page, "mr.overview") && !strings.Contains(page, "Overview") {
@@ -141,7 +144,7 @@ func TestBranchesAndMergeRequest(t *testing.T) {
141 }
144 }
142
145
143 branches := read(t, mustGet(t, tim, ts.URL+"/tim/takken/-/branches"))
146 branches := read(t, mustGet(t, tim, ts.URL+"/tim/takken/-/branches"))
144 if !strings.Contains(branches, "/-/merge-requests/1") {
147 if !strings.Contains(branches, "/-/merge-requests/1") || !strings.Contains(branches, ">!1<") {
145 t.Fatalf("mr-link:\n%s", branches)
148 t.Fatalf("mr-link:\n%s", branches)
146 }
149 }
147
150
internal/server/branches.go +21 −3
@@ -3,9 +3,13 @@ package server
3 3 import (
4 4 "net/http"
5 5 "sort"
6 "strconv"
7 "strings"
8 "time"
6 9
7 10 "gitlab.com/Timfa/bluegit/internal/access"
8 11 "gitlab.com/Timfa/bluegit/internal/gitrepo"
12 "gitlab.com/Timfa/bluegit/internal/i18n"
9 13 "gitlab.com/Timfa/bluegit/internal/store"
10 14 )
11 15
@@ -14,15 +18,18 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
14 18 if !ok {
15 19 return
16 20 }
21 s.absorbMergedMRs(r.Context(), repo)
17 22 v := s.repoView(w, r, repo, role, "title.branches")
18 23 v.Page = "branches"
19 24 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
20 25 tips, _ := gitrepo.BranchTips(r.Context(), s.Git, dir)
21 26 patterns, _ := s.Store.ProtectedPatterns(r.Context(), repo.ID)
27 lang := s.langOf(r)
22 28 for _, tip := range tips {
29 when, title := branchWhen(lang, tip.Date)
23 30 row := BranchRow{
24 31 Name: tip.Name, SHA: tip.SHA, Short: shortSHA(tip.SHA),
25 Subject: tip.Subject, When: tip.Date,
32 Subject: tip.Subject, When: when, WhenTitle: title,
26 33 Protected: access.BranchProtected(patterns, tip.Name),
27 34 Default: tip.Name == repo.DefaultBranch,
28 35 }
@@ -38,8 +45,10 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
38 45 row.PipeStatus = displayStatus(p.Status, jobs)
39 46 row.PipeLabel = s.tr(r, "pipe."+row.PipeStatus)
40 47 }
41 if mrs, err := s.Store.OpenMergeRequestsBySource(r.Context(), repo.ID, tip.Name); err == nil && len(mrs) > 0 {
42 row.MRNumber = mrs[0].Number
48 if mrs, err := s.Store.OpenMergeRequestsBySource(r.Context(), repo.ID, tip.Name); err == nil {
49 for _, mr := range mrs {
50 row.OpenMRs = append(row.OpenMRs, mr.Number)
51 }
43 52 }
44 53 v.Branches = append(v.Branches, row)
45 54 }
@@ -92,6 +101,15 @@ func (s *Server) renameBranch(w http.ResponseWriter, r *http.Request) {
92 101 s.redirect(w, r, back, s.tr(r, "flash.branchRenamed"), "")
93 102 }
94 103
104 func branchWhen(lang i18n.Lang, unixText string) (short, title string) {
105 unix, err := strconv.ParseInt(strings.TrimSpace(unixText), 10, 64)
106 if err != nil || unix <= 0 {
107 return "", ""
108 }
109 at := time.Unix(unix, 0).UTC()
110 return i18n.ShortAgo(lang, unix), at.Format("2006-01-02 15:04 UTC")
111 }
112
95 113 // branchLocked weigert de standaardbranch en elke beschermde branch, ook voor een beheerder.
96 114 func (s *Server) branchLocked(r *http.Request, repo store.Repo, name string) (bool, string) {
97 115 if name == repo.DefaultBranch {
@@ -3,9 +3,13 @@ package server
3import (
3import (
4 "net/http"
4 "net/http"
5 "sort"
5 "sort"
6 "strconv"
7 "strings"
8 "time"
6
9
7 "gitlab.com/Timfa/bluegit/internal/access"
10 "gitlab.com/Timfa/bluegit/internal/access"
8 "gitlab.com/Timfa/bluegit/internal/gitrepo"
11 "gitlab.com/Timfa/bluegit/internal/gitrepo"
12 "gitlab.com/Timfa/bluegit/internal/i18n"
9 "gitlab.com/Timfa/bluegit/internal/store"
13 "gitlab.com/Timfa/bluegit/internal/store"
10)
14)
11
15
@@ -14,15 +18,18 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
14 if !ok {
18 if !ok {
15 return
19 return
16 }
20 }
21 s.absorbMergedMRs(r.Context(), repo)
17 v := s.repoView(w, r, repo, role, "title.branches")
22 v := s.repoView(w, r, repo, role, "title.branches")
18 v.Page = "branches"
23 v.Page = "branches"
19 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
24 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
20 tips, _ := gitrepo.BranchTips(r.Context(), s.Git, dir)
25 tips, _ := gitrepo.BranchTips(r.Context(), s.Git, dir)
21 patterns, _ := s.Store.ProtectedPatterns(r.Context(), repo.ID)
26 patterns, _ := s.Store.ProtectedPatterns(r.Context(), repo.ID)
27 lang := s.langOf(r)
22 for _, tip := range tips {
28 for _, tip := range tips {
29 when, title := branchWhen(lang, tip.Date)
23 row := BranchRow{
30 row := BranchRow{
24 Name: tip.Name, SHA: tip.SHA, Short: shortSHA(tip.SHA),
31 Name: tip.Name, SHA: tip.SHA, Short: shortSHA(tip.SHA),
25 Subject: tip.Subject, When: tip.Date,
32 Subject: tip.Subject, When: when, WhenTitle: title,
26 Protected: access.BranchProtected(patterns, tip.Name),
33 Protected: access.BranchProtected(patterns, tip.Name),
27 Default: tip.Name == repo.DefaultBranch,
34 Default: tip.Name == repo.DefaultBranch,
28 }
35 }
@@ -38,8 +45,10 @@ func (s *Server) branches(w http.ResponseWriter, r *http.Request) {
38 row.PipeStatus = displayStatus(p.Status, jobs)
45 row.PipeStatus = displayStatus(p.Status, jobs)
39 row.PipeLabel = s.tr(r, "pipe."+row.PipeStatus)
46 row.PipeLabel = s.tr(r, "pipe."+row.PipeStatus)
40 }
47 }
41 if mrs, err := s.Store.OpenMergeRequestsBySource(r.Context(), repo.ID, tip.Name); err == nil && len(mrs) > 0 {
48 if mrs, err := s.Store.OpenMergeRequestsBySource(r.Context(), repo.ID, tip.Name); err == nil {
42 row.MRNumber = mrs[0].Number
49 for _, mr := range mrs {
50 row.OpenMRs = append(row.OpenMRs, mr.Number)
51 }
43 }
52 }
44 v.Branches = append(v.Branches, row)
53 v.Branches = append(v.Branches, row)
45 }
54 }
@@ -92,6 +101,15 @@ func (s *Server) renameBranch(w http.ResponseWriter, r *http.Request) {
92 s.redirect(w, r, back, s.tr(r, "flash.branchRenamed"), "")
101 s.redirect(w, r, back, s.tr(r, "flash.branchRenamed"), "")
93}
102}
94
103
104func branchWhen(lang i18n.Lang, unixText string) (short, title string) {
105 unix, err := strconv.ParseInt(strings.TrimSpace(unixText), 10, 64)
106 if err != nil || unix <= 0 {
107 return "", ""
108 }
109 at := time.Unix(unix, 0).UTC()
110 return i18n.ShortAgo(lang, unix), at.Format("2006-01-02 15:04 UTC")
111}
112
95// branchLocked weigert de standaardbranch en elke beschermde branch, ook voor een beheerder.
113// branchLocked weigert de standaardbranch en elke beschermde branch, ook voor een beheerder.
96func (s *Server) branchLocked(r *http.Request, repo store.Repo, name string) (bool, string) {
114func (s *Server) branchLocked(r *http.Request, repo store.Repo, name string) (bool, string) {
97 if name == repo.DefaultBranch {
115 if name == repo.DefaultBranch {
internal/server/events.go +79 −0
@@ -67,6 +67,7 @@ func (s *Server) AfterPush(repo store.Repo, user store.User, before, after map[s
67 67 s.startPipeline(context.Background(), repo, commit, ref, actor, "push", before[ref], nil)
68 68 s.startMergeRequestPipelines(context.Background(), repo, commit, branch, actor, before[ref])
69 69 s.recordMRPushes(repo, user, branch, before[ref], sha)
70 s.markContainedMRs(repo, user, branch, sha)
70 71 s.rerunMergeRequestsOnTarget(context.Background(), repo, branch, actor)
71 72 s.pushHook(repo, actor, ref, before[ref], sha)
72 73 if branch == repo.DefaultBranch {
@@ -312,6 +313,84 @@ func urlParse(raw string) (*url.URL, error) {
312 313 return u, nil
313 314 }
314 315
316 // markContainedMRs zet open merge requests op merged wanneer de bron-head
317 // al in de zojuist gepushte doelbranch zit. Dat is dezelfde regel als GitLab
318 // na een merge die buiten de knop om is gepusht.
319 func (s *Server) markContainedMRs(repo store.Repo, user store.User, branch, sha string) {
320 if s.Store == nil || s.StoragePath() == "" || branch == "" || isZero(sha) {
321 return
322 }
323 ctx := context.Background()
324 mrs, err := s.Store.OpenMergeRequestsByTarget(ctx, repo.ID, branch)
325 if err != nil {
326 return
327 }
328 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
329 for _, mr := range mrs {
330 s.markIfContained(ctx, repo, user, dir, mr, sha)
331 }
332 }
333
334 // absorbMergedMRs doet dezelfde controle bij het openen van een pagina,
335 // zodat een merge die al gepusht was voordat deze code draaide alsnog merged wordt.
336 func (s *Server) absorbMergedMRs(ctx context.Context, repo store.Repo) {
337 if s.Store == nil || s.StoragePath() == "" {
338 return
339 }
340 mrs, err := s.Store.ListMergeRequests(ctx, repo.ID)
341 if err != nil {
342 return
343 }
344 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
345 for _, mr := range mrs {
346 if mr.Status != "open" {
347 continue
348 }
349 s.markIfContained(ctx, repo, store.User{}, dir, mr, "")
350 }
351 }
352
353 func (s *Server) markIfContained(ctx context.Context, repo store.Repo, user store.User, dir string, mr store.MergeRequest, targetSHA string) {
354 if targetSHA == "" {
355 targetSHA = gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "refs/heads/"+mr.TargetBranch)
356 }
357 src := gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "refs/heads/"+mr.SourceBranch)
358 if src == "" || targetSHA == "" || !gitrepo.IsAncestor(ctx, s.Git, dir, src, targetSHA) {
359 return
360 }
361 if user.ID == 0 {
362 if pushers, err := s.Store.PushersBySHA(ctx, repo.ID, []string{targetSHA}); err == nil {
363 if p, ok := pushers[targetSHA]; ok && p.UserID != 0 {
364 user = store.User{ID: p.UserID, Username: p.Username}
365 }
366 }
367 }
368 if err := s.Store.SetMergeRequestStatus(ctx, mr.ID, "merged"); err != nil {
369 return
370 }
371 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "merged", "")
372 mr.Status = "merged"
373 s.mrHook(repo, mr, user.Username, "merged", "")
374 s.closeMergedMR(ctx, repo, user, mr)
375 }
376
377 func (s *Server) closeMergedMR(ctx context.Context, repo store.Repo, user store.User, mr store.MergeRequest) {
378 texts := []string{mr.Description}
379 if s.StoragePath() != "" {
380 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
381 commits, err := gitrepo.RangeLog(ctx, s.Git, dir, mr.TargetBranch, mr.SourceBranch)
382 if err == nil {
383 for i, c := range commits {
384 if i >= 50 {
385 break
386 }
387 texts = append(texts, commitText(c))
388 }
389 }
390 }
391 s.closeIssueNumbers(ctx, repo, user, closingNumbers(texts...))
392 }
393
315 394 func gitSHA(r *http.Request, gitBin, dir, rev string) (string, error) {
316 395 out, err := exec.CommandContext(r.Context(), gitBin, "-C", dir, "rev-parse", "--verify", rev+"^{commit}").Output()
317 396 if err != nil {
@@ -67,6 +67,7 @@ func (s *Server) AfterPush(repo store.Repo, user store.User, before, after map[s
67 s.startPipeline(context.Background(), repo, commit, ref, actor, "push", before[ref], nil)
67 s.startPipeline(context.Background(), repo, commit, ref, actor, "push", before[ref], nil)
68 s.startMergeRequestPipelines(context.Background(), repo, commit, branch, actor, before[ref])
68 s.startMergeRequestPipelines(context.Background(), repo, commit, branch, actor, before[ref])
69 s.recordMRPushes(repo, user, branch, before[ref], sha)
69 s.recordMRPushes(repo, user, branch, before[ref], sha)
70 s.markContainedMRs(repo, user, branch, sha)
70 s.rerunMergeRequestsOnTarget(context.Background(), repo, branch, actor)
71 s.rerunMergeRequestsOnTarget(context.Background(), repo, branch, actor)
71 s.pushHook(repo, actor, ref, before[ref], sha)
72 s.pushHook(repo, actor, ref, before[ref], sha)
72 if branch == repo.DefaultBranch {
73 if branch == repo.DefaultBranch {
@@ -312,6 +313,84 @@ func urlParse(raw string) (*url.URL, error) {
312 return u, nil
313 return u, nil
313}
314}
314
315
316// markContainedMRs zet open merge requests op merged wanneer de bron-head
317// al in de zojuist gepushte doelbranch zit. Dat is dezelfde regel als GitLab
318// na een merge die buiten de knop om is gepusht.
319func (s *Server) markContainedMRs(repo store.Repo, user store.User, branch, sha string) {
320 if s.Store == nil || s.StoragePath() == "" || branch == "" || isZero(sha) {
321 return
322 }
323 ctx := context.Background()
324 mrs, err := s.Store.OpenMergeRequestsByTarget(ctx, repo.ID, branch)
325 if err != nil {
326 return
327 }
328 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
329 for _, mr := range mrs {
330 s.markIfContained(ctx, repo, user, dir, mr, sha)
331 }
332}
333
334// absorbMergedMRs doet dezelfde controle bij het openen van een pagina,
335// zodat een merge die al gepusht was voordat deze code draaide alsnog merged wordt.
336func (s *Server) absorbMergedMRs(ctx context.Context, repo store.Repo) {
337 if s.Store == nil || s.StoragePath() == "" {
338 return
339 }
340 mrs, err := s.Store.ListMergeRequests(ctx, repo.ID)
341 if err != nil {
342 return
343 }
344 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
345 for _, mr := range mrs {
346 if mr.Status != "open" {
347 continue
348 }
349 s.markIfContained(ctx, repo, store.User{}, dir, mr, "")
350 }
351}
352
353func (s *Server) markIfContained(ctx context.Context, repo store.Repo, user store.User, dir string, mr store.MergeRequest, targetSHA string) {
354 if targetSHA == "" {
355 targetSHA = gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "refs/heads/"+mr.TargetBranch)
356 }
357 src := gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "refs/heads/"+mr.SourceBranch)
358 if src == "" || targetSHA == "" || !gitrepo.IsAncestor(ctx, s.Git, dir, src, targetSHA) {
359 return
360 }
361 if user.ID == 0 {
362 if pushers, err := s.Store.PushersBySHA(ctx, repo.ID, []string{targetSHA}); err == nil {
363 if p, ok := pushers[targetSHA]; ok && p.UserID != 0 {
364 user = store.User{ID: p.UserID, Username: p.Username}
365 }
366 }
367 }
368 if err := s.Store.SetMergeRequestStatus(ctx, mr.ID, "merged"); err != nil {
369 return
370 }
371 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "merged", "")
372 mr.Status = "merged"
373 s.mrHook(repo, mr, user.Username, "merged", "")
374 s.closeMergedMR(ctx, repo, user, mr)
375}
376
377func (s *Server) closeMergedMR(ctx context.Context, repo store.Repo, user store.User, mr store.MergeRequest) {
378 texts := []string{mr.Description}
379 if s.StoragePath() != "" {
380 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
381 commits, err := gitrepo.RangeLog(ctx, s.Git, dir, mr.TargetBranch, mr.SourceBranch)
382 if err == nil {
383 for i, c := range commits {
384 if i >= 50 {
385 break
386 }
387 texts = append(texts, commitText(c))
388 }
389 }
390 }
391 s.closeIssueNumbers(ctx, repo, user, closingNumbers(texts...))
392}
393
315func gitSHA(r *http.Request, gitBin, dir, rev string) (string, error) {
394func gitSHA(r *http.Request, gitBin, dir, rev string) (string, error) {
316 out, err := exec.CommandContext(r.Context(), gitBin, "-C", dir, "rev-parse", "--verify", rev+"^{commit}").Output()
395 out, err := exec.CommandContext(r.Context(), gitBin, "-C", dir, "rev-parse", "--verify", rev+"^{commit}").Output()
317 if err != nil {
396 if err != nil {
internal/server/merge_fix_test.go added +192 −0
@@ -0,0 +1,192 @@
1 package server
2
3 import (
4 "context"
5 "net/http"
6 "net/http/cookiejar"
7 "net/http/httptest"
8 "net/url"
9 "os/exec"
10 "path/filepath"
11 "strings"
12 "testing"
13
14 "gitlab.com/Timfa/bluegit/internal/auth"
15 "gitlab.com/Timfa/bluegit/internal/config"
16 "gitlab.com/Timfa/bluegit/internal/store"
17 )
18
19 func TestForceMergeDespiteDraft(t *testing.T) {
20 srv, ts, st := mergeFixServer(t)
21 _ = srv
22 tim := loginClient(t, ts)
23 token := mintToken(t, tim, ts)
24 work := pushPair(t, ts, token, "forcey", "alpha\n", "beta\n")
25 page := read(t, mustGet(t, tim, ts.URL+"/tim/forcey/-/merge-requests/new?source=topic&target=master"))
26 page = read(t, mustPost(t, tim, ts.URL+"/tim/forcey/-/merge-requests", url.Values{
27 "csrf": {csrfOf(t, page)}, "title": {"Concept"}, "description": {"Closes #9"},
28 "source": {"topic"}, "target": {"master"}, "draft": {"1"},
29 }))
30 if !strings.Contains(page, "This merge request is a draft.") || !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
31 t.Fatalf("reden ontbreekt:\n%s", page)
32 }
33 if strings.Contains(page, `>{{t "action.merge"}}`) {
34 t.Fatal("gewone mergeknop")
35 }
36 stayed := read(t, mustPost(t, tim, ts.URL+"/tim/forcey/-/merge-requests/1/merge", url.Values{
37 "csrf": {csrfOf(t, page)}, "force": {"1"},
38 }))
39 if !strings.Contains(stayed, "Confirm that you want to merge anyway.") {
40 t.Fatalf("zonder bevestiging:\n%s", stayed)
41 }
42 ctx := context.Background()
43 repo, err := st.RepoByPath(ctx, "tim", "forcey")
44 if err != nil {
45 t.Fatal(err)
46 }
47 mr, err := st.MergeRequestByNumber(ctx, repo.ID, 1)
48 if err != nil || mr.Status != "open" {
49 t.Fatalf("status %s %v", mr.Status, err)
50 }
51 merged := read(t, mustPost(t, tim, ts.URL+"/tim/forcey/-/merge-requests/1/merge", url.Values{
52 "csrf": {csrfOf(t, stayed)}, "force": {"1"}, "confirm_force": {"1"},
53 }))
54 if !strings.Contains(merged, "merged anyway") || !strings.Contains(merged, "This merge request is a draft.") {
55 t.Fatalf("activiteit:\n%s", merged)
56 }
57 mr, err = st.MergeRequestByNumber(ctx, repo.ID, 1)
58 if err != nil || mr.Status != "merged" {
59 t.Fatalf("na toch mergen: %s %v", mr.Status, err)
60 }
61 _ = work
62 }
63
64 func TestPushMarksMergeRequestMerged(t *testing.T) {
65 _, ts, st := mergeFixServer(t)
66 tim := loginClient(t, ts)
67 token := mintToken(t, tim, ts)
68 work := pushPair(t, ts, token, "hand", "een\n", "twee\n")
69 page := read(t, mustGet(t, tim, ts.URL+"/tim/hand/-/merge-requests/new?source=topic&target=master"))
70 page = read(t, mustPost(t, tim, ts.URL+"/tim/hand/-/merge-requests", url.Values{
71 "csrf": {csrfOf(t, page)}, "title": {"Handmatig"}, "source": {"topic"}, "target": {"master"},
72 }))
73 if !strings.Contains(page, ">open<") && !strings.Contains(page, "open") {
74 t.Fatalf("open:\n%s", page)
75 }
76 git(t, work, "checkout", "master")
77 git(t, work, "merge", "--no-edit", "topic")
78 git(t, work, "push", "origin", "master")
79 ctx := context.Background()
80 repo, err := st.RepoByPath(ctx, "tim", "hand")
81 if err != nil {
82 t.Fatal(err)
83 }
84 mr, err := st.MergeRequestByNumber(ctx, repo.ID, 1)
85 if err != nil || mr.Status != "merged" {
86 t.Fatalf("push hoort de MR merged te zetten: %s %v", mr.Status, err)
87 }
88 shown := read(t, mustGet(t, tim, ts.URL+"/tim/hand/-/merge-requests/1"))
89 if !strings.Contains(shown, "merged this merge request") {
90 t.Fatalf("tijdlijn:\n%s", shown)
91 }
92 branches := read(t, mustGet(t, tim, ts.URL+"/tim/hand/-/branches"))
93 if strings.Contains(branches, "/-/merge-requests/1") {
94 t.Fatalf("gemergde MR hoort niet meer in de kolom:\n%s", branches)
95 }
96 }
97
98 func TestMergeShowsConflict(t *testing.T) {
99 _, ts, _ := mergeFixServer(t)
100 tim := loginClient(t, ts)
101 token := mintToken(t, tim, ts)
102 work := pushPair(t, ts, token, "bots", "zelfde\n", "links\n")
103 git(t, work, "checkout", "master")
104 writeFile(t, filepath.Join(work, "hello.txt"), "rechts\n")
105 git(t, work, "add", "hello.txt")
106 git(t, work, "commit", "-m", "master wijzigt")
107 git(t, work, "push", "origin", "master")
108 page := read(t, mustGet(t, tim, ts.URL+"/tim/bots/-/merge-requests/new?source=topic&target=master"))
109 page = read(t, mustPost(t, tim, ts.URL+"/tim/bots/-/merge-requests", url.Values{
110 "csrf": {csrfOf(t, page)}, "title": {"Bots"}, "source": {"topic"}, "target": {"master"},
111 }))
112 if !strings.Contains(page, "The branches conflict.") || !strings.Contains(page, "Merge anyway") {
113 t.Fatalf("conflict:\n%s", page)
114 }
115 tried := read(t, mustPost(t, tim, ts.URL+"/tim/bots/-/merge-requests/1/merge", url.Values{
116 "csrf": {csrfOf(t, page)}, "force": {"1"}, "confirm_force": {"1"},
117 }))
118 if !strings.Contains(tried, "conflict") || !strings.Contains(tried, ">open<") && !strings.Contains(tried, "open") {
119 t.Fatalf("toch mergen bij een conflict:\n%s", tried)
120 }
121 }
122
123 func mergeFixServer(t *testing.T) (*Server, *httptest.Server, *store.Store) {
124 t.Helper()
125 if _, err := exec.LookPath("git"); err != nil {
126 t.Skip("git ontbreekt")
127 }
128 storage := t.TempDir()
129 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
130 if err != nil {
131 t.Fatal(err)
132 }
133 t.Cleanup(func() { _ = st.Close() })
134 cfg := config.Config{
135 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
136 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
137 Git: config.Git{Binary: "git", DefaultBranch: "master"},
138 }
139 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
140 ts := httptest.NewServer(srv.Handler())
141 t.Cleanup(ts.Close)
142 return srv, ts, st
143 }
144
145 func loginClient(t *testing.T, ts *httptest.Server) *http.Client {
146 t.Helper()
147 jar, _ := cookiejar.New(nil)
148 tim := &http.Client{Jar: jar}
149 read(t, mustGet(t, tim, ts.URL+"/login"))
150 return tim
151 }
152
153 func mintToken(t *testing.T, tim *http.Client, ts *httptest.Server) string {
154 t.Helper()
155 page := read(t, mustGet(t, tim, ts.URL+"/settings"))
156 page = read(t, mustPost(t, tim, ts.URL+"/settings/tokens", url.Values{
157 "csrf": {csrfOf(t, page)}, "name": {"laptop"},
158 }))
159 return between(page, `<p class="code">`, "</p>")
160 }
161
162 func pushPair(t *testing.T, ts *httptest.Server, token, name, base, next string) string {
163 t.Helper()
164 page := read(t, mustGet(t, loginOwner(t, ts), ts.URL+"/new/repo"))
165 _ = page
166 tim := loginOwner(t, ts)
167 home := read(t, mustGet(t, tim, ts.URL+"/"))
168 _ = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
169 "csrf": {csrfOf(t, home)}, "name": {name}, "visibility": {"public"},
170 }))
171 remote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/" + name + ".git"
172 work := t.TempDir()
173 git(t, work, "init", "-b", "master")
174 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
175 git(t, work, "config", "user.name", "tim")
176 writeFile(t, filepath.Join(work, "hello.txt"), base)
177 git(t, work, "add", "hello.txt")
178 git(t, work, "commit", "-m", "start")
179 git(t, work, "remote", "add", "origin", remote)
180 git(t, work, "push", "-u", "origin", "master")
181 git(t, work, "checkout", "-b", "topic")
182 writeFile(t, filepath.Join(work, "hello.txt"), next)
183 git(t, work, "add", "hello.txt")
184 git(t, work, "commit", "-m", "verder")
185 git(t, work, "push", "-u", "origin", "topic")
186 return work
187 }
188
189 func loginOwner(t *testing.T, ts *httptest.Server) *http.Client {
190 t.Helper()
191 return loginClient(t, ts)
192 }
@@ -0,0 +1,192 @@
1package server
2
3import (
4 "context"
5 "net/http"
6 "net/http/cookiejar"
7 "net/http/httptest"
8 "net/url"
9 "os/exec"
10 "path/filepath"
11 "strings"
12 "testing"
13
14 "gitlab.com/Timfa/bluegit/internal/auth"
15 "gitlab.com/Timfa/bluegit/internal/config"
16 "gitlab.com/Timfa/bluegit/internal/store"
17)
18
19func TestForceMergeDespiteDraft(t *testing.T) {
20 srv, ts, st := mergeFixServer(t)
21 _ = srv
22 tim := loginClient(t, ts)
23 token := mintToken(t, tim, ts)
24 work := pushPair(t, ts, token, "forcey", "alpha\n", "beta\n")
25 page := read(t, mustGet(t, tim, ts.URL+"/tim/forcey/-/merge-requests/new?source=topic&target=master"))
26 page = read(t, mustPost(t, tim, ts.URL+"/tim/forcey/-/merge-requests", url.Values{
27 "csrf": {csrfOf(t, page)}, "title": {"Concept"}, "description": {"Closes #9"},
28 "source": {"topic"}, "target": {"master"}, "draft": {"1"},
29 }))
30 if !strings.Contains(page, "This merge request is a draft.") || !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
31 t.Fatalf("reden ontbreekt:\n%s", page)
32 }
33 if strings.Contains(page, `>{{t "action.merge"}}`) {
34 t.Fatal("gewone mergeknop")
35 }
36 stayed := read(t, mustPost(t, tim, ts.URL+"/tim/forcey/-/merge-requests/1/merge", url.Values{
37 "csrf": {csrfOf(t, page)}, "force": {"1"},
38 }))
39 if !strings.Contains(stayed, "Confirm that you want to merge anyway.") {
40 t.Fatalf("zonder bevestiging:\n%s", stayed)
41 }
42 ctx := context.Background()
43 repo, err := st.RepoByPath(ctx, "tim", "forcey")
44 if err != nil {
45 t.Fatal(err)
46 }
47 mr, err := st.MergeRequestByNumber(ctx, repo.ID, 1)
48 if err != nil || mr.Status != "open" {
49 t.Fatalf("status %s %v", mr.Status, err)
50 }
51 merged := read(t, mustPost(t, tim, ts.URL+"/tim/forcey/-/merge-requests/1/merge", url.Values{
52 "csrf": {csrfOf(t, stayed)}, "force": {"1"}, "confirm_force": {"1"},
53 }))
54 if !strings.Contains(merged, "merged anyway") || !strings.Contains(merged, "This merge request is a draft.") {
55 t.Fatalf("activiteit:\n%s", merged)
56 }
57 mr, err = st.MergeRequestByNumber(ctx, repo.ID, 1)
58 if err != nil || mr.Status != "merged" {
59 t.Fatalf("na toch mergen: %s %v", mr.Status, err)
60 }
61 _ = work
62}
63
64func TestPushMarksMergeRequestMerged(t *testing.T) {
65 _, ts, st := mergeFixServer(t)
66 tim := loginClient(t, ts)
67 token := mintToken(t, tim, ts)
68 work := pushPair(t, ts, token, "hand", "een\n", "twee\n")
69 page := read(t, mustGet(t, tim, ts.URL+"/tim/hand/-/merge-requests/new?source=topic&target=master"))
70 page = read(t, mustPost(t, tim, ts.URL+"/tim/hand/-/merge-requests", url.Values{
71 "csrf": {csrfOf(t, page)}, "title": {"Handmatig"}, "source": {"topic"}, "target": {"master"},
72 }))
73 if !strings.Contains(page, ">open<") && !strings.Contains(page, "open") {
74 t.Fatalf("open:\n%s", page)
75 }
76 git(t, work, "checkout", "master")
77 git(t, work, "merge", "--no-edit", "topic")
78 git(t, work, "push", "origin", "master")
79 ctx := context.Background()
80 repo, err := st.RepoByPath(ctx, "tim", "hand")
81 if err != nil {
82 t.Fatal(err)
83 }
84 mr, err := st.MergeRequestByNumber(ctx, repo.ID, 1)
85 if err != nil || mr.Status != "merged" {
86 t.Fatalf("push hoort de MR merged te zetten: %s %v", mr.Status, err)
87 }
88 shown := read(t, mustGet(t, tim, ts.URL+"/tim/hand/-/merge-requests/1"))
89 if !strings.Contains(shown, "merged this merge request") {
90 t.Fatalf("tijdlijn:\n%s", shown)
91 }
92 branches := read(t, mustGet(t, tim, ts.URL+"/tim/hand/-/branches"))
93 if strings.Contains(branches, "/-/merge-requests/1") {
94 t.Fatalf("gemergde MR hoort niet meer in de kolom:\n%s", branches)
95 }
96}
97
98func TestMergeShowsConflict(t *testing.T) {
99 _, ts, _ := mergeFixServer(t)
100 tim := loginClient(t, ts)
101 token := mintToken(t, tim, ts)
102 work := pushPair(t, ts, token, "bots", "zelfde\n", "links\n")
103 git(t, work, "checkout", "master")
104 writeFile(t, filepath.Join(work, "hello.txt"), "rechts\n")
105 git(t, work, "add", "hello.txt")
106 git(t, work, "commit", "-m", "master wijzigt")
107 git(t, work, "push", "origin", "master")
108 page := read(t, mustGet(t, tim, ts.URL+"/tim/bots/-/merge-requests/new?source=topic&target=master"))
109 page = read(t, mustPost(t, tim, ts.URL+"/tim/bots/-/merge-requests", url.Values{
110 "csrf": {csrfOf(t, page)}, "title": {"Bots"}, "source": {"topic"}, "target": {"master"},
111 }))
112 if !strings.Contains(page, "The branches conflict.") || !strings.Contains(page, "Merge anyway") {
113 t.Fatalf("conflict:\n%s", page)
114 }
115 tried := read(t, mustPost(t, tim, ts.URL+"/tim/bots/-/merge-requests/1/merge", url.Values{
116 "csrf": {csrfOf(t, page)}, "force": {"1"}, "confirm_force": {"1"},
117 }))
118 if !strings.Contains(tried, "conflict") || !strings.Contains(tried, ">open<") && !strings.Contains(tried, "open") {
119 t.Fatalf("toch mergen bij een conflict:\n%s", tried)
120 }
121}
122
123func mergeFixServer(t *testing.T) (*Server, *httptest.Server, *store.Store) {
124 t.Helper()
125 if _, err := exec.LookPath("git"); err != nil {
126 t.Skip("git ontbreekt")
127 }
128 storage := t.TempDir()
129 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
130 if err != nil {
131 t.Fatal(err)
132 }
133 t.Cleanup(func() { _ = st.Close() })
134 cfg := config.Config{
135 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
136 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
137 Git: config.Git{Binary: "git", DefaultBranch: "master"},
138 }
139 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
140 ts := httptest.NewServer(srv.Handler())
141 t.Cleanup(ts.Close)
142 return srv, ts, st
143}
144
145func loginClient(t *testing.T, ts *httptest.Server) *http.Client {
146 t.Helper()
147 jar, _ := cookiejar.New(nil)
148 tim := &http.Client{Jar: jar}
149 read(t, mustGet(t, tim, ts.URL+"/login"))
150 return tim
151}
152
153func mintToken(t *testing.T, tim *http.Client, ts *httptest.Server) string {
154 t.Helper()
155 page := read(t, mustGet(t, tim, ts.URL+"/settings"))
156 page = read(t, mustPost(t, tim, ts.URL+"/settings/tokens", url.Values{
157 "csrf": {csrfOf(t, page)}, "name": {"laptop"},
158 }))
159 return between(page, `<p class="code">`, "</p>")
160}
161
162func pushPair(t *testing.T, ts *httptest.Server, token, name, base, next string) string {
163 t.Helper()
164 page := read(t, mustGet(t, loginOwner(t, ts), ts.URL+"/new/repo"))
165 _ = page
166 tim := loginOwner(t, ts)
167 home := read(t, mustGet(t, tim, ts.URL+"/"))
168 _ = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
169 "csrf": {csrfOf(t, home)}, "name": {name}, "visibility": {"public"},
170 }))
171 remote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/" + name + ".git"
172 work := t.TempDir()
173 git(t, work, "init", "-b", "master")
174 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
175 git(t, work, "config", "user.name", "tim")
176 writeFile(t, filepath.Join(work, "hello.txt"), base)
177 git(t, work, "add", "hello.txt")
178 git(t, work, "commit", "-m", "start")
179 git(t, work, "remote", "add", "origin", remote)
180 git(t, work, "push", "-u", "origin", "master")
181 git(t, work, "checkout", "-b", "topic")
182 writeFile(t, filepath.Join(work, "hello.txt"), next)
183 git(t, work, "add", "hello.txt")
184 git(t, work, "commit", "-m", "verder")
185 git(t, work, "push", "-u", "origin", "topic")
186 return work
187}
188
189func loginOwner(t *testing.T, ts *httptest.Server) *http.Client {
190 t.Helper()
191 return loginClient(t, ts)
192}
internal/server/mr_page.go +2 −0
@@ -225,6 +225,8 @@ func mrEventKey(kind string) string {
225 225 return "mr.relabeled"
226 226 case "merged":
227 227 return "mr.mergedEvent"
228 case "forced":
229 return "mr.forcedEvent"
228 230 case "closed":
229 231 return "mr.closedEvent"
230 232 case "reopened":
@@ -225,6 +225,8 @@ func mrEventKey(kind string) string {
225 return "mr.relabeled"
225 return "mr.relabeled"
226 case "merged":
226 case "merged":
227 return "mr.mergedEvent"
227 return "mr.mergedEvent"
228 case "forced":
229 return "mr.forcedEvent"
228 case "closed":
230 case "closed":
229 return "mr.closedEvent"
231 return "mr.closedEvent"
230 case "reopened":
232 case "reopened":
internal/server/mr_pipeline.go +22 −1
@@ -147,7 +147,28 @@ func (s *Server) mergeBlocks(r *http.Request, repo store.Repo, mr store.MergeReq
147 147 if s.Cfg.CI.Enabled && s.StoragePath() != "" {
148 148 blocks = append(blocks, s.pipelineBlocks(r, repo, mr)...)
149 149 }
150 return append(blocks, s.reviewBlocks(r, repo, mr)...)
150 blocks = append(blocks, s.reviewBlocks(r, repo, mr)...)
151 if s.StoragePath() != "" {
152 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
153 if conflict, known := s.branchConflict(r.Context(), dir, mr.TargetBranch, mr.SourceBranch); known && conflict {
154 blocks = append(blocks, s.tr(r, "mr.block.conflict"))
155 }
156 }
157 return blocks
158 }
159
160 func (s *Server) branchConflict(ctx context.Context, dir, target, source string) (conflict, known bool) {
161 if gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "--quiet", "refs/heads/"+target) == "" {
162 return false, false
163 }
164 if gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "--quiet", "refs/heads/"+source) == "" {
165 return false, false
166 }
167 conflict, err := gitrepo.Conflicts(ctx, s.Git, dir, "refs/heads/"+target, "refs/heads/"+source)
168 if err != nil {
169 return false, false
170 }
171 return conflict, true
151 172 }
152 173
153 174 func (s *Server) pipelineBlocks(r *http.Request, repo store.Repo, mr store.MergeRequest) []string {
@@ -147,7 +147,28 @@ func (s *Server) mergeBlocks(r *http.Request, repo store.Repo, mr store.MergeReq
147 if s.Cfg.CI.Enabled && s.StoragePath() != "" {
147 if s.Cfg.CI.Enabled && s.StoragePath() != "" {
148 blocks = append(blocks, s.pipelineBlocks(r, repo, mr)...)
148 blocks = append(blocks, s.pipelineBlocks(r, repo, mr)...)
149 }
149 }
150 return append(blocks, s.reviewBlocks(r, repo, mr)...)
150 blocks = append(blocks, s.reviewBlocks(r, repo, mr)...)
151 if s.StoragePath() != "" {
152 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
153 if conflict, known := s.branchConflict(r.Context(), dir, mr.TargetBranch, mr.SourceBranch); known && conflict {
154 blocks = append(blocks, s.tr(r, "mr.block.conflict"))
155 }
156 }
157 return blocks
158}
159
160func (s *Server) branchConflict(ctx context.Context, dir, target, source string) (conflict, known bool) {
161 if gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "--quiet", "refs/heads/"+target) == "" {
162 return false, false
163 }
164 if gitOne(ctx, s.Git, dir, "rev-parse", "--verify", "--quiet", "refs/heads/"+source) == "" {
165 return false, false
166 }
167 conflict, err := gitrepo.Conflicts(ctx, s.Git, dir, "refs/heads/"+target, "refs/heads/"+source)
168 if err != nil {
169 return false, false
170 }
171 return conflict, true
151}
172}
152
173
153func (s *Server) pipelineBlocks(r *http.Request, repo store.Repo, mr store.MergeRequest) []string {
174func (s *Server) pipelineBlocks(r *http.Request, repo store.Repo, mr store.MergeRequest) []string {
internal/server/mr_pipeline_test.go +2 −2
@@ -102,7 +102,7 @@ soft:
102 102 if !strings.Contains(page, "mr_job") || !strings.Contains(page, "soft") || strings.Contains(page, "push_job") {
103 103 t.Fatalf("mr-pipeline op de pagina:\n%s", page)
104 104 }
105 if !strings.Contains(page, "The pipeline is still running.") || !strings.Contains(page, "disabled") {
105 if !strings.Contains(page, "The pipeline is still running.") || !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
106 106 t.Fatalf("merge hoort geblokkeerd:\n%s", page)
107 107 }
108 108
@@ -181,7 +181,7 @@ soft:
181 181 t.Fatal(err)
182 182 }
183 183 page = read(t, res)
184 if strings.Contains(page, "The pipeline is still running.") || strings.Contains(page, "disabled") {
184 if strings.Contains(page, "The pipeline is still running.") || strings.Contains(page, "Merge anyway") {
185 185 t.Fatalf("merge hoort open:\n%s", page)
186 186 }
187 187 if !strings.Contains(page, "Warning") && !strings.Contains(page, "Passed") {
@@ -102,7 +102,7 @@ soft:
102 if !strings.Contains(page, "mr_job") || !strings.Contains(page, "soft") || strings.Contains(page, "push_job") {
102 if !strings.Contains(page, "mr_job") || !strings.Contains(page, "soft") || strings.Contains(page, "push_job") {
103 t.Fatalf("mr-pipeline op de pagina:\n%s", page)
103 t.Fatalf("mr-pipeline op de pagina:\n%s", page)
104 }
104 }
105 if !strings.Contains(page, "The pipeline is still running.") || !strings.Contains(page, "disabled") {
105 if !strings.Contains(page, "The pipeline is still running.") || !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
106 t.Fatalf("merge hoort geblokkeerd:\n%s", page)
106 t.Fatalf("merge hoort geblokkeerd:\n%s", page)
107 }
107 }
108
108
@@ -181,7 +181,7 @@ soft:
181 t.Fatal(err)
181 t.Fatal(err)
182 }
182 }
183 page = read(t, res)
183 page = read(t, res)
184 if strings.Contains(page, "The pipeline is still running.") || strings.Contains(page, "disabled") {
184 if strings.Contains(page, "The pipeline is still running.") || strings.Contains(page, "Merge anyway") {
185 t.Fatalf("merge hoort open:\n%s", page)
185 t.Fatalf("merge hoort open:\n%s", page)
186 }
186 }
187 if !strings.Contains(page, "Warning") && !strings.Contains(page, "Passed") {
187 if !strings.Contains(page, "Warning") && !strings.Contains(page, "Passed") {
internal/server/ops_mr.go +21 −7
@@ -268,9 +268,17 @@ func (s *Server) opMergeMR(r *http.Request, user store.User, repo store.Repo, nu
268 268 if !role.CanMerge(access.BranchProtected(patterns, mr.TargetBranch)) {
269 269 return fail(403, i18n.E("err.targetAccess"))
270 270 }
271 if blocks := s.mergeBlocks(r, repo, mr); len(blocks) > 0 {
272 return fail(409, i18n.E("err.mrBlocked", blocks[0]))
271 blocks := s.mergeBlocks(r, repo, mr)
272 force := r.FormValue("force") == "1" && role.CanManageSettings()
273 if len(blocks) > 0 {
274 if !force {
275 return fail(409, i18n.E("err.mrBlocked", strings.Join(blocks, " ")))
276 }
277 if r.FormValue("confirm_force") != "1" {
278 return fail(409, i18n.E("mr.force.need"))
279 }
273 280 }
281 texts := s.mergeCloseTexts(r, repo, mr)
274 282 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
275 283 work, err := s.scratchDir("merge")
276 284 if err != nil {
@@ -283,11 +291,17 @@ func (s *Server) opMergeMR(r *http.Request, user store.User, repo store.Repo, nu
283 291 }); err != nil {
284 292 return fail(400, err)
285 293 }
286 _ = s.Store.SetMergeRequestStatus(ctx, mr.ID, "merged")
287 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "merged", "")
288 mr.Status = "merged"
289 s.mrHook(repo, mr, user.Username, "merged", "")
290 s.closeIssueNumbers(ctx, repo, user, closingNumbers(s.mergeCloseTexts(r, repo, mr)...))
294 fresh, ferr := s.Store.MergeRequestByNumber(ctx, repo.ID, mr.Number)
295 if ferr != nil || fresh.Status != "merged" {
296 _ = s.Store.SetMergeRequestStatus(ctx, mr.ID, "merged")
297 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "merged", "")
298 mr.Status = "merged"
299 s.mrHook(repo, mr, user.Username, "merged", "")
300 s.closeIssueNumbers(ctx, repo, user, closingNumbers(texts...))
301 }
302 if force && len(blocks) > 0 {
303 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "forced", strings.Join(blocks, "\n"))
304 }
291 305 return nil
292 306 }
293 307
@@ -268,9 +268,17 @@ func (s *Server) opMergeMR(r *http.Request, user store.User, repo store.Repo, nu
268 if !role.CanMerge(access.BranchProtected(patterns, mr.TargetBranch)) {
268 if !role.CanMerge(access.BranchProtected(patterns, mr.TargetBranch)) {
269 return fail(403, i18n.E("err.targetAccess"))
269 return fail(403, i18n.E("err.targetAccess"))
270 }
270 }
271 if blocks := s.mergeBlocks(r, repo, mr); len(blocks) > 0 {
271 blocks := s.mergeBlocks(r, repo, mr)
272 return fail(409, i18n.E("err.mrBlocked", blocks[0]))
272 force := r.FormValue("force") == "1" && role.CanManageSettings()
273 if len(blocks) > 0 {
274 if !force {
275 return fail(409, i18n.E("err.mrBlocked", strings.Join(blocks, " ")))
276 }
277 if r.FormValue("confirm_force") != "1" {
278 return fail(409, i18n.E("mr.force.need"))
279 }
273 }
280 }
281 texts := s.mergeCloseTexts(r, repo, mr)
274 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
282 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
275 work, err := s.scratchDir("merge")
283 work, err := s.scratchDir("merge")
276 if err != nil {
284 if err != nil {
@@ -283,11 +291,17 @@ func (s *Server) opMergeMR(r *http.Request, user store.User, repo store.Repo, nu
283 }); err != nil {
291 }); err != nil {
284 return fail(400, err)
292 return fail(400, err)
285 }
293 }
286 _ = s.Store.SetMergeRequestStatus(ctx, mr.ID, "merged")
294 fresh, ferr := s.Store.MergeRequestByNumber(ctx, repo.ID, mr.Number)
287 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "merged", "")
295 if ferr != nil || fresh.Status != "merged" {
288 mr.Status = "merged"
296 _ = s.Store.SetMergeRequestStatus(ctx, mr.ID, "merged")
289 s.mrHook(repo, mr, user.Username, "merged", "")
297 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "merged", "")
290 s.closeIssueNumbers(ctx, repo, user, closingNumbers(s.mergeCloseTexts(r, repo, mr)...))
298 mr.Status = "merged"
299 s.mrHook(repo, mr, user.Username, "merged", "")
300 s.closeIssueNumbers(ctx, repo, user, closingNumbers(texts...))
301 }
302 if force && len(blocks) > 0 {
303 _ = s.Store.AddMREvent(ctx, repo.ID, mr.ID, user.ID, "forced", strings.Join(blocks, "\n"))
304 }
291 return nil
305 return nil
292}
306}
293
307
internal/server/repo_handlers.go +3 −0
@@ -171,6 +171,7 @@ func (s *Server) mergeRequests(w http.ResponseWriter, r *http.Request) {
171 171 if !ok {
172 172 return
173 173 }
174 s.absorbMergedMRs(r.Context(), repo)
174 175 v := s.repoView(w, r, repo, role, "title.mrs")
175 176 v.Page = "mrs"
176 177 v.MRs, _ = s.Store.ListMergeRequests(r.Context(), repo.ID)
@@ -203,6 +204,7 @@ func (s *Server) showMR(w http.ResponseWriter, r *http.Request) {
203 204 if !ok {
204 205 return
205 206 }
207 s.absorbMergedMRs(r.Context(), repo)
206 208 n, err := strconv.ParseInt(r.PathValue("number"), 10, 64)
207 209 if err != nil {
208 210 http.NotFound(w, r)
@@ -222,6 +224,7 @@ func (s *Server) showMR(w http.ResponseWriter, r *http.Request) {
222 224 v.CanMerge = mr.Status == "open" && role.CanMerge(access.BranchProtected(patterns, mr.TargetBranch))
223 225 v.CanApply = mr.Status == "open" && role.CanPushBranch(access.BranchProtected(patterns, mr.SourceBranch))
224 226 v.MergeBlocks = s.mergeBlocks(r, repo, mr)
227 v.CanForce = v.CanMerge && role.CanManageSettings() && len(v.MergeBlocks) > 0
225 228 s.fillMRPipeline(r, &v, repo, mr)
226 229 s.fillReviews(r, &v, repo, mr, role)
227 230 if u.ID != 0 {
@@ -171,6 +171,7 @@ func (s *Server) mergeRequests(w http.ResponseWriter, r *http.Request) {
171 if !ok {
171 if !ok {
172 return
172 return
173 }
173 }
174 s.absorbMergedMRs(r.Context(), repo)
174 v := s.repoView(w, r, repo, role, "title.mrs")
175 v := s.repoView(w, r, repo, role, "title.mrs")
175 v.Page = "mrs"
176 v.Page = "mrs"
176 v.MRs, _ = s.Store.ListMergeRequests(r.Context(), repo.ID)
177 v.MRs, _ = s.Store.ListMergeRequests(r.Context(), repo.ID)
@@ -203,6 +204,7 @@ func (s *Server) showMR(w http.ResponseWriter, r *http.Request) {
203 if !ok {
204 if !ok {
204 return
205 return
205 }
206 }
207 s.absorbMergedMRs(r.Context(), repo)
206 n, err := strconv.ParseInt(r.PathValue("number"), 10, 64)
208 n, err := strconv.ParseInt(r.PathValue("number"), 10, 64)
207 if err != nil {
209 if err != nil {
208 http.NotFound(w, r)
210 http.NotFound(w, r)
@@ -222,6 +224,7 @@ func (s *Server) showMR(w http.ResponseWriter, r *http.Request) {
222 v.CanMerge = mr.Status == "open" && role.CanMerge(access.BranchProtected(patterns, mr.TargetBranch))
224 v.CanMerge = mr.Status == "open" && role.CanMerge(access.BranchProtected(patterns, mr.TargetBranch))
223 v.CanApply = mr.Status == "open" && role.CanPushBranch(access.BranchProtected(patterns, mr.SourceBranch))
225 v.CanApply = mr.Status == "open" && role.CanPushBranch(access.BranchProtected(patterns, mr.SourceBranch))
224 v.MergeBlocks = s.mergeBlocks(r, repo, mr)
226 v.MergeBlocks = s.mergeBlocks(r, repo, mr)
227 v.CanForce = v.CanMerge && role.CanManageSettings() && len(v.MergeBlocks) > 0
225 s.fillMRPipeline(r, &v, repo, mr)
228 s.fillMRPipeline(r, &v, repo, mr)
226 s.fillReviews(r, &v, repo, mr, role)
229 s.fillReviews(r, &v, repo, mr, role)
227 if u.ID != 0 {
230 if u.ID != 0 {
internal/server/reviews_test.go +2 −2
@@ -198,7 +198,7 @@ func TestReviewsApprovalsAndReopen(t *testing.T) {
198 198 t.Fatal(err)
199 199 }
200 200 page = read(t, res)
201 if !strings.Contains(page, "disabled") {
201 if !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
202 202 t.Fatalf("mergeknop hoort uit:\n%s", page)
203 203 }
204 204 bobID := ""
@@ -216,7 +216,7 @@ func TestReviewsApprovalsAndReopen(t *testing.T) {
216 216 t.Fatal(err)
217 217 }
218 218 body = read(t, res)
219 if strings.Contains(body, "bob requested changes.") || strings.Contains(body, "disabled") {
219 if strings.Contains(body, "bob requested changes.") || strings.Contains(body, "Merge anyway") {
220 220 t.Fatalf("na ongeldig verklaren:\n%s", body)
221 221 }
222 222 if !strings.Contains(body, "Invalidated") {
@@ -198,7 +198,7 @@ func TestReviewsApprovalsAndReopen(t *testing.T) {
198 t.Fatal(err)
198 t.Fatal(err)
199 }
199 }
200 page = read(t, res)
200 page = read(t, res)
201 if !strings.Contains(page, "disabled") {
201 if !strings.Contains(page, "Merge anyway") || !strings.Contains(page, "cannot be merged yet") {
202 t.Fatalf("mergeknop hoort uit:\n%s", page)
202 t.Fatalf("mergeknop hoort uit:\n%s", page)
203 }
203 }
204 bobID := ""
204 bobID := ""
@@ -216,7 +216,7 @@ func TestReviewsApprovalsAndReopen(t *testing.T) {
216 t.Fatal(err)
216 t.Fatal(err)
217 }
217 }
218 body = read(t, res)
218 body = read(t, res)
219 if strings.Contains(body, "bob requested changes.") || strings.Contains(body, "disabled") {
219 if strings.Contains(body, "bob requested changes.") || strings.Contains(body, "Merge anyway") {
220 t.Fatalf("na ongeldig verklaren:\n%s", body)
220 t.Fatalf("na ongeldig verklaren:\n%s", body)
221 }
221 }
222 if !strings.Contains(body, "Invalidated") {
222 if !strings.Contains(body, "Invalidated") {
internal/server/server.go +7 −6
@@ -507,6 +507,7 @@ type View struct {
507 507 CanWrite bool
508 508 CanAdmin bool
509 509 CanMerge bool
510 CanForce bool
510 511 CanComment bool
511 512 CanApply bool
512 513 Commits []CommitRow
@@ -695,12 +696,12 @@ type EntryRow struct {
695 696
696 697 // BranchRow is een branch, met of zonder bescherming.
697 698 type BranchRow struct {
698 Name, SHA, Short, Subject, When string
699 Protected, Default bool
700 Ahead, Behind int
701 PipeID int64
702 PipeStatus, PipeLabel string
703 MRNumber int64
699 Name, SHA, Short, Subject, When, WhenTitle string
700 Protected, Default bool
701 Ahead, Behind int
702 PipeID int64
703 PipeStatus, PipeLabel string
704 OpenMRs []int64
704 705 }
705 706
706 707 // TimelineItem is één gebeurtenis of reactie op een merge request.
@@ -507,6 +507,7 @@ type View struct {
507 CanWrite bool
507 CanWrite bool
508 CanAdmin bool
508 CanAdmin bool
509 CanMerge bool
509 CanMerge bool
510 CanForce bool
510 CanComment bool
511 CanComment bool
511 CanApply bool
512 CanApply bool
512 Commits []CommitRow
513 Commits []CommitRow
@@ -695,12 +696,12 @@ type EntryRow struct {
695
696
696// BranchRow is een branch, met of zonder bescherming.
697// BranchRow is een branch, met of zonder bescherming.
697type BranchRow struct {
698type BranchRow struct {
698 Name, SHA, Short, Subject, When string
699 Name, SHA, Short, Subject, When, WhenTitle string
699 Protected, Default bool
700 Protected, Default bool
700 Ahead, Behind int
701 Ahead, Behind int
701 PipeID int64
702 PipeID int64
702 PipeStatus, PipeLabel string
703 PipeStatus, PipeLabel string
703 MRNumber int64
704 OpenMRs []int64
704}
705}
705
706
706// TimelineItem is één gebeurtenis of reactie op een merge request.
707// TimelineItem is één gebeurtenis of reactie op een merge request.
internal/server/static/style.css +23 −2
@@ -782,8 +782,29 @@ a.btn { text-decoration: none; }
782 782 }
783 783 .branchtable th { font-size: var(--fs-sm); color: var(--muted); font-weight: 650; }
784 784 .branchtable .nums, .branchtable .addstat, .branchtable .delstat { font-variant-numeric: tabular-nums; white-space: nowrap; }
785 .branchacts { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; min-height: 2.4rem; }
786 .branchacts a { white-space: nowrap; }
785 .branchacts { white-space: nowrap; width: 1%; }
786 .branchline { display: inline-flex; flex-wrap: nowrap; align-items: center; gap: 0.3rem; }
787 .branchline .tiny, .tiny-menu > summary {
788 min-height: 1.7rem; padding: 0 0.45rem; font-size: var(--fs-sm);
789 background: white; color: var(--ink); border: 1px solid var(--line);
790 border-radius: var(--radius); text-decoration: none; line-height: 1.2;
791 }
792 .tiny-menu > summary { display: inline-flex; align-items: center; }
793 .mrlinks { white-space: nowrap; }
794 .mrlinks a + a { margin-left: 0.35rem; }
795 .branchtable .subject {
796 display: inline-block; max-width: 16rem; overflow: hidden;
797 text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
798 }
799 .when-short { white-space: nowrap; }
800 .mergewhy {
801 border: 1px solid var(--line); border-radius: var(--radius);
802 padding: 0.7rem 0.9rem; margin: 0.6rem 0; background: #fff8f0;
803 }
804 .mergewhy p { margin: 0; font-weight: 650; }
805 .mergewhy ul { margin: 0.35rem 0 0; }
806 .force-merge { margin: 0.4rem 0 1rem; }
807 .force-merge .check { display: flex; gap: 0.4rem; align-items: center; margin: 0.4rem 0; }
787 808 .branch-dialog {
788 809 border: 0; border-radius: var(--radius-lg); padding: 1.2rem 1.3rem;
789 810 max-width: 32rem; width: calc(100% - 2rem);
@@ -782,8 +782,29 @@ a.btn { text-decoration: none; }
782}
782}
783.branchtable th { font-size: var(--fs-sm); color: var(--muted); font-weight: 650; }
783.branchtable th { font-size: var(--fs-sm); color: var(--muted); font-weight: 650; }
784.branchtable .nums, .branchtable .addstat, .branchtable .delstat { font-variant-numeric: tabular-nums; white-space: nowrap; }
784.branchtable .nums, .branchtable .addstat, .branchtable .delstat { font-variant-numeric: tabular-nums; white-space: nowrap; }
785.branchacts { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; min-height: 2.4rem; }
785.branchacts { white-space: nowrap; width: 1%; }
786.branchacts a { white-space: nowrap; }
786.branchline { display: inline-flex; flex-wrap: nowrap; align-items: center; gap: 0.3rem; }
787.branchline .tiny, .tiny-menu > summary {
788 min-height: 1.7rem; padding: 0 0.45rem; font-size: var(--fs-sm);
789 background: white; color: var(--ink); border: 1px solid var(--line);
790 border-radius: var(--radius); text-decoration: none; line-height: 1.2;
791}
792.tiny-menu > summary { display: inline-flex; align-items: center; }
793.mrlinks { white-space: nowrap; }
794.mrlinks a + a { margin-left: 0.35rem; }
795.branchtable .subject {
796 display: inline-block; max-width: 16rem; overflow: hidden;
797 text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom;
798}
799.when-short { white-space: nowrap; }
800.mergewhy {
801 border: 1px solid var(--line); border-radius: var(--radius);
802 padding: 0.7rem 0.9rem; margin: 0.6rem 0; background: #fff8f0;
803}
804.mergewhy p { margin: 0; font-weight: 650; }
805.mergewhy ul { margin: 0.35rem 0 0; }
806.force-merge { margin: 0.4rem 0 1rem; }
807.force-merge .check { display: flex; gap: 0.4rem; align-items: center; margin: 0.4rem 0; }
787.branch-dialog {
808.branch-dialog {
788 border: 0; border-radius: var(--radius-lg); padding: 1.2rem 1.3rem;
809 border: 0; border-radius: var(--radius-lg); padding: 1.2rem 1.3rem;
789 max-width: 32rem; width: calc(100% - 2rem);
810 max-width: 32rem; width: calc(100% - 2rem);
internal/server/templates/branches.html +14 −7
@@ -27,7 +27,7 @@
27 27 {{if .Protected}}<span class="pill">{{t "vis.protected"}}</span>{{end}}
28 28 </td>
29 29 <td>
30 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a> {{.Subject}} <span class="muted">{{.When}}</span>{{end}}
30 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a> <span class="subject" title="{{.Subject}}">{{.Subject}}</span> <span class="muted when-short" title="{{.WhenTitle}}">{{.When}}</span>{{end}}
31 31 </td>
32 32 <td class="nums">
33 33 {{if and (eq .Ahead 0) (eq .Behind 0)}}<span class="muted">{{t "branch.even"}}</span>{{else}}
@@ -38,18 +38,25 @@
38 38 <td>
39 39 {{if .PipeStatus}}<a class="status {{.PipeStatus}}" href="/{{$.Repo.FullPath}}/-/pipelines/{{.PipeID}}"><span class="mark"></span>{{.PipeLabel}}</a>{{end}}
40 40 </td>
41 <td>
42 {{if .MRNumber}}<a href="/{{$.Repo.FullPath}}/-/merge-requests/{{.MRNumber}}">!{{.MRNumber}}</a>{{end}}
41 <td class="mrlinks">
42 {{range .OpenMRs}}<a href="/{{$.Repo.FullPath}}/-/merge-requests/{{.}}">!{{.}}</a>{{end}}
43 43 </td>
44 44 <td class="branchacts">
45 <div class="branchline">
45 46 {{if not .Default}}
46 <a href="/{{$.Repo.FullPath}}/-/compare?from={{urlquery $.Repo.DefaultBranch}}&amp;to={{urlquery .Name}}">{{t "branch.compare"}}</a>
47 <a href="/{{$.Repo.FullPath}}/-/merge-requests/new?source={{urlquery .Name}}&amp;target={{urlquery $.Repo.DefaultBranch}}">{{t "branch.newMR"}}</a>
47 <a class="tiny" href="/{{$.Repo.FullPath}}/-/compare?from={{urlquery $.Repo.DefaultBranch}}&amp;to={{urlquery .Name}}">{{t "branch.compare"}}</a>
48 {{if not .OpenMRs}}<a class="tiny" href="/{{$.Repo.FullPath}}/-/merge-requests/new?source={{urlquery .Name}}&amp;target={{urlquery $.Repo.DefaultBranch}}">{{t "branch.mrShort"}}</a>{{end}}
48 49 {{end}}
49 50 {{if and $.CanWrite (not .Default) (not .Protected)}}
50 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
51 <button type="button" class="ghost" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
51 <details class="rowmenu tiny-menu">
52 <summary aria-label="{{t "branch.more"}}">⋯</summary>
53 <div class="menu-panel">
54 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
55 <button type="button" class="ghost" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
56 </div>
57 </details>
52 58 {{end}}
59 </div>
53 60 </td>
54 61 </tr>
55 62 {{else}}
@@ -27,7 +27,7 @@
27 {{if .Protected}}<span class="pill">{{t "vis.protected"}}</span>{{end}}
27 {{if .Protected}}<span class="pill">{{t "vis.protected"}}</span>{{end}}
28 </td>
28 </td>
29 <td>
29 <td>
30 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a> {{.Subject}} <span class="muted">{{.When}}</span>{{end}}
30 {{if .SHA}}<a href="/{{$.Repo.FullPath}}/-/commit/{{.SHA}}"><code>{{.Short}}</code></a> <span class="subject" title="{{.Subject}}">{{.Subject}}</span> <span class="muted when-short" title="{{.WhenTitle}}">{{.When}}</span>{{end}}
31 </td>
31 </td>
32 <td class="nums">
32 <td class="nums">
33 {{if and (eq .Ahead 0) (eq .Behind 0)}}<span class="muted">{{t "branch.even"}}</span>{{else}}
33 {{if and (eq .Ahead 0) (eq .Behind 0)}}<span class="muted">{{t "branch.even"}}</span>{{else}}
@@ -38,18 +38,25 @@
38 <td>
38 <td>
39 {{if .PipeStatus}}<a class="status {{.PipeStatus}}" href="/{{$.Repo.FullPath}}/-/pipelines/{{.PipeID}}"><span class="mark"></span>{{.PipeLabel}}</a>{{end}}
39 {{if .PipeStatus}}<a class="status {{.PipeStatus}}" href="/{{$.Repo.FullPath}}/-/pipelines/{{.PipeID}}"><span class="mark"></span>{{.PipeLabel}}</a>{{end}}
40 </td>
40 </td>
41 <td>
41 <td class="mrlinks">
42 {{if .MRNumber}}<a href="/{{$.Repo.FullPath}}/-/merge-requests/{{.MRNumber}}">!{{.MRNumber}}</a>{{end}}
42 {{range .OpenMRs}}<a href="/{{$.Repo.FullPath}}/-/merge-requests/{{.}}">!{{.}}</a>{{end}}
43 </td>
43 </td>
44 <td class="branchacts">
44 <td class="branchacts">
45 <div class="branchline">
45 {{if not .Default}}
46 {{if not .Default}}
46 <a href="/{{$.Repo.FullPath}}/-/compare?from={{urlquery $.Repo.DefaultBranch}}&amp;to={{urlquery .Name}}">{{t "branch.compare"}}</a>
47 <a class="tiny" href="/{{$.Repo.FullPath}}/-/compare?from={{urlquery $.Repo.DefaultBranch}}&amp;to={{urlquery .Name}}">{{t "branch.compare"}}</a>
47 <a href="/{{$.Repo.FullPath}}/-/merge-requests/new?source={{urlquery .Name}}&amp;target={{urlquery $.Repo.DefaultBranch}}">{{t "branch.newMR"}}</a>
48 {{if not .OpenMRs}}<a class="tiny" href="/{{$.Repo.FullPath}}/-/merge-requests/new?source={{urlquery .Name}}&amp;target={{urlquery $.Repo.DefaultBranch}}">{{t "branch.mrShort"}}</a>{{end}}
48 {{end}}
49 {{end}}
49 {{if and $.CanWrite (not .Default) (not .Protected)}}
50 {{if and $.CanWrite (not .Default) (not .Protected)}}
50 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
51 <details class="rowmenu tiny-menu">
51 <button type="button" class="ghost" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
52 <summary aria-label="{{t "branch.more"}}">⋯</summary>
53 <div class="menu-panel">
54 <button type="button" class="ghost" data-rename="{{.Name}}">{{t "branch.rename"}}</button>
55 <button type="button" class="ghost" data-delete="{{.Name}}">{{t "branch.delete"}}</button>
56 </div>
57 </details>
52 {{end}}
58 {{end}}
59 </div>
53 </td>
60 </td>
54 </tr>
61 </tr>
55 {{else}}
62 {{else}}
internal/server/templates/collab.html +19 −3
@@ -38,10 +38,26 @@
38 38 </div>
39 39 </div>
40 40 {{else}}<p class="muted">{{t "mr.noPipeline"}}</p>{{end}}
41 {{range .MergeBlocks}}<p class="flash bad">{{.}}</p>{{end}}
42 {{if .CanMerge}}
41 {{if .MergeBlocks}}
42 <div class="mergewhy" role="status">
43 <p>{{t "mr.block.why"}}</p>
44 <ul>
45 {{range .MergeBlocks}}<li>{{.}}</li>{{end}}
46 </ul>
47 </div>
48 {{end}}
49 {{if and .CanMerge (not .MergeBlocks)}}
43 50 <form method="post" action="/{{.Repo.FullPath}}/-/merge-requests/{{.MR.Number}}/merge">
44 <input type="hidden" name="csrf" value="{{.CSRF}}"><button type="submit"{{if .MergeBlocks}} disabled{{end}}>{{t "action.merge"}}</button>
51 <input type="hidden" name="csrf" value="{{.CSRF}}"><button type="submit">{{t "action.merge"}}</button>
52 </form>
53 {{end}}
54 {{if .CanForce}}
55 <form class="force-merge" method="post" action="/{{.Repo.FullPath}}/-/merge-requests/{{.MR.Number}}/merge">
56 <input type="hidden" name="csrf" value="{{.CSRF}}">
57 <input type="hidden" name="force" value="1">
58 <p class="flash bad">{{t "mr.force.warn"}}</p>
59 <label class="check"><input type="checkbox" name="confirm_force" value="1" required> {{t "mr.force.confirm"}}</label>
60 <button class="ghost" type="submit">{{t "mr.force"}}</button>
45 61 </form>
46 62 {{end}}
47 63 {{if .CanClose}}
@@ -38,10 +38,26 @@
38 </div>
38 </div>
39</div>
39</div>
40{{else}}<p class="muted">{{t "mr.noPipeline"}}</p>{{end}}
40{{else}}<p class="muted">{{t "mr.noPipeline"}}</p>{{end}}
41{{range .MergeBlocks}}<p class="flash bad">{{.}}</p>{{end}}
41{{if .MergeBlocks}}
42{{if .CanMerge}}
42<div class="mergewhy" role="status">
43 <p>{{t "mr.block.why"}}</p>
44 <ul>
45 {{range .MergeBlocks}}<li>{{.}}</li>{{end}}
46 </ul>
47</div>
48{{end}}
49{{if and .CanMerge (not .MergeBlocks)}}
43<form method="post" action="/{{.Repo.FullPath}}/-/merge-requests/{{.MR.Number}}/merge">
50<form method="post" action="/{{.Repo.FullPath}}/-/merge-requests/{{.MR.Number}}/merge">
44 <input type="hidden" name="csrf" value="{{.CSRF}}"><button type="submit"{{if .MergeBlocks}} disabled{{end}}>{{t "action.merge"}}</button>
51 <input type="hidden" name="csrf" value="{{.CSRF}}"><button type="submit">{{t "action.merge"}}</button>
52</form>
53{{end}}
54{{if .CanForce}}
55<form class="force-merge" method="post" action="/{{.Repo.FullPath}}/-/merge-requests/{{.MR.Number}}/merge">
56 <input type="hidden" name="csrf" value="{{.CSRF}}">
57 <input type="hidden" name="force" value="1">
58 <p class="flash bad">{{t "mr.force.warn"}}</p>
59 <label class="check"><input type="checkbox" name="confirm_force" value="1" required> {{t "mr.force.confirm"}}</label>
60 <button class="ghost" type="submit">{{t "mr.force"}}</button>
45</form>
61</form>
46{{end}}
62{{end}}
47{{if .CanClose}}
63{{if .CanClose}}