Let's test some edge cases. #19
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Close Pull Requests | |
| on: | |
| push: | |
| branches: | |
| - 'test-close-prs' | |
| jobs: | |
| close-prs: | |
| name: Close Pull Requests on Push | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Find fixed tickets | |
| id: parse-commit | |
| run: | | |
| COMMIT_MESSAGE=$(cat <<'EOF' | sed -n '/^Fixes #/,/\./p' | |
| ${{ github.event.head_commit.message }} | |
| EOF | |
| ) | |
| echo "fixed_list=$(echo \"$COMMIT_MESSAGE\" | grep -oP '(?<=Fixes )#\d+(, #\d+)*' | grep -oP '\d+' | tr '\n' ' ')" >> $GITHUB_OUTPUT | |
| - name: Get the SVN revision | |
| id: git-svn-id | |
| run: | | |
| COMMIT_MESSAGE=$(cat <<'EOF' | sed -n '$p' | |
| ${{ github.event.head_commit.message }} | |
| EOF | |
| ) | |
| SVN_REVISION=$(echo "$COMMIT_MESSAGE" | sed -n 's/.*git-svn-id: https:\/\/develop.svn.wordpress.org\/[^@]*@\([0-9]*\) .*/\1/p') | |
| echo "svn_revision_number=${SVN_REVISION}" >> $GITHUB_OUTPUT | |
| - name: Print fixes list for debugging | |
| if: ${{ steps.parse-commit.outputs.fixed_list != '' && steps.git-svn-id.outputs.svn_revision_number != '' }} | |
| run: | | |
| echo "Fixes list: ${{ steps.parse-commit.outputs.fixed_list }}" | |
| echo "SVN revision: ${{ steps.git-svn-id.outputs.svn_revision_number }}" | |
| - name: Find pull requests | |
| id: pr-results | |
| if: ${{ steps.parse-commit.outputs.fixed_list != '' && steps.git-svn-id.outputs.svn_revision_number != '' }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fixedList = "${{ steps.parse-commit.outputs.fixed_list }}".split(' ').filter(Boolean); | |
| console.debug( fixedList ); | |
| let prNumbers = []; | |
| for (const ticket of fixedList) { | |
| console.log( ticket ); | |
| const query = 'is:pr is:open repo:WordPress/wordpress-develop in:body https://core.trac.wordpress.org/ticket/' + ticket; | |
| const result = await github.rest.search.issuesAndPullRequests({ q: query }); | |
| prNumbers = prNumbers.concat(result.data.items.map(pr => pr.number)); | |
| } | |
| console.log(prNumbers); | |
| return prNumbers; | |
| - name: Comment on pull requests | |
| if: ${{ steps.parse-commit.outputs.fixed_list != '' && steps.git-svn-id.outputs.svn_revision_number != '' }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prNumbers = ${{ steps.pr-results.outputs.result }}; | |
| for (const prNumber of prNumbers) { | |
| const pr = await github.rest.pulls.get({ | |
| owner: 'desrosj', | |
| repo: 'wordpress-develop', | |
| pull_number: 155 | |
| }); | |
| if ( pr.data.state === 'closed' ) { | |
| continue; | |
| } | |
| const commentBody = `A commit was made that fixes a Trac ticket referenced in the description of this pull request. | |
| SVN changeset: [${{ steps.git-svn-id.outputs.svn_revision_number }}](https://core.trac.wordpress.org/changeset/${{ steps.git-svn-id.outputs.svn_revision_number }}) | |
| GitHub changeset: ${{ github.sha }} | |
| This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.`; | |
| // Comment on the pull request with details. | |
| await github.rest.issues.createComment({ | |
| owner: 'desrosj', | |
| repo: 'wordpress-develop', | |
| issue_number: 155, | |
| body: commentBody | |
| }); | |
| // Close the pull request. | |
| await github.rest.pulls.update({ | |
| owner: 'desrosj', | |
| repo: 'wordpress-develop', | |
| pull_number: 155, | |
| state: 'closed' | |
| }); | |
| } | |