Skip end tasks when empty. #4
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: Parse commit message | |
| id: parse-commit | |
| run: | | |
| COMMIT_MESSAGE=$(cat <<'EOF' | sed -n '/^Fixes #/,/\./p' | |
| ${{ github.event.head_commit.message }} | |
| EOF | |
| ) | |
| echo "fixed_list=${COMMIT_MESSAGE}" >> $GITHUB_OUTPUT | |
| - name: Check if fixes list is empty | |
| if: ${{ steps.parse-commit.outputs.fixed_list == '' }} | |
| run: echo "No fixes found in commit message. Stopping workflow." && exit 0 | |
| - name: Print fixes list for debugging | |
| if: ${{ steps.parse-commit.outputs.fixed_list != '' }} | |
| run: | | |
| echo "Fixes list: ${{ steps.parse-commit.outputs.fixed_list }}" | |
| - name: Find pull requests | |
| id: pr-results | |
| if: ${{ steps.parse-commit.outputs.fixed_list != '' }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fixesList = "${{ steps.parse-commit.outputs.fixed_list }}".split('\n'); | |
| let relatedPRs = []; | |
| for (const value of fixesList) { | |
| const query = `is:pr is:open repo:WordPress/wordpress-develop in:body https://core.trac.wordpress.org/ticket/${value}`; | |
| const result = await github.rest.search.issuesAndPullRequests({ q: query }); | |
| relatedPRs = relatedPRs.concat(result.data.items.map(pr => ({ | |
| owner: 'wordpress', | |
| repo: pr.repository_url.split('/').slice(-2).join('/'), | |
| number: pr.number | |
| }))); | |
| } | |
| console.log(relatedPRs); | |
| return relatedPRs; |