|
| 1 | +name: PR Title Validation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, edited, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + validate-title: |
| 9 | + if: | |
| 10 | + github.event.pull_request.user.login != 'actions-user' && |
| 11 | + github.event.pull_request.user.login != 'opencode' && |
| 12 | + github.event.pull_request.user.login != 'rekram1-node' && |
| 13 | + github.event.pull_request.user.login != 'thdxr' && |
| 14 | + github.event.pull_request.user.login != 'kommander' && |
| 15 | + github.event.pull_request.user.login != 'jayair' && |
| 16 | + github.event.pull_request.user.login != 'fwang' && |
| 17 | + github.event.pull_request.user.login != 'adamdotdevin' && |
| 18 | + github.event.pull_request.user.login != 'iamdavidhill' && |
| 19 | + github.event.pull_request.user.login != 'opencode-agent[bot]' |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + pull-requests: write |
| 23 | + steps: |
| 24 | + - name: Validate PR title |
| 25 | + uses: actions/github-script@v7 |
| 26 | + with: |
| 27 | + script: | |
| 28 | + const title = context.payload.pull_request.title; |
| 29 | + const validPrefixes = ['feat:', 'fix:', 'docs:', 'chore:', 'refactor:', 'test:']; |
| 30 | + const isValid = validPrefixes.some(prefix => title.startsWith(prefix)); |
| 31 | +
|
| 32 | + if (!isValid) { |
| 33 | + const body = `👋 Thanks for opening this PR! |
| 34 | +
|
| 35 | + Your PR title \`${title}\` doesn't follow our conventional commit format. |
| 36 | +
|
| 37 | + Please update it to start with one of these prefixes: |
| 38 | + - \`feat:\` new feature or functionality |
| 39 | + - \`fix:\` bug fix |
| 40 | + - \`docs:\` documentation or README changes |
| 41 | + - \`chore:\` maintenance tasks, dependency updates, etc. |
| 42 | + - \`refactor:\` code refactoring without changing behavior |
| 43 | + - \`test:\` adding or updating tests |
| 44 | +
|
| 45 | + **Examples:** |
| 46 | + - \`docs: update contributing guidelines\` |
| 47 | + - \`fix: resolve crash on startup\` |
| 48 | + - \`feat: add dark mode support\` |
| 49 | +
|
| 50 | + See [CONTRIBUTING.md](../blob/dev/CONTRIBUTING.md#pr-titles) for more details.`; |
| 51 | +
|
| 52 | + await github.rest.issues.createComment({ |
| 53 | + owner: context.repo.owner, |
| 54 | + repo: context.repo.repo, |
| 55 | + issue_number: context.payload.pull_request.number, |
| 56 | + body: body |
| 57 | + }); |
| 58 | +
|
| 59 | + core.setFailed('PR title does not follow conventional commit format'); |
| 60 | + } else { |
| 61 | + console.log('PR title is valid:', title); |
| 62 | + } |
0 commit comments