-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add loading yaml label template files #22976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0595ec4
Add loading yaml label template files
lafriks 1f079f3
Lint check fixes
lafriks 068da38
Add label color normalization for API methods
lafriks 76edc8b
Merge remote-tracking branch 'upstream/main' into feat/adv_labels
lafriks fb035a6
Deduplicate label code color handling and simplify default label temp…
lafriks ed56ef4
Fix lint
lafriks 6d15590
Merge remote-tracking branch 'origin/main' into feat/adv_labels
lafriks 9dbd4f4
Merge remote-tracking branch 'origin/main' into feat/adv_labels
lafriks 9d79146
Small fixes
lafriks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package label | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
// colorPattern is a regexp witch can validate label color | ||
var colorPattern = regexp.MustCompile("^#?(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})$") | ||
|
||
// Label represents label information loaded from template | ||
type Label struct { | ||
Name string `yaml:"name"` | ||
Color string `yaml:"color"` | ||
Description string `yaml:"description,omitempty"` | ||
Exclusive bool `yaml:"exclusive,omitempty"` | ||
} | ||
|
||
// NormalizeColor normalizes a color string to a 6-character hex code | ||
func NormalizeColor(color string) (string, error) { | ||
// normalize case | ||
color = strings.TrimSpace(strings.ToLower(color)) | ||
|
||
// add leading hash | ||
if len(color) == 6 || len(color) == 3 { | ||
color = "#" + color | ||
} | ||
|
||
if !colorPattern.MatchString(color) { | ||
return "", fmt.Errorf("bad color code: %s", color) | ||
} | ||
|
||
// convert 3-character shorthand into 6-character version | ||
if len(color) == 4 { | ||
r := color[1] | ||
g := color[2] | ||
b := color[3] | ||
color = fmt.Sprintf("#%c%c%c%c%c%c", r, r, g, g, b, b) | ||
} | ||
|
||
return color, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.