Skip to content

Commit dde47d5

Browse files
authored
Merge pull request #5 from paopa/feat/prefix-base-parsing-for-scopes
feat: support prefix based parsing for scopes
2 parents 80b0102 + ae76679 commit dde47d5

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ feat(client): add component
1717

1818
The action can be used with both the `pull_request` and `pull_request_target` trigger.
1919

20-
`default`
20+
### Default
2121

2222
```yaml
2323
name: validate-pull-request-title
@@ -41,7 +41,7 @@ jobs:
4141
uses: kontrolplane/pull-request-title-validator@v1.2.0
4242
```
4343
44-
`custom types`
44+
### Custom types
4545
4646
```yaml
4747
name: validate-pull-request-title
@@ -67,7 +67,9 @@ jobs:
6767
types: "fix,feat,chore"
6868
```
6969
70-
`custom scopes`
70+
### Custom scopes
71+
72+
Scopes support regular expression patterns, allowing you to define specific patterns to match the scopes you want to allow. You can also separate multiple scopes using commas.
7173
7274
```yaml
7375
name: validate-pull-request-title
@@ -88,7 +90,7 @@ jobs:
8890
runs-on: ubuntu-latest
8991
steps:
9092
- name: validate pull request title
91-
uses: kontrolplane/pull-request-title-validator@v1.2.0
93+
uses: kontrolplane/pull-request-title-validator@v1.4.0
9294
with:
93-
scopes: "api,lang,parser"
95+
scopes: "api,lang,parser,package/.+"
9496
```

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func main() {
4040
os.Exit(1)
4141
}
4242

43-
if err := checkAgainstScopes(titleScope, scopes); err != nil && len(scopes) > 1 {
43+
if err := checkAgainstScopes(titleScope, scopes); err != nil && len(scopes) >= 1 {
4444
fmt.Println(err)
4545
os.Exit(1)
4646
}
@@ -114,12 +114,12 @@ func checkAgainstConventionTypes(titleType string, conventionTypes []string) err
114114

115115
func checkAgainstScopes(titleScope string, scopes []string) error {
116116
for _, scope := range scopes {
117-
if titleScope == scope {
117+
if regexp.MustCompile("(?i)" + scope + "$").MatchString(titleScope) {
118118
return nil
119119
}
120120
}
121121

122-
return fmt.Errorf("the scope '%s' is not allowed. Please choose from the following scopes: %s", titleScope, scopes)
122+
return fmt.Errorf("the scope '%s' is not allowed. Please choose from the following patterns of scopes: %s", titleScope, scopes)
123123
}
124124

125125
func parseTypes(input string, fallback []string) []string {

0 commit comments

Comments
 (0)