diff --git a/revup/shell.py b/revup/shell.py index 654bdfe..d2c1124 100644 --- a/revup/shell.py +++ b/revup/shell.py @@ -8,6 +8,7 @@ from typing import ( IO, Any, + Callable, Coroutine, Dict, List, @@ -45,7 +46,10 @@ def merge_dicts(x: Dict[K, V], y: Dict[K, V]) -> Dict[K, V]: async def process_stream( - proc_stream: Optional[asyncio.StreamReader], setting: _HANDLE, default_stream: IO[str] + proc_stream: Optional[asyncio.StreamReader], + setting: _HANDLE, + default_stream: IO[str], + transform: Optional[Callable], ) -> bytes: # The things we do for logging... # @@ -68,14 +72,16 @@ async def process_stream( line = await proc_stream.readexactly(e.consumed) except asyncio.IncompleteReadError as e: line = e.partial + if transform: + line = transform(line) if not line: - if isinstance(setting, int) and setting != -1: + if isinstance(setting, int) and setting not in (-1, subprocess.PIPE, subprocess.STDOUT): os.close(setting) break if setting == subprocess.PIPE: output.append(line) elif setting == subprocess.STDOUT: - sys.stdout.buffer.write(line) + logging.info(line.decode("utf-8").strip()) elif isinstance(setting, int) and setting != -1: os.write(setting, line) elif setting is None: @@ -137,6 +143,7 @@ async def create_sh_task( input_str: Optional[str] = None, stdin: _HANDLE = None, stdout: _HANDLE = subprocess.PIPE, + output_transform: Optional[Callable] = None, ) -> Tuple[ Coroutine[Any, Any, None], Coroutine[Any, Any, bytes], @@ -163,8 +170,8 @@ async def create_sh_task( return ( feed_input(ret.stdin, input_str), - process_stream(ret.stdout, stdout, sys.stdout), - process_stream(ret.stderr, stderr, sys.stderr), + process_stream(ret.stdout, stdout, sys.stdout, output_transform), + process_stream(ret.stderr, stderr, sys.stderr, output_transform), ret.wait(), ) @@ -179,6 +186,7 @@ async def sh( stdout: _HANDLE = subprocess.PIPE, raiseonerror: bool = True, quiet: bool = False, + output_transform: Optional[Callable] = None, ) -> Tuple[int, str]: """ Run a command specified by args, and return string representing @@ -210,6 +218,7 @@ async def sh( input_str=input_str, stdin=stdin, stdout=stdout, + output_transform=output_transform, ) _, out, err, ret = await asyncio.gather(*tasks) diff --git a/revup/topic_stack.py b/revup/topic_stack.py index 335d540..ce6efc7 100644 --- a/revup/topic_stack.py +++ b/revup/topic_stack.py @@ -1039,7 +1039,13 @@ async def push_git_refs(self, uploader: str, create_local_branches: bool) -> Non self.git_ctx.remote_name, *push_targets, ] - await self.git_ctx.git(*push_args, stderr=subprocess.PIPE) + await self.git_ctx.git( + *push_args, + stdout=subprocess.STDOUT, + stderr=subprocess.STDOUT, + # Hide the remote output that says "Create a pull request for '' on GitHub" + output_transform=lambda l: b"" if l.startswith(b"remote: ") else l, + ) async def query_github(self) -> None: """