diff --git a/.github/workflows/jira-pr-title-tmp.yml b/.github/workflows/jira-pr-title-tmp.yml deleted file mode 100644 index eb91102..0000000 --- a/.github/workflows/jira-pr-title-tmp.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: "Jira PR Title Check - Temporary" -on: - 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.runner }} - 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 `depdependencies` 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({owener, repo, pull_number, title}); - } - } else if (!jiraPattern.test(prTitle)) { - core.setFailed('Cannot find a JIRA ticket in the PR title'); - } diff --git a/.github/workflows/jira-pr-title.yml b/.github/workflows/jira-pr-title.yml index 7fe3307..d397cc1 100644 --- a/.github/workflows/jira-pr-title.yml +++ b/.github/workflows/jira-pr-title.yml @@ -3,9 +3,32 @@ 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: arc-runner-set + runs-on: ${{ github.event.inputs && github.event.inputs.runner || 'arc-runner-set' }} steps: - name: Check PR title uses: actions/github-script@v7 @@ -14,25 +37,38 @@ jobs: 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.request('GET /repos/{owner}/{repo}/pulls/{pr}', { - owner: context.repo.owner, - repo: context.repo.repo, - pr: context.payload.pull_request.number - }); + 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) + const ip = await github.request('https://icanhazip.com'); + console.log('IP Address: ', ip); throw error; } - const prTitle = data.title + const prTitle = data.title; - const jiraPattern = /[A-Z]+-\d+/g - if (!jiraPattern.test(prTitle)) { - core.setFailed('Cannot find a JIRA ticket in the PR title') - } + const jiraPattern = /[A-Z]+-\d+/g; + + + if (prTitle.includes('[Snyk]')) { + console.log('PR title contains [Snyk]'); + console.log('1. Labeling PR with `depdependencies` 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({owener, repo, pull_number, title}); + } + } else if (!jiraPattern.test(prTitle)) { + core.setFailed('Cannot find a JIRA ticket in the PR title'); + }