Skip to content

Commit 800da4c

Browse files
authored
fix: Parse headerPatternCorrespondence properly (#295)
1 parent 677b895 commit 800da4c

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 'Lint PR title preview (current branch, all options specified)'
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- edited
7+
- synchronize
8+
9+
jobs:
10+
main:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: read
14+
steps:
15+
- uses: actions/checkout@v5
16+
- uses: pnpm/action-setup@v4
17+
with:
18+
version: 9
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: 24
22+
- run: pnpm install
23+
- run: pnpm build
24+
- uses: ./
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
with:
28+
# Configure which types are allowed (newline-delimited).
29+
# Default: https://github.com/commitizen/conventional-commit-types
30+
types: |
31+
fix
32+
feat
33+
# Configure which scopes are allowed (newline-delimited).
34+
# These are regex patterns auto-wrapped in `^ $`.
35+
scopes: |
36+
core
37+
ui
38+
JIRA-\d+
39+
# Configure that a scope must always be provided.
40+
requireScope: false
41+
# Configure which scopes are disallowed in PR titles (newline-delimited).
42+
# For instance by setting the value below, `chore(release): ...` (lowercase)
43+
# and `ci(e2e,release): ...` (unknown scope) will be rejected.
44+
# These are regex patterns auto-wrapped in `^ $`.
45+
disallowScopes: |
46+
release
47+
[A-Z]+
48+
# Configure additional validation for the subject based on a regex.
49+
# This example ensures the subject doesn't start with an uppercase character.
50+
subjectPattern: ^(?![A-Z]).+$
51+
# If `subjectPattern` is configured, you can use this property to override
52+
# the default error message that is shown when the pattern doesn't match.
53+
# The variables `subject` and `title` can be used within the message.
54+
subjectPatternError: |
55+
The subject "{subject}" found in the pull request title "{title}"
56+
didn't match the configured pattern. Please ensure that the subject
57+
doesn't start with an uppercase character.
58+
# The GitHub base URL will be automatically set to the correct value from the GitHub context variable.
59+
# If you want to override this, you can do so here (not recommended).
60+
# githubBaseUrl: https://github.com/api/v3
61+
# If the PR contains one of these newline-delimited labels, the
62+
# validation is skipped. If you want to rerun the validation when
63+
# labels change, you might want to use the `labeled` and `unlabeled`
64+
# event triggers in your workflow.
65+
ignoreLabels: |
66+
bot
67+
ignore-semantic-pull-request
68+
# If you're using a format for the PR title that differs from the traditional Conventional
69+
# Commits spec, you can use these options to customize the parsing of the type, scope and
70+
# subject. The `headerPattern` should contain a regex where the capturing groups in parentheses
71+
# correspond to the parts listed in `headerPatternCorrespondence`.
72+
# See: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser#headerpattern
73+
headerPattern: '^(\w*)(?:\(([\w$.\-*/ ]*)\))?: (.*)$'
74+
headerPatternCorrespondence: type, scope, subject

src/parseConfig.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ export default function parseConfig() {
4040

4141
let headerPatternCorrespondence;
4242
if (process.env.INPUT_HEADERPATTERNCORRESPONDENCE) {
43-
headerPatternCorrespondence = ConfigParser.parseString(
44-
process.env.INPUT_HEADERPATTERNCORRESPONDENCE
45-
);
43+
// todo: this should be migrated to an enum w/ ConfigParser.parseEnum
44+
headerPatternCorrespondence =
45+
process.env.INPUT_HEADERPATTERNCORRESPONDENCE.split(',')
46+
.map((part) => part.trim())
47+
.filter((part) => part.length > 0);
4648
}
4749

4850
let wip;

0 commit comments

Comments
 (0)