1111from types import TracebackType
1212from typing import Any , Optional
1313
14+ import loguru
15+
1416
1517class RepoSandbox :
1618 def __init__ (self , repo : str , dry_run : bool = False ) -> None :
@@ -30,6 +32,10 @@ def __exit__(
3032 ) -> None :
3133 self ._stack .close ()
3234
35+ @cached_property
36+ def logger (self ) -> "loguru.Logger" :
37+ return loguru .logger .bind (repo = self .repo )
38+
3339 @cached_property
3440 def tempdir (self ) -> Path :
3541 return Path (
@@ -73,7 +79,7 @@ def run(
7379
7480 def shell (self ) -> None :
7581 if sys .__stdin__ .isatty ():
76- print ('Starting shell. Run "exit 1" to abort.' )
82+ self . logger . info ('Starting shell. Run "exit 1" to abort.' )
7783 self .run ([os .environ .get ("SHELL" , "/bin/bash" )])
7884
7985 def commit_changes (self , message : str ) -> None :
@@ -104,12 +110,13 @@ def lint_test(self) -> None:
104110 try :
105111 self .run (["poetry" , "run" , "poe" , "test" ])
106112 except subprocess .CalledProcessError as e :
107- print ( e )
108- print ("Resolve errors and exit shell to continue" )
113+ self . logger . error ( str ( e ) )
114+ self . logger . error ("Resolve errors and exit shell to continue" )
109115 self .shell ()
110116
111117 def open_pr (self , message : str ) -> None :
112118 if self .dry_run :
119+ self .logger .success ("Would open PR" )
113120 return
114121 self .run (["git" , "push" , "origin" , self .branch ])
115122 commit_title , _ , * commit_body = message .splitlines ()
@@ -129,3 +136,4 @@ def open_pr(self, message: str) -> None:
129136 ],
130137 input = os .linesep .join (commit_body ).encode ("utf-8" ),
131138 )
139+ self .logger .success ("Opened PR" )
0 commit comments