mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
refactor: remove features beyond the UX plan
Drop additions that the UX plan does not ask for: - the interactive label edit form; label edit now requires a flag - label clone and the skip mode of label creation it needed - repo rename rewriting the Git remote or tea.repository; it now warns that the remote still points to the old name - the extra "source" remote on clones of pull mirrors - run artifact download, which duplicates run download --zip - 256-color and 24-bit label swatches; colors stay ANSI 16 - config list --show-source (config get keeps it) - the membership and access GETs before team member/repo add and remove; Gitea's PUT and DELETE are idempotent label edit/delete keep --by-name: it is the only way to address a label whose name is a number that is also another label's ID. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
22 files changed
+69
-560
No files matched your search
+6
-50
@@ -42,7 +42,7 @@ addressed by name or ID.`}
|
||||
}
|
||||
complete := a.completeScopedLabels(&org)
|
||||
group.AddCommand(a.labelListCommand(scope), a.labelCreateCommand(scope), a.labelEditCommand(scope, complete), a.labelDeleteCommand(scope, complete),
|
||||
a.labelImportCommand(scope), a.labelCloneCommand(scope), a.labelExportCommand(scope))
|
||||
a.labelImportCommand(scope), a.labelExportCommand(scope))
|
||||
return group
|
||||
}
|
||||
|
||||
@@ -240,16 +240,14 @@ func (a *application) reportLabel(cmd *cobra.Command, s services.Labels, item se
|
||||
func (a *application) labelEditCommand(scope labelScope, complete cobra.CompletionFunc) *cobra.Command {
|
||||
var fields labelFields
|
||||
var byName bool
|
||||
cmd := &cobra.Command{Use: "edit <label>", Short: "Edit a label", Long: "Edit a label. Without flags on a terminal, a form starts from the current values.", Example: `$ tea label edit bug --name defect --color b60205
|
||||
cmd := &cobra.Command{Use: "edit <label>", Short: "Edit a label", Example: `$ tea label edit bug --name defect --color b60205
|
||||
$ tea label edit "kind/question" --description "Further information is requested"
|
||||
$ tea label edit old-stuff --archived`, Annotations: map[string]string{"tea.arguments": labelArguments}, Args: argsExact(1), RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts, err := fields.options(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prompt := a.canPrompt()
|
||||
form, hasForm := a.deps.Prompter.(terminal.LabelForm)
|
||||
if opts == (services.LabelOptions{}) && (!prompt || !hasForm) {
|
||||
if opts == (services.LabelOptions{}) {
|
||||
return errNothingToEdit
|
||||
}
|
||||
s, err := scope(cmd)
|
||||
@@ -260,16 +258,6 @@ $ tea label edit old-stuff --archived`, Annotations: map[string]string{"tea.argu
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if opts == (services.LabelOptions{}) {
|
||||
current := found[0]
|
||||
values, err := form.EditLabel(cmd.Context(), "Editing "+labelName(s, current), terminal.LabelFormValues{
|
||||
Name: current.Name, Color: current.Color, Description: current.Description, Exclusive: current.Exclusive, Archived: current.Archived,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts = services.LabelOptions{Name: &values.Name, Color: &values.Color, Description: &values.Description, Exclusive: &values.Exclusive, Archived: &values.Archived}
|
||||
}
|
||||
item, err := s.Edit(cmd.Context(), found[0].ID, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -345,12 +333,12 @@ func (a *application) importLabels(cmd *cobra.Command, scope labelScope, file st
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return a.createLabels(cmd, s, rows, force, false)
|
||||
return a.createLabels(cmd, s, rows, force)
|
||||
}
|
||||
|
||||
// createLabels creates each label in rows, continuing past failures. A label that exists already
|
||||
// is updated with force, skipped with skip, and fails otherwise.
|
||||
func (a *application) createLabels(cmd *cobra.Command, s services.Labels, rows []services.LabelOptions, force, skip bool) error {
|
||||
// is updated with force and fails otherwise.
|
||||
func (a *application) createLabels(cmd *cobra.Command, s services.Labels, rows []services.LabelOptions, force bool) error {
|
||||
existing, err := s.All(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -358,11 +346,7 @@ func (a *application) createLabels(cmd *cobra.Command, s services.Labels, rows [
|
||||
outcome := map[string]string{}
|
||||
results, failures := applyBatch(cmd, rows, func(row services.LabelOptions) string { return "label " + strconv.Quote(*row.Name) }, func(row services.LabelOptions) (services.Label, error) {
|
||||
item, updated, err := s.CreateUnique(cmd.Context(), existing, row, force)
|
||||
var conflict *services.ConflictError
|
||||
switch {
|
||||
case skip && errors.As(err, &conflict) && conflict.Reason == services.ReasonExists:
|
||||
outcome[*row.Name] = "Skipped"
|
||||
return services.Label{Name: *row.Name}, nil
|
||||
case err != nil:
|
||||
return item, err
|
||||
case updated:
|
||||
@@ -373,10 +357,6 @@ func (a *application) createLabels(cmd *cobra.Command, s services.Labels, rows [
|
||||
}
|
||||
return item, nil
|
||||
}, func(item services.Label) {
|
||||
if outcome[item.Name] == "Skipped" {
|
||||
a.warn(cmd, "Skipped %s: it exists already", labelName(s, item))
|
||||
return
|
||||
}
|
||||
a.done(cmd, "%s %s", outcome[item.Name], labelName(s, item))
|
||||
})
|
||||
if a.options.json != "" {
|
||||
@@ -385,30 +365,6 @@ func (a *application) createLabels(cmd *cobra.Command, s services.Labels, rows [
|
||||
return errors.Join(failures...)
|
||||
}
|
||||
|
||||
func (a *application) labelCloneCommand(scope labelScope) *cobra.Command {
|
||||
var force bool
|
||||
cmd := &cobra.Command{Use: "clone <source-repository>", Short: "Copy the labels of another repository", Long: `Create the labels of the source repository in the selected repository or organization.
|
||||
Labels that exist already are skipped unless --force updates them.`, Example: `$ tea label clone alice/project
|
||||
$ tea label clone alice/project --repo alice/new --force`, Args: argsExact(1), RunE: func(cmd *cobra.Command, args []string) error {
|
||||
s, err := scope(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
source, err := (services.Labels{Client: s.Client, Repository: args[0]}).All(cmd.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rows := make([]services.LabelOptions, len(source))
|
||||
for i, item := range source {
|
||||
rows[i] = services.LabelOptions{Name: &item.Name, Color: &item.Color, Description: &item.Description, Exclusive: &item.Exclusive}
|
||||
}
|
||||
return a.createLabels(cmd, s, rows, force, true)
|
||||
}}
|
||||
cmd.Flags().BoolVarP(&force, "force", "f", false, "Update labels that exist already")
|
||||
cmd.ValidArgsFunction = a.completeRepos()
|
||||
return cmd
|
||||
}
|
||||
|
||||
// completeScopedLabels completes the label names of the repository or, with --org, of the
|
||||
// organization that *org names.
|
||||
func (a *application) completeScopedLabels(org *string) cobra.CompletionFunc {
|
||||
|
||||
Reference in new issue
Block a user