diff --git a/tests/trestlebot/test_gitlab.py b/tests/trestlebot/test_gitlab.py index d4aa19a9..b1fe533e 100644 --- a/tests/trestlebot/test_gitlab.py +++ b/tests/trestlebot/test_gitlab.py @@ -191,12 +191,12 @@ def test_gitlab_ci_results_reporter() -> None: results = BotResults(changes=[], commit_sha="123456", pr_number=2) expected_output = ( - "section_start:1234567890`:Commit Hash" - "[collapsed=true]\r\\e[0KCommit hash for the changes\n123456\n" - "section_end:1234567890:$Commit Hash\r\\e[0K\n" - "section_start:1234567890`:Pull Request Number[collapsed=true]\r\\e[0K" - "Pull Request number for the changes\n2\nsection_end:1234567890:$Pull Request" - " Number\r\\e[0K\n" + "\x1b[0Ksection_start:1234567890:Commit Hash" + "[collapsed=true]\r\x1b[0KCommit hash for the changes\n123456\n" + "\x1b[0Ksection_end:1234567890:Commit Hash\r\x1b[0K\n" + "\x1b[0Ksection_start:1234567890:Pull Request Number[collapsed=true]\r\x1b[0K" + "Pull Request number for the changes\n2\n\x1b[0Ksection_end:1234567890:Pull Request" + " Number\r\x1b[0K\n" ) with patch("builtins.print") as mock_print: with patch("time.time_ns", return_value=1234567890): @@ -205,8 +205,8 @@ def test_gitlab_ci_results_reporter() -> None: results = BotResults(changes=["file2"], commit_sha="", pr_number=0) expected_output = ( - "section_start:1234567890`:Changes[collapsed=true]\r\\e" - "[0KChanges detected\nfile2\nsection_end:1234567890:$Changes\r\\e[0K\n" + "\x1b[0Ksection_start:1234567890:Changes[collapsed=true]\r\x1b" + "[0KChanges detected\nfile2\n\x1b[0Ksection_end:1234567890:Changes\r\x1b[0K\n" ) with patch("builtins.print") as mock_print: with patch("time.time_ns", return_value=1234567890): diff --git a/trestlebot/gitlab.py b/trestlebot/gitlab.py index f74c8090..db799722 100644 --- a/trestlebot/gitlab.py +++ b/trestlebot/gitlab.py @@ -99,6 +99,9 @@ def create_pull_request( class GitLabCIResultsReporter(ResultsReporter): """Report bot results to the console in GitLabCI""" + escape_sequence = "\x1b[0K" + carriage_return = "\r" + def report_results(self, results: BotResults) -> None: """ Report the results of the Trestle Bot in GitLab CI @@ -136,12 +139,14 @@ def _create_group( section_title: str, section_description: str, content: str ) -> str: """Create a group for the GitLab CI output""" + start_char = GitLabCIResultsReporter.escape_sequence + end_char = f"{GitLabCIResultsReporter.carriage_return}{GitLabCIResultsReporter.escape_sequence}" group_str = "" - group_str += f"section_start:{time.time_ns()}`:{section_title}[collapsed=true]" - group_str += f"\r\e[0K{section_description}" # noqa: W605 + group_str += f"{start_char}section_start:{time.time_ns()}:{section_title}[collapsed=true]" + group_str += f"{end_char}{section_description}" group_str += f"\n{content}\n" group_str += ( - f"section_end:{time.time_ns()}:${section_title}\r\e[0K\n" # noqa: W605 + f"{start_char}section_end:{time.time_ns()}:{section_title}{end_char}\n" ) return group_str