|
| 1 | +name: "Jira PR Title Check - Temporary" |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + owner: |
| 6 | + description: "Owner of the repository" |
| 7 | + required: true |
| 8 | + default: "peakon" |
| 9 | + repo: |
| 10 | + description: "Name of the repository" |
| 11 | + required: true |
| 12 | + default: ".github" |
| 13 | + pull_number: |
| 14 | + description: "Pull request number" |
| 15 | + required: true |
| 16 | + default: "1" |
| 17 | + runner: |
| 18 | + description: "Runner to use" |
| 19 | + required: true |
| 20 | + type: choice |
| 21 | + options: |
| 22 | + - "arc-runner-set" |
| 23 | + - "ubuntu-latest" |
| 24 | + - "windows-latest" |
| 25 | + - "macos-latest" |
| 26 | + default: "arc-runner-set" |
| 27 | +jobs: |
| 28 | + check-title: |
| 29 | + runs-on: ${{ github.event.inputs.runner }} |
| 30 | + steps: |
| 31 | + - name: Check PR title |
| 32 | + uses: actions/github-script@v7 |
| 33 | + with: |
| 34 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + retries: 3 |
| 36 | + script: | |
| 37 | + let data; |
| 38 | + const owner = context.payload.inputs?.owner || context.repo.owner; |
| 39 | + const repo = context.payload.inputs?.repo || context.repo.repo; |
| 40 | + const pull_number = context.payload.inputs?.pull_number || context.issue.number; |
| 41 | +
|
| 42 | +
|
| 43 | + try { |
| 44 | + const result = await github.rest.pulls.get({ owner, repo, pull_number }); |
| 45 | +
|
| 46 | + data = result.data; |
| 47 | + } catch (error) { |
| 48 | + const ip = await github.request('https://icanhazip.com'); |
| 49 | + console.log('IP Address: ', ip); |
| 50 | +
|
| 51 | + throw error; |
| 52 | + } |
| 53 | +
|
| 54 | + const prTitle = data.title; |
| 55 | +
|
| 56 | + const jiraPattern = /[A-Z]+-\d+/g; |
| 57 | +
|
| 58 | +
|
| 59 | + if (prTitle.includes('[Snyk]')) { |
| 60 | + console.log('PR title contains [Snyk]'); |
| 61 | + console.log('1. Labeling PR with `depdependencies` and `security`'); |
| 62 | + const issue_number = data.number; |
| 63 | + const labels = ['dependencies', 'security']; |
| 64 | + await github.rest.issues.addLabels({owner, repo, issue_number, labels}); |
| 65 | + if (!jiraPattern.test(prTitle)) { |
| 66 | + console.log('2. Adding `[PEAKON-2516]` prefix to PR title'); |
| 67 | + const title = `[PEAKON-2516] ${prTitle}`; |
| 68 | + await github.rest.pulls.update({owener, repo, pull_number, title}); |
| 69 | + } |
| 70 | + } else if (!jiraPattern.test(prTitle)) { |
| 71 | + core.setFailed('Cannot find a JIRA ticket in the PR title'); |
| 72 | + } |
0 commit comments