Skip to content

Commit dbebce1

Browse files
committed
Parse Pagure PR events
Fixes #2579
1 parent 4679eed commit dbebce1

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
@@ -194,7 +194,7 @@ def __init__(
194194
base_repo_namespace: str,
195195
base_repo_name: str,
196196
base_repo_owner: str,
197-
base_ref: str,
197+
base_ref: Optional[str],
198198
target_repo: str,
199199
project_url: str,
200200
commit_sha: str,
@@ -228,6 +228,15 @@ def get_base_project(self) -> GitProject:
228228
logger.debug(f"Base project: {fork} owned by {self.base_repo_owner}")
229229
return fork
230230

231+
def get_packages_config(self) -> Optional[PackageConfig]:
232+
return PackageConfigGetter.get_package_config_from_repo(
233+
base_project=self.base_project,
234+
project=self.project,
235+
reference=self.commit_sha,
236+
pr_id=self.pr_id,
237+
fail_when_missing=self.fail_when_config_file_missing,
238+
)
239+
231240

232241
class PullRequestFlagPagureEvent(AbstractPagureEvent):
233242
def __init__(

packit_service/worker/parser.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@
7171
AnityaVersionUpdateEvent,
7272
NewHotnessUpdateEvent,
7373
)
74-
from packit_service.worker.events.pagure import PullRequestFlagPagureEvent
74+
from packit_service.worker.events.pagure import (
75+
PullRequestFlagPagureEvent,
76+
PullRequestPagureEvent,
77+
)
7578
from packit_service.worker.handlers.abstract import MAP_CHECK_PREFIX_TO_HANDLER
7679
from packit_service.worker.helpers.build import CoprBuildJobHelper, KojiBuildJobHelper
7780
from packit_service.worker.helpers.testing_farm import TestingFarmJobHelper
@@ -112,6 +115,7 @@ def parse_event(
112115
PipelineGitlabEvent,
113116
PullRequestFlagPagureEvent,
114117
PullRequestCommentPagureEvent,
118+
PullRequestPagureEvent,
115119
PushPagureEvent,
116120
CheckRerunCommitEvent,
117121
CheckRerunPullRequestEvent,
@@ -173,6 +177,7 @@ def parse_event(
173177
Parser.parse_openscanhub_task_finished_event,
174178
Parser.parse_openscanhub_task_started_event,
175179
Parser.parse_commit_comment_event,
180+
Parser.parse_pagure_pull_request_event,
176181
)
177182
):
178183
if response:
@@ -1703,6 +1708,48 @@ def parse_pagure_pull_request_comment_event(
17031708
comment_id=comment_id,
17041709
)
17051710

1711+
@staticmethod
1712+
def parse_pagure_pull_request_event(
1713+
event,
1714+
) -> Optional[PullRequestPagureEvent]:
1715+
if (topic := event.get("topic", "")) not in (
1716+
"org.fedoraproject.prod.pagure.pull-request.new",
1717+
"org.fedoraproject.prod.pagure.pull-request.updated",
1718+
"org.fedoraproject.prod.pagure.pull-request.rebased",
1719+
):
1720+
return None
1721+
1722+
logger.info(f"Pagure PR event, topic: {topic}")
1723+
1724+
action = (
1725+
PullRequestAction.opened.value
1726+
if topic.endswith("new")
1727+
else PullRequestAction.synchronize.value
1728+
)
1729+
pr_id = event["pullrequest"]["id"]
1730+
pagure_login = event["agent"]
1731+
1732+
base_repo_namespace = event["pullrequest"]["project"]["namespace"]
1733+
base_repo_name = event["pullrequest"]["project"]["name"]
1734+
repo_from = event["pullrequest"]["repo_from"]
1735+
base_repo_owner = repo_from["user"]["name"] if repo_from else pagure_login
1736+
target_repo = repo_from["name"] if repo_from else base_repo_name
1737+
https_url = event["pullrequest"]["project"]["full_url"]
1738+
commit_sha = event["pullrequest"]["commit_stop"]
1739+
1740+
return PullRequestPagureEvent(
1741+
action=PullRequestAction[action],
1742+
pr_id=pr_id,
1743+
base_repo_namespace=base_repo_namespace,
1744+
base_repo_name=base_repo_name,
1745+
base_repo_owner=base_repo_owner,
1746+
base_ref=None,
1747+
target_repo=target_repo,
1748+
project_url=https_url,
1749+
commit_sha=commit_sha,
1750+
user_login=pagure_login,
1751+
)
1752+
17061753
@staticmethod
17071754
def parse_new_hotness_update_event(event) -> Optional[NewHotnessUpdateEvent]:
17081755
if "hotness.update.bug.file" not in event.get("topic", ""):
@@ -1848,6 +1895,9 @@ def parse_openscanhub_task_started_event(
18481895
"pagure.pull-request.flag.added": parse_pagure_pr_flag_event.__func__, # type: ignore
18491896
"pagure.pull-request.flag.updated": parse_pagure_pr_flag_event.__func__, # type: ignore
18501897
"pagure.pull-request.comment.added": parse_pagure_pull_request_comment_event.__func__, # type: ignore
1898+
"pagure.pull-request.new": parse_pagure_pull_request_event.__func__, # type: ignore
1899+
"pagure.pull-request.updated": parse_pagure_pull_request_event.__func__, # type: ignore
1900+
"pagure.pull-request.rebased": parse_pagure_pull_request_event.__func__, # type: ignore
18511901
"pagure.git.receive": parse_pagure_push_event.__func__, # type: ignore
18521902
"copr.build.start": parse_copr_event.__func__, # type: ignore
18531903
"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)