22
22
import re
23
23
import subprocess
24
24
25
+
25
26
def print_pulls (repo_name , title , pulls ):
26
- if len (pulls ) > 0 :
27
+ if len (pulls ) > 0 :
27
28
print ("**{}:**" .format (title ))
28
29
print ()
29
- for ( pull , commit ) in pulls :
30
+ for pull , commit in pulls :
30
31
url = "https://github.com/{}/pull/{}" .format (repo_name , pull .number )
31
- print ("- {} [#{}]({}) ({})" .format (pull .title , pull .number , url , commit .author .login ))
32
+ print (
33
+ "- {} [#{}]({}) ({})" .format (
34
+ pull .title , pull .number , url , commit .author .login
35
+ )
36
+ )
32
37
print ()
33
38
34
39
35
40
def generate_changelog (repo , repo_name , tag1 , tag2 , version ):
36
-
37
41
# get a list of commits between two tags
38
42
print (f"Fetching list of commits between { tag1 } and { tag2 } " , file = sys .stderr )
39
43
comparison = repo .compare (tag1 , tag2 )
@@ -61,29 +65,27 @@ def generate_changelog(repo, repo_name, tag1, tag2, version):
61
65
62
66
# categorize the pull requests based on GitHub labels
63
67
print ("Categorizing pull requests" , file = sys .stderr )
64
- for (pull , commit ) in all_pulls :
65
-
68
+ for pull , commit in all_pulls :
66
69
# see if PR title uses Conventional Commits
67
- cc_type = ''
68
- cc_scope = ''
69
- cc_breaking = ''
70
- parts = re .findall (r'^([a-z]+)(\([a-z]+\))?(!)?:' , pull .title )
70
+ cc_type = ""
71
+ cc_breaking = ""
72
+ parts = re .findall (r"^([a-z]+)(\([a-z]+\))?(!)?:" , pull .title )
71
73
if len (parts ) == 1 :
72
74
parts_tuple = parts [0 ]
73
- cc_type = parts_tuple [0 ] # fix, feat, docs, chore
74
- cc_scope = parts_tuple [1 ] # component within project
75
- cc_breaking = parts_tuple [2 ] == '!'
75
+ cc_type = parts_tuple [0 ] # fix, feat, docs, chore
76
+ # cc_scope = parts_tuple[1] # component within project
77
+ cc_breaking = parts_tuple [2 ] == "!"
76
78
77
79
labels = [label .name for label in pull .labels ]
78
- if ' api change' in labels or cc_breaking :
80
+ if " api change" in labels or cc_breaking :
79
81
breaking .append ((pull , commit ))
80
- elif ' bug' in labels or cc_type == ' fix' :
82
+ elif " bug" in labels or cc_type == " fix" :
81
83
bugs .append ((pull , commit ))
82
- elif ' performance' in labels or cc_type == ' perf' :
84
+ elif " performance" in labels or cc_type == " perf" :
83
85
performance .append ((pull , commit ))
84
- elif ' enhancement' in labels or cc_type == ' feat' :
86
+ elif " enhancement" in labels or cc_type == " feat" :
85
87
enhancements .append ((pull , commit ))
86
- elif ' documentation' in labels or cc_type == ' docs' or cc_type == ' doc' :
88
+ elif " documentation" in labels or cc_type == " docs" or cc_type == " doc" :
87
89
docs .append ((pull , commit ))
88
90
else :
89
91
other .append ((pull , commit ))
@@ -114,13 +116,19 @@ def generate_changelog(repo, repo_name, tag1, tag2, version):
114
116
print (f"# Apache DataFusion Python { version } Changelog\n " )
115
117
116
118
# get the number of commits
117
- commit_count = subprocess .check_output (f"git log --pretty=oneline { tag1 } ..{ tag2 } | wc -l" , shell = True , text = True ).strip ()
119
+ commit_count = subprocess .check_output (
120
+ f"git log --pretty=oneline { tag1 } ..{ tag2 } | wc -l" , shell = True , text = True
121
+ ).strip ()
118
122
119
123
# get number of contributors
120
- contributor_count = subprocess .check_output (f"git shortlog -sn { tag1 } ..{ tag2 } | wc -l" , shell = True , text = True ).strip ()
124
+ contributor_count = subprocess .check_output (
125
+ f"git shortlog -sn { tag1 } ..{ tag2 } | wc -l" , shell = True , text = True
126
+ ).strip ()
121
127
122
- print (f"This release consists of { commit_count } commits from { contributor_count } contributors. "
123
- f"See credits at the end of this changelog for more information.\n " )
128
+ print (
129
+ f"This release consists of { commit_count } commits from { contributor_count } contributors. "
130
+ f"See credits at the end of this changelog for more information.\n "
131
+ )
124
132
125
133
print_pulls (repo_name , "Breaking changes" , breaking )
126
134
print_pulls (repo_name , "Performance related" , performance )
@@ -130,17 +138,24 @@ def generate_changelog(repo, repo_name, tag1, tag2, version):
130
138
print_pulls (repo_name , "Other" , other )
131
139
132
140
# show code contributions
133
- credits = subprocess .check_output (f"git shortlog -sn { tag1 } ..{ tag2 } " , shell = True , text = True ).rstrip ()
141
+ credits = subprocess .check_output (
142
+ f"git shortlog -sn { tag1 } ..{ tag2 } " , shell = True , text = True
143
+ ).rstrip ()
134
144
135
145
print ("## Credits\n " )
136
- print ("Thank you to everyone who contributed to this release. Here is a breakdown of commits (PRs merged) "
137
- "per contributor.\n " )
146
+ print (
147
+ "Thank you to everyone who contributed to this release. Here is a breakdown of commits (PRs merged) "
148
+ "per contributor.\n "
149
+ )
138
150
print ("```" )
139
151
print (credits )
140
152
print ("```\n " )
141
153
142
- print ("Thank you also to everyone who contributed in other ways such as filing issues, reviewing "
143
- "PRs, and providing feedback on this release.\n " )
154
+ print (
155
+ "Thank you also to everyone who contributed in other ways such as filing issues, reviewing "
156
+ "PRs, and providing feedback on this release.\n "
157
+ )
158
+
144
159
145
160
def cli (args = None ):
146
161
"""Process command line arguments."""
@@ -150,7 +165,9 @@ def cli(args=None):
150
165
parser = argparse .ArgumentParser ()
151
166
parser .add_argument ("tag1" , help = "The previous commit or tag (e.g. 0.1.0)" )
152
167
parser .add_argument ("tag2" , help = "The current commit or tag (e.g. HEAD)" )
153
- parser .add_argument ("version" , help = "The version number to include in the changelog" )
168
+ parser .add_argument (
169
+ "version" , help = "The version number to include in the changelog"
170
+ )
154
171
args = parser .parse_args ()
155
172
156
173
token = os .getenv ("GITHUB_TOKEN" )
@@ -160,5 +177,6 @@ def cli(args=None):
160
177
repo = g .get_repo (project )
161
178
generate_changelog (repo , project , args .tag1 , args .tag2 , args .version )
162
179
180
+
163
181
if __name__ == "__main__" :
164
- cli ()
182
+ cli ()
0 commit comments