diff --git a/.github/workflows/board.yml b/.github/workflows/board.yml index 478058a062..c4967047cc 100644 --- a/.github/workflows/board.yml +++ b/.github/workflows/board.yml @@ -42,6 +42,7 @@ on: jobs: assign_to_project: + if: github.event_name == 'pull_request_target' || github.event_name == 'issues' env: # Cannot use `secrets.GITHUB_TOKEN` because the project board # exists at org level. You cannot add permissions outside the scope @@ -84,19 +85,18 @@ jobs: echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV echo 'TODO_OPTION_ID='$(jq -r --arg TODO_COL_NAME "$TODO_COL_NAME" '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$TODO_COL_NAME) |.id' project_data.json) >> $GITHUB_ENV echo 'PR_OPTION_ID='$(jq -r --arg PR_COL_NAME "$PR_COL_NAME" '.data.organization.projectV2.fields.nodes[] | select(.name== "Status") | .options[] | select(.name==$PR_COL_NAME) |.id' project_data.json) >> $GITHUB_ENV - - name: Assign PR to Project - if: github.event_name == 'pull_request_target' + - name: Assign Issue/PR to Project run: | - # Add PR to board + # Add Issue/PR to board depending on event type item_id="$( gh api graphql -f query=' - mutation($project:ID!, $pr:ID!) { + mutation($project:ID!, $id:ID!) { addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) { item { id } } - }' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectV2ItemById.item.id')" - # Update the status to Needs PR Review + }' -f project=$PROJECT_ID -f id=$ISSUE_OR_PR_ID --jq '.data.addProjectV2ItemById.item.id')" + # Update the status to Triage Needed/Needs PR Review depending on event type gh api graphql -f query=' mutation ( $project: ID! @@ -116,41 +116,6 @@ jobs: id } } - }' -f project=$PROJECT_ID -f item=$item_id -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.PR_OPTION_ID }} --silent + }' -f project=$PROJECT_ID -f item=$item_id -f status_field=$STATUS_FIELD_ID -f status_value=${{ github.event_name === 'pull_request_target' && env.PR_OPTION_ID || env.TODO_OPTION_ID }} --silent env: - PR_ID: ${{ github.event.pull_request.node_id }} - - name: Assign Issue to Project - if: github.event_name == 'issues' - run: | - # Add issue to board - item_id="$( gh api graphql -f query=' - mutation($project:ID!, $issue:ID!) { - addProjectV2ItemById(input: {projectId: $project, contentId: $issue}) { - item { - id - } - } - }' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')" - # Update the status to Needs PR Review - gh api graphql -f query=' - mutation ( - $project: ID! - $item: ID! - $status_field: ID! - $status_value: String! - ) { - set_status: 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=${{ env.TODO_OPTION_ID }} --silent - env: - ISSUE_ID: ${{ github.event.issue.node_id }} + ISSUE_OR_PR_ID: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.node_id || github.event.issue.node_id }}