Skip to content

Commit

Permalink
Merge pull request #300 from lachmanfrantisek/issue-on-failed-propose…
Browse files Browse the repository at this point in the history
…-update

Issue on failed propose update

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] authored Dec 13, 2019
2 parents 5f892f0 + 620c313 commit ad76a22
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packit_service/worker/github_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,35 @@ def run(self) -> HandlerResults:

self.api = PackitAPI(self.config, self.package_config, self.local_project)

errors = []
errors = {}
for branch in get_branches(self.job.metadata.get("dist-git-branch", "master")):
try:
self.api.sync_release(
dist_git_branch=branch, version=self.event.tag_name
)
except Exception as ex:
sentry_integration.send_to_sentry(ex)
errors.append(f"Propose update for branch {branch} failed: {ex}")
errors[branch] = str(ex)

if errors:
branch_errors = "\n".join(
f"| `{branch}` | `{err}` |" for branch, err in errors.items()
)

body_msg = (
f"Packit failed on creating pull-requests in dist-git:\n\n"
f"| dist-git branch | error |\n"
f"| --------------- | ----- |\n"
f"{branch_errors}\n\n"
"You can re-trigger the update by adding `/packit propose-update`"
" to the issue comment.\n"
)

self.project.create_issue(
title=f"[packit] Propose update failed for release {self.event.tag_name}",
body=body_msg,
)

return HandlerResults(
success=False,
details={"msg": "Propose update failed.", "errors": errors},
Expand Down
105 changes: 105 additions & 0 deletions tests/integration/test_release_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from packit_service.config import ServiceConfig
from packit_service.constants import SANDCASTLE_WORK_DIR
from packit_service.worker import sentry_integration
from packit_service.worker.jobs import SteveJobs
from packit_service.worker.whitelist import Whitelist
from tests.spellbook import DATA_DIR
Expand Down Expand Up @@ -44,3 +45,107 @@ def test_dist_git_push_release_handle(release_event):
results = SteveJobs().process_message(release_event)
assert results["jobs"]["propose_downstream"]["success"]
assert results["event"]["trigger"] == "release"


def test_dist_git_push_release_handle_multiple_branches(release_event):
packit_yaml = (
"{'specfile_path': '', 'synced_files': []"
", jobs: [{trigger: release, job: propose_downstream, "
"metadata: {targets:[], dist-git-branch: fedora-all}}]}"
)
flexmock(Github, get_repo=lambda full_name_or_id: None)
flexmock(
GithubProject,
get_file_content=lambda path, ref: packit_yaml,
full_repo_name="packit-service/hello-world",
)
flexmock(LocalProject, refresh_the_arguments=lambda: None)
flexmock(Whitelist, check_and_report=True)
flexmock(SteveJobs, _is_private=False)
config = ServiceConfig()
config.command_handler_work_dir = SANDCASTLE_WORK_DIR
flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
# it would make sense to make LocalProject offline
flexmock(PackitAPI).should_receive("sync_release").with_args(
dist_git_branch="master", version="0.3.0"
).once()

flexmock(PackitAPI).should_receive("sync_release").with_args(
dist_git_branch="f30", version="0.3.0"
).once()

flexmock(PackitAPI).should_receive("sync_release").with_args(
dist_git_branch="f31", version="0.3.0"
).once()

results = SteveJobs().process_message(release_event)
assert results["jobs"]["propose_downstream"]["success"]
assert results["event"]["trigger"] == "release"


def test_dist_git_push_release_handle_one_failed(release_event):
packit_yaml = (
"{'specfile_path': '', 'synced_files': []"
", jobs: [{trigger: release, job: propose_downstream, "
"metadata: {targets:[], dist-git-branch: fedora-all}}]}"
)
flexmock(Github, get_repo=lambda full_name_or_id: None)
flexmock(
GithubProject,
get_file_content=lambda path, ref: packit_yaml,
full_repo_name="packit-service/hello-world",
).should_receive("create_issue").once()
flexmock(LocalProject, refresh_the_arguments=lambda: None)
flexmock(Whitelist, check_and_report=True)
flexmock(SteveJobs, _is_private=False)
config = ServiceConfig()
config.command_handler_work_dir = SANDCASTLE_WORK_DIR
flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
# it would make sense to make LocalProject offline
flexmock(PackitAPI).should_receive("sync_release").with_args(
dist_git_branch="master", version="0.3.0"
).once()

flexmock(PackitAPI).should_receive("sync_release").with_args(
dist_git_branch="f30", version="0.3.0"
).and_raise(Exception, "Failed f30").once()

flexmock(PackitAPI).should_receive("sync_release").with_args(
dist_git_branch="f31", version="0.3.0"
).once()

flexmock(sentry_integration).should_receive("send_to_sentry").and_return().once()

results = SteveJobs().process_message(release_event)
assert not results["jobs"]["propose_downstream"]["success"]
assert results["event"]["trigger"] == "release"


def test_dist_git_push_release_handle_all_failed(release_event):
packit_yaml = (
"{'specfile_path': '', 'synced_files': []"
", jobs: [{trigger: release, job: propose_downstream, "
"metadata: {targets:[], dist-git-branch: fedora-all}}]}"
)
flexmock(Github, get_repo=lambda full_name_or_id: None)
flexmock(
GithubProject,
get_file_content=lambda path, ref: packit_yaml,
full_repo_name="packit-service/hello-world",
).should_receive("create_issue").once()
flexmock(LocalProject, refresh_the_arguments=lambda: None)
flexmock(Whitelist, check_and_report=True)
flexmock(SteveJobs, _is_private=False)
config = ServiceConfig()
config.command_handler_work_dir = SANDCASTLE_WORK_DIR
flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
# it would make sense to make LocalProject offline
flexmock(PackitAPI).should_receive("sync_release").and_raise(
Exception, "Failed"
).times(3)

flexmock(sentry_integration).should_receive("send_to_sentry").and_return().times(3)

results = SteveJobs().process_message(release_event)
assert not results["jobs"]["propose_downstream"]["success"]
assert results["event"]["trigger"] == "release"

0 comments on commit ad76a22

Please sign in to comment.