11
11
12
12
13
13
# The owner and repository name. For example, octocat/Hello-World.
14
- GITHUB_REPOSITORY = os .getenv (' GITHUB_REPOSITORY' )
14
+ GITHUB_REPOSITORY = os .getenv (" GITHUB_REPOSITORY" )
15
15
16
- GITHUB_TOKEN = os .getenv (' GITHUB_TOKEN' )
17
- GITHUB_REF_NAME = os .getenv (' GITHUB_REF_NAME' )
16
+ GITHUB_TOKEN = os .getenv (" GITHUB_TOKEN" )
17
+ GITHUB_REF_NAME = os .getenv (" GITHUB_REF_NAME" )
18
18
19
19
CURRENT_FILE = Path (__file__ )
20
20
ROOT = CURRENT_FILE .parents [1 ]
21
- CHANGELOG_PATH = ROOT / ' CHANGELOG.md'
22
- LIBRARY_FILE_PATH = ROOT / ' src/Curl/Curl.php'
21
+ CHANGELOG_PATH = ROOT / " CHANGELOG.md"
22
+ LIBRARY_FILE_PATH = ROOT / " src/Curl/Curl.php"
23
23
24
24
# TODO: Adjust number of recent pull requests to include likely number of
25
25
# pull requests since the last release.
@@ -35,32 +35,32 @@ def main():
35
35
# git tag --list | sort --reverse --version-sort
36
36
tags = sorted (
37
37
local_repo .tags ,
38
- key = lambda tag : list (map (int , tag .name .split ('.' ))),
38
+ key = lambda tag : list (map (int , tag .name .split ("." ))),
39
39
reverse = True ,
40
40
)
41
41
42
42
most_recent_tag = tags [0 ]
43
- print (' most_recent_tag: {}' .format (most_recent_tag ))
43
+ print (" most_recent_tag: {}" .format (most_recent_tag ))
44
44
most_recent_tag_datetime = most_recent_tag .commit .committed_datetime
45
- print (' most_recent_tag_datetime: {}' .format (most_recent_tag_datetime ))
45
+ print (" most_recent_tag_datetime: {}" .format (most_recent_tag_datetime ))
46
46
47
47
# Find merged pull requests since the most recent tag.
48
48
github_repo = Github (login_or_token = GITHUB_TOKEN ).get_repo (GITHUB_REPOSITORY )
49
49
recent_pulls = github_repo .get_pulls (
50
- state = ' closed' ,
51
- sort = ' updated' ,
52
- direction = ' desc' ,
50
+ state = " closed" ,
51
+ sort = " updated" ,
52
+ direction = " desc" ,
53
53
)[:RECENT_PULL_REQUEST_LIMIT ]
54
54
55
55
pull_request_changes = []
56
56
57
57
# Group pull requests by semantic version change type.
58
58
pull_request_by_type = {
59
- ' major' : [],
60
- ' minor' : [],
61
- ' patch' : [],
62
- ' cleanup' : [],
63
- ' unspecified' : [],
59
+ " major" : [],
60
+ " minor" : [],
61
+ " patch" : [],
62
+ " cleanup" : [],
63
+ " unspecified" : [],
64
64
}
65
65
66
66
# Track if any pull request is missing a semantic version change type.
@@ -85,16 +85,16 @@ def main():
85
85
continue
86
86
87
87
pull_labels = {label .name for label in pull .labels }
88
- if ' major-incompatible-changes' in pull_labels :
89
- group_name = ' major'
90
- elif ' minor-backwards-compatible-added-functionality' in pull_labels :
91
- group_name = ' minor'
92
- elif ' patch-backwards-compatible-bug-fixes' in pull_labels :
93
- group_name = ' patch'
94
- elif ' cleanup-no-release-required' in pull_labels :
95
- group_name = ' cleanup'
88
+ if " major-incompatible-changes" in pull_labels :
89
+ group_name = " major"
90
+ elif " minor-backwards-compatible-added-functionality" in pull_labels :
91
+ group_name = " minor"
92
+ elif " patch-backwards-compatible-bug-fixes" in pull_labels :
93
+ group_name = " patch"
94
+ elif " cleanup-no-release-required" in pull_labels :
95
+ group_name = " cleanup"
96
96
else :
97
- group_name = ' unspecified'
97
+ group_name = " unspecified"
98
98
pulls_missing_semver_label .append (pull )
99
99
pull_request_by_type [group_name ].append (pull )
100
100
@@ -103,80 +103,80 @@ def main():
103
103
# pprint.pprint('merged at: {}'.format(pull.merged_at))
104
104
# print(pull.html_url)
105
105
106
- if group_name in [' major' , ' minor' , ' patch' ]:
106
+ if group_name in [" major" , " minor" , " patch" ]:
107
107
pull_request_changes .append (
108
- ' - {} ([#{}]({}))' .format (pull .title , pull .number , pull .html_url )
108
+ " - {} ([#{}]({}))" .format (pull .title , pull .number , pull .html_url )
109
109
)
110
110
111
111
# print('-' * 10)
112
112
113
113
# pprint.pprint(pull_request_changes)
114
114
115
115
if not pull_request_changes :
116
- print (' No merged pull requests since the most recent tag release were found' )
116
+ print (" No merged pull requests since the most recent tag release were found" )
117
117
return
118
118
119
119
# Raise error if any pull request is missing a semantic version change type.
120
120
if pulls_missing_semver_label :
121
121
error_message = (
122
- ' Merged pull request(s) found without semantic version label:\n '
123
- '{}' .format (
124
- ' \n ' .join (
125
- ' {}' .format (pull .html_url ) for pull in pulls_missing_semver_label
122
+ " Merged pull request(s) found without semantic version label:\n "
123
+ "{}" .format (
124
+ " \n " .join (
125
+ " {}" .format (pull .html_url ) for pull in pulls_missing_semver_label
126
126
)
127
127
)
128
128
)
129
129
raise Exception (error_message )
130
130
131
131
# pprint.pprint(pull_request_by_type)
132
- if pull_request_by_type .get (' major' ):
133
- highest_semantic_version = ' major'
134
- php_file_path = ' scripts/bump_major_version.php'
135
- elif pull_request_by_type .get (' minor' ):
136
- highest_semantic_version = ' minor'
137
- php_file_path = ' scripts/bump_minor_version.php'
138
- elif pull_request_by_type .get (' patch' ):
139
- highest_semantic_version = ' patch'
140
- php_file_path = ' scripts/bump_patch_version.php'
132
+ if pull_request_by_type .get (" major" ):
133
+ highest_semantic_version = " major"
134
+ php_file_path = " scripts/bump_major_version.php"
135
+ elif pull_request_by_type .get (" minor" ):
136
+ highest_semantic_version = " minor"
137
+ php_file_path = " scripts/bump_minor_version.php"
138
+ elif pull_request_by_type .get (" patch" ):
139
+ highest_semantic_version = " patch"
140
+ php_file_path = " scripts/bump_patch_version.php"
141
141
else :
142
142
highest_semantic_version = None
143
- php_file_path = ''
144
- print (' highest_semantic_version: {}' .format (highest_semantic_version ))
143
+ php_file_path = ""
144
+ print (" highest_semantic_version: {}" .format (highest_semantic_version ))
145
145
146
146
# Bump version and get next semantic version.
147
- command = [' php' , php_file_path ]
148
- print (' running command: {}' .format (command ))
147
+ command = [" php" , php_file_path ]
148
+ print (" running command: {}" .format (command ))
149
149
proc = subprocess .Popen (
150
150
command , shell = False , stdout = subprocess .PIPE , stdin = subprocess .PIPE
151
151
)
152
152
stdout , stderr = proc .communicate ()
153
- print (' stdout: {}' .format (stdout ))
154
- print (' stderr: {}' .format (stderr ))
153
+ print (" stdout: {}" .format (stdout ))
154
+ print (" stderr: {}" .format (stderr ))
155
155
result = json .loads (stdout )
156
156
pprint .pprint (result )
157
157
158
- release_version = result [' new_version' ]
158
+ release_version = result [" new_version" ]
159
159
today = datetime .today ()
160
- print (' today: {} (tzinfo={})' .format (today , today .tzinfo ))
160
+ print (" today: {} (tzinfo={})" .format (today , today .tzinfo ))
161
161
today = today .replace (tzinfo = timezone .utc )
162
- print (' today: {} (tzinfo={})' .format (today , today .tzinfo ))
163
- release_date = today .strftime (' %Y-%m-%d' )
164
- print (' release_date: {}' .format (release_date ))
165
- release_title = ' {} - {}' .format (release_version , release_date )
166
- print (' release_title: {}' .format (release_title ))
162
+ print (" today: {} (tzinfo={})" .format (today , today .tzinfo ))
163
+ release_date = today .strftime (" %Y-%m-%d" )
164
+ print (" release_date: {}" .format (release_date ))
165
+ release_title = " {} - {}" .format (release_version , release_date )
166
+ print (" release_title: {}" .format (release_title ))
167
167
168
- release_content = '' .join (
168
+ release_content = "" .join (
169
169
[
170
- ' ## {}\n ' ,
171
- ' \n ' ,
172
- '{}' ,
170
+ " ## {}\n " ,
171
+ " \n " ,
172
+ "{}" ,
173
173
]
174
- ).format (release_title , ' \n ' .join (pull_request_changes ))
174
+ ).format (release_title , " \n " .join (pull_request_changes ))
175
175
176
176
old_content = CHANGELOG_PATH .read_text ()
177
177
new_content = old_content .replace (
178
- ' <!-- CHANGELOG_PLACEHOLDER -->' ,
179
- ' <!-- CHANGELOG_PLACEHOLDER -->\n \n {}' .format (release_content ),
178
+ " <!-- CHANGELOG_PLACEHOLDER -->" ,
179
+ " <!-- CHANGELOG_PLACEHOLDER -->\n \n {}" .format (release_content ),
180
180
)
181
181
# print(new_content[:800])
182
182
CHANGELOG_PATH .write_text (new_content )
@@ -195,19 +195,19 @@ def main():
195
195
# print(local_repo.git.diff(cached=True, color='always'))
196
196
197
197
local_repo .git .commit (
198
- message = result [' message' ],
199
- author = ' {} <{}>' .format (
200
- local_repo .git .config (' --get' , ' user.name' ),
201
- local_repo .git .config (' --get' , ' user.email' ),
198
+ message = result [" message" ],
199
+ author = " {} <{}>" .format (
200
+ local_repo .git .config (" --get" , " user.name" ),
201
+ local_repo .git .config (" --get" , " user.email" ),
202
202
),
203
203
)
204
204
205
- print (' diff after commit:' )
205
+ print (" diff after commit:" )
206
206
# git log --max-count=1 --patch --color=always
207
- print (local_repo .git .log (max_count = '1' , patch = True , color = ' always' ))
207
+ print (local_repo .git .log (max_count = "1" , patch = True , color = " always" ))
208
208
209
209
# Push local changes.
210
- server = ' https://{}@github.com/{}.git' .format (GITHUB_TOKEN , GITHUB_REPOSITORY )
210
+ server = " https://{}@github.com/{}.git" .format (GITHUB_TOKEN , GITHUB_REPOSITORY )
211
211
print (
212
212
'pushing changes to branch "{}" of repository "{}"' .format (
213
213
GITHUB_REF_NAME , GITHUB_REPOSITORY
@@ -216,35 +216,35 @@ def main():
216
216
local_repo .git .push (server , GITHUB_REF_NAME )
217
217
218
218
# Create tag and release.
219
- tag = result [' new_version' ]
220
- tag_message = result [' message' ]
221
- release_name = ' Release {}' .format (release_version )
219
+ tag = result [" new_version" ]
220
+ tag_message = result [" message" ]
221
+ release_name = " Release {}" .format (release_version )
222
222
release_message = (
223
- ' See [change log](https://github.com/php-curl-class/php-curl-class/blob/master/CHANGELOG.md) for changes.\n '
224
- ' \n '
225
- ' https://github.com/php-curl-class/php-curl-class/compare/{}...{}' .format (
226
- result [' old_version' ],
227
- result [' new_version' ],
223
+ " See [change log](https://github.com/php-curl-class/php-curl-class/blob/master/CHANGELOG.md) for changes.\n "
224
+ " \n "
225
+ " https://github.com/php-curl-class/php-curl-class/compare/{}...{}" .format (
226
+ result [" old_version" ],
227
+ result [" new_version" ],
228
228
)
229
229
)
230
230
commit_sha = local_repo .head .commit .hexsha
231
- print (' tag: {}' .format (tag ))
231
+ print (" tag: {}" .format (tag ))
232
232
print ('tag_message: "{}"' .format (tag_message ))
233
233
print ('release_name: "{}"' .format (release_name ))
234
234
print ('release_message: "{}"' .format (release_message ))
235
- print (' commit_sha: {}' .format (commit_sha ))
235
+ print (" commit_sha: {}" .format (commit_sha ))
236
236
237
237
github_repo .create_git_tag_and_release (
238
238
tag = tag ,
239
239
tag_message = tag_message ,
240
240
release_name = release_name ,
241
241
release_message = release_message ,
242
242
object = commit_sha ,
243
- type = ' commit' ,
243
+ type = " commit" ,
244
244
draft = False ,
245
245
)
246
- print (' created tag and release' )
246
+ print (" created tag and release" )
247
247
248
248
249
- if __name__ == ' __main__' :
249
+ if __name__ == " __main__" :
250
250
main ()
0 commit comments