14
14
15
15
import requests
16
16
import toml
17
- from ghapi .core import GhApi
18
17
from packaging .version import parse as parse_version
19
18
from pkginfo import SDist , Wheel
20
19
@@ -183,17 +182,14 @@ def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=F
183
182
184
183
# Create the pull
185
184
owner , repo_name = repo .split ("/" )
186
- gh = GhApi ( owner = owner , repo = repo_name , token = auth )
185
+ gh = util . get_gh_object ( dry_run = dry_run , owner = owner , repo = repo_name , token = auth )
187
186
188
187
base = branch
189
188
head = pr_branch
190
189
maintainer_can_modify = True
191
190
192
- if dry_run :
193
- util .log ("Skipping pull request due to dry run" )
194
- return
195
-
196
- util .run (f"git push origin { pr_branch } " )
191
+ if not dry_run :
192
+ util .run (f"git push origin { pr_branch } " )
197
193
198
194
# title, head, base, body, maintainer_can_modify, draft, issue
199
195
pull = gh .pulls .create (title , head , base , body , maintainer_can_modify , False , None )
@@ -255,11 +251,8 @@ def draft_release(
255
251
util .log (post_version_message .format (post_version = post_version ))
256
252
util .run (f'git commit -a -m "Bump to { post_version } "' )
257
253
258
- if dry_run :
259
- return
260
-
261
254
owner , repo_name = repo .split ("/" )
262
- gh = GhApi ( owner = owner , repo = repo_name , token = auth )
255
+ gh = util . get_gh_object ( dry_run = dry_run , owner = owner , repo = repo_name , token = auth )
263
256
264
257
# Remove draft releases over a day old
265
258
if bool (os .environ .get ("GITHUB_ACTIONS" )):
@@ -273,7 +266,7 @@ def draft_release(
273
266
gh .repos .delete_release (release .id )
274
267
275
268
remote_url = util .run ("git config --get remote.origin.url" )
276
- if not os .path .exists (remote_url ):
269
+ if not dry_run and not os .path .exists (remote_url ):
277
270
util .run (f"git push origin HEAD:{ branch } --follow-tags --tags" )
278
271
279
272
util .log (f"Creating release for { version } " )
@@ -292,14 +285,14 @@ def draft_release(
292
285
util .actions_output ("release_url" , release .html_url )
293
286
294
287
295
- def delete_release (auth , release_url ):
288
+ def delete_release (auth , release_url , dry_run = False ):
296
289
"""Delete a draft GitHub release by url to the release page"""
297
290
match = re .match (util .RELEASE_HTML_PATTERN , release_url )
298
291
match = match or re .match (util .RELEASE_API_PATTERN , release_url )
299
292
if not match :
300
293
raise ValueError (f"Release url is not valid: { release_url } " )
301
294
302
- gh = GhApi ( owner = match ["owner" ], repo = match ["repo" ], token = auth )
295
+ gh = util . get_gh_object ( dry_run = dry_run , owner = match ["owner" ], repo = match ["repo" ], token = auth )
303
296
release = util .release_for_url (gh , release_url )
304
297
for asset in release .assets :
305
298
gh .repos .delete_release_asset (asset .id )
@@ -320,7 +313,8 @@ def extract_release(
320
313
"""Download and verify assets from a draft GitHub release"""
321
314
match = parse_release_url (release_url )
322
315
owner , repo = match ["owner" ], match ["repo" ]
323
- gh = GhApi (owner = owner , repo = repo , token = auth )
316
+
317
+ gh = util .get_gh_object (dry_run = dry_run , owner = owner , repo = repo , token = auth )
324
318
release = util .release_for_url (gh , release_url )
325
319
branch = release .target_commitish
326
320
assets = release .assets
@@ -494,14 +488,14 @@ def publish_assets(
494
488
util .log ("No files to upload" )
495
489
496
490
497
- def publish_release (auth , release_url ):
491
+ def publish_release (auth , dry_run , release_url ):
498
492
"""Publish GitHub release"""
499
493
util .log (f"Publishing { release_url } " )
500
494
501
495
match = parse_release_url (release_url )
502
496
503
497
# Take the release out of draft
504
- gh = GhApi ( owner = match ["owner" ], repo = match ["repo" ], token = auth )
498
+ gh = util . get_gh_object ( dry_run = dry_run , owner = match ["owner" ], repo = match ["repo" ], token = auth )
505
499
release = util .release_for_url (gh , release_url )
506
500
507
501
release = gh .repos .update_release (
@@ -625,7 +619,8 @@ def forwardport_changelog(auth, ref, branch, repo, username, changelog_path, dry
625
619
"""Forwardport Changelog Entries to the Default Branch"""
626
620
# Set up the git repo with the branch
627
621
match = parse_release_url (release_url )
628
- gh = GhApi (owner = match ["owner" ], repo = match ["repo" ], token = auth )
622
+
623
+ gh = util .get_gh_object (dry_run = dry_run , owner = match ["owner" ], repo = match ["repo" ], token = auth )
629
624
release = util .release_for_url (gh , release_url )
630
625
tag = release .tag_name
631
626
source_branch = release .target_commitish
0 commit comments