Support setting project item number to 0

This commit is contained in:
Aryan Bhosale 2025-02-10 16:42:15 +05:30 committed by William Martin
parent 1710f7dace
commit bf37ac9a69
2 changed files with 22 additions and 7 deletions

View file

@ -28,6 +28,7 @@ type editItemOpts struct {
singleSelectOptionID string
iterationID string
clear bool
numberChanged bool
// format
exporter cmdutil.Exporter
}
@ -76,10 +77,11 @@ func NewCmdEditItem(f *cmdutil.Factory, runF func(config editItemConfig) error)
gh project item-edit --id <item-ID> --field-id <field-ID> --project-id <project-ID> --clear
`),
RunE: func(cmd *cobra.Command, args []string) error {
opts.numberChanged = cmd.Flags().Changed("number")
if err := cmdutil.MutuallyExclusive(
"only one of `--text`, `--number`, `--date`, `--single-select-option-id` or `--iteration-id` may be used",
opts.text != "",
opts.number != 0,
opts.numberChanged,
opts.date != "",
opts.singleSelectOptionID != "",
opts.iterationID != "",
@ -89,7 +91,7 @@ func NewCmdEditItem(f *cmdutil.Factory, runF func(config editItemConfig) error)
if err := cmdutil.MutuallyExclusive(
"cannot use `--text`, `--number`, `--date`, `--single-select-option-id` or `--iteration-id` in conjunction with `--clear`",
opts.text != "" || opts.number != 0 || opts.date != "" || opts.singleSelectOptionID != "" || opts.iterationID != "",
opts.text != "" || opts.numberChanged || opts.date != "" || opts.singleSelectOptionID != "" || opts.iterationID != "",
opts.clear,
); err != nil {
return err
@ -146,7 +148,7 @@ func runEditItem(config editItemConfig) error {
}
// update item values
if config.opts.text != "" || config.opts.number != 0 || config.opts.date != "" || config.opts.singleSelectOptionID != "" || config.opts.iterationID != "" {
if config.opts.text != "" || config.opts.numberChanged || config.opts.date != "" || config.opts.singleSelectOptionID != "" || config.opts.iterationID != "" {
return updateItemValues(config)
}
@ -176,6 +178,10 @@ func buildUpdateItem(config editItemConfig, date time.Time) (*UpdateProjectV2Fie
value = githubv4.ProjectV2FieldValue{
Number: githubv4.NewFloat(githubv4.Float(config.opts.number)),
}
} else if config.opts.numberChanged {
value = githubv4.ProjectV2FieldValue{
Number: githubv4.NewFloat(githubv4.Float(config.opts.number)),
}
} else if config.opts.date != "" {
value = githubv4.ProjectV2FieldValue{
Date: githubv4.NewDate(githubv4.Date{Time: date}),

View file

@ -55,6 +55,14 @@ func TestNewCmdeditItem(t *testing.T) {
itemID: "123",
},
},
{
name: "number zero",
cli: "--number 0 --id 123",
wants: editItemOpts{
number: 0,
itemID: "123",
},
},
{
name: "field-id",
cli: "--field-id FIELD_ID --id 123",
@ -292,10 +300,11 @@ func TestRunItemEdit_Number(t *testing.T) {
config := editItemConfig{
io: ios,
opts: editItemOpts{
number: 123.45,
itemID: "item_id",
projectID: "project_id",
fieldID: "field_id",
number: 123.45,
numberChanged: true,
itemID: "item_id",
projectID: "project_id",
fieldID: "field_id",
},
client: client,
}