From 40f5f75116348473a8b13f3c991973080c78bd11 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Thu, 26 Jan 2023 14:21:13 +0100 Subject: [PATCH] chore: update graphql to projectV2 (#17) --- action.yml | 58 ++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/action.yml b/action.yml index e5fde5a..f651f91 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ -name: 'Project Board Automation' -description: 'Automate GitHub Projects with ease' +name: "Project Board Automation" +description: "Automate GitHub Projects with ease" inputs: project: description: Project board number @@ -32,25 +32,31 @@ runs: - name: Fetch project data run: | + set -x gh api graphql -f query=' - query($org: String!, $num: Int!) { - organization(login: $org){ - projectNext(number: $num) { + query ($org: String!, $num: Int!) { + organization(login: $org) { + projectV2(number: $num) { id fields(first: 20) { nodes { - id - name - settings + ... on ProjectV2SingleSelectField { + id + name + options { + id + name + } + } } } } } }' -f org=$ORG -F num=${{ inputs.project }} > project_data.json - echo 'PROJECT_ID='$(jq -r '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV - echo 'STATUS_FIELD_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").id' project_data.json) >> $GITHUB_ENV - echo 'TODO_OPTION_ID='$(jq -r '.data.organization.projectNext.fields.nodes[] | select(.name == "Status").settings | fromjson.options[] | select(.name=="${{ inputs.todo_status }}").id' project_data.json) >> $GITHUB_ENV + echo 'PROJECT_ID='$(jq -r '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV + echo 'STATUS_FIELD_ID='$(jq -r '.data.organization.projectV2.fields.nodes[] | select(.name == "Status").id' project_data.json) >> $GITHUB_ENV + echo 'TODO_OPTION_ID='$(jq -r '.data.organization.projectV2.fields.nodes[] | select(.name == "Status").options[] | select(.name=="${{ inputs.todo_status }}").id' project_data.json) >> $GITHUB_ENV env: GITHUB_TOKEN: ${{ inputs.token }} ORG: ${{ inputs.org }} @@ -69,15 +75,15 @@ runs: run: | item_id="$( gh api graphql -f query=' mutation($project: ID!, $id: ID!) { - addProjectNextItem(input: { + addProjectV2ItemById(input: { projectId: $project, contentId: $id, }) { - projectNextItem { + item { id } } - }' -f project=$PROJECT_ID -f id=$ISSUE_PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')" + }' -f project=$PROJECT_ID -f id=$ISSUE_PR_ID --jq '.data.addProjectV2ItemById.item.id')" echo 'ITEM_ID='$item_id >> $GITHUB_ENV env: @@ -87,22 +93,14 @@ runs: - name: Set fields on project ticket run: | gh api graphql -f query=' - mutation ( - $project: ID! - $item: ID! - $status_field: ID! - $status_value: String! - ) { - updateProjectNextItemField(input: { - projectId: $project - itemId: $item - fieldId: $status_field - value: $status_value - }) { - projectNextItem { - id - } - } + mutation ($project: ID!, $item: ID!, $status_field: ID!, $status_value: String!) { + updateProjectV2ItemFieldValue( + input: {projectId: $project, itemId: $item, fieldId: $status_field, value: {singleSelectOptionId: $status_value}} + ) { + projectV2Item { + id + } + } }' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=$TODO_OPTION_ID env: GITHUB_TOKEN: ${{ inputs.token }}