Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PTFE-1481 fixes for check run interactions #175

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions bert_e/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

class BertE_Exception(Exception):
code = -1
status: Literal[None, "in_progress", "queued", "success", "failure"] = None


# base exceptions
class TemplateException(BertE_Exception):
code = -2
template = None
status: Literal[None, "in_progress", "success", "failure"] = None
# whether to re-publish if the message is already in the history
dont_repeat_if_in_history = -1

Expand Down Expand Up @@ -148,7 +148,7 @@ class Conflict(TemplateException):
class ApprovalRequired(TemplateException):
code = 115
template = 'need_approval.md'
status = "in_progress"
status = "queued"


class BuildFailed(TemplateException):
Expand All @@ -160,7 +160,7 @@ class BuildFailed(TemplateException):
class AfterPullRequest(TemplateException):
code = 120
template = 'after_pull_request.md'
status = "in_progress"
status = "queued"


class IntegrationDataCreated(InformationException):
Expand Down Expand Up @@ -265,7 +265,7 @@ class RequestIntegrationBranches(TemplateException):
code = 135
template = "request_integration_branches.md"
# TODO: review if it should be failure.
status = "in_progress"
status = "queued"


class QueueBuildFailedMessage(TemplateException):
Expand Down Expand Up @@ -568,6 +568,7 @@ class NothingToDo(SilentException):

class BuildInProgress(SilentException):
code = 303
status = "in_progress"


class BuildNotStarted(SilentException):
Expand Down
30 changes: 17 additions & 13 deletions bert_e/git_host/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def __init__(self, login: str, password: str, email: str,
self.password = password
self.app_id = app_id
self.installation_id = installation_id
self.private_key = jwk_from_pem(private_key)
self.private_key = jwk_from_pem(private_key.encode('utf-8')) \
if private_key else None
self.email = email
self.org = org
self.base_url = base_url.rstrip('/')
Expand Down Expand Up @@ -832,11 +833,11 @@ def set_bot_status(self, status: str | None, title: str, summary: str):
if status == "success":
conclusion = "success"
status = "completed"
elif status == "in_progress":
conclusion = None
elif status == "failure":
conclusion = "failure"
status = "completed"
else:
conclusion = None

self._add_checkrun(
name='bert-e', status=status, conclusion=conclusion,
Expand All @@ -846,18 +847,21 @@ def set_bot_status(self, status: str | None, title: str, summary: str):
def _add_checkrun(
self, name: str, status: str, conclusion: str | None,
title: str, summary: str):
data = {
'name': name,
'head_sha': self.src_commit,
'status': status,
'output': {
'title': title,
'summary': summary,
},
}
if conclusion is not None:
data['conclusion'] = conclusion
LOG.debug(data)
return CheckRun.create(
client=self.client,
data={
'name': name,
'head_sha': self.src_commit,
'status': status,
'conclusion': conclusion,
'output': {
'title': title,
'summary': summary,
},
},
data=data,
owner=self.repo.owner, repo=self.repo.slug
)

Expand Down
2 changes: 1 addition & 1 deletion bert_e/git_host/github/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AggregateCheckSuites(GitHubSchema):
class Output(GitHubSchema):
title = fields.Str()
summary = fields.Str()
text = fields.Str()
text = fields.Str(allow_none=True)


class CheckRun(GitHubSchema):
Expand Down
2 changes: 1 addition & 1 deletion bert_e/tests/test_bert_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -4797,7 +4797,7 @@ def test_set_bot_status(self):
pr.src_commit, key="bert-e") == "failure"
self.handle(pr.id, settings=settings, options=["bypass_jira_check"])
assert self.get_build_status(
pr.src_commit, key="bert-e") == "in_progress"
pr.src_commit, key="bert-e") == "queued"
self.handle(pr.id, settings=settings, options=self.bypass_all)


Expand Down
2 changes: 1 addition & 1 deletion bert_e/tests/unit/test_github_app_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def client_app():
serialization.Encoding.PEM,
serialization.PrivateFormat.PKCS8,
serialization.NoEncryption()
),
).decode('utf-8'),
base_url="http://localhost:4010",
accept_header="application/json"
)
Expand Down
4 changes: 2 additions & 2 deletions bert_e/workflow/pr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def _send_comment(settings, pull_request: AbstractPullRequest, msg: str,
def _send_bot_status(settings, pull_request: AbstractPullRequest,
comment: exceptions.TemplateException):
"""Post the bot status in a pull request."""
if settings.send_bot_status is False:
LOG.debug("Not sending bot status (send_bot_status==False)")
if settings.send_bot_status is False or comment.status is None:
LOG.debug("No need to send bot status")
return
LOG.info(f"Setting bot status to {comment.status} as {comment.title}")
pull_request.set_bot_status(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ setenv =
WEBHOOK_LOGIN = {env:WEBHOOK_LOGIN:'webhook'}
WEBHOOK_PWD = {env:WEBHOOK_PWD:'webhook'}

commands = bert-e-serve -v -f {env:BERT_E_SETTINGS:'settings.yml'}
commands = bert-e-serve -v -f {env:BERT_E_SETTINGS:'settings.yml'} -p 8000

[testenv:tests-githost]
passenv = BERT_E_*
Expand Down