fix: it should handle already encoded parts in the URL when redirecting #2011
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: Comment Jira Ticket in PR | |
| on: | |
| # Trigger when a pull request is opened or reopened | |
| pull_request: | |
| types: [opened, reopened, ready_for_review, synchronize] | |
| permissions: | |
| contents: read | |
| jobs: | |
| comment-jira-ticket: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Comment with the jira ticket | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const branch = `${{ github.head_ref }}` | |
| const match = branch.match(/\b(MI|AS)-\d+\b/i); | |
| const jiraTicket = match ? match[0].toUpperCase() : null; | |
| if (!jiraTicket) { | |
| console.log('No Jira ticket found') | |
| return | |
| } | |
| console.log(`Found ticket ${jiraTicket}`) | |
| const knownString = '### Jira ticket' | |
| const pullRequest = await github.rest.pulls.get({ | |
| pull_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }) | |
| const hasAlreadyCommented = pullRequest.data.body ? pullRequest.data.body.includes(knownString) : false | |
| if (hasAlreadyCommented) { | |
| console.log('Already commented once') | |
| } else { | |
| console.log('Creating comment for the first time') | |
| const body = pullRequest.data.body | |
| ? `${pullRequest.data.body}\n\n${knownString}\n${jiraTicket}` | |
| : `${knownString}\n${jiraTicket}` | |
| await github.rest.pulls.update({ | |
| pull_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body, | |
| }) | |
| } |