From d16ca1b36c314eea30ddfcea8de2258ba04d7da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Kocei=C4=87?= Date: Tue, 1 Jul 2025 12:44:01 +0200 Subject: [PATCH 1/4] Added check for ticket number in PR title --- .github/workflows/ci.yaml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 91b83d6e..b7d49223 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,6 +5,7 @@ on: branches: - main pull_request: + types: [opened, edited, synchronize, reopened] permissions: contents: read @@ -16,6 +17,31 @@ env: TEST_TAG_WORKER: user/worker:test jobs: + check-title: + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: actions/checkout@v4 + + - name: Check PR title for ticket number + run: | + # Fetch the PR title using GitHub API + PR_TITLE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq -r .title) + + echo "PR Title: $PR_TITLE" + + # Regex pattern for a ticket number + TICKET_PATTERN="DXTA-[0-9]+" # Matches strings like DXTA-123 + + # Check if PR title matches the pattern + if [[ ! "$PR_TITLE" =~ $TICKET_PATTERN ]]; then + echo "Error: PR title does not contain a valid ticket number!" + exit 1 # Fail the CI/CD pipeline + fi + + echo "PR title contains a valid ticket number." + test: runs-on: ubuntu-latest steps: From f140ed1e38a76fb885dc85c8088aae6fc30b73fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Kocei=C4=87?= Date: Wed, 2 Jul 2025 09:49:30 +0200 Subject: [PATCH 2/4] Simplified logic --- .github/workflows/ci.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b7d49223..a3605933 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,8 +26,7 @@ jobs: - name: Check PR title for ticket number run: | # Fetch the PR title using GitHub API - PR_TITLE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq -r .title) + PR_TITLE=${{ github.event.pull_request.title }} echo "PR Title: $PR_TITLE" From 20ef07ebb4ce00c772f0883add688fe8ced6fccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Kocei=C4=87?= Date: Wed, 2 Jul 2025 09:58:19 +0200 Subject: [PATCH 3/4] Removed variable --- .github/workflows/ci.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a3605933..7697a6d0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,15 +26,14 @@ jobs: - name: Check PR title for ticket number run: | # Fetch the PR title using GitHub API - PR_TITLE=${{ github.event.pull_request.title }} - echo "PR Title: $PR_TITLE" + echo "PR Title: ${{ github.event.pull_request.title }}" # Regex pattern for a ticket number TICKET_PATTERN="DXTA-[0-9]+" # Matches strings like DXTA-123 # Check if PR title matches the pattern - if [[ ! "$PR_TITLE" =~ $TICKET_PATTERN ]]; then + if [[ ! "${{ github.event.pull_request.title }}" =~ $TICKET_PATTERN ]]; then echo "Error: PR title does not contain a valid ticket number!" exit 1 # Fail the CI/CD pipeline fi From d819232e3631bd9a59d83f679f0c410472518774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ante=20Kocei=C4=87?= Date: Fri, 4 Jul 2025 11:29:39 +0200 Subject: [PATCH 4/4] Removed comment --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7697a6d0..613db0e6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,8 +25,6 @@ jobs: - name: Check PR title for ticket number run: | - # Fetch the PR title using GitHub API - echo "PR Title: ${{ github.event.pull_request.title }}" # Regex pattern for a ticket number