Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support all types of field values, including all-digit single-select IDs #8

Merged

Conversation

maxdanilov
Copy link
Contributor

@maxdanilov maxdanilov commented Aug 27, 2022

Problem

A single select option id is an 8-character hexadecimal value (e.g. 47fc9ee4).
There's a 2.3% chance that this id will be comprised only of digits (e.g. 12345678): (10/16)^8 = 0.0232
If an option id is comprised of digits only, this action cannot set the field to this value.

Investigation Results

The underlying gh api graphql field update call is doing an automatic conversion of values that look like integers (source):

The -F/--field flag has magic type conversion based on the format of the value:

  • literal values "true", "false", "null", and integer numbers get converted to appropriate JSON types;

It leads to this kind of error (98236657 in the example is an option ID (VALUE_TO_SET) passed in as -F value="$VALUE_TO_SET":

gh: Variable $value of type String was provided invalid value
{
  "errors": [
    {
      "extensions": {
        "value": 98236657,
        "problems": [
          {
            "path": [],
            "explanation": "Could not coerce value 98236657 to String"
          }
        ]
      },
      "locations": [
        {
          "line": 1,
          "column": 50
        }
      ],
      "message": "Variable $value of type String was provided invalid value"
    }
  ]
}

Solution

Switching from direct value passing to reading the value from stdin since it bypasses the conversion and treats the passed value as a string.

@maxdanilov maxdanilov marked this pull request as draft August 27, 2022 19:50
@maxdanilov maxdanilov force-pushed the support-all-digit-single-select-ids branch 3 times, most recently from 25ea6b0 to 74be92b Compare August 27, 2022 20:02
@maxdanilov maxdanilov force-pushed the support-all-digit-single-select-ids branch from 74be92b to 58e8a4d Compare August 27, 2022 20:04
@maxdanilov maxdanilov marked this pull request as ready for review August 27, 2022 20:17
@maxdanilov
Copy link
Contributor Author

@benbalter what do you think about this proposal?

@maxdanilov
Copy link
Contributor Author

@benbalter could you review this one, please?

@benbalter
Copy link
Collaborator

I'm currently on leave. Your proposal is great, but given the complexity, I might want to explore moving the logic to JS/TS so that we can add tests, etc. If I have the chance to review your PR, I will, if not, I look forward to reviewing it when I am back from leave. Thanks for the contribution!

@benbalter
Copy link
Collaborator

given the complexity, I might want to explore moving the logic to JS/TS so that we can add tests

Work in progress over in #11, but we can merge this PR In the interim. Thanks again!

@benbalter benbalter merged commit d511f43 into github:main Jan 4, 2023
@maxdanilov maxdanilov deleted the support-all-digit-single-select-ids branch January 4, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants