From 816aa1a0a396d792cfa6720e627a42b4653d43f9 Mon Sep 17 00:00:00 2001 From: Stephen Riolo Date: Fri, 11 Jul 2025 14:57:19 +0200 Subject: [PATCH 1/3] feat(pr-validations): added functionality to validate a pr with required fields --- .github/workflows/validate-pr.yml | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/validate-pr.yml diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml new file mode 100644 index 0000000..0386705 --- /dev/null +++ b/.github/workflows/validate-pr.yml @@ -0,0 +1,66 @@ +name: PR Title and Label Validation + +on: + pull_request: + types: [opened, edited, synchronize, reopened, labeled, unlabeled] + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Validate PR Title + shell: bash + run: | + PR_TITLE="${{ github.event.pull_request.title }}" + if [[ ! "$PR_TITLE" =~ ^\[[A-Za-z0-9]+\]:\ [^ ]+\ .+ ]]; then + echo "❌ PR title does not match the required format: [ClickUp Task ID]: [emoji] [Task Name]" + echo "Example: [CU-1234]: :sparkles: Add user authentication flow" + exit 1 + fi + # Check for x.xx version anywhere in the title + if ! [[ "$PR_TITLE" =~ [0-9]+\.[0-9]{2} ]]; then + echo "❌ PR title must contain a version in the format x.xx (e.g. 2.49, 3.07, etc.)" + exit 1 + fi + + - name: Validate PR Labels + shell: bash + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + REPO: ${{ github.repository }} + run: | + labels=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels -q '.labels[].name' | tr '\n' ' ') + + echo "Labels: $labels" + + fail=0 + + # Type + if ! echo "$labels" | grep -Eq '\b(feature|fix|refactor|hotfix)\b'; then + echo "❌ Missing Type label (feature, fix, refactor, hotfix)" + fail=1 + fi + + # Version introduced: accept any x.xx + if ! echo "$labels" | grep -Eq '\b[0-9]+\.[0-9]{2}\b'; then + echo "❌ Missing Version introduced label (e.g. 2.49, 3.07, etc.)" + fail=1 + fi + + # Stream/Team + if ! echo "$labels" | grep -Eq '\b(rewards|vector|reliability)\b'; then + echo "❌ Missing Stream/Team label (rewards, vector, reliability)" + fail=1 + fi + + if [ "$fail" -eq 1 ]; then + exit 1 + fi + + - name: Success + if: ${{ success() }} + run: echo "✅ PR title and labels are valid!" \ No newline at end of file From 59e59032c14c052fb8e7a4454e5c9eb6c00e26c0 Mon Sep 17 00:00:00 2001 From: Stephen Riolo Date: Fri, 11 Jul 2025 15:02:21 +0200 Subject: [PATCH 2/3] chore: changing some syntax --- .github/workflows/validate-pr.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index 0386705..d3eafdf 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -15,13 +15,15 @@ jobs: shell: bash run: | PR_TITLE="${{ github.event.pull_request.title }}" - if [[ ! "$PR_TITLE" =~ ^\[[A-Za-z0-9]+\]:\ [^ ]+\ .+ ]]; then + # Use a variable for the regex pattern + regex='^\[[A-Za-z0-9]+\]: [^ ]+ .+' + if [[ ! "$PR_TITLE" =~ $regex ]]; then echo "❌ PR title does not match the required format: [ClickUp Task ID]: [emoji] [Task Name]" echo "Example: [CU-1234]: :sparkles: Add user authentication flow" exit 1 fi # Check for x.xx version anywhere in the title - if ! [[ "$PR_TITLE" =~ [0-9]+\.[0-9]{2} ]]; then + if [[ ! "$PR_TITLE" =~ [0-9]+\.[0-9]{2} ]]; then echo "❌ PR title must contain a version in the format x.xx (e.g. 2.49, 3.07, etc.)" exit 1 fi From fe8132bd7ec63fcb4e3a96333a374eb25bbe1c5a Mon Sep 17 00:00:00 2001 From: Stephen Riolo Date: Fri, 11 Jul 2025 15:19:52 +0200 Subject: [PATCH 3/3] chore: change pr title validation --- .github/workflows/validate-pr.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index d3eafdf..ac72028 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -15,18 +15,12 @@ jobs: shell: bash run: | PR_TITLE="${{ github.event.pull_request.title }}" - # Use a variable for the regex pattern - regex='^\[[A-Za-z0-9]+\]: [^ ]+ .+' + regex='^\[([A-Za-z0-9-]+)\]:\s(\S+)\s(.+)$' if [[ ! "$PR_TITLE" =~ $regex ]]; then echo "❌ PR title does not match the required format: [ClickUp Task ID]: [emoji] [Task Name]" - echo "Example: [CU-1234]: :sparkles: Add user authentication flow" + echo "Example: [86c4em56j]: ⛩️ PR Title Validations Workflow or [DEV-1234]: 🧨 Testing" exit 1 - fi - # Check for x.xx version anywhere in the title - if [[ ! "$PR_TITLE" =~ [0-9]+\.[0-9]{2} ]]; then - echo "❌ PR title must contain a version in the format x.xx (e.g. 2.49, 3.07, etc.)" - exit 1 - fi + fi - name: Validate PR Labels shell: bash @@ -36,7 +30,6 @@ jobs: REPO: ${{ github.repository }} run: | labels=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels -q '.labels[].name' | tr '\n' ' ') - echo "Labels: $labels" fail=0