Skip to content

Commit

Permalink
Corrects columns of Pull Requests in milestone projects (#1199)
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
Ryan089 authored May 15, 2023
1 parent eaf83c5 commit 99947c3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .github/actions/determine-status-column/action.yml
Original file line number Diff line number Diff line change
@@ -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'
25 changes: 25 additions & 0 deletions .github/actions/determine-status-column/index.js
Original file line number Diff line number Diff line change
@@ -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);
16 changes: 11 additions & 5 deletions .github/workflows/AddIssueToMilestoneProject.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Add Issue To Milestone Project
name: Add Issues and Pull Requests To Milestone Project
on:
issues:
types: [milestoned]
Expand Down Expand Up @@ -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/[email protected]
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
}
Expand Down

0 comments on commit 99947c3

Please sign in to comment.