From 2a157b128d4919d3e850410f115525e9c63b6384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Arnholtz?= Date: Fri, 2 May 2025 10:56:06 +0200 Subject: [PATCH] Revert "PEAKONDEVEX-1212: Move .github/workflows/jira-pr-title.yml (#21)" This reverts commit 1d2599df2762411e89df702cbbaf38828adb3e36. --- .github/workflows/jira-pr-title.yml | 74 +++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/jira-pr-title.yml diff --git a/.github/workflows/jira-pr-title.yml b/.github/workflows/jira-pr-title.yml new file mode 100644 index 0000000..b6b6d67 --- /dev/null +++ b/.github/workflows/jira-pr-title.yml @@ -0,0 +1,74 @@ +name: "Jira PR Title Check" +on: + pull_request: + types: [opened, reopened, synchronize] + workflow_dispatch: + inputs: + owner: + description: "Owner of the repository" + required: true + default: "peakon" + repo: + description: "Name of the repository" + required: true + default: ".github" + pull_number: + description: "Pull request number" + required: true + default: "1" + runner: + description: "Runner to use" + required: true + type: choice + options: + - "arc-runner-set" + - "ubuntu-latest" + - "windows-latest" + - "macos-latest" + default: "arc-runner-set" +jobs: + check-title: + runs-on: ${{ github.event.inputs && github.event.inputs.runner || 'arc-runner-set' }} + steps: + - name: Check PR title + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + retries: 3 + script: | + let data; + const owner = context.payload.inputs?.owner || context.repo.owner; + const repo = context.payload.inputs?.repo || context.repo.repo; + const pull_number = context.payload.inputs?.pull_number || context.issue.number; + + + try { + const result = await github.rest.pulls.get({ owner, repo, pull_number }); + + data = result.data; + } catch (error) { + const ip = await github.request('https://icanhazip.com'); + console.log('IP Address: ', ip); + + throw error; + } + + const prTitle = data.title; + + const jiraPattern = /[A-Z]+-\d+/g; + + + if (prTitle.includes('[Snyk]')) { + console.log('PR title contains [Snyk]'); + console.log('1. Labeling PR with `dependencies` and `security`'); + const issue_number = data.number; + const labels = ['dependencies', 'security']; + await github.rest.issues.addLabels({owner, repo, issue_number, labels}); + if (!jiraPattern.test(prTitle)) { + console.log('2. Adding `[PEAKON-2516]` prefix to PR title'); + const title = `[PEAKON-2516] ${prTitle}`; + await github.rest.pulls.update({owner, repo, pull_number, title}); + } + } else if (!jiraPattern.test(prTitle)) { + core.setFailed('Cannot find a JIRA ticket in the PR title'); + }