BlueGit

timfa bluegit

Merge branch 'cursor/activity-level-65da' into 'master'

fix: kleur de activiteitenkalender met de GitLab-grenzen

See merge request Timfa/bluegit!53

timfa Tim Falken · pushed by timfa

Authored 2026-10-23 · 3 weeks ago

Hash
a83cf1b67d1d5cd6df838bc1a7aa630e4e52976a
Pipeline
Passed
2 files changed +13 −6
internal/activity/calendar.go +5 −4
@@ -37,16 +37,17 @@ func Location() *time.Location {
37 37 return loc
38 38 }
39 39
40 // Level zet een aantal om in 0..4. Vijf tinten, waarvan de eerste leeg is.
40 // Level zet een aantal om in 0..4, met de grenzen van GitLab:
41 // 0, 1-9, 10-19, 20-29 en 30 of meer.
41 42 func Level(n int) int {
42 43 switch {
43 44 case n <= 0:
44 45 return 0
45 case n == 1:
46 case n < 10:
46 47 return 1
47 case n <= 3:
48 case n < 20:
48 49 return 2
49 case n <= 6:
50 case n < 30:
50 51 return 3
51 52 default:
52 53 return 4
@@ -37,16 +37,17 @@ func Location() *time.Location {
37 return loc
37 return loc
38}
38}
39
39
40// Level zet een aantal om in 0..4. Vijf tinten, waarvan de eerste leeg is.
40// Level zet een aantal om in 0..4, met de grenzen van GitLab:
41// 0, 1-9, 10-19, 20-29 en 30 of meer.
41func Level(n int) int {
42func Level(n int) int {
42 switch {
43 switch {
43 case n <= 0:
44 case n <= 0:
44 return 0
45 return 0
45 case n == 1:
46 case n < 10:
46 return 1
47 return 1
47 case n <= 3:
48 case n < 20:
48 return 2
49 return 2
49 case n <= 6:
50 case n < 30:
50 return 3
51 return 3
51 default:
52 default:
52 return 4
53 return 4
internal/activity/calendar_test.go +8 −2
@@ -9,7 +9,13 @@ import (
9 9 )
10 10
11 11 func TestLevel(t *testing.T) {
12 cases := []struct{ n, want int }{{0, 0}, {1, 1}, {2, 2}, {3, 2}, {4, 3}, {6, 3}, {7, 4}, {40, 4}}
12 cases := []struct{ n, want int }{
13 {-1, 0}, {0, 0},
14 {1, 1}, {9, 1},
15 {10, 2}, {19, 2},
16 {20, 3}, {29, 3},
17 {30, 4}, {40, 4},
18 }
13 19 for _, c := range cases {
14 20 if got := Level(c.n); got != c.want {
15 21 t.Fatalf("level %d = %d, wil %d", c.n, got, c.want)
@@ -46,7 +52,7 @@ func TestBuildYearGrid(t *testing.T) {
46 52 if len(last.Days) != 4 {
47 53 t.Fatalf("laatste week heeft %d dagen", len(last.Days))
48 54 }
49 if last.Days[2].Level != 3 || last.Days[2].Tip != "4 contributions on 20 October 2026" {
55 if last.Days[2].Level != 1 || last.Days[2].Tip != "4 contributions on 20 October 2026" {
50 56 t.Fatalf("dinsdag %+v", last.Days[2])
51 57 }
52 58 if last.Days[3].Level != 1 || !strings.Contains(last.Days[3].Tip, "1 contribution on 21 October 2026") {
@@ -9,7 +9,13 @@ import (
9)
9)
10
10
11func TestLevel(t *testing.T) {
11func TestLevel(t *testing.T) {
12 cases := []struct{ n, want int }{{0, 0}, {1, 1}, {2, 2}, {3, 2}, {4, 3}, {6, 3}, {7, 4}, {40, 4}}
12 cases := []struct{ n, want int }{
13 {-1, 0}, {0, 0},
14 {1, 1}, {9, 1},
15 {10, 2}, {19, 2},
16 {20, 3}, {29, 3},
17 {30, 4}, {40, 4},
18 }
13 for _, c := range cases {
19 for _, c := range cases {
14 if got := Level(c.n); got != c.want {
20 if got := Level(c.n); got != c.want {
15 t.Fatalf("level %d = %d, wil %d", c.n, got, c.want)
21 t.Fatalf("level %d = %d, wil %d", c.n, got, c.want)
@@ -46,7 +52,7 @@ func TestBuildYearGrid(t *testing.T) {
46 if len(last.Days) != 4 {
52 if len(last.Days) != 4 {
47 t.Fatalf("laatste week heeft %d dagen", len(last.Days))
53 t.Fatalf("laatste week heeft %d dagen", len(last.Days))
48 }
54 }
49 if last.Days[2].Level != 3 || last.Days[2].Tip != "4 contributions on 20 October 2026" {
55 if last.Days[2].Level != 1 || last.Days[2].Tip != "4 contributions on 20 October 2026" {
50 t.Fatalf("dinsdag %+v", last.Days[2])
56 t.Fatalf("dinsdag %+v", last.Days[2])
51 }
57 }
52 if last.Days[3].Level != 1 || !strings.Contains(last.Days[3].Tip, "1 contribution on 21 October 2026") {
58 if last.Days[3].Level != 1 || !strings.Contains(last.Days[3].Tip, "1 contribution on 21 October 2026") {