5
5
from typing import TYPE_CHECKING
6
6
7
7
import typer
8
+ from packaging .version import Version
8
9
from rich import print as rprint
9
10
from rich .console import Group
10
11
from rich .panel import Panel
11
12
from rich .text import Text
12
13
14
+ from upgrade_dependencies .dependency import GitHubDependency , PyPIDependency
13
15
from upgrade_dependencies .project import Project
16
+ from upgrade_dependencies .utils import run_shell_command
14
17
15
18
if TYPE_CHECKING :
16
19
from upgrade_dependencies .dependency import Dependency
@@ -320,11 +323,14 @@ def update(
320
323
):
321
324
"""_summary_.
322
325
326
+ Make sure branch locally and on github do not already exist!
327
+
323
328
Args:
324
329
dependency: _description_
325
330
version: _description_
326
331
project_path: _description_
327
332
"""
333
+ # TODO: print status
328
334
project = Project (
329
335
project_path = project_path ,
330
336
gh_pat = GH_PAT ,
@@ -343,35 +349,69 @@ def update(
343
349
if version is None :
344
350
version = str (dep .get_latest_version ())
345
351
346
- # # create new branch
347
- # if isinstance(dep, GitHubDependency) and dep.action:
348
- # v = Version(version)
349
- # branch_name = f"dependency/{dep.short_name}-v{v.major}"
350
- # else:
351
- # branch_name = f"dependency/{dep.short_name}-{version}"
352
+ # create new branch
353
+ if isinstance (dep , GitHubDependency ) and dep .action :
354
+ v = Version (version )
355
+ branch_name = f"dependency/{ dep .short_name } -v{ v .major } "
356
+ else :
357
+ branch_name = f"dependency/{ dep .short_name } -{ version } "
352
358
353
- # subprocess.run([' git', ' checkout', '-b' , branch_name])
359
+ run_shell_command ([ " git" , " checkout" , "-b" , branch_name ])
354
360
355
361
# update dependency
356
362
project .update_dependency (dependency = dep , version = version )
357
363
358
- # # stage changes - TODO: get files that are changed
359
- # subprocess.run(['git', 'add', '.github/'])
360
-
361
- # # commit the changes
362
- # if isinstance(dep, GitHubDependency) and dep.action:
363
- # old_v = Version(old_ver)
364
- # v = Version(version)
365
- # commit_message = f"Bump {dep.package_name} from v{old_v.major} to v{v.major}"
366
- # else:
367
- # commit_message = f"Bump {dep.package_name} from {old_ver} to {version}"
368
-
369
- # subprocess.run(['git', 'commit', '-m', commit_message])
370
-
371
- # # push the branch
372
- # subprocess.run(['git', 'push', 'origin', branch_name])
364
+ # stage changes - TODO: get files that are changed
365
+ run_shell_command (["git" , "add" , ".github/" ])
366
+
367
+ # commit the changes
368
+ if isinstance (dep , GitHubDependency ) and dep .action :
369
+ old_v = Version (old_ver )
370
+ v = Version (version )
371
+ commit_message = f"Bump { dep .package_name } from v{ old_v .major } to v{ v .major } "
372
+ else :
373
+ commit_message = f"Bump { dep .package_name } from { old_ver } to { version } "
374
+
375
+ run_shell_command (["git" , "commit" , "-m" , commit_message ])
376
+
377
+ # push the branch
378
+ run_shell_command (["git" , "push" , "origin" , branch_name ])
379
+
380
+ # create pr_body
381
+ if isinstance (dep , PyPIDependency ):
382
+ url = f"https://pypi.org/project/{ dep .package_name } "
383
+ pr_body = f"Bumps [{ dep .package_name } ]({ url } ) from { old_ver } to { version } ."
384
+ elif isinstance (dep , GitHubDependency ):
385
+ old_v = Version (old_ver )
386
+ v = Version (version )
387
+ url = f"https://github.com/{ dep .owner } /{ dep .repo } "
388
+ pr_body = (
389
+ f"Bumps [{ dep .package_name } ]({ url } ) from v{ old_v .major } to v{ v .major } ."
390
+ )
391
+ else :
392
+ pr_body = ""
393
+
394
+ # create pull request
395
+ run_shell_command (
396
+ [
397
+ "gh" ,
398
+ "pr" ,
399
+ "create" ,
400
+ "-a" ,
401
+ "@me" ,
402
+ "--base" ,
403
+ "master" ,
404
+ "--body" ,
405
+ pr_body ,
406
+ "--label" ,
407
+ "dependencies" ,
408
+ "--title" ,
409
+ commit_message ,
410
+ ],
411
+ )
373
412
374
- # TODO: create pull request
413
+ # re-checkout master
414
+ run_shell_command (["git" , "checkout" , "master" ])
375
415
376
416
377
417
def main ():
0 commit comments