-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Describe the bug
#6614 added support for a syntax that supports adding arrays and/or nested objects, e.g.
gh api -f labels[]=bug -f labels[]=p1
#=> { "labels": ["bug", "p1"] }
gh api -f branch[name]=patch-1 -F branch[protected]=true
#=> { "branch": { "name": "patch-1", "protected": true }You're able to set an array of objects like so,
gh api -f labels[][name]=a -f "labels[][description]=label a"would turn into,
{
"labels": {
"name": "a",
"description": "label a"
}
}The order of the arguments matters for adding multiple items to the same object. But if you try to set add more than one item in an array in one of these objects the gh cli messes up the parsing and no longer thinks that the next item in the array is part of the same object.
For example,
gh api -f labels[][name]=a -f "labels[][description]=label a" -f "labels[][allowedColors][]=red"Works and adds allowedColors to the object as an array with one item, red, e.g.
{
"labels": {
"name": "a",
"description": "label a",
"allowedColors": ["red"]
},
{
"allowedColors": ["blue"]
}
}But the following command does not add another item to the array,
gh api -f labels[][name]=a -f "labels[][description]=label a" -f "labels[][allowedColors][]=red" -f "labels[][allowedColors][]=blue"It errors when it should result in the following JSON,
{
"labels": {
"name": "a",
"description": "label a",
"allowedColors": ["red", "blue"]
}
}Logs
I discovered this bug while attempting to add docs to our GitHub CLI example tab on GitHub docs. There are requests that require passing more than one item to an array, but are not able to due to this bug.
An example from docs for creating / updating custom properties for an org. In the link the GitHub CLI example is bugged, but it should be able to show the following,
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/orgs/ORG/properties/schema \
-f "properties[][property_name]=environment" -f "properties[][value_type]=single_select" -F "properties[][required]=true" -f "properties[][default_value]=production" -f "properties[][description]=Prod or dev environment" -f "properties[][allowed_values][]=production" -f "properties[][allowed_values][]=development" -f "properties[][values_editable_by]=org_actors" -f "properties[][property_name]=service" -f "properties[][value_type]=string" -f "properties[][property_name]=team" -f "properties[][value_type]=string" -f "properties[][description]=Team owning the repository"