Skip to content

Commit

Permalink
Merge pull request #5 from paopa/feat/prefix-base-parsing-for-scopes
Browse files Browse the repository at this point in the history
feat: support prefix based parsing for scopes
  • Loading branch information
levivannoort authored Aug 1, 2024
2 parents 80b0102 + ae76679 commit dde47d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ feat(client): add component

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

`default`
### Default

```yaml
name: validate-pull-request-title
Expand All @@ -41,7 +41,7 @@ jobs:
uses: kontrolplane/[email protected]
```
`custom types`
### Custom types
```yaml
name: validate-pull-request-title
Expand All @@ -67,7 +67,9 @@ jobs:
types: "fix,feat,chore"
```
`custom scopes`
### Custom scopes
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.
```yaml
name: validate-pull-request-title
Expand All @@ -88,7 +90,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: validate pull request title
uses: kontrolplane/pull-request-title-validator@v1.2.0
uses: kontrolplane/pull-request-title-validator@v1.4.0
with:
scopes: "api,lang,parser"
scopes: "api,lang,parser,package/.+"
```
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
os.Exit(1)
}

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

func checkAgainstScopes(titleScope string, scopes []string) error {
for _, scope := range scopes {
if titleScope == scope {
if regexp.MustCompile("(?i)" + scope + "$").MatchString(titleScope) {
return nil
}
}

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

func parseTypes(input string, fallback []string) []string {
Expand Down

0 comments on commit dde47d5

Please sign in to comment.