From 848d91d276008ccffecde51085f3073492140c5d Mon Sep 17 00:00:00 2001 From: Thomas Carmet <8408330+tcarmet@users.noreply.github.com> Date: Wed, 27 Nov 2024 21:47:24 +0000 Subject: [PATCH] PTFE-2192 add more information to build failed status --- bert_e/git_host/github/__init__.py | 3 ++- bert_e/templates/build_failed.md | 7 ++++++- bert_e/tests/test_bert_e.py | 26 ++++++++++++++++++------ bert_e/workflow/gitwaterflow/__init__.py | 3 ++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/bert_e/git_host/github/__init__.py b/bert_e/git_host/github/__init__.py index b791e1b6..cc4a36a1 100644 --- a/bert_e/git_host/github/__init__.py +++ b/bert_e/git_host/github/__init__.py @@ -593,7 +593,8 @@ def __init__(self, *args, **kwargs): def url(self): if len(self._workflow_runs) == 0: return None - return f"https://github.com/{self.full_repo}/commit/{self.commit}" + + return f"https://github.com/{self.full_repo}/actions?query=branch%3A{self.branch}" # noqa @property def commit(self) -> str | None: diff --git a/bert_e/templates/build_failed.md b/bert_e/templates/build_failed.md index c80c800d..35f55552 100644 --- a/bert_e/templates/build_failed.md +++ b/bert_e/templates/build_failed.md @@ -5,5 +5,10 @@ Build failed {% endblock %} {% block message %} -The {% if build_url %}[build]({{ build_url }}){% else %}build{% endif %}{% if commit_url %} for [commit]({{ commit_url }}){% endif %} did not succeed in branch {{ branch }}. +The {% if build_url -%}[build]({{ build_url }}) {% else -%}build {% endif -%} +{% if commit_url -%} for [commit]({{ commit_url }}){%- endif %} did not succeed in branch +{%- if githost == 'bitbucket' %} [{{ branch.name }}](https://bitbucket.org/{{ owner }}/{{ slug }}/branch/{{ branch.name }}?dest={{ branch.dst_branch }}) +{%- elif githost == 'github' %} [{{ branch.name }}](https://github.com/{{ owner }}/{{ slug }}/compare/{{ branch.dst_branch }}...{{ branch.name }}) +{%- else %} `{{ branch.name }}` +{%- endif -%} {% endblock %} diff --git a/bert_e/tests/test_bert_e.py b/bert_e/tests/test_bert_e.py index 44810f11..cb030ef1 100644 --- a/bert_e/tests/test_bert_e.py +++ b/bert_e/tests/test_bert_e.py @@ -822,16 +822,30 @@ class BuildFailedTest(unittest.TestCase): def test_build_fail_with_build_url(self): build_url = 'http://host/path/to/the?build=url' commit_url = 'http://host/path/to/the?commit=url' - build_fail = exns.BuildFailed(branch='spam', build_url=build_url, - commit_url=commit_url, - active_options=None) + branch = gwfb.IntegrationBranch(FakeGitRepo(), 'w/5.0/feature/TEST-01') + + build_fail = exns.BuildFailed( + branch=branch, + build_url=build_url, + commit_url=commit_url, + githost="github", + active_options=None, + owner="owner", + slug="slug", + ) self.assertIn('The [build]({}) for [commit]({})' ' did not succeed'.format(build_url, commit_url), build_fail.msg) def test_build_fail_with_url_to_none(self): - build_fail = exns.BuildFailed(branch='spam', build_url=None, - commit_url=None, active_options=None) + branch = gwfb.IntegrationBranch(FakeGitRepo(), 'w/5.0/feature/TEST-01') + build_fail = exns.BuildFailed( + branch=branch, + build_url=None, + githost="mock", + commit_url=None, + active_options=None + ) self.assertIn('The build did not succeed', build_fail.msg) @@ -3000,7 +3014,7 @@ def test_bypass_author_options_build_status(self): backtrace=True) except exns.BuildFailed as excp: self.assertIn( - "did not succeed in branch w/10/bugfix/TEST-00081", + "did not succeed in branch `w/10/bugfix/TEST-00081`", excp.msg, ) else: diff --git a/bert_e/workflow/gitwaterflow/__init__.py b/bert_e/workflow/gitwaterflow/__init__.py index 9ea21833..bdf36112 100644 --- a/bert_e/workflow/gitwaterflow/__init__.py +++ b/bert_e/workflow/gitwaterflow/__init__.py @@ -653,12 +653,13 @@ def status(branch): if worst_status in ('FAILED', 'STOPPED'): raise messages.BuildFailed( active_options=job.active_options, - branch=worst.name, + branch=worst, build_url=job.project_repo.get_build_url( worst.get_latest_commit, key), commit_url=job.project_repo.get_commit_url( worst.get_latest_commit()), + githost=job.settings.repository_host, ) elif worst_status == 'NOTSTARTED': raise messages.BuildNotStarted()