@@ -51,6 +51,22 @@ const (
5151var (
5252 // hashFromLinePattern grabs the hash from the end of a github commit URL
5353 hashFromLinePattern = regexp .MustCompile (`.*/(?P<hash>[a-zA-Z0-9]*).*` )
54+
55+ // conventionalCommitTypes to look out for in multi-line commit blocks.
56+ // Pulled from: https://github.com/googleapis/release-please/blob/656b9a9ad1ec77853d16ae1f40e63c4da1e12f0f/src/strategies/go-yoshi.ts#L25-L37
57+ conventionalCommitTypes = map [string ]bool {
58+ "feat" : true ,
59+ "fix" : true ,
60+ "perf" : true ,
61+ "revert" : true ,
62+ "docs" : true ,
63+ "style" : true ,
64+ "chore" : true ,
65+ "refactor" : true ,
66+ "test" : true ,
67+ "build" : true ,
68+ "ci" : true ,
69+ }
5470)
5571
5672var (
@@ -497,7 +513,7 @@ func (p *postProcessor) processCommit(title, body string) (string, string, error
497513 }
498514 }
499515
500- // Add scope to each commit
516+ // Add scope to each commit and every nested commit therein.
501517 for commitIndex , commit := range commitsSlice {
502518 commitLines := strings .Split (strings .TrimSpace (commit ), "\n " )
503519 var currTitle string
@@ -528,13 +544,34 @@ func (p *postProcessor) processCommit(title, body string) (string, string, error
528544 scope = scopes [0 ]
529545 }
530546
531- newCommitTitle := updateCommitTitle (currTitle , scope )
547+ newCommitTitle := updateCommit (currTitle , scope )
532548 if newTitle == "" {
533549 newTitle = newCommitTitle
534550 } else {
535551 newBody .WriteString (fmt .Sprintf ("%v\n " , newCommitTitle ))
536552 }
537553
554+ for i , line := range commitLines {
555+ if ! strings .Contains (line , ":" ) {
556+ // couldn't be a conventional commit line
557+ continue
558+ }
559+ commitType := line [:strings .Index (line , ":" )]
560+ if strings .Contains (commitType , "(" ) {
561+ // if it has a scope, remove it - updateCommitTitle does
562+ // already, we want to force our own scope.
563+ commitType = commitType [:strings .Index (commitType , "(" )]
564+ }
565+
566+ // always trim any potential bang
567+ commitType = strings .TrimSuffix (commitType , "!" )
568+
569+ if _ , ok := conventionalCommitTypes [commitType ]; ! ok {
570+ // not a known conventional commit type, ignore
571+ continue
572+ }
573+ commitLines [i ] = updateCommit (line , scope )
574+ }
538575 newBody .WriteString (strings .Join (commitLines , "\n " ))
539576 if commitIndex != 0 {
540577 newBody .WriteString (fmt .Sprintf ("\n %v" , endNestedCommitDelimiter ))
@@ -607,7 +644,7 @@ func extractHashFromLine(line string) string {
607644 return hashVal
608645}
609646
610- func updateCommitTitle (title , titlePkg string ) string {
647+ func updateCommit (title , titlePkg string ) string {
611648 var breakChangeIndicator string
612649 titleParts := strings .Split (title , ":" )
613650 commitPrefix := titleParts [0 ]
@@ -619,6 +656,8 @@ func updateCommitTitle(title, titlePkg string) string {
619656 }
620657 if strings .HasSuffix (commitPrefix , "!" ) {
621658 breakChangeIndicator = "!"
659+ // trim it so we don't dupe it, but put it back in the right place
660+ commitPrefix = strings .TrimSuffix (commitPrefix , "!" )
622661 }
623662 if titlePkg == "" {
624663 return fmt .Sprintf ("%v%v: %v" , commitPrefix , breakChangeIndicator , msg )
0 commit comments