1
1
import sys
2
2
import argparse
3
3
from yaml import dump
4
+ from .text_utils import handle_context_arg
5
+ from .text_utils import handle_tag_message_args
6
+ from commit_helper .conventions .karma_angular import angular_convention
7
+ from commit_helper .conventions .changelog import changelog_convention
8
+ from commit_helper .conventions .symphony_cmf import symphony_convention
9
+
4
10
5
11
supported_conventions = [
6
12
"angular" ,
24
30
def gen_co_author (co_author ):
25
31
if co_author is '' :
26
32
return ''
27
- return " \n Co-authored-by: %s" % co_author
33
+ return ' \n Co-authored-by: %s' % co_author
28
34
29
35
30
36
def create_file (convention_name , dont_create = False ): # pragma: no cover
@@ -38,23 +44,36 @@ def create_file(convention_name, dont_create=False): # pragma: no cover
38
44
39
45
40
46
def parser_cli ():
41
- desc = " A commit formatter tool to help you follow commit conventions."
47
+ desc = ' A commit formatter tool to help you follow commit conventions.'
42
48
help_convention = \
43
49
"""
44
50
Selects a convention to be used for the commit.
45
51
Required if there's no commiter.yml file.
46
52
"""
47
53
parser = argparse .ArgumentParser (description = desc )
48
- parser .add_argument ("-ca" , "--co-author" ,
49
- help = "Make your friend an co-author to the commit" ,
50
- dest = "co_author" , default = '' )
51
- parser .add_argument ("-nf" , "--no-file" , dest = "no_file" ,
52
- help = "Disables the creation of a commiter.yml file" ,
53
- action = "store_true" )
54
- parser .add_argument ("-c" , "--convention" , choices = supported_conventions ,
55
- dest = "convention" , default = '' , help = help_convention )
56
- parser .add_argument ("-d" , "--debug" , action = "store_true" , dest = "debug" ,
57
- help = "Toggles debug option" )
54
+ parser .add_argument ('-t' , '--tag' , dest = 'tag' , default = '' ,
55
+ help = 'Pass your commit tag directly' )
56
+
57
+ parser .add_argument ('-m' , '--message' , dest = 'message' , default = '' ,
58
+ help = 'Pass your commit message directly' )
59
+
60
+ parser .add_argument ('-ct' , '--context' , dest = 'context' , default = '' ,
61
+ help = 'Pass your commit context directly' )
62
+
63
+ parser .add_argument ('-ca' , '--co-author' ,
64
+ help = 'Make your friend an co-author to the commit' ,
65
+ dest = 'co_author' , default = '' )
66
+
67
+ parser .add_argument ('-nf' , '--no-file' , dest = 'no_file' ,
68
+ help = 'Disables the creation of a commiter.yml file' ,
69
+ action = 'store_true' )
70
+
71
+ parser .add_argument ('-c' , '--convention' , choices = supported_conventions ,
72
+ dest = 'convention' , default = '' , help = help_convention )
73
+
74
+ parser .add_argument ('-d' , '--debug' , action = 'store_true' , dest = 'debug' ,
75
+ help = 'Toggles debug option' )
76
+
58
77
return parser
59
78
60
79
@@ -69,3 +88,19 @@ def validate_commiter_file(stream_file): # pragma: no cover
69
88
if stream_file ['commit_pattern' ] is None or stream_file ['context' ] is None :
70
89
print ("Error: Your commiter file lacks a commit_pattern or context!" )
71
90
sys .exit (0 )
91
+
92
+
93
+ def handle_conventioned_commit (convention , args ):
94
+ tag , msg = handle_tag_message_args (args .tag , args .message )
95
+
96
+ if convention == 'angular' or convention == 'karma' :
97
+ context = handle_context_arg (args .context )
98
+ commit_message = angular_convention (tag , msg , context )
99
+
100
+ elif convention == 'changelog' :
101
+ commit_message = changelog_convention (tag , msg )
102
+
103
+ elif convention == 'symphony' :
104
+ commit_message = symphony_convention (tag , msg )
105
+
106
+ return commit_message
0 commit comments