chore: simplify GitHub issue template #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Commit Message Validation | |
| on: | |
| pull_request: | |
| types: [opened, synchronize] | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| jobs: | |
| validate-commit-messages: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate Commit Messages | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { execSync } = require('child_process'); | |
| const pr = context.payload.pull_request; | |
| // Get commits in the PR | |
| const commits = await github.rest.pulls.listCommits({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr.number | |
| }); | |
| const validCommitPattern = /^(feat|fix|docs|style|refactor|perf|test|chore|ci)(\(.+\))?!?: .{1,100}$/; | |
| const invalidCommits = []; | |
| commits.data.forEach(commit => { | |
| const message = commit.commit.message.split('\n')[0]; // Get first line | |
| if (!validCommitPattern.test(message)) { | |
| invalidCommits.push({ | |
| sha: commit.sha.substring(0, 7), | |
| message: message | |
| }); | |
| } | |
| }); | |
| if (invalidCommits.length > 0) { | |
| core.setFailed(` Found ${invalidCommits.length} commit(s) with invalid message format`); | |
| return; | |
| } | |
| core.info(' All commit messages follow the conventional commits format'); | |
| - name: Comment on commit validation failure | |
| if: failure() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { execSync } = require('child_process'); | |
| const pr = context.payload.pull_request; | |
| const commits = await github.rest.pulls.listCommits({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: pr.number | |
| }); | |
| const validCommitPattern = /^(feat|fix|docs|style|refactor|perf|test|chore|ci)(\(.+\))?!?: .{1,100}$/; | |
| const invalidCommits = []; | |
| commits.data.forEach(commit => { | |
| const message = commit.commit.message.split('\n')[0]; | |
| if (!validCommitPattern.test(message)) { | |
| invalidCommits.push({ | |
| sha: commit.sha.substring(0, 7), | |
| message: message | |
| }); | |
| } | |
| }); | |
| if (invalidCommits.length > 0) { | |
| let commitsList = invalidCommits.map(c => '- `' + c.sha + '`: ' + c.message).join('\n'); | |
| const body = '### Commit Message Validation Failed \n\n' + | |
| 'The following commits do not follow the Conventional Commits format:\n\n' + | |
| commitsList + '\n\n' + | |
| '**Required Format:** `type(scope)?: message`\n\n' + | |
| '**Allowed Types:**\n' + | |
| '- `feat` - A new feature\n' + | |
| '- `fix` - A bug fix\n' + | |
| '- `docs` - Documentation only changes\n' + | |
| '- `style` - Changes that do not affect code meaning (formatting, etc.)\n' + | |
| '- `refactor` - A code change that neither fixes a bug nor adds a feature\n' + | |
| '- `perf` - A code change that improves performance\n' + | |
| '- `test` - Adding missing tests or correcting existing tests\n' + | |
| '- `chore` - Changes to build process, dependencies, or tooling\n' + | |
| '- `ci` - Changes to CI configuration files\n\n' + | |
| '**Message Rules:**\n' + | |
| '- Use imperative mood ("add" not "adds" or "added")\n' + | |
| '- Do not capitalize the first letter\n' + | |
| '- Do not end with a period\n' + | |
| '- Maximum 100 characters\n' + | |
| '- Be specific and descriptive\n\n' + | |
| '**Examples:**\n' + | |
| '- `feat: add user authentication system`\n' + | |
| '- `fix(login): resolve session timeout issue`\n' + | |
| '- `docs: update API documentation`\n' + | |
| '- `refactor(utils): simplify date formatting`\n' + | |
| '- `Added new feature` (missing type)\n' + | |
| '- `feat: Add user authentication system` (capitalized)\n' + | |
| '- `feat: add user authentication system.` (period at end)\n\n' + | |
| 'Please amend your commits to follow the conventional commits format.'; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); | |
| } |