]> source.dussan.org Git - gitea.git/commitdiff
Migration Tool: Backport GitLab Label Color Normalizer (#12793) (#13100)
author6543 <6543@obermui.de>
Sun, 11 Oct 2020 20:56:51 +0000 (22:56 +0200)
committerGitHub <noreply@github.com>
Sun, 11 Oct 2020 20:56:51 +0000 (21:56 +0100)
fix bug mentioned in #13085

backport of #12793

modules/migrations/gitlab.go

index cca036aa279e90325f4c833f5e79a40377e11630..09e1a77d36e6e08a27fd057dcc7dc01a6db3d018 100644 (file)
@@ -241,6 +241,19 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
        return milestones, nil
 }
 
+func (g *GitlabDownloader) normalizeColor(val string) string {
+       val = strings.TrimLeft(val, "#")
+       val = strings.ToLower(val)
+       if len(val) == 3 {
+               c := []rune(val)
+               val = fmt.Sprintf("%c%c%c%c%c%c", c[0], c[0], c[1], c[1], c[2], c[2])
+       }
+       if len(val) != 6 {
+               return ""
+       }
+       return val
+}
+
 // GetLabels returns labels
 func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
        if g == nil {
@@ -259,7 +272,7 @@ func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
                for _, label := range ls {
                        baseLabel := &base.Label{
                                Name:        label.Name,
-                               Color:       strings.TrimLeft(label.Color, "#)"),
+                               Color:       g.normalizeColor(label.Color),
                                Description: label.Description,
                        }
                        labels = append(labels, baseLabel)