11package com .fulinlin .ui ;
22
33import com .fulinlin .model .ChangeType ;
4+ import com .fulinlin .model .CommitTemplate ;
5+ import com .fulinlin .model .TypeAlias ;
6+ import com .fulinlin .storage .GitCommitMessageHelperSettings ;
7+ import com .fulinlin .utils .VelocityUtils ;
48import org .apache .commons .lang .WordUtils ;
59
610import static org .apache .commons .lang .StringUtils .isNotBlank ;
@@ -12,44 +16,36 @@ public class CommitMessage {
1216 private static final int MAX_LINE_LENGTH = 72 ; // https://stackoverflow.com/a/2120040/5138796
1317 private final String content ;
1418
15- public CommitMessage (ChangeType changeType , String changeScope , String shortDescription , String longDescription , String closedIssues , String breakingChanges ) {
16- this .content = buildContent (changeType , changeScope , shortDescription , longDescription , closedIssues , breakingChanges );
19+ public CommitMessage (GitCommitMessageHelperSettings settings , TypeAlias typeAlias , String changeScope , String shortDescription , String longDescription , String closedIssues , String breakingChanges ) {
20+ this .content = buildContent (
21+ settings ,
22+ typeAlias ,
23+ changeScope ,
24+ shortDescription ,
25+ longDescription ,
26+ breakingChanges ,
27+ closedIssues
28+ );
1729 }
1830
19- private String buildContent (ChangeType changeType , String changeScope , String shortDescription , String longDescription , String closedIssues , String breakingChanges ) {
20- StringBuilder builder = new StringBuilder ();
21- builder .append (changeType .label ());
22- if (isNotBlank (changeScope )) {
23- builder
24- .append ('(' )
25- .append (changeScope )
26- .append (')' );
27- }
28- builder
29- .append (": " )
30- .append (shortDescription )
31- .append (System .lineSeparator ())
32- .append (System .lineSeparator ())
33- .append (WordUtils .wrap (longDescription , MAX_LINE_LENGTH ));
34-
35- if (isNotBlank (breakingChanges )) {
36- builder
37- .append (System .lineSeparator ())
38- .append (System .lineSeparator ())
39- .append (WordUtils .wrap ("BREAKING CHANGE: " + breakingChanges , MAX_LINE_LENGTH ));
40- }
41-
42- if (isNotBlank (closedIssues )) {
43- builder .append (System .lineSeparator ());
44- for (String closedIssue : closedIssues .split ("," )) {
45- builder
46- .append (System .lineSeparator ())
47- .append ("Closes " )
48- .append (closedIssue );
49- }
50- }
51-
52- return builder .toString ();
31+ private String buildContent (GitCommitMessageHelperSettings settings ,
32+ TypeAlias typeAlias ,
33+ String changeScope ,
34+ String shortDescription ,
35+ String longDescription ,
36+ String breakingChanges ,
37+ String closedIssues
38+ ) {
39+
40+ CommitTemplate commitTemplate = new CommitTemplate ();
41+ commitTemplate .setType (typeAlias .toString ());
42+ commitTemplate .setScope (changeScope );
43+ commitTemplate .setSubject (shortDescription );
44+ commitTemplate .setBody (longDescription );
45+ commitTemplate .setChanges (breakingChanges );
46+ commitTemplate .setCloses (closedIssues );
47+ String template = settings .getDateSettings ().getTemplate ();
48+ return VelocityUtils .convert (template , commitTemplate );
5349 }
5450
5551 @ Override
0 commit comments