Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1d846b9

Browse files
committedMar 31, 2025·
Add global slice with all styles
1 parent ad7e126 commit 1d846b9

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed
 

Diff for: ‎modules/badge/badge.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,20 @@ const (
6565
DefaultStyle = StyleFlat
6666
)
6767

68-
var StatusColorMap = map[actions_model.Status]string{
69-
actions_model.StatusSuccess: "#4c1", // Green
70-
actions_model.StatusSkipped: "#dfb317", // Yellow
71-
actions_model.StatusUnknown: "#97ca00", // Light Green
72-
actions_model.StatusFailure: "#e05d44", // Red
73-
actions_model.StatusCancelled: "#fe7d37", // Orange
74-
actions_model.StatusWaiting: "#dfb317", // Yellow
75-
actions_model.StatusRunning: "#dfb317", // Yellow
76-
actions_model.StatusBlocked: "#dfb317", // Yellow
77-
}
68+
var (
69+
StatusColorMap = map[actions_model.Status]string{
70+
actions_model.StatusSuccess: "#4c1", // Green
71+
actions_model.StatusSkipped: "#dfb317", // Yellow
72+
actions_model.StatusUnknown: "#97ca00", // Light Green
73+
actions_model.StatusFailure: "#e05d44", // Red
74+
actions_model.StatusCancelled: "#fe7d37", // Orange
75+
actions_model.StatusWaiting: "#dfb317", // Yellow
76+
actions_model.StatusRunning: "#dfb317", // Yellow
77+
actions_model.StatusBlocked: "#dfb317", // Yellow
78+
}
79+
80+
AllStyles = []Style{StyleFlat, StyleFlatSquare}
81+
)
7882

7983
// GenerateBadge generates badge with given template
8084
func GenerateBadge(label, message, color string) Badge {

Diff for: ‎routers/web/devtest/devtest.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func prepareMockDataBadgeCommitSign(ctx *context.Context) {
128128

129129
func prepareMockDataBadgeActionsSvg(ctx *context.Context) {
130130
fontFamilyNames := strings.Split(badge.DefaultFontFamily, ",")
131-
styles := []badge.Style{badge.StyleFlat, badge.StyleFlatSquare}
132131
selectedFontFamilyName := ctx.FormString("font", fontFamilyNames[0])
133132
selectedStyle := ctx.FormString("style", badge.DefaultStyle)
134133
var badges []badge.Badge
@@ -163,7 +162,7 @@ func prepareMockDataBadgeActionsSvg(ctx *context.Context) {
163162
ctx.Data["BadgeSVGs"] = badgeSVGs
164163
ctx.Data["BadgeFontFamilyNames"] = fontFamilyNames
165164
ctx.Data["SelectedFontFamilyName"] = selectedFontFamilyName
166-
ctx.Data["BadgeStyles"] = styles
165+
ctx.Data["BadgeStyles"] = badge.AllStyles
167166
ctx.Data["SelectedStyle"] = selectedStyle
168167
}
169168

Diff for: ‎routers/web/repo/actions/badge.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func GetWorkflowBadge(ctx *context.Context) {
2727
event := ctx.Req.URL.Query().Get("event")
2828

2929
style := ctx.Req.URL.Query().Get("style")
30-
if !slices.Contains([]badge.Style{badge.StyleFlat, badge.StyleFlatSquare}, badge.Style(style)) {
30+
if !slices.Contains(badge.AllStyles, badge.Style(style)) {
3131
style = badge.DefaultStyle
3232
}
3333

0 commit comments

Comments
 (0)
Please sign in to comment.