99)
1010
1111var desiredFormat string = "<type>(optional: <scope>): <message>"
12+ var defaultConventionTypes []string = []string {"fix" , "feat" , "chore" , "docs" , "build" , "ci" , "refactor" , "perf" , "test" }
1213
1314type PullRequest struct {
1415 Title string `json:"title"`
@@ -23,7 +24,7 @@ type Event struct {
2324func main () {
2425 githubEventName := os .Getenv ("GITHUB_EVENT_NAME" )
2526 githubEventPath := os .Getenv ("GITHUB_EVENT_PATH" )
26- conventionTypes := [] string { "fix" , "feat" , "chore" , "docs" , "build" , "ci" , "refactor" , "perf" , "test" }
27+ conventionTypes := parseTypes ( os . Getenv ( "INPUT_TYPES" ), defaultConventionTypes )
2728
2829 if githubEventName != "pull_request" && githubEventName != "pull_request_target" {
2930 fmt .Printf ("Error: the 'pull_request' trigger type should be used, received '%s'\n " , githubEventName )
@@ -87,7 +88,7 @@ func splitTitle(title string) (titleType string, titleScope string, titleMessage
8788 titleMessage = strings .SplitAfter (title , ":" )[1 ]
8889 titleMessage = strings .TrimSpace (titleMessage )
8990 } else {
90- fmt .Println ("No message was included in the pull request title." )
91+ fmt .Println ("no message was included in the pull request title." )
9192 fmt .Println (desiredFormat )
9293 os .Exit (1 )
9394 }
@@ -104,3 +105,18 @@ func checkAgainstConventionTypes(titleType string, conventionTypes []string) err
104105
105106 return fmt .Errorf ("the type passed '%s' is not present in the types allowed by the convention: %s" , titleType , conventionTypes )
106107}
108+
109+ func parseTypes (input string , fallback []string ) []string {
110+ if input == "" {
111+ fmt .Println ("no custom list of commit types was passed using fallback." )
112+ return fallback
113+ }
114+ types := strings .Split (input , "," )
115+ for i := range types {
116+ types [i ] = strings .TrimSpace (types [i ])
117+ }
118+ if len (types ) == 0 {
119+ return fallback
120+ }
121+ return types
122+ }
0 commit comments