Skip to content

gh project item-edit should allow explicit --number 0 field values #10380

Description

@andyfeller

Describe the bug

Here's another case that I found out for --number that 0 is discarded as an invalid value:

$ bin/gh project item-edit --project-id $projectId --id $itemId --field-id $fieldId --number 0
error: no changes to make

However, given above valid ranges, it is a valid value and can be set from UI:

Image

Originally posted by @iamazeem in #10342

As stated in the issue, this appears to prevent users from accidentally setting item field values to zero due to zero value for float flags:

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.date != "",
opts.singleSelectOptionID != "",
opts.iterationID != "",
); err != nil {
return err
}
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.clear,
); err != nil {
return err
}

// update item values
if config.opts.text != "" || config.opts.number != 0 || config.opts.date != "" || config.opts.singleSelectOptionID != "" || config.opts.iterationID != "" {
return updateItemValues(config)
}
if _, err := fmt.Fprintln(config.io.ErrOut, "error: no changes to make"); err != nil {
return err
}

Affected version

2.66.1

Steps to reproduce the behavior

  1. Create v2 project with Number fields
  2. Add issue to project
  3. gh project item-edit --project-id $projectId --id $itemId --field-id $fieldId --number 0

Expected vs actual behavior

When a user calls gh project item-edit and --number 0 is explicitly set, then we allow the item field value to be set to zero.

Logs

$ GH_DEBUG=api ./bin/gh project item-edit --project-id PVT_kwDOBWmBn84Al2QA --id PVTI_lADOBWmBn84Al2QAzgXCZ4c --field-id PVTF_lADOBWmBn84Al2QAzgnpmgo --number 0                    
error: no changes to make

Activity

  1. andyfeller commented on Feb 6, 2025

    @andyfeller
    ContributorAuthor

    Initial thoughts

    Rather than simply checking opts.number != 0, I think the right way to solve this is to also see if the flag is changed or not.

    For example:

    			if err := cmdutil.MutuallyExclusive(
    				"only one of `--text`, `--number`, `--date`, `--single-select-option-id` or `--iteration-id` may be used",
    				opts.text != "",
    				cmd.Flags().Changed("number"),
    				opts.date != "",
    				opts.singleSelectOptionID != "",
    				opts.iterationID != "",
    			); err != nil {
    				return err
    			}
  2. BagToad commented on Feb 6, 2025

    @BagToad
    Member

    Acceptance Criteria

    Given I have a V2 project with a number field
    When I run gh project item-edit with the --number 0 arg
    Then the item field value is correctly set to zero

    @andyfeller I'm going to call this triaged and add the help wanted flag, but please feel free to correct the A/C or labels if I got anything wrong 🙏

  3. added
    priority-2Affects more than a few users but doesn't prevent core functions
    and removed on Feb 6, 2025
  4. iamazeem commented on Feb 7, 2025

    @iamazeem
    Contributor

    Initial thoughts

    Rather than simply checking opts.number != 0, I think the right way to solve this is to also see if the flag is changed or not.

    For example:

      	if err := cmdutil.MutuallyExclusive(
      		"only one of `--text`, `--number`, `--date`, `--single-select-option-id` or `--iteration-id` may be used",
      		opts.text != "",
      		cmd.Flags().Changed("number"),
      		opts.date != "",
      		opts.singleSelectOptionID != "",
      		opts.iterationID != "",
      	); err != nil {
      		return err
      	}
    

    cmd.Flags().Changed("number") won't be accessible for the rest of the flow.

    For example:

    if config.opts.text != "" || config.opts.number != 0 || config.opts.date != "" || config.opts.singleSelectOptionID != "" || config.opts.iterationID != "" {

    } else if config.opts.number != 0 {

    Any ideas or preferences for these cases?

  5. aryanbhosale commented on Feb 10, 2025

    @aryanbhosale
    Contributor

    Does #10417 fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggh-projectrelating to the gh project commandhelp wantedContributions welcomepriority-2Affects more than a few users but doesn't prevent core functions

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions