Skip to content
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
2 changes: 2 additions & 0 deletions packit_service/worker/handlers/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def run(self):
chroot=self.copr_event.chroot,
)
self.measure_time_after_reporting()
self.copr_build_helper.notify_about_failure_if_configured()
self.build.set_status(BuildStatus.failure)
return TaskResults(success=False, details={"msg": failed_msg})

Expand Down Expand Up @@ -370,6 +371,7 @@ def handle_srpm_end(self):
description=failed_msg,
url=url,
)
self.copr_build_helper.notify_about_failure_if_configured()
self.build.set_status(BuildStatus.failure)
self.copr_build_helper.monitor_not_submitted_copr_builds(
len(self.copr_build_helper.build_targets), "srpm_failure"
Expand Down
2 changes: 2 additions & 0 deletions packit_service/worker/handlers/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def run(self):
url=url,
chroot=build.target,
)
if self.koji_task_event.state == KojiTaskState.failed:
build_job_helper.notify_about_failure_if_configured()

koji_build_logs = KojiTaskEvent.get_koji_build_logs_url(
rpm_build_task_id=int(build.build_id),
Expand Down
4 changes: 4 additions & 0 deletions packit_service/worker/handlers/testing_farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def run(self) -> TaskResults:
success=True, details={"msg": "Testing farm results already processed"}
)

failure = False
if self.result == TestingFarmResult.running:
status = BaseCommitStatus.running
summary = self.summary or "Tests are running ..."
Expand All @@ -416,6 +417,7 @@ def run(self) -> TaskResults:
else:
status = BaseCommitStatus.failure
summary = self.summary or "Tests failed ..."
failure = True

if self.result == TestingFarmResult.running:
self.pushgateway.test_runs_started.inc()
Expand All @@ -437,6 +439,8 @@ def run(self) -> TaskResults:
else self.log_url,
links_to_external_services={"Testing Farm": self.log_url},
)
if failure:
self.testing_farm_job_helper.notify_about_failure_if_configured()

test_run_model.set_status(self.result, created=self.created)

Expand Down
20 changes: 19 additions & 1 deletion packit_service/worker/helpers/build/build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from packit_service.worker.events import EventData
from packit_service.worker.helpers.job_helper import BaseJobHelper
from packit_service.worker.monitoring import Pushgateway
from packit_service.worker.reporting import BaseCommitStatus
from packit_service.worker.reporting import BaseCommitStatus, DuplicateCheckMode
from packit_service.worker.result import TaskResults

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -754,3 +754,21 @@ def report_status_to_configured_job(
links_to_external_services=links_to_external_services,
update_feedback_time=update_feedback_time,
)

def notify_about_failure_if_configured(self):
"""
If there is a failure_comment_message configured for the job,
post a comment and include the configured message. Do not post
the comment if the last comment from the Packit user is identical.
"""
if not (
configured_message := self.job_config.notifications.failure_comment.message
):
return

formatted_message = configured_message.format(
commit_sha=self.db_project_event.commit_sha
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like the job_name variable, or, maybe some links might be requested. But we can freely stay with this and add on request later on.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it since users can define their custom messages per-job which can replace this, but I am not strongly against

maybe @martinpitt could help us with the feedback here: would you be interested in Packit providing some other variables besides commit_sha (see the docs in preparation) that you could utilise in the configuration of the custom failure messages? :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The big enabler here is to get a configurable list of people to ping, all the details can then be examined on the PR page.

Personally I liked the first version (i.e. just the first commit) a bit better: it's (mildly) useful to have the job name in the message, and it is IMHO much better to not interpolate configured_message -- adding variables to the text sounds like a recipe for bugs.

But it's not a strong opinion -- I'd be happy either way (and really looking forward to this!)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback! I can see that as @lachmanfrantisek wrote before, some users would like to have this completely customizable and by providing the commit_sha, actually, the duplication of the comment in the PR can be configured as well: when {commit_sha} is not present in the configured message, there will be only one Packit comment per PR and when it will be present, Packit will place a new comment for each failure for different commit

I would probably test it in staging in the current form and we can still easily tweak the content of the comment if needed

)
self.status_reporter.comment(
formatted_message, duplicate_check=DuplicateCheckMode.check_last_comment
)
43 changes: 43 additions & 0 deletions tests/unit/test_build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import pytest
from flexmock import flexmock

from packit.config.notifications import (
NotificationsConfig,
FailureCommentNotificationsConfig,
)
from packit.copr_helper import CoprHelper
from packit.config import (
CommonPackageConfig,
Expand All @@ -23,6 +27,7 @@

# packit.config.aliases.get_aliases() return value example
from packit_service.worker.helpers.testing_farm import TestingFarmJobHelper
from packit_service.worker.reporting import StatusReporter, DuplicateCheckMode

ALIASES = {
"fedora-development": ["fedora-33", "fedora-rawhide"],
Expand Down Expand Up @@ -2858,3 +2863,41 @@ def test_local_project_not_called_when_initializing_api():
flexmock(LocalProject).should_receive("__init__").never()
assert copr_build_helper.api
assert copr_build_helper.api.copr_helper


def test_notify_about_failure_if_configured():
jobs = [
JobConfig(
type=JobType.copr_build,
trigger=JobConfigTriggerType.pull_request,
packages={
"packages": CommonPackageConfig(
notifications=NotificationsConfig(
failure_comment=FailureCommentNotificationsConfig(
"One of the Copr builds failed for "
"commit {commit_sha}, ping @admin"
)
)
)
},
)
]
copr_build_helper = CoprBuildJobHelper(
service_config=ServiceConfig.get_service_config(),
package_config=PackageConfig(
jobs=jobs, packages={"package": CommonPackageConfig()}
),
job_config=jobs[0],
project=flexmock(),
metadata=flexmock(pr_id=1, commit_sha="123"),
db_project_event=flexmock(id=12, commit_sha="123")
.should_receive("get_project_event_object")
.and_return(flexmock(job_config_trigger_type=JobConfigTriggerType.pull_request))
.mock(),
)

flexmock(StatusReporter).should_receive("comment").with_args(
"One of the Copr builds failed for commit 123, ping @admin",
duplicate_check=DuplicateCheckMode.check_last_comment,
)
copr_build_helper.notify_about_failure_if_configured()