generated from fallion/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for conventional commit style PR titles
This commit adds support for checking that a PR title is conventional commit style compliant. Closes #296
- Loading branch information
Showing
9 changed files
with
134 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,3 +3,5 @@ verbose: true | |
commits: | ||
strict: true | ||
disabled: false | ||
pull_request: | ||
conventional: true |
This file contains 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 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 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,2 @@ | ||
/*package prpipeline handles all actions related to PR checking */ | ||
package prpipeline |
This file contains 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,27 @@ | ||
package prpipeline | ||
|
||
type Options struct { | ||
// Path to the git repository | ||
Path string | ||
// Style is the style of PR title to enforce | ||
Style PRStyle | ||
// Keys checks for required keys in the PR title | ||
Keys []string | ||
} | ||
|
||
// Pip | ||
type Pipeline struct { | ||
options Options | ||
} | ||
|
||
func New(options Options) (*Pipeline, error) { | ||
if options.Path == "" { | ||
options.Path = "." | ||
} | ||
|
||
return &Pipeline{options: options}, nil | ||
} | ||
|
||
func (pipeline *Pipeline) Name() string { | ||
return "pr-pipeline" | ||
} |
This file contains 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,50 @@ | ||
package prpipeline | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/aevea/commitsar/internal/dispatcher" | ||
"github.com/aevea/commitsar/pkg/jira" | ||
"github.com/aevea/commitsar/pkg/text" | ||
"github.com/aevea/quoad" | ||
"github.com/logrusorgru/aurora" | ||
) | ||
|
||
func (pipeline *Pipeline) Run() (*dispatcher.PipelineSuccess, error) { | ||
title, err := getPRTitle(pipeline.options.Path) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
switch pipeline.options.Style { | ||
case JiraStyle: | ||
references, err := jira.FindReferences(pipeline.options.Keys, *title) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(references) > 0 { | ||
return &dispatcher.PipelineSuccess{ | ||
PipelineName: pipeline.Name(), | ||
Message: aurora.Sprintf(aurora.Green("Success! Found the following JIRA issue references: %v"), references), | ||
}, nil | ||
} | ||
case ConvetionalStyle: | ||
commit := quoad.ParseCommitMessage(*title) | ||
|
||
err := text.CheckMessageTitle(commit, true) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &dispatcher.PipelineSuccess{ | ||
PipelineName: pipeline.Name(), | ||
Message: aurora.Sprintf(aurora.Green("Success! PR title is compliant with conventional commit")), | ||
}, nil | ||
} | ||
|
||
return nil, errors.New("pr checking is configured, but no style has been chosen") | ||
} |
This file contains 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 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,8 @@ | ||
package prpipeline | ||
|
||
type PRStyle = string | ||
|
||
const ( | ||
JiraStyle PRStyle = "jira" | ||
ConvetionalStyle PRStyle = "conventional" | ||
) |
This file contains 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