From c2e43a5bc212a9707dedb642aaba8563297682a5 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Wed, 3 Apr 2024 18:10:33 +0800 Subject: [PATCH] chore: add action to check title prefix --- .github/workflows/pr.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000000..f8b7aba2b6 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,27 @@ +name: PR + +on: + pull_request: + types: [opened, edited, synchronize] + +jobs: + check-title: + runs-on: ubuntu-latest + steps: + - name: Check PR Title Prefix + uses: actions/github-script@v7 + with: + script: | + const titlePrefixes = ['feat', 'fix', 'break', 'chore']; + const title = context.payload.pull_request.title.toLowerCase(); + const titleHasValidPrefix = titlePrefixes.some(prefix => title.startsWith(`${prefix}:`)); + + if (!titleHasValidPrefix) { + github.rest.issues.createComment({ + issue_number: context.payload.pull_request.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "🚨 PR title does not meet the requirements. It must start with one of the following prefixes: 'feat:', 'fix:', 'chore:', 'break:'." + }); + throw new Error(message); + }