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

Aliases for distgit branches #285

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
15 changes: 5 additions & 10 deletions packit_service/worker/copr_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from packit_service.config import ServiceConfig, Deployment
from packit_service.service.events import PullRequestEvent, PullRequestCommentEvent
from packit_service.service.models import CoprBuild
from packit_service.worker import sentry_integration
from packit_service.worker.copr_db import CoprBuildDB
from packit_service.worker.handler import (
HandlerResults,
Expand Down Expand Up @@ -243,14 +244,8 @@ def run_copr_build(self) -> HandlerResults:

return HandlerResults(success=True, details={})

def send_to_sentry(self, ex):
# so that we don't have to have sentry sdk installed locally
import sentry_sdk

sentry_sdk.capture_exception(ex)

def _process_general_exception(self, ex):
self.send_to_sentry(ex)
sentry_integration.send_to_sentry(ex)
msg = f"There was an error while running a copr build:\n```\n{ex}\n```\n"
logger.error(msg)
self.project.pr_comment(self.event.pr_id, f"{msg}\n{MSG_RETRIGGER}")
Expand All @@ -262,7 +257,7 @@ def _process_general_exception(self, ex):
return HandlerResults(success=False, details={"msg": msg})

def _process_failed_srpm_build(self, ex):
self.send_to_sentry(ex)
sentry_integration.send_to_sentry(ex)
msg = f"Failed to create a SRPM: {ex}"
self.status_reporter.report(
state="failure",
Expand All @@ -286,7 +281,7 @@ def _process_failed_command(self, ex):
f"\nReturn code: {ex.rc}"
)
self.project.pr_comment(self.event.pr_id, msg)
self.send_to_sentry(output)
sentry_integration.send_to_sentry(output)
msg = "Failed to create a SRPM."
self.status_reporter.report(
state="failure",
Expand All @@ -305,7 +300,7 @@ def _process_timeout(self):
return HandlerResults(success=False, details={"msg": msg})

def _process_openshift_error(self, ex: ApiException):
self.send_to_sentry(ex)
sentry_integration.send_to_sentry(ex)

error_message = f"({ex.status})\nReason: {ex.reason}\n"
if ex.headers:
Expand Down
48 changes: 32 additions & 16 deletions packit_service/worker/github_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
PackageConfig,
get_package_config_from_repo,
)
from packit.config.aliases import get_branches
from packit.exceptions import PackitException
from packit.local_project import LocalProject

Expand All @@ -53,6 +54,7 @@
CoprBuildEvent,
)
from packit_service.service.models import Installation
from packit_service.worker import sentry_integration
from packit_service.worker.comment_action_handler import (
CommentAction,
add_to_comment_action_mapping,
Expand Down Expand Up @@ -197,14 +199,22 @@ def run(self) -> HandlerResults:
)

self.api = PackitAPI(self.config, self.package_config, self.local_project)
# create_pr is set to False.
# Each upstream project decides
# if creates PR or pushes directly into dist-git directly from packit.yaml file.
self.api.sync_release(
dist_git_branch=self.job.metadata.get("dist-git-branch", "master"),
version=self.event.tag_name,
create_pr=False,
)

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}")

if errors:
return HandlerResults(
success=False,
details={"msg": "Propose update failed.", "errors": errors},
)

return HandlerResults(success=True, details={})

Expand Down Expand Up @@ -514,16 +524,21 @@ def __init__(self, config: ServiceConfig, event: IssueCommentEvent):
raise ValueError(f"No config file found in {self.project.full_repo_name}")
self.package_config.upstream_project_url = event.project_url

def get_build_metadata_for_build(self) -> List[str]:
@property
def dist_git_branches_to_sync(self) -> List[str]:
"""
Check if there are propose-update defined
:return: JobConfig or Empty list
Get the dist-git branches to sync to with the aliases expansion.

:return: list of dist-git branches
"""
return [
configured_branches = [
job.metadata.get("dist-git-branch")
for job in self.package_config.jobs
if job.job == JobType.propose_downstream
]
if configured_branches:
return list(get_branches(*configured_branches))
return []

def run(self) -> HandlerResults:
self.local_project = LocalProject(
Expand All @@ -538,16 +553,17 @@ def run(self) -> HandlerResults:
self.project.issue_comment(self.event.issue_id, msg)
return HandlerResults(success=True, details={"msg": msg})

branches = self.get_build_metadata_for_build()
sync_failed = False
for brn in branches:
for branch in self.dist_git_branches_to_sync:
msg = (
f"a new update for the Fedora package "
f"`{self.package_config.downstream_package_name}`"
f"with the tag `{self.event.tag_name}` in the `{brn}` branch.\n"
f"with the tag `{self.event.tag_name}` in the `{branch}` branch.\n"
)
try:
self.api.sync_release(dist_git_branch=brn, version=self.event.tag_name)
self.api.sync_release(
dist_git_branch=branch, version=self.event.tag_name
)
msg = f"Packit-as-a-Service proposed {msg}"
self.project.issue_comment(self.event.issue_id, msg)
except PackitException as ex:
Expand Down
28 changes: 28 additions & 0 deletions packit_service/worker/sentry_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# MIT License
#
# Copyright (c) 2018-2019 Red Hat, Inc.

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


def send_to_sentry(ex):
# so that we don't have to have sentry sdk installed locally
import sentry_sdk

sentry_sdk.capture_exception(ex)
4 changes: 2 additions & 2 deletions tests/integration/test_release_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import pytest
from flexmock import flexmock
from github import Github

from ogr.services.github import GithubProject
from packit.api import PackitAPI
from packit.local_project import LocalProject

from packit_service.config import ServiceConfig
from packit_service.constants import SANDCASTLE_WORK_DIR
from packit_service.worker.jobs import SteveJobs
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_dist_git_push_release_handle(release_event):
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", create_pr=False
dist_git_branch="master", version="0.3.0"
).once()

results = SteveJobs().process_message(release_event)
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_copr_build.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.service.models import CoprBuild
from packit_service.worker import sentry_integration
from packit_service.worker.copr_build import CoprBuildHandler
from packit_service.worker.copr_db import CoprBuildDB
from packit_service.worker.handler import BuildStatusReporter
Expand Down Expand Up @@ -131,7 +132,7 @@ def test_copr_build_fails_in_packit():
handler = build_handler()
flexmock(GitProject).should_receive("set_commit_status").and_return().times(6)
flexmock(CoprBuild).should_receive("create").and_return(FakeCoprBuildModel())
flexmock(CoprBuildHandler).should_receive("send_to_sentry").and_return().once()
flexmock(sentry_integration).should_receive("send_to_sentry").and_return().once()
flexmock(CoprBuildDB).should_receive("add_build").never()
flexmock(PackitAPI).should_receive("run_copr_build").and_raise(FailedCreateSRPM)
assert not handler.run_copr_build()["success"]
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_steve.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import pytest
from flexmock import flexmock
from github import Github

from ogr.services.github import GithubProject
from packit.api import PackitAPI
from packit.local_project import LocalProject

from packit_service.config import ServiceConfig
from packit_service.constants import SANDCASTLE_WORK_DIR
from packit_service.worker.jobs import SteveJobs
Expand Down Expand Up @@ -60,6 +60,7 @@ def test_process_message(event):
"synced_files": [],
"jobs": [{"trigger": "release", "job": "propose_downstream"}],
}

flexmock(Github, get_repo=lambda full_name_or_id: None)
flexmock(
GithubProject,
Expand All @@ -70,9 +71,8 @@ def test_process_message(event):
config = ServiceConfig()
config.command_handler_work_dir = SANDCASTLE_WORK_DIR
flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)

flexmock(PackitAPI).should_receive("sync_release").with_args(
dist_git_branch="master", version="1.2.3", create_pr=False
dist_git_branch="master", version="1.2.3"
).once()
flexmock(Whitelist, check_and_report=True)
flexmock(SteveJobs, _is_private=False)
Expand Down