From aefd2e9af28b548afa079e5dbc6654dad7ae66c0 Mon Sep 17 00:00:00 2001 From: Afonso Jorge Ramos Date: Mon, 22 May 2023 12:11:07 +0100 Subject: [PATCH] feat: add pr title validator --- .github/workflows/pr-title-validator.yml | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/pr-title-validator.yml diff --git a/.github/workflows/pr-title-validator.yml b/.github/workflows/pr-title-validator.yml new file mode 100644 index 000000000..079934bd1 --- /dev/null +++ b/.github/workflows/pr-title-validator.yml @@ -0,0 +1,31 @@ +name: PR Title Validator + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + +jobs: + pr-lint: + name: Validate PR name + runs-on: ubuntu-latest + steps: + - name: Validate PR title + uses: actions/github-script@v6 + with: + script: | + const title = context.payload.pull_request.title; + const regex = /^(?build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|deps)(?\(\w+\)?((?=:\s)|(?=!:\s)))?(?!)?(?:\s.*)?/gm; + const match = regex.exec(title); + + if (!match) { + core.setFailed('Invalid PR title'); + } + if (!match.groups.type && !match.groups.subject) { + core.setFailed('Missing type and subject in PR title'); + } + if (!match.groups.type) { + core.setFailed('Missing type in PR title'); + } + if (!match.groups.subject) { + core.setFailed('Missing subject in PR title'); + }