mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(label): refuse duplicate label names unless --force
tea label create --name bug twice created a second "bug" label, after which issue edit --add-labels bug failed as ambiguous and issue list --label bug matched nothing. label create (and --file imports) now fail with "label "bug" already exists in alice/project; pass --force to update it", ignoring case; --force updates the existing label. The ambiguity error for labels that already share a name lists their IDs. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+92
-10
No files matched your search
@@ -45,7 +45,7 @@ func (a *application) labelCommand() *cobra.Command {
|
||||
group.AddCommand(list)
|
||||
for _, verb := range []string{"create", "edit"} {
|
||||
var name, color, description, file string
|
||||
var exclusive, archived bool
|
||||
var exclusive, archived, force bool
|
||||
command := &cobra.Command{Use: verb, Short: titleCase(verb) + " a label"}
|
||||
if verb == "edit" {
|
||||
command.Use += " <id>"
|
||||
@@ -60,6 +60,7 @@ func (a *application) labelCommand() *cobra.Command {
|
||||
command.Flags().BoolVar(&archived, "archived", false, "Archive the label so it cannot be newly applied")
|
||||
if verb == "create" {
|
||||
command.Flags().StringVar(&file, "file", "", "Import color/name rows with optional ;description")
|
||||
command.Flags().BoolVar(&force, "force", false, "Update the label if one with the same name exists")
|
||||
}
|
||||
command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
opts := services.LabelOptions{}
|
||||
@@ -106,10 +107,10 @@ func (a *application) labelCommand() *cobra.Command {
|
||||
}
|
||||
opts.Color = &color
|
||||
}
|
||||
if verb == "create" || cmd.Flags().Changed("description") {
|
||||
if cmd.Flags().Changed("description") {
|
||||
opts.Description = &description
|
||||
}
|
||||
if verb == "create" || cmd.Flags().Changed("exclusive") {
|
||||
if cmd.Flags().Changed("exclusive") {
|
||||
opts.Exclusive = &exclusive
|
||||
}
|
||||
if cmd.Flags().Changed("archived") {
|
||||
@@ -123,22 +124,28 @@ func (a *application) labelCommand() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var existing []services.Label
|
||||
if verb == "create" {
|
||||
if existing, err = s.All(cmd.Context()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if file != "" {
|
||||
results := []services.Label{}
|
||||
var failures []error
|
||||
for _, row := range imported {
|
||||
item, err := s.Create(cmd.Context(), row)
|
||||
item, err := s.CreateUnique(cmd.Context(), existing, row, force)
|
||||
if err != nil {
|
||||
failures = append(failures, fmt.Errorf("label %s: %w", *row.Name, err))
|
||||
continue
|
||||
}
|
||||
results = append(results, item)
|
||||
results, existing = append(results, item), append(existing, item)
|
||||
}
|
||||
return errors.Join(append(failures, writeList(a, cmd, results, labelRow))...)
|
||||
}
|
||||
var item services.Label
|
||||
if verb == "create" {
|
||||
item, err = s.Create(cmd.Context(), opts)
|
||||
item, err = s.CreateUnique(cmd.Context(), existing, opts, force)
|
||||
} else {
|
||||
item, err = s.Edit(cmd.Context(), id, opts)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user