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
gh api -F <key=val>
not accepting int
or boolean
on ruleset creation
#8983
Comments
I see the same behaviour on Looking at your examples using the {
"enforcement": "active",
"name": "Test",
"rules": [
{
"parameters": {
"required_approving_review_count": 1
},
"type": "pull_request"
}
],
"target": "branch"
} {
"enforcement": "active",
"name": "Test",
"rules": [
{
"parameters": {
"dismiss_stale_reviews_on_push": true
},
"type": "pull_request"
}
],
"target": "branch"
} Is there anything that looks wrong in these request to you? I must admit I'm not an expert on the ruleset API. Also, the example |
@AlexVermette-Eaton : Just to share how I was testing #8762 by creating rule: QUERY='
mutation($input:CreateRepositoryRulesetInput!){
createRepositoryRuleset(input:$input){
ruleset{
id
name
createdAt
}
}
}
'
GH_DEBUG=api ./bin/gh api graphql -f query="$QUERY" \
-F 'input[name]=test repo rule name3' \
-F 'input[enforcement]=DISABLED' \
-F 'input[conditions][refName][include][]=~DEFAULT_BRANCH' \
-F 'input[conditions][refName][exclude][]=refs/heads/ignore-*' \
-F 'input[sourceId]=R_kgDOIVGotg' \
-F 'input[rules][][type]=CREATION' Let me be clear, this took a bit of reversing by manually creating a rule and playing with it. |
The requests look good to me. This is exactly what i would expect. To get the latest structure of the ruleset object i used the export tool of rulesets available in the GitHub UI and looked at the json file it gave.
It definitely is broken. I should have probably reported this too but here's what I found that is broken:
I would assume |
If anyone has a work around I would gladly take it, as this is blocking for what |
I left a note for the team that owns this API endpoint on Saturday but given that it was the weekend I wouldn't expect a reply. In terms of your original comment, the way to have the most control is to craft your own JSON body and go from there: {
"query": "mutation($input:CreateRepositoryRulesetInput!){\n createRepositoryRuleset(input:$input){\n ruleset{\n id\n name\n createdAt\n }\n }\n}",
"variables": {
"input": {
"enforcement": "ACTIVE",
"name": "Test",
"conditions": {},
"rules": [
{
"parameters": {
"pullRequest": {
"dismissStaleReviewsOnPush": false,
"requireCodeOwnerReview": false,
"requireLastPushApproval": false,
"requiredApprovingReviewCount": 1,
"requiredReviewThreadResolution": false
}
},
"type": "PULL_REQUEST"
}
],
"sourceId": "<REPOSITORY_GQL_ID>",
"target": "BRANCH"
}
}
}
You can get the
I appreciate this is not particularly pleasant. I will get back to you when we hear back from the team that own the ruleset REST API. |
Looks like the issue is that for the What this means is that you need a body like so: {
"enforcement": "active",
"name": "Test",
"rules": [
{
"parameters": {
"dismiss_stale_reviews_on_push": false,
"require_code_owner_review": false,
"require_last_push_approval": false,
"required_approving_review_count": 1,
"required_review_thread_resolution": false
},
"type": "pull_request"
}
],
"target": "branch"
} Could be used like so:
The |
Limitation of #8761 involving nested objects within arrays@williammartin : I believe we're experiencing a limitation behind ExplanationThe following explanation resolves around the following 2 blocks of code: Lines 63 to 84 in 8181c62
Lines 135 to 150 in 8181c62
Take the following example: gh api -X POST "repos/{owner}/{repo}/rulesets" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-f "name=Test" \
-f "target=branch" \
-f "enforcement=active" \
-F "rules[][type]=pull_request" \
-F "rules[][parameters][dismiss_stale_reviews_on_push]=false" \
-F "rules[][parameters][require_code_owner_review]=false" \
-F "rules[][parameters][require_last_push_approval]=false" \
-F "rules[][parameters][required_approving_review_count]=1" \
-F "rules[][parameters][required_review_thread_resolution]=false" The problem occurs because Assuming the following state before {
"name": "Test",
"target": "branch",
"enforcement": "active",
}
This feels like a problem with the field set design as users cannot set a whole object in a single flag. Test for debuggingLocally, I created the following test within func Test_parseFields_nested2(t *testing.T) {
ios, stdin, _, _ := iostreams.Test()
fmt.Fprint(stdin, "pasted contents")
opts := ApiOptions{
IO: ios,
RawFields: []string{
"name=Test",
"target=branch",
"enforcement=active",
"rules[][type]=pull_request",
},
MagicFields: []string{
"rules[][parameters][dismiss_stale_reviews_on_push]=false",
"rules[][parameters][require_code_owner_review]=false",
"rules[][parameters][require_last_push_approval]=false",
"rules[][parameters][required_approving_review_count]=1",
"rules[][parameters][required_review_thread_resolution]=false",
},
}
params, err := parseFields(&opts)
if err != nil {
t.Fatalf("parseFields error: %v", err)
}
jsonData, err := json.MarshalIndent(params, "", "\t")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, strings.TrimSuffix(heredoc.Doc(`{}`), "\n"), string(jsonData))
} |
Your suggested approach is answering all my needs. I don't specifically needed the |
I tripped up over this bug, trying to ( ultimately set up a ruleset as described above ). I noticed that the examples given in the API documentation didn't work either. I'm currently using The workaround worked perfectly for me to create a ruleset
and I learnt a lot about the --input - flag, as well as the --verbose flag. I can't help but wonder if we should include in the gh API manual page an example of how to use the --input - flag to correctly pass the json in when all else fails. Also add a --verbose example too, as this provides useful debugging information when it comes to finding out what is going wrong. I created a zendesk ticket 2777197 for myself, in the hope that if a customer logs a support ticket, then support will search and find the ticket - which will point them here. |
@erichanson1 : I think that is an excellent idea especially because how you do it is likely to differ by person. For example, my local REPOSITORIES=("$@")
# shellcheck disable=SC2016
local MIGRATION_JQ='{
"lock_repositories": $lock_repositories,
"exclude_attachments": $exclude_attachments,
"exclude_git_data": $exclude_git_data,
"exclude_metadata": $exclude_metadata,
"exclude_owner_projects": $exclude_owner_projects,
"exclude_releases": $exclude_releases,
"repositories": $ARGS.positional,
}'
local MIGRATION_INPUTS=$(
jq -n "$MIGRATION_JQ" \
--argjson exclude_attachments "$EXCLUDE_ATTACHMENTS" \
--argjson exclude_git_data "$EXCLUDE_GIT_DATA" \
--argjson exclude_metadata "$EXCLUDE_METADATA" \
--argjson exclude_owner_projects "$EXCLUDE_OWNER_PROJECTS" \
--argjson exclude_releases "$EXCLUDE_RELEASES" \
--argjson lock_repositories "$LOCK_REPOSITORIES" \
--args "${REPOSITORIES[@]}")
local MIGRATION_ID=$(echo "$MIGRATION_INPUTS" | gh api "/orgs/$ORGANIZATION/migrations" -X POST -p wyandotte --input - --jq '.id') |
Describe the bug
Version : gh version 2.48.0
Using the gh api command to create ruleset, it is impossible to pass anything other than a string as a "key=value" pair. I tried using
-F
flag but it does not work either.Here's an example:
I get the following error:
I get the same behavior when i try with a property that should have a boolean value. For example:
The text was updated successfully, but these errors were encountered: