I'm pretty new to GraphQL and Github Actions, here I'm trying to update an item in my GitHub Project (V2) using the Github CLI and the GraphQL API within the Github Action workflow file, I'm having trouble passing the $bugOptionId to the query properly.
I've check all the variables and they're all correct (based on the previous steps that is not shown here). Here's the snippet of the code:
- name: Update item status to Bugs
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
ITEM_ID: ${{ env.ITEM_ID }}
STATUS_FIELD_ID: ${{ env.STATUS_FIELD_ID }}
BUGS_OPTION_ID: ${{ env.BUGS_OPTION_ID }}
PROJECT_ID: ${{ env.PROJECT_ID }}
run: |
gh api graphql -f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $bugsOptionId: String!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId,
itemId: $itemId,
fieldId: $fieldId,
value: {singleSelectOptionId: $bugsOptionId}
}
) {
clientMutationId
}
}' -f itemId=$ITEM_ID -f projectId=$PROJECT_ID -f fieldId=$STATUS_FIELD_ID -f bugsOptionId=$BUGS_OPTION_ID
The code above produces this error:
gh: The single select option Id does not belong to the field
{"data":{"updateProjectV2ItemFieldValue":null},"errors":[{"type":"VALIDATION","path":["updateProjectV2ItemFieldValue"],"locations":[{"line":3,"column":5}],"message":"The single select option Id does not belong to the field"}]}
Error: Process completed with exit code 1.
I've tried to put a double quote around the variables:
-f bugsOptionId="$BUGS_OPTION_ID"
BUGS_OPTION_ID: "${{ env.BUGS_OPTION_ID }}"
But nothing works, so Finally I tried to put the $bugOptionId manually like this:
- name: Update item status to Bugs
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
ITEM_ID: ${{ env.ITEM_ID }}
STATUS_FIELD_ID: ${{ env.STATUS_FIELD_ID }}
BUGS_OPTION_ID: "${{ env.BUGS_OPTION_ID }}"
PROJECT_ID: ${{ env.PROJECT_ID }}
run: |
gh api graphql -f query='
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!) {
updateProjectV2ItemFieldValue(
input: {
projectId: $projectId,
itemId: $itemId,
fieldId: $fieldId,
value: {singleSelectOptionId: "acbd1234"}
}
) {
clientMutationId
}
}' -f itemId=$ITEM_ID -f projectId=$PROJECT_ID -f fieldId=$STATUS_FIELD_ID
Of course the real value is not "abcd1234" but it works and the api gives a response of something like this:
{"data":{"updateProjectV2ItemFieldValue":{"clientMutationId":null}}}
Did I miss something? I've been trying to solve this for 3 days reading the docs but couldn't find any solution other than manually put the bugOptionId.