Skip to content

Commit e1ed2a7

Browse files
authored
Migration Tool: Backport GitLab Label Color Normalizer (#12793) (#13100)
fix bug mentioned in #13085 backport of #12793
1 parent 2bd7fee commit e1ed2a7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

modules/migrations/gitlab.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,19 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
241241
return milestones, nil
242242
}
243243

244+
func (g *GitlabDownloader) normalizeColor(val string) string {
245+
val = strings.TrimLeft(val, "#")
246+
val = strings.ToLower(val)
247+
if len(val) == 3 {
248+
c := []rune(val)
249+
val = fmt.Sprintf("%c%c%c%c%c%c", c[0], c[0], c[1], c[1], c[2], c[2])
250+
}
251+
if len(val) != 6 {
252+
return ""
253+
}
254+
return val
255+
}
256+
244257
// GetLabels returns labels
245258
func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
246259
if g == nil {
@@ -259,7 +272,7 @@ func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
259272
for _, label := range ls {
260273
baseLabel := &base.Label{
261274
Name: label.Name,
262-
Color: strings.TrimLeft(label.Color, "#)"),
275+
Color: g.normalizeColor(label.Color),
263276
Description: label.Description,
264277
}
265278
labels = append(labels, baseLabel)

0 commit comments

Comments
 (0)