Skip to content

Commit

Permalink
Parse Pagure PR events (#2600)
Browse files Browse the repository at this point in the history
Parse Pagure PR events

Fixes #2579
Related to packit/packit-service-fedmsg#115
Related to packit/deployment#608
RELEASE NOTES BEGIN
N/A
RELEASE NOTES END

Reviewed-by: Nikola Forró
Reviewed-by: Matej Focko
Reviewed-by: Laura Barcziová
  • Loading branch information
softwarefactory-project-zuul[bot] authored Oct 24, 2024
2 parents 4679eed + e87f527 commit a72fc6b
Show file tree
Hide file tree
Showing 6 changed files with 612 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packit_service/worker/events/pagure.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def __init__(
base_repo_namespace: str,
base_repo_name: str,
base_repo_owner: str,
base_ref: str,
base_ref: Optional[str],
target_repo: str,
project_url: str,
commit_sha: str,
Expand Down Expand Up @@ -228,6 +228,15 @@ def get_base_project(self) -> GitProject:
logger.debug(f"Base project: {fork} owned by {self.base_repo_owner}")
return fork

def get_packages_config(self) -> Optional[PackageConfig]:
return PackageConfigGetter.get_package_config_from_repo(
base_project=self.base_project,
project=self.project,
reference=self.commit_sha,
pr_id=self.pr_id,
fail_when_missing=self.fail_when_config_file_missing,
)


class PullRequestFlagPagureEvent(AbstractPagureEvent):
def __init__(
Expand Down
52 changes: 51 additions & 1 deletion packit_service/worker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@
AnityaVersionUpdateEvent,
NewHotnessUpdateEvent,
)
from packit_service.worker.events.pagure import PullRequestFlagPagureEvent
from packit_service.worker.events.pagure import (
PullRequestFlagPagureEvent,
PullRequestPagureEvent,
)
from packit_service.worker.handlers.abstract import MAP_CHECK_PREFIX_TO_HANDLER
from packit_service.worker.helpers.build import CoprBuildJobHelper, KojiBuildJobHelper
from packit_service.worker.helpers.testing_farm import TestingFarmJobHelper
Expand Down Expand Up @@ -112,6 +115,7 @@ def parse_event(
PipelineGitlabEvent,
PullRequestFlagPagureEvent,
PullRequestCommentPagureEvent,
PullRequestPagureEvent,
PushPagureEvent,
CheckRerunCommitEvent,
CheckRerunPullRequestEvent,
Expand Down Expand Up @@ -173,6 +177,7 @@ def parse_event(
Parser.parse_openscanhub_task_finished_event,
Parser.parse_openscanhub_task_started_event,
Parser.parse_commit_comment_event,
Parser.parse_pagure_pull_request_event,
)
):
if response:
Expand Down Expand Up @@ -1703,6 +1708,48 @@ def parse_pagure_pull_request_comment_event(
comment_id=comment_id,
)

@staticmethod
def parse_pagure_pull_request_event(
event,
) -> Optional[PullRequestPagureEvent]:
if (topic := event.get("topic", "")) not in (
"org.fedoraproject.prod.pagure.pull-request.new",
"org.fedoraproject.prod.pagure.pull-request.updated",
"org.fedoraproject.prod.pagure.pull-request.rebased",
):
return None

logger.info(f"Pagure PR event, topic: {topic}")

action = (
PullRequestAction.opened.value
if topic.endswith("new")
else PullRequestAction.synchronize.value
)
pr_id = event["pullrequest"]["id"]
pagure_login = event["agent"]

base_repo_namespace = event["pullrequest"]["project"]["namespace"]
base_repo_name = event["pullrequest"]["project"]["name"]
repo_from = event["pullrequest"]["repo_from"]
base_repo_owner = repo_from["user"]["name"] if repo_from else pagure_login
target_repo = repo_from["name"] if repo_from else base_repo_name
https_url = event["pullrequest"]["project"]["full_url"]
commit_sha = event["pullrequest"]["commit_stop"]

return PullRequestPagureEvent(
action=PullRequestAction[action],
pr_id=pr_id,
base_repo_namespace=base_repo_namespace,
base_repo_name=base_repo_name,
base_repo_owner=base_repo_owner,
base_ref=None,
target_repo=target_repo,
project_url=https_url,
commit_sha=commit_sha,
user_login=pagure_login,
)

@staticmethod
def parse_new_hotness_update_event(event) -> Optional[NewHotnessUpdateEvent]:
if "hotness.update.bug.file" not in event.get("topic", ""):
Expand Down Expand Up @@ -1848,6 +1895,9 @@ def parse_openscanhub_task_started_event(
"pagure.pull-request.flag.added": parse_pagure_pr_flag_event.__func__, # type: ignore
"pagure.pull-request.flag.updated": parse_pagure_pr_flag_event.__func__, # type: ignore
"pagure.pull-request.comment.added": parse_pagure_pull_request_comment_event.__func__, # type: ignore
"pagure.pull-request.new": parse_pagure_pull_request_event.__func__, # type: ignore
"pagure.pull-request.updated": parse_pagure_pull_request_event.__func__, # type: ignore
"pagure.pull-request.rebased": parse_pagure_pull_request_event.__func__, # type: ignore
"pagure.git.receive": parse_pagure_push_event.__func__, # type: ignore
"copr.build.start": parse_copr_event.__func__, # type: ignore
"copr.build.end": parse_copr_event.__func__, # type: ignore
Expand Down
140 changes: 140 additions & 0 deletions tests/data/fedmsg/pagure_pr_new.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"topic": "org.fedoraproject.prod.pagure.pull-request.new",
"agent": "zbyszek",
"pullrequest": {
"assignee": null,
"branch": "rawhide",
"branch_from": "build-only-on-aarch64",
"cached_merge_status": "unknown",
"closed_at": null,
"closed_by": null,
"comments": [],
"commit_start": "889f07af35d27bbcaf9c535c17a63b974aa42ee3",
"commit_stop": "889f07af35d27bbcaf9c535c17a63b974aa42ee3",
"date_created": "1729687175",
"full_url": "https://src.fedoraproject.org/rpms/optee_os/pull-request/2",
"id": 2,
"initial_comment": "Previously the package was \"built\" on all architectures, but no output\r\nwas produced. Only on aarch64, a noarch package was produced, which\r\nthen was distributed to all architectures. Mock/koji allow this, but\r\nit's rather pointless and confusing. We can achieve the same result by\r\nonly building on aarch64.\r\n\r\nI think this DTRT, but please don't merge without waiting for the scratch build result.",
"last_updated": "1729687175",
"project": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": [],
"collaborator": [],
"commit": [],
"owner": ["eballetbo"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1695137284",
"date_modified": "1704875184",
"description": "The optee_os package\n",
"full_url": "https://src.fedoraproject.org/rpms/optee_os",
"fullname": "rpms/optee_os",
"id": 66326,
"milestones": {},
"name": "optee_os",
"namespace": "rpms",
"parent": null,
"priorities": {},
"tags": [],
"url_path": "rpms/optee_os",
"user": {
"full_url": "https://src.fedoraproject.org/user/eballetbo",
"fullname": "Enric Balletbo i Serra",
"name": "eballetbo",
"url_path": "user/eballetbo"
}
},
"remote_git": null,
"repo_from": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": [],
"collaborator": [],
"commit": [],
"owner": ["zbyszek"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1729687100",
"date_modified": "1729687100",
"description": "The optee_os package\n",
"full_url": "https://src.fedoraproject.org/fork/zbyszek/rpms/optee_os",
"fullname": "forks/zbyszek/rpms/optee_os",
"id": 79602,
"milestones": {},
"name": "optee_os",
"namespace": "rpms",
"parent": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": [],
"collaborator": [],
"commit": [],
"owner": ["eballetbo"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1695137284",
"date_modified": "1704875184",
"description": "The optee_os package\n",
"full_url": "https://src.fedoraproject.org/rpms/optee_os",
"fullname": "rpms/optee_os",
"id": 66326,
"milestones": {},
"name": "optee_os",
"namespace": "rpms",
"parent": null,
"priorities": {},
"tags": [],
"url_path": "rpms/optee_os",
"user": {
"full_url": "https://src.fedoraproject.org/user/eballetbo",
"fullname": "Enric Balletbo i Serra",
"name": "eballetbo",
"url_path": "user/eballetbo"
}
},
"priorities": {},
"tags": [],
"url_path": "fork/zbyszek/rpms/optee_os",
"user": {
"full_url": "https://src.fedoraproject.org/user/zbyszek",
"fullname": "Zbigniew J\u0119drzejewski-Szmek",
"name": "zbyszek",
"url_path": "user/zbyszek"
}
},
"status": "Open",
"tags": [],
"threshold_reached": null,
"title": "Only build on aarch64",
"uid": "6bce8aea08204d12a74c2d17ecc505df",
"updated_on": "1729687175",
"user": {
"full_url": "https://src.fedoraproject.org/user/zbyszek",
"fullname": "Zbigniew J\u0119drzejewski-Szmek",
"name": "zbyszek",
"url_path": "user/zbyszek"
}
}
}
140 changes: 140 additions & 0 deletions tests/data/fedmsg/pagure_pr_rebased.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"topic": "org.fedoraproject.prod.pagure.pull-request.rebased",
"agent": "pagure",
"pullrequest": {
"assignee": null,
"branch": "rawhide",
"branch_from": "fedora_plans",
"cached_merge_status": "unknown",
"closed_at": null,
"closed_by": null,
"comments": [],
"commit_start": "196f3c99b21d75bf441331e1a82fb76d243e82d5",
"commit_stop": "196f3c99b21d75bf441331e1a82fb76d243e82d5",
"date_created": "1727942209",
"full_url": "https://src.fedoraproject.org/rpms/ftp/pull-request/6",
"id": 6,
"initial_comment": "Update plans and gating",
"last_updated": "1729685933",
"project": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": ["mruprich"],
"collaborator": [],
"commit": [],
"owner": ["mruprich"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1501867757",
"date_modified": "1507273635",
"description": "The ftp rpms",
"full_url": "https://src.fedoraproject.org/rpms/ftp",
"fullname": "rpms/ftp",
"id": 4014,
"milestones": {},
"name": "ftp",
"namespace": "rpms",
"parent": null,
"priorities": {},
"tags": [],
"url_path": "rpms/ftp",
"user": {
"full_url": "https://src.fedoraproject.org/user/mruprich",
"fullname": "Michal Ruprich",
"name": "mruprich",
"url_path": "user/mruprich"
}
},
"remote_git": null,
"repo_from": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": [],
"collaborator": [],
"commit": [],
"owner": ["omejzlik"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1727942177",
"date_modified": "1727942177",
"description": "The ftp rpms",
"full_url": "https://src.fedoraproject.org/fork/omejzlik/rpms/ftp",
"fullname": "forks/omejzlik/rpms/ftp",
"id": 79045,
"milestones": {},
"name": "ftp",
"namespace": "rpms",
"parent": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": ["mruprich"],
"collaborator": [],
"commit": [],
"owner": ["mruprich"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1501867757",
"date_modified": "1507273635",
"description": "The ftp rpms",
"full_url": "https://src.fedoraproject.org/rpms/ftp",
"fullname": "rpms/ftp",
"id": 4014,
"milestones": {},
"name": "ftp",
"namespace": "rpms",
"parent": null,
"priorities": {},
"tags": [],
"url_path": "rpms/ftp",
"user": {
"full_url": "https://src.fedoraproject.org/user/mruprich",
"fullname": "Michal Ruprich",
"name": "mruprich",
"url_path": "user/mruprich"
}
},
"priorities": {},
"tags": [],
"url_path": "fork/omejzlik/rpms/ftp",
"user": {
"full_url": "https://src.fedoraproject.org/user/omejzlik",
"fullname": "Ond\u0159ej Mejzl\u00edk",
"name": "omejzlik",
"url_path": "user/omejzlik"
}
},
"status": "Open",
"tags": [],
"threshold_reached": null,
"title": "Update plans and gating",
"uid": "0e726e2c759b46a4beee5824dd8e9f39",
"updated_on": "1729589491",
"user": {
"full_url": "https://src.fedoraproject.org/user/omejzlik",
"fullname": "Ond\u0159ej Mejzl\u00edk",
"name": "omejzlik",
"url_path": "user/omejzlik"
}
}
}
Loading

0 comments on commit a72fc6b

Please sign in to comment.