55from typing import TYPE_CHECKING
66
77import typer
8+ from packaging .version import Version
89from rich import print as rprint
910from rich .console import Group
1011from rich .panel import Panel
1112from rich .text import Text
1213
14+ from upgrade_dependencies .dependency import GitHubDependency , PyPIDependency
1315from upgrade_dependencies .project import Project
16+ from upgrade_dependencies .utils import run_shell_command
1417
1518if TYPE_CHECKING :
1619 from upgrade_dependencies .dependency import Dependency
@@ -320,11 +323,14 @@ def update(
320323):
321324 """_summary_.
322325
326+ Make sure branch locally and on github do not already exist!
327+
323328 Args:
324329 dependency: _description_
325330 version: _description_
326331 project_path: _description_
327332 """
333+ # TODO: print status
328334 project = Project (
329335 project_path = project_path ,
330336 gh_pat = GH_PAT ,
@@ -343,35 +349,69 @@ def update(
343349 if version is None :
344350 version = str (dep .get_latest_version ())
345351
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 } "
352358
353- # subprocess.run([' git', ' checkout', '-b' , branch_name])
359+ run_shell_command ([ " git" , " checkout" , "-b" , branch_name ])
354360
355361 # update dependency
356362 project .update_dependency (dependency = dep , version = version )
357363
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+ )
373412
374- # TODO: create pull request
413+ # re-checkout master
414+ run_shell_command (["git" , "checkout" , "master" ])
375415
376416
377417def main ():
0 commit comments