Skip to content

Commit 380ce08

Browse files
committed
Parse Pagure PR events
Fixes #2579
1 parent 772f124 commit 380ce08

File tree

6 files changed

+614
-2
lines changed

6 files changed

+614
-2
lines changed

packit_service/worker/events/pagure.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def __init__(
198198
base_repo_namespace: str,
199199
base_repo_name: str,
200200
base_repo_owner: str,
201-
base_ref: str,
201+
base_ref: Optional[str],
202202
target_repo: str,
203203
project_url: str,
204204
commit_sha: str,
@@ -232,6 +232,15 @@ def get_base_project(self) -> GitProject:
232232
logger.debug(f"Base project: {fork} owned by {self.base_repo_owner}")
233233
return fork
234234

235+
def get_packages_config(self) -> Optional[PackageConfig]:
236+
return PackageConfigGetter.get_package_config_from_repo(
237+
base_project=self.base_project,
238+
project=self.project,
239+
reference=self.commit_sha,
240+
pr_id=self.pr_id,
241+
fail_when_missing=self.fail_when_config_file_missing,
242+
)
243+
235244

236245
class PullRequestFlagPagureEvent(AbstractPagureEvent):
237246
def __init__(

packit_service/worker/parser.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@
7070
AnityaVersionUpdateEvent,
7171
NewHotnessUpdateEvent,
7272
)
73-
from packit_service.worker.events.pagure import PullRequestFlagPagureEvent
73+
from packit_service.worker.events.pagure import (
74+
PullRequestFlagPagureEvent,
75+
PullRequestPagureEvent,
76+
)
7477
from packit_service.worker.handlers.abstract import MAP_CHECK_PREFIX_TO_HANDLER
7578
from packit_service.worker.helpers.build import CoprBuildJobHelper, KojiBuildJobHelper
7679
from packit_service.worker.helpers.testing_farm import TestingFarmJobHelper
@@ -111,6 +114,7 @@ def parse_event(
111114
PipelineGitlabEvent,
112115
PullRequestFlagPagureEvent,
113116
PullRequestCommentPagureEvent,
117+
PullRequestPagureEvent,
114118
PushPagureEvent,
115119
CheckRerunCommitEvent,
116120
CheckRerunPullRequestEvent,
@@ -172,6 +176,7 @@ def parse_event(
172176
Parser.parse_openscanhub_task_finished_event,
173177
Parser.parse_openscanhub_task_started_event,
174178
Parser.parse_commit_comment_event,
179+
Parser.parse_pagure_pull_request_event,
175180
)
176181
):
177182
if response:
@@ -1718,6 +1723,48 @@ def parse_pagure_pull_request_comment_event(
17181723
comment_id=comment_id,
17191724
)
17201725

1726+
@staticmethod
1727+
def parse_pagure_pull_request_event(
1728+
event,
1729+
) -> Optional[PullRequestPagureEvent]:
1730+
if (topic := event.get("topic", "")) not in (
1731+
"org.fedoraproject.prod.pagure.pull-request.new",
1732+
"org.fedoraproject.prod.pagure.pull-request.updated",
1733+
"org.fedoraproject.prod.pagure.pull-request.rebased",
1734+
):
1735+
return None
1736+
1737+
logger.info(f"Pagure PR event, topic: {topic}")
1738+
1739+
action = (
1740+
PullRequestAction.opened.value
1741+
if topic.endswith("new")
1742+
else PullRequestAction.synchronize.value
1743+
)
1744+
pr_id = event["pullrequest"]["id"]
1745+
pagure_login = event["agent"]
1746+
1747+
base_repo_namespace = event["pullrequest"]["project"]["namespace"]
1748+
base_repo_name = event["pullrequest"]["project"]["name"]
1749+
repo_from = event["pullrequest"]["repo_from"]
1750+
base_repo_owner = repo_from["user"]["name"] if repo_from else pagure_login
1751+
target_repo = repo_from["name"] if repo_from else base_repo_name
1752+
https_url = event["pullrequest"]["project"]["full_url"]
1753+
commit_sha = event["pullrequest"]["commit_stop"]
1754+
1755+
return PullRequestPagureEvent(
1756+
action=PullRequestAction[action],
1757+
pr_id=pr_id,
1758+
base_repo_namespace=base_repo_namespace,
1759+
base_repo_name=base_repo_name,
1760+
base_repo_owner=base_repo_owner,
1761+
base_ref=None,
1762+
target_repo=target_repo,
1763+
project_url=https_url,
1764+
commit_sha=commit_sha,
1765+
user_login=pagure_login,
1766+
)
1767+
17211768
@staticmethod
17221769
def parse_new_hotness_update_event(event) -> Optional[NewHotnessUpdateEvent]:
17231770
if "hotness.update.bug.file" not in event.get("topic", ""):
@@ -1865,6 +1912,9 @@ def parse_openscanhub_task_started_event(
18651912
"pagure.pull-request.flag.added": parse_pagure_pr_flag_event.__func__, # type: ignore
18661913
"pagure.pull-request.flag.updated": parse_pagure_pr_flag_event.__func__, # type: ignore
18671914
"pagure.pull-request.comment.added": parse_pagure_pull_request_comment_event.__func__, # type: ignore # noqa: E501
1915+
"pagure.pull-request.new": parse_pagure_pull_request_event.__func__, # type: ignore # noqa: E501
1916+
"pagure.pull-request.updated": parse_pagure_pull_request_event.__func__, # type: ignore # noqa: E501
1917+
"pagure.pull-request.rebased": parse_pagure_pull_request_event.__func__, # type: ignore # noqa: E501
18681918
"pagure.git.receive": parse_pagure_push_event.__func__, # type: ignore
18691919
"copr.build.start": parse_copr_event.__func__, # type: ignore
18701920
"copr.build.end": parse_copr_event.__func__, # type: ignore
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"topic": "org.fedoraproject.prod.pagure.pull-request.new",
3+
"agent": "zbyszek",
4+
"pullrequest": {
5+
"assignee": null,
6+
"branch": "rawhide",
7+
"branch_from": "build-only-on-aarch64",
8+
"cached_merge_status": "unknown",
9+
"closed_at": null,
10+
"closed_by": null,
11+
"comments": [],
12+
"commit_start": "889f07af35d27bbcaf9c535c17a63b974aa42ee3",
13+
"commit_stop": "889f07af35d27bbcaf9c535c17a63b974aa42ee3",
14+
"date_created": "1729687175",
15+
"full_url": "https://src.fedoraproject.org/rpms/optee_os/pull-request/2",
16+
"id": 2,
17+
"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.",
18+
"last_updated": "1729687175",
19+
"project": {
20+
"access_groups": {
21+
"admin": [],
22+
"collaborator": [],
23+
"commit": [],
24+
"ticket": []
25+
},
26+
"access_users": {
27+
"admin": [],
28+
"collaborator": [],
29+
"commit": [],
30+
"owner": ["eballetbo"],
31+
"ticket": []
32+
},
33+
"close_status": [],
34+
"custom_keys": [],
35+
"date_created": "1695137284",
36+
"date_modified": "1704875184",
37+
"description": "The optee_os package\n",
38+
"full_url": "https://src.fedoraproject.org/rpms/optee_os",
39+
"fullname": "rpms/optee_os",
40+
"id": 66326,
41+
"milestones": {},
42+
"name": "optee_os",
43+
"namespace": "rpms",
44+
"parent": null,
45+
"priorities": {},
46+
"tags": [],
47+
"url_path": "rpms/optee_os",
48+
"user": {
49+
"full_url": "https://src.fedoraproject.org/user/eballetbo",
50+
"fullname": "Enric Balletbo i Serra",
51+
"name": "eballetbo",
52+
"url_path": "user/eballetbo"
53+
}
54+
},
55+
"remote_git": null,
56+
"repo_from": {
57+
"access_groups": {
58+
"admin": [],
59+
"collaborator": [],
60+
"commit": [],
61+
"ticket": []
62+
},
63+
"access_users": {
64+
"admin": [],
65+
"collaborator": [],
66+
"commit": [],
67+
"owner": ["zbyszek"],
68+
"ticket": []
69+
},
70+
"close_status": [],
71+
"custom_keys": [],
72+
"date_created": "1729687100",
73+
"date_modified": "1729687100",
74+
"description": "The optee_os package\n",
75+
"full_url": "https://src.fedoraproject.org/fork/zbyszek/rpms/optee_os",
76+
"fullname": "forks/zbyszek/rpms/optee_os",
77+
"id": 79602,
78+
"milestones": {},
79+
"name": "optee_os",
80+
"namespace": "rpms",
81+
"parent": {
82+
"access_groups": {
83+
"admin": [],
84+
"collaborator": [],
85+
"commit": [],
86+
"ticket": []
87+
},
88+
"access_users": {
89+
"admin": [],
90+
"collaborator": [],
91+
"commit": [],
92+
"owner": ["eballetbo"],
93+
"ticket": []
94+
},
95+
"close_status": [],
96+
"custom_keys": [],
97+
"date_created": "1695137284",
98+
"date_modified": "1704875184",
99+
"description": "The optee_os package\n",
100+
"full_url": "https://src.fedoraproject.org/rpms/optee_os",
101+
"fullname": "rpms/optee_os",
102+
"id": 66326,
103+
"milestones": {},
104+
"name": "optee_os",
105+
"namespace": "rpms",
106+
"parent": null,
107+
"priorities": {},
108+
"tags": [],
109+
"url_path": "rpms/optee_os",
110+
"user": {
111+
"full_url": "https://src.fedoraproject.org/user/eballetbo",
112+
"fullname": "Enric Balletbo i Serra",
113+
"name": "eballetbo",
114+
"url_path": "user/eballetbo"
115+
}
116+
},
117+
"priorities": {},
118+
"tags": [],
119+
"url_path": "fork/zbyszek/rpms/optee_os",
120+
"user": {
121+
"full_url": "https://src.fedoraproject.org/user/zbyszek",
122+
"fullname": "Zbigniew J\u0119drzejewski-Szmek",
123+
"name": "zbyszek",
124+
"url_path": "user/zbyszek"
125+
}
126+
},
127+
"status": "Open",
128+
"tags": [],
129+
"threshold_reached": null,
130+
"title": "Only build on aarch64",
131+
"uid": "6bce8aea08204d12a74c2d17ecc505df",
132+
"updated_on": "1729687175",
133+
"user": {
134+
"full_url": "https://src.fedoraproject.org/user/zbyszek",
135+
"fullname": "Zbigniew J\u0119drzejewski-Szmek",
136+
"name": "zbyszek",
137+
"url_path": "user/zbyszek"
138+
}
139+
}
140+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
{
2+
"topic": "org.fedoraproject.prod.pagure.pull-request.rebased",
3+
"agent": "pagure",
4+
"pullrequest": {
5+
"assignee": null,
6+
"branch": "rawhide",
7+
"branch_from": "fedora_plans",
8+
"cached_merge_status": "unknown",
9+
"closed_at": null,
10+
"closed_by": null,
11+
"comments": [],
12+
"commit_start": "196f3c99b21d75bf441331e1a82fb76d243e82d5",
13+
"commit_stop": "196f3c99b21d75bf441331e1a82fb76d243e82d5",
14+
"date_created": "1727942209",
15+
"full_url": "https://src.fedoraproject.org/rpms/ftp/pull-request/6",
16+
"id": 6,
17+
"initial_comment": "Update plans and gating",
18+
"last_updated": "1729685933",
19+
"project": {
20+
"access_groups": {
21+
"admin": [],
22+
"collaborator": [],
23+
"commit": [],
24+
"ticket": []
25+
},
26+
"access_users": {
27+
"admin": ["mruprich"],
28+
"collaborator": [],
29+
"commit": [],
30+
"owner": ["mruprich"],
31+
"ticket": []
32+
},
33+
"close_status": [],
34+
"custom_keys": [],
35+
"date_created": "1501867757",
36+
"date_modified": "1507273635",
37+
"description": "The ftp rpms",
38+
"full_url": "https://src.fedoraproject.org/rpms/ftp",
39+
"fullname": "rpms/ftp",
40+
"id": 4014,
41+
"milestones": {},
42+
"name": "ftp",
43+
"namespace": "rpms",
44+
"parent": null,
45+
"priorities": {},
46+
"tags": [],
47+
"url_path": "rpms/ftp",
48+
"user": {
49+
"full_url": "https://src.fedoraproject.org/user/mruprich",
50+
"fullname": "Michal Ruprich",
51+
"name": "mruprich",
52+
"url_path": "user/mruprich"
53+
}
54+
},
55+
"remote_git": null,
56+
"repo_from": {
57+
"access_groups": {
58+
"admin": [],
59+
"collaborator": [],
60+
"commit": [],
61+
"ticket": []
62+
},
63+
"access_users": {
64+
"admin": [],
65+
"collaborator": [],
66+
"commit": [],
67+
"owner": ["omejzlik"],
68+
"ticket": []
69+
},
70+
"close_status": [],
71+
"custom_keys": [],
72+
"date_created": "1727942177",
73+
"date_modified": "1727942177",
74+
"description": "The ftp rpms",
75+
"full_url": "https://src.fedoraproject.org/fork/omejzlik/rpms/ftp",
76+
"fullname": "forks/omejzlik/rpms/ftp",
77+
"id": 79045,
78+
"milestones": {},
79+
"name": "ftp",
80+
"namespace": "rpms",
81+
"parent": {
82+
"access_groups": {
83+
"admin": [],
84+
"collaborator": [],
85+
"commit": [],
86+
"ticket": []
87+
},
88+
"access_users": {
89+
"admin": ["mruprich"],
90+
"collaborator": [],
91+
"commit": [],
92+
"owner": ["mruprich"],
93+
"ticket": []
94+
},
95+
"close_status": [],
96+
"custom_keys": [],
97+
"date_created": "1501867757",
98+
"date_modified": "1507273635",
99+
"description": "The ftp rpms",
100+
"full_url": "https://src.fedoraproject.org/rpms/ftp",
101+
"fullname": "rpms/ftp",
102+
"id": 4014,
103+
"milestones": {},
104+
"name": "ftp",
105+
"namespace": "rpms",
106+
"parent": null,
107+
"priorities": {},
108+
"tags": [],
109+
"url_path": "rpms/ftp",
110+
"user": {
111+
"full_url": "https://src.fedoraproject.org/user/mruprich",
112+
"fullname": "Michal Ruprich",
113+
"name": "mruprich",
114+
"url_path": "user/mruprich"
115+
}
116+
},
117+
"priorities": {},
118+
"tags": [],
119+
"url_path": "fork/omejzlik/rpms/ftp",
120+
"user": {
121+
"full_url": "https://src.fedoraproject.org/user/omejzlik",
122+
"fullname": "Ond\u0159ej Mejzl\u00edk",
123+
"name": "omejzlik",
124+
"url_path": "user/omejzlik"
125+
}
126+
},
127+
"status": "Open",
128+
"tags": [],
129+
"threshold_reached": null,
130+
"title": "Update plans and gating",
131+
"uid": "0e726e2c759b46a4beee5824dd8e9f39",
132+
"updated_on": "1729589491",
133+
"user": {
134+
"full_url": "https://src.fedoraproject.org/user/omejzlik",
135+
"fullname": "Ond\u0159ej Mejzl\u00edk",
136+
"name": "omejzlik",
137+
"url_path": "user/omejzlik"
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)