GitLab DL: normalizeColor (#12793)

This commit is contained in:
6543 2020-09-10 15:04:30 +02:00 committed by GitHub
parent 0db9043aa7
commit e10327168d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -215,6 +215,19 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) {
return milestones, nil 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 // GetLabels returns labels
func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) { func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
var perPage = 100 var perPage = 100
@ -230,7 +243,7 @@ func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) {
for _, label := range ls { for _, label := range ls {
baseLabel := &base.Label{ baseLabel := &base.Label{
Name: label.Name, Name: label.Name,
Color: strings.TrimLeft(label.Color, "#)"), Color: g.normalizeColor(label.Color),
Description: label.Description, Description: label.Description,
} }
labels = append(labels, baseLabel) labels = append(labels, baseLabel)