@@ -51,6 +51,22 @@ const (
51
51
var (
52
52
// hashFromLinePattern grabs the hash from the end of a github commit URL
53
53
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
+ }
54
70
)
55
71
56
72
var (
@@ -497,7 +513,7 @@ func (p *postProcessor) processCommit(title, body string) (string, string, error
497
513
}
498
514
}
499
515
500
- // Add scope to each commit
516
+ // Add scope to each commit and every nested commit therein.
501
517
for commitIndex , commit := range commitsSlice {
502
518
commitLines := strings .Split (strings .TrimSpace (commit ), "\n " )
503
519
var currTitle string
@@ -528,13 +544,34 @@ func (p *postProcessor) processCommit(title, body string) (string, string, error
528
544
scope = scopes [0 ]
529
545
}
530
546
531
- newCommitTitle := updateCommitTitle (currTitle , scope )
547
+ newCommitTitle := updateCommit (currTitle , scope )
532
548
if newTitle == "" {
533
549
newTitle = newCommitTitle
534
550
} else {
535
551
newBody .WriteString (fmt .Sprintf ("%v\n " , newCommitTitle ))
536
552
}
537
553
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
+ }
538
575
newBody .WriteString (strings .Join (commitLines , "\n " ))
539
576
if commitIndex != 0 {
540
577
newBody .WriteString (fmt .Sprintf ("\n %v" , endNestedCommitDelimiter ))
@@ -607,7 +644,7 @@ func extractHashFromLine(line string) string {
607
644
return hashVal
608
645
}
609
646
610
- func updateCommitTitle (title , titlePkg string ) string {
647
+ func updateCommit (title , titlePkg string ) string {
611
648
var breakChangeIndicator string
612
649
titleParts := strings .Split (title , ":" )
613
650
commitPrefix := titleParts [0 ]
@@ -619,6 +656,8 @@ func updateCommitTitle(title, titlePkg string) string {
619
656
}
620
657
if strings .HasSuffix (commitPrefix , "!" ) {
621
658
breakChangeIndicator = "!"
659
+ // trim it so we don't dupe it, but put it back in the right place
660
+ commitPrefix = strings .TrimSuffix (commitPrefix , "!" )
622
661
}
623
662
if titlePkg == "" {
624
663
return fmt .Sprintf ("%v%v: %v" , commitPrefix , breakChangeIndicator , msg )
0 commit comments