-
Notifications
You must be signed in to change notification settings - Fork 179
π· add CI check enforcing gitmoji PR title convention #4619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thomas-lebeau
wants to merge
3
commits into
main
Choose a base branch
from
worktree-pr-title-lint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: 'Lint PR title' | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, edited, reopened, synchronize] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| lint: | ||
| if: github.event.pull_request.user.type != 'Bot' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | ||
| with: | ||
| node-version-file: 'package.json' | ||
| cache: 'yarn' | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn install --immutable | ||
|
|
||
| - name: Check PR title follows gitmoji convention | ||
| env: | ||
| # Passing via env (not inline ${{ }}) avoids shell injection via PR titles. | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: node scripts/check-pr-title.ts |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { describe, it } from 'node:test' | ||
| import { isValidPrTitle } from './check-pr-title.ts' | ||
|
|
||
| describe('isValidPrTitle', () => { | ||
| it('accepts titles starting with an allowed emoji', () => { | ||
| assert.equal(isValidPrTitle('β¨ Add new feature'), true) | ||
| assert.equal(isValidPrTitle('π Fix bug'), true) | ||
| assert.equal(isValidPrTitle('π· Update CI'), true) | ||
| assert.equal(isValidPrTitle('β»οΈ Refactor module'), true) | ||
| }) | ||
|
|
||
| it('accepts the performance emoji with or without the variation selector', () => { | ||
| assert.equal(isValidPrTitle('β‘οΈ Speed up'), true) | ||
| assert.equal(isValidPrTitle('β‘ Speed up'), true) | ||
| }) | ||
|
|
||
| it('rejects titles without any allowed emoji prefix', () => { | ||
| assert.equal(isValidPrTitle('Add new feature'), false) | ||
| assert.equal(isValidPrTitle('feat: add thing'), false) | ||
| assert.equal(isValidPrTitle(''), false) | ||
| }) | ||
|
|
||
| it('rejects titles where the emoji is not at the start', () => { | ||
| assert.equal(isValidPrTitle('Fix β¨ thing'), false) | ||
| }) | ||
|
|
||
| it('rejects emojis that are not in the allowed list', () => { | ||
| assert.equal(isValidPrTitle('π Launch'), false) | ||
| assert.equal(isValidPrTitle('π¦ Package'), false) | ||
| }) | ||
| }) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { printError, printLog, runMain } from './lib/executionUtils.ts' | ||
| import { GITMOJI, normalizeGitmoji } from './lib/gitmoji.ts' | ||
|
|
||
| export function isValidPrTitle(title: string): boolean { | ||
| const normalized = normalizeGitmoji(title) | ||
| return GITMOJI.some(({ emoji }) => normalized.startsWith(normalizeGitmoji(emoji))) | ||
| } | ||
|
|
||
| export function formatAllowedPrefixes(): string { | ||
| return GITMOJI.map(({ emoji, label }) => ` ${emoji} ${label}`).join('\n') | ||
| } | ||
|
|
||
| if (!process.env.NODE_TEST_CONTEXT) { | ||
| runMain(() => { | ||
| const title = process.env.PR_TITLE | ||
|
|
||
| if (title === undefined) { | ||
| throw new Error('PR_TITLE environment variable is not set.') | ||
| } | ||
|
|
||
| if (isValidPrTitle(title)) { | ||
| printLog(`PR title OK: ${title}`) | ||
| return | ||
| } | ||
|
|
||
| printError( | ||
| 'PR title must start with one of the allowed gitmoji prefixes.\n\n' + | ||
| `Current title: ${title}\n\n` + | ||
| `Allowed prefixes:\n${formatAllowedPrefixes()}\n\n` + | ||
| 'See docs/DEVELOPMENT.md for the full convention.' | ||
| ) | ||
| process.exit(1) | ||
| }) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Canonical gitmoji prefix convention. Must stay in sync with docs/DEVELOPMENT.md. | ||
| // The order within each category is the priority used by the changelog generator. | ||
|
|
||
| export type GitmojiCategory = 'public' | 'internal' | ||
|
|
||
| export interface Gitmoji { | ||
| emoji: string | ||
| label: string | ||
| category: GitmojiCategory | ||
| } | ||
|
|
||
| export const GITMOJI: readonly Gitmoji[] = [ | ||
| // User-facing changes | ||
| { emoji: 'π₯', label: 'Breaking change', category: 'public' }, | ||
| { emoji: 'β¨', label: 'New feature', category: 'public' }, | ||
| { emoji: 'π', label: 'Bug fix', category: 'public' }, | ||
| { emoji: 'β‘οΈ', label: 'Performance', category: 'public' }, | ||
| { emoji: 'π', label: 'Documentation', category: 'public' }, | ||
| { emoji: 'βοΈ', label: 'Experimental', category: 'public' }, | ||
|
|
||
| // Internal changes | ||
| { emoji: 'π·', label: 'Build/CI', category: 'internal' }, | ||
| { emoji: 'β»οΈ', label: 'Refactor', category: 'internal' }, | ||
| { emoji: 'π¨', label: 'Code structure', category: 'internal' }, | ||
| { emoji: 'β ', label: 'Tests', category: 'internal' }, | ||
| { emoji: 'π§', label: 'Configuration', category: 'internal' }, | ||
| { emoji: 'π₯', label: 'Removal', category: 'internal' }, | ||
| { emoji: 'π', label: 'Code review', category: 'internal' }, | ||
| { emoji: 'π¨', label: 'Linting', category: 'internal' }, | ||
| { emoji: 'π§Ή', label: 'Cleanup', category: 'internal' }, | ||
| { emoji: 'π', label: 'Logging', category: 'internal' }, | ||
| ] | ||
|
|
||
| // Strip the Unicode variation selector (U+FE0F) so 'β‘' and 'β‘οΈ' compare equal. | ||
| const VARIATION_SELECTOR = /οΈ/g | ||
| export const normalizeGitmoji = (value: string): string => value.replace(VARIATION_SELECTOR, '') | ||
|
|
||
| // Exported priorities are normalized so they match the output of `\p{Extended_Pictographic}`, | ||
| // which strips the U+FE0F variation selector. | ||
| export const PUBLIC_EMOJI_PRIORITY: readonly string[] = GITMOJI.filter((g) => g.category === 'public').map((g) => | ||
| normalizeGitmoji(g.emoji) | ||
| ) | ||
| export const INTERNAL_EMOJI_PRIORITY: readonly string[] = GITMOJI.filter((g) => g.category === 'internal').map((g) => | ||
| normalizeGitmoji(g.emoji) | ||
| ) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,4 @@ | ||
| export { PUBLIC_EMOJI_PRIORITY, INTERNAL_EMOJI_PRIORITY } from '../../../lib/gitmoji.ts' | ||
|
|
||
| export const CONTRIBUTING_FILE = 'docs/DEVELOPMENT.md' | ||
| export const CHANGELOG_FILE = 'CHANGELOG.md' | ||
| export const PUBLIC_EMOJI_PRIORITY: string[] = ['π₯', 'β¨', 'π', 'β‘', 'π'] | ||
| export const INTERNAL_EMOJI_PRIORITY: string[] = [ | ||
| 'π·', | ||
| 'π§', | ||
| 'π¦', // build conf | ||
| 'β»οΈ', | ||
| 'π¨', // refactoring | ||
| 'π§ͺ', | ||
| 'β ', // tests | ||
| 'π', | ||
| 'π', // telemetry | ||
| 'π', | ||
| 'π', | ||
| 'βοΈ', // experiment | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.