Skip to content

Commit

Permalink
PTFE-2192 add more information to build failed status
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Nov 27, 2024
1 parent a4cb851 commit 848d91d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion bert_e/templates/build_failed.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
26 changes: 20 additions & 6 deletions bert_e/tests/test_bert_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion bert_e/workflow/gitwaterflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 848d91d

Please sign in to comment.