11import os
22from commitizen .cz .cz_base import BaseCommitizen
3-
3+ import re
4+ import textwrap
45
56__all__ = ['ConventionalChangelogCz' ]
67
78
89class ConventionalChangelogCz (BaseCommitizen ):
9-
1010 def questions (self ):
1111 questions = [
1212 {
@@ -57,49 +57,75 @@ def questions(self):
5757 {
5858 'type' : 'input' ,
5959 'name' : 'scope' ,
60- 'message' : ('Scope. Could be anything specifying place of the '
61- 'commit change (users, db, poll):\n ' )
60+ 'message' : ('What is the scope of this change (e.g. component or file name)? (press enter to skip)\n ' )
6261 },
6362 {
6463 'type' : 'input' ,
6564 'name' : 'subject' ,
66- 'message' : ('Subject. Concise description of the changes. '
67- 'Imperative, lower case and no final dot:\n ' )
65+ 'message' : ('Write a short, imperative tense description of the change:\n ' )
6866 },
6967 {
7068 'type' : 'input' ,
7169 'name' : 'body' ,
72- 'message' : ('Body. Motivation for the change and contrast this '
73- 'with previous behavior:\n ' )
70+ 'message' : ('Provide a longer description of the change: (press enter to skip)\n ' )
7471 },
7572 {
76- 'type' : 'input' ,
77- 'name' : 'footer' ,
78- 'message' : ('Footer. Information about Breaking Changes and '
79- 'reference issues that this commit closes:\n ' )
73+ 'type' : 'confirm' ,
74+ 'name' : 'isBreaking' ,
75+ 'message' : 'Are there any breaking changes?' ,
76+ 'default' : False
77+ },
78+ {
79+ "type" : "input" ,
80+ "name" : "breaking" ,
81+ "message" : "Describe the breaking changes:\n " ,
82+ "when" : self .is_breaking_answers
83+ },
84+ {
85+ "type" : 'confirm' ,
86+ "name" : 'isIssueAffected' ,
87+ "message" : 'Does this change affect any open issues?' ,
88+ "default" : False
89+ },
90+ {
91+ "type" : 'input' ,
92+ "name" : 'issues' ,
93+ "message" : 'Add issue refere nces (e.g. "fix #123", "re #123".):\n ' ,
94+ "when" : self .is_issued_affected
8095 }
8196 ]
8297 return questions
8398
8499 def message (self , answers ):
100+ wrapper = textwrap .TextWrapper (width = 100 )
85101 prefix = answers ['prefix' ]
86102 scope = answers ['scope' ]
103+ issues = ' ' .join (wrapper .wrap (answers .get ('issues' ))) if 'issues' in answers else ''
87104 subject = answers ['subject' ]
88105 body = answers ['body' ]
89- footer = answers ['footer' ]
106+ # footer = answers['footer']
107+ breaking = answers ['breaking' ] if 'breaking' in answers else ''
108+ if len (breaking ) > 0 :
109+ breaking = 'BREAKING CHANGE: ' + re .sub (r'/^BREAKING CHANGE: /' , '' , breaking )
110+ breaking = ' ' .join (wrapper .wrap (breaking ))
111+ # breaking = wrapper.fill(breaking)
112+ footer = '{}\n \n ' .format (breaking )
90113 message = ''
91114
92115 if prefix :
93116 message += '{0}' .format (prefix )
94117 if scope :
95118 message += '({0})' .format (scope )
96119 message += ': '
120+ if issues :
121+ message += '{} ' .format (issues )
97122 if subject :
98123 message += '{0}' .format (subject )
99124 if body :
100125 message += '\n \n {0}' .format (body )
101126 if footer :
102127 message += '\n \n {0}' .format (footer )
128+ print message
103129 return message
104130
105131 def example (self ):
@@ -124,3 +150,9 @@ def info(self):
124150 with open (filepath , 'r' ) as f :
125151 content = f .read ()
126152 return content
153+
154+ def is_breaking_answers (self , answers ):
155+ return answers .get ('isBreaking' )
156+
157+ def is_issued_affected (self , answers ):
158+ return answers .get ('isIssueAffected' )
0 commit comments