Skip to content

Commit

Permalink
ci: add pr-title-checker action (#472)
Browse files Browse the repository at this point in the history
* ci: add pr-title-checker action

Signed-off-by: Lin Yang <[email protected]>

* feat: Add comment to fix PR title

Signed-off-by: Lin Yang <[email protected]>

---------

Signed-off-by: Lin Yang <[email protected]>

fix: pr-title-checker permission

Signed-off-by: Lin Yang <[email protected]>

fix: pr-title-checker permission

Signed-off-by: Lin Yang <[email protected]>
  • Loading branch information
reaver-flomesh committed Nov 25, 2024
1 parent b6ed336 commit 1247939
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/pr-title-checker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"LABEL": {
"name": "title needs formatting",
"color": "EEEEEE"
},
"CHECKS": {
"prefixes": ["[Bot] docs: "],
"regexp": "^(feat|fix|docs|test|ci|chore|refactor|perf)!?(\\(.*\\))?!?:.*"
},
"MESSAGES": {
"success": "PR title is valid",
"failure": "PR title is invalid",
"notice": "PR Title needs to pass regex '^(feat|fix|docs|test|ci|chore|refactor|perf)!?(\\(.*\\))?!?:.*"
}
}
61 changes: 61 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: "Lint PR"

on:
pull_request_target:
types: [opened, edited, reopened, synchronize]


# IMPORTANT: No checkout actions, scripts, or builds should be added to this workflow. Permissions should always be used
# with extreme caution. https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
permissions:
pull-requests: write
contents: read

# PR updates can happen in quick succession leading to this
# workflow being trigger a number of times. This limits it
# to one run per PR.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}


jobs:
validate:
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- name: PR Title Check
uses: thehanimo/[email protected]
id: check
continue-on-error: true
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
configuration_path: ".github/pr-title-checker-config.json"

- name: Add comment to fix PR title
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.check.outputs.success == 'false'}}
with:
header: 'PR Title Check'
recreate: true
message: |
### 🚨 PR Title Needs Formatting
The title of this PR needs to be formatted correctly.
Please update the title to match the format `type: description AB#xxx`. Examples:
* `fix: fix typo in README.md AB#123`
* `chore: update dependencies AB#456`
* `feat: add new feature AB#789`
* `chore: fixing build pipeline` - no AB reference
For more details, please refer to the [Conventional Commits Specification](https://www.conventionalcommits.org/en/v1.0.0)
and the [PR Title Configuration File](.github/pr-title-checker-config.json).
- name: Add comment that PR title is fixed
if: ${{ steps.check.outputs.success == 'true'}}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: 'PR Title Check'
recreate: true
message: |
### ✅ PR Title Formatted Correctly
The title of this PR has been updated to match the correct format. Thank you!

0 comments on commit 1247939

Please sign in to comment.