From 99947c3e1faa682c7861db37c48b168e96e14b78 Mon Sep 17 00:00:00 2001 From: Ryan Puth <64360820+Ryan089@users.noreply.github.com> Date: Tue, 16 May 2023 03:06:19 +1000 Subject: [PATCH] Corrects columns of Pull Requests in milestone projects (#1199) * Check which Project column a particular issue or pull request should be added to. * Amended the title. * Only needs to run on Issues (PR's are a subset) * Changed variable * x * Remove $ * Variables * issues * pull_request * Changed method of determining whether PR or issue. * Change to empty string rather than null. * Adds to the correct column (i.e. not necessarily the backlog column). --- .../determine-status-column/action.yml | 14 +++++++++++ .../actions/determine-status-column/index.js | 25 +++++++++++++++++++ .../workflows/AddIssueToMilestoneProject.yml | 16 ++++++++---- 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .github/actions/determine-status-column/action.yml create mode 100644 .github/actions/determine-status-column/index.js diff --git a/.github/actions/determine-status-column/action.yml b/.github/actions/determine-status-column/action.yml new file mode 100644 index 0000000000..01bc978345 --- /dev/null +++ b/.github/actions/determine-status-column/action.yml @@ -0,0 +1,14 @@ +name: 'Determine Status Column' +inputs: + ISSUE_TITLE: + description: 'Title of the Issue or Pull Request' + required: true + PULL_REQUEST_URL: + description: 'Pull request URL (existence used to confirm whether pull request or issue)' + required: true +outputs: + COLUMN: + description: 'The appropriate column to place the issue in.' +runs: + using: 'node16' + main: 'index.js' \ No newline at end of file diff --git a/.github/actions/determine-status-column/index.js b/.github/actions/determine-status-column/index.js new file mode 100644 index 0000000000..5469552c49 --- /dev/null +++ b/.github/actions/determine-status-column/index.js @@ -0,0 +1,25 @@ +const core = require('@actions/core'); +const url = core.getInput('PULL_REQUEST_URL') +const title = core.getInput('ISSUE_TITLE') + +var column = null +console.log(url); +console.log(title); + +if (url == "") { // If Pull Request URL is empty, the event must be an issue. + column = "Backlog"; +} +else // Otherwise, it's a pull request. +{ + var potentialPrefix = title.toUpperCase().slice(0, 5); + console.log(potentialPrefix); + if (potentialPrefix == "[WIP]") { + column = "In Progress"; + } + else + { + column = "In Review"; + } +} +console.log(column); +core.setOutput('COLUMN', column); \ No newline at end of file diff --git a/.github/workflows/AddIssueToMilestoneProject.yml b/.github/workflows/AddIssueToMilestoneProject.yml index f674dfd80e..060e6e726f 100644 --- a/.github/workflows/AddIssueToMilestoneProject.yml +++ b/.github/workflows/AddIssueToMilestoneProject.yml @@ -1,4 +1,4 @@ -name: Add Issue To Milestone Project +name: Add Issues and Pull Requests To Milestone Project on: issues: types: [milestoned] @@ -102,21 +102,27 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} - run: "echo 'Field options: ${{ steps.get-backlog-id.outputs.data }}'" + - name: Determine status column + uses: ./.github/actions/determine-status-column + id: determine-status-column + with: + PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }} + ISSUE_TITLE: ${{ github.event.issue.title }} - name: Get target field ID uses: ./.github/actions/get-single-select-field-id id: get-single-select-field-id with: JSON_FIELD_OPTIONS: ${{ steps.get-backlog-id.outputs.data }} - TARGET_OPTION: Backlog + TARGET_OPTION: ${{ steps.determine-status-column.outputs.COLUMN }} env: GITHUB_TOKEN: ${{ secrets.PROJECT_MANAGEMENT_TOKEN }} - - name: Add To Backlog + - name: Add To correct column uses: octokit/graphql-action@v2.2.24 - id: add-issue-to-backlog-column + id: add-issue-to-correct-column if: ${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID != ''}} with: query: | - mutation AddToBacklog { + mutation AddToCorrectColumn { updateProjectV2ItemFieldValue(input: {projectId:"${{ steps.check-milestone-exists.outputs.EXISTING_PROJECT_ID }}", itemId:"${{ fromJSON(steps.add-issue-to-milestone-project.outputs.data).addProjectV2ItemById.item.id }}", fieldId: "${{ fromJSON(steps.locate-status-column.outputs.data).node.field.id }}", value: { singleSelectOptionId: "${{steps.get-single-select-field-id.outputs.OPTION_ID}}" }}) { clientMutationId }