-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now that we only allow existing labels with issues/merge requests, it is no longer possible to create a new label on-the-fly. Instead, cover that use case with a new dedicated command.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/spf13/cobra" | ||
gitlab "github.com/xanzy/go-gitlab" | ||
"github.com/zaquestion/lab/internal/action" | ||
lab "github.com/zaquestion/lab/internal/gitlab" | ||
) | ||
|
||
var labelCreateCmd = &cobra.Command{ | ||
Use: "create [remote] <name>", | ||
Aliases: []string{"add"}, | ||
Short: "Create a new label", | ||
Long: ``, | ||
Example: `lab label create my-label | ||
lab label create --color cornflowerblue --description "Blue as a cornflower" blue | ||
lab label create --color #6495ed --description "Also blue as a cornflower" blue2`, | ||
PersistentPreRun: LabPersistentPreRun, | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rn, name, err := parseArgsRemoteAndProject(args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
color, err := cmd.Flags().GetString("color") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
desc, err := cmd.Flags().GetString("description") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = lab.LabelCreate(rn, &gitlab.CreateLabelOptions{ | ||
Name: &name, | ||
Description: &desc, | ||
Color: &color, | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
labelCreateCmd.Flags().String("color", "#428BCA", "color of the new label in HTML hex notation or CSS color name") | ||
labelCreateCmd.Flags().String("description", "", "description of the new label") | ||
labelCmd.AddCommand(labelCreateCmd) | ||
carapace.Gen(labelCmd).PositionalCompletion( | ||
action.Remotes(), | ||
) | ||
} |
This file contains 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