1
1
import os
2
2
from argparse import ArgumentParser
3
- from typing import List , NamedTuple , Sequence
4
3
5
- from jinja2 import Environment , FileSystemLoader
6
-
7
- from changelog_generator .commit import Commit
8
- from changelog_generator .repository_manager import RepositoryManager
9
-
10
-
11
- class CommitTree (NamedTuple ):
12
- commit_type : str
13
- commits : Sequence [Commit ]
14
-
15
-
16
- def render_changelog (
17
- organization : str ,
18
- repository : str ,
19
- previous_tag : str ,
20
- current_tag : str ,
21
- commit_trees : Sequence [CommitTree ],
22
- ) -> str :
23
- template_loader = FileSystemLoader (searchpath = os .path .dirname (__file__ ))
24
- template_environment = Environment (loader = template_loader )
25
- template = template_environment .get_template ("changelog_template.jinja" )
26
-
27
- return template .render (
28
- organization = organization ,
29
- repository = repository ,
30
- previous_tag = previous_tag ,
31
- current_tag = current_tag ,
32
- commit_trees = commit_trees ,
33
- )
34
-
35
-
36
- def get_commit_from_type (
37
- commits : Sequence [Commit ], commit_type : str
38
- ) -> Sequence [Commit ]:
39
- return sorted (
40
- filter (lambda commit : commit .commit_type == commit_type , commits ),
41
- key = lambda commit : commit .scope ,
42
- )
43
-
44
-
45
- def get_commit_but_types (
46
- commits : Sequence [Commit ], commit_types : Sequence [str ]
47
- ) -> Sequence [Commit ]:
48
- return sorted (
49
- filter (
50
- lambda commit : commit .commit_type
51
- and commit .commit_type not in commit_types ,
52
- commits ,
53
- ),
54
- key = lambda commit : commit .scope ,
55
- )
4
+ from .generator import generate
56
5
57
6
58
7
def main () -> None :
@@ -69,58 +18,23 @@ def main() -> None:
69
18
nargs = "*" , # optional list
70
19
help = "Filter commits with this semicolon separated git path regex" ,
71
20
)
21
+ parser .add_argument (
22
+ "--target" ,
23
+ nargs = "?" , # optional argument
24
+ help = "A rev1..rev2 string to be used to generate the commit list" ,
25
+ )
72
26
args = parser .parse_args ()
73
27
#
74
28
prefix = args .tag_prefix or os .environ .get ("TAG_PREFIX" )
75
29
filter_paths = args .path_filters
76
- repository = RepositoryManager (uri = "./" , prefix = prefix , filter_paths = filter_paths )
77
-
78
- commits = repository .commits_since_last_tag
79
- trees : List [CommitTree ] = []
80
-
81
- documentations = CommitTree (
82
- commit_type = ":notebook_with_decorative_cover: Documentation" ,
83
- commits = get_commit_from_type (commits , "docs" ),
84
- )
85
- if documentations .commits :
86
- trees .append (documentations )
87
-
88
- features = CommitTree (
89
- commit_type = ":rocket: Features" , commits = get_commit_from_type (commits , "feat" )
90
- )
91
- if features .commits :
92
- trees .append (features )
93
-
94
- fixes = CommitTree (
95
- commit_type = ":bug: Fixes" , commits = get_commit_from_type (commits , "fix" )
96
- )
97
- if fixes .commits :
98
- trees .append (fixes )
99
-
100
- reverts = CommitTree (
101
- commit_type = ":scream: Revert" , commits = get_commit_from_type (commits , "revert" )
102
- )
103
- if reverts .commits :
104
- trees .append (reverts )
105
-
106
- others = CommitTree (
107
- commit_type = ":nut_and_bolt: Others" ,
108
- commits = get_commit_but_types (
109
- commits , ["documentations" , "feat" , "fix" , "revert" ]
110
- ),
111
- )
112
- if others .commits :
113
- trees .append (others )
114
30
115
- print (
116
- render_changelog (
117
- organization = repository .organization ,
118
- repository = repository .name ,
119
- previous_tag = repository .previous_tag ,
120
- current_tag = repository .current_tag ,
121
- commit_trees = trees ,
122
- )
31
+ changelog = generate (
32
+ repository_path = "./" ,
33
+ prefix = prefix ,
34
+ filter_paths = filter_paths ,
35
+ target = args .target ,
123
36
)
37
+ print (changelog )
124
38
125
39
126
40
if __name__ == "__main__" :
0 commit comments