From 86c4ac49113803d09b20da0303cc2d9b3473b511 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Wed, 3 Apr 2024 18:10:33 +0800 Subject: [PATCH 1/3] chore: add action to check title prefix --- .github/workflows/pr.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 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..4cda7833b4 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,25 @@ +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) { process.exit(-1); } + + - if: failure() + uses: thollander/actions-comment-pull-request@v2 + with: + message: | + "🚨 PR title does not meet the requirements. It must start with one of the following prefixes: 'feat:', 'fix:', 'chore:', 'break:'." + comment_tag: PR title check result From 6dca084058e038b3ea7dd6dafe36bb39999f7512 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Wed, 3 Apr 2024 18:32:52 +0800 Subject: [PATCH 2/3] fix --- .github/workflows/pr.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 4cda7833b4..48a30ed66a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -9,16 +9,24 @@ jobs: runs-on: ubuntu-latest steps: - name: Check PR Title Prefix + id: title-check uses: actions/github-script@v7 with: script: | - const titlePrefixes = ['feat', 'fix', 'break', 'chore']; + const titlePrefixes = ["feat", "fix", "break", "chore"]; const title = context.payload.pull_request.title.toLowerCase(); - const titleHasValidPrefix = titlePrefixes.some(prefix => title.startsWith(`${prefix}:`)); + const titleHasValidPrefix = titlePrefixes.some((prefix) => title.startsWith(`${prefix}:`)); if (!titleHasValidPrefix) { process.exit(-1); } - - if: failure() - uses: thollander/actions-comment-pull-request@v2 + - uses: thollander/actions-comment-pull-request@v2 + if: success() + with: + message: | + "✅ PR title meet the requirements" + comment_tag: PR title check result + + - uses: thollander/actions-comment-pull-request@v2 + if: failure() with: message: | "🚨 PR title does not meet the requirements. It must start with one of the following prefixes: 'feat:', 'fix:', 'chore:', 'break:'." From 4b91d7e9c1e4d125ea6993def38b1fce46da661d Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Wed, 3 Apr 2024 18:38:37 +0800 Subject: [PATCH 3/3] clean --- .github/workflows/pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 48a30ed66a..bf0538c5f2 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -22,12 +22,12 @@ jobs: if: success() with: message: | - "✅ PR title meet the requirements" + ✅ PR title meet the requirements. comment_tag: PR title check result - uses: thollander/actions-comment-pull-request@v2 if: failure() with: message: | - "🚨 PR title does not meet the requirements. It must start with one of the following prefixes: 'feat:', 'fix:', 'chore:', 'break:'." + 🚨 PR title does not meet the requirements. It must start with one of the following prefixes: 'feat:', 'fix:', 'chore:', 'break:'. comment_tag: PR title check result