diff --git a/.github/workflows/pr-naming-check.yml b/.github/workflows/pr-naming-check.yml new file mode 100644 index 00000000000..a19be89a55e --- /dev/null +++ b/.github/workflows/pr-naming-check.yml @@ -0,0 +1,40 @@ +name: Pull Request Title Validation + +on: + pull_request: + types: [opened, reopened, edited] + +jobs: + pull-request-title-validation: + runs-on: ubuntu-latest + + steps: + - name: Check PR title format + id: check_title + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const titleRegex = /^(Revert \")?(feat|build|chore|style|fix|update|ci)\((\w|\/|-)+\)\:.+/g; + const title = context.payload.pull_request.title; + const isValid = titleRegex.test(title); + if (!isValid) { + console.error(`PR title "${title}" doesn't match the required format.`); + } + return isValid; + + - name: Leave comment for OP + if: steps.check_title.outputs.result == 'false' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.payload.pull_request.number; + const author = context.payload.pull_request.user.login; + const message = `@${author} your pull request title "${context.payload.pull_request.title}" does not conform to our naming conventions (https://www.conventionalcommits.org/en/v1.0.0/).\n\nPlease update the title to match the pattern: "feat|build|chore|style|fix|update|ci(): "`; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: message + });