Skip to content

Commit bd38a84

Browse files
Migrate to org.fedoraproject.prod.pagure.git.receive (#2351)
Migrate to org.fedoraproject.prod.pagure.git.receive Supersedes #2303 Related to #2305 RELEASE NOTES BEGIN N/A RELEASE NOTES END Reviewed-by: Laura Barcziová Reviewed-by: Nikola Forró
2 parents a439cb5 + 8a8d1e1 commit bd38a84

File tree

9 files changed

+90
-135
lines changed

9 files changed

+90
-135
lines changed

packit_service/worker/checker/distgit.py

+4-30
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,6 @@ def pre_check(self) -> bool:
4141

4242

4343
class PermissionOnDistgit(Checker, GetPagurePullRequestMixin):
44-
def contains_specfile_change(self):
45-
"""
46-
Check whether the dist-git commit contains
47-
any specfile change (do the check only for pushes from PRs,
48-
with direct pushes we do the filtering in fedmsg).
49-
"""
50-
if not self.pull_request:
51-
return True
52-
53-
pr_id = self.pull_request.id
54-
logger.debug(f"PR {pr_id} status: {self.pull_request.status}")
55-
# Pagure API tends to return ENOPRSTATS error when a pull request is transitioning
56-
# from open to merged state, give it some extra time
57-
diff = self.project.get_pr_files_diff(pr_id, retries=7, wait_seconds=7) or {}
58-
if not any(change.endswith(".spec") for change in diff):
59-
logger.info(f"PR {pr_id} does not contain a specfile change.")
60-
return False
61-
return True
62-
6344
@staticmethod
6445
def is_koji_allowed_accounts_alias(value: str) -> bool:
6546
return any(value == alias.value for alias in KojiAllowedAccountsAlias)
@@ -139,17 +120,7 @@ def pre_check(self) -> bool:
139120
)
140121
return False
141122

142-
if self.data.event_dict["committer"] == "pagure":
143-
if not self.pull_request:
144-
logger.debug(
145-
"Not able to get the pull request "
146-
"(may not be the head commit of the PR)."
147-
)
148-
return False
149-
150-
if not self.contains_specfile_change():
151-
return False
152-
123+
if self.pull_request:
153124
pr_author = self.get_pr_author()
154125
logger.debug(f"PR author: {pr_author}")
155126
if not self.check_allowed_accounts(
@@ -162,6 +133,9 @@ def pre_check(self) -> bool:
162133
)
163134
return False
164135
else:
136+
logger.debug(
137+
"Not able to get the pull request, we are handling direct push."
138+
)
165139
committer = self.data.event_dict["committer"]
166140
logger.debug(f"Committer: {committer}")
167141
if not self.check_allowed_accounts(

packit_service/worker/events/enums.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ class IssueCommentAction(Enum):
2828

2929

3030
class FedmsgTopic(Enum):
31-
dist_git_push = "org.fedoraproject.prod.git.receive"
31+
dist_git_push = "org.fedoraproject.prod.pagure.git.receive"
3232
copr_build_finished = "org.fedoraproject.prod.copr.build.end"
3333
copr_build_started = "org.fedoraproject.prod.copr.build.start"

packit_service/worker/handlers/distgit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class AbortSyncRelease(Exception):
504504
@reacts_to(event=AbstractIssueCommentEvent)
505505
@reacts_to(event=CheckRerunReleaseEvent)
506506
class ProposeDownstreamHandler(AbstractSyncReleaseHandler):
507-
topic = "org.fedoraproject.prod.git.receive"
507+
topic = "org.fedoraproject.prod.pagure.git.receive"
508508
task_name = TaskName.propose_downstream
509509
helper_kls = ProposeDownstreamJobHelper
510510
sync_release_job_type = SyncReleaseJobType.propose_downstream
@@ -664,7 +664,7 @@ class AbstractDownstreamKojiBuildHandler(
664664
This handler can submit a build in Koji from a dist-git.
665665
"""
666666

667-
topic = "org.fedoraproject.prod.git.receive"
667+
topic = "org.fedoraproject.prod.pagure.git.receive"
668668
task_name = TaskName.downstream_koji_build
669669

670670
def __init__(

packit_service/worker/mixin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class GetPagurePullRequestMixin(GetPagurePullRequest):
254254

255255
@property
256256
def pull_request(self):
257-
if not self._pull_request and self.data.event_dict["committer"] == "pagure":
257+
if not self._pull_request:
258258
logger.debug(
259259
f"Getting pull request with head commit {self.data.commit_sha}"
260260
f"for repo {self.project.namespace}/{self.project.repo}"

packit_service/worker/parser.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1078,25 +1078,25 @@ def parse_release_event(event) -> Optional[ReleaseEvent]:
10781078
def parse_pagure_push_event(event) -> Optional[PushPagureEvent]:
10791079
"""this corresponds to dist-git event when someone pushes new commits"""
10801080
topic = event.get("topic")
1081-
if topic != "org.fedoraproject.prod.git.receive":
1081+
if topic != "org.fedoraproject.prod.pagure.git.receive":
10821082
return None
10831083

10841084
logger.info(f"Dist-git commit event, topic: {topic}")
10851085

1086-
dg_repo_namespace = nested_get(event, "commit", "namespace")
1087-
dg_repo_name = nested_get(event, "commit", "repo")
1086+
dg_repo_namespace = nested_get(event, "repo", "namespace")
1087+
dg_repo_name = nested_get(event, "repo", "name")
10881088

10891089
if not (dg_repo_namespace and dg_repo_name):
10901090
logger.warning("No full name of the repository.")
10911091
return None
10921092

1093-
dg_branch = nested_get(event, "commit", "branch")
1094-
dg_commit = nested_get(event, "commit", "rev")
1093+
dg_branch = nested_get(event, "branch")
1094+
dg_commit = nested_get(event, "end_commit")
10951095
if not (dg_branch and dg_commit):
10961096
logger.warning("Target branch/rev for the new commits is not set.")
10971097
return None
10981098

1099-
username = nested_get(event, "commit", "username")
1099+
username = nested_get(event, "agent")
11001100

11011101
logger.info(
11021102
f"New commits added to dist-git repo {dg_repo_namespace}/{dg_repo_name},"
@@ -1591,7 +1591,7 @@ def parse_new_hotness_update_event(event) -> Optional[NewHotnessUpdateEvent]:
15911591
"pagure.pull-request.flag.added": parse_pagure_pr_flag_event.__func__, # type: ignore
15921592
"pagure.pull-request.flag.updated": parse_pagure_pr_flag_event.__func__, # type: ignore
15931593
"pagure.pull-request.comment.added": parse_pagure_pull_request_comment_event.__func__, # type: ignore # noqa: E501
1594-
"git.receive": parse_pagure_push_event.__func__, # type: ignore
1594+
"pagure.git.receive": parse_pagure_push_event.__func__, # type: ignore
15951595
"copr.build.start": parse_copr_event.__func__, # type: ignore
15961596
"copr.build.end": parse_copr_event.__func__, # type: ignore
15971597
"buildsys.task.state.change": parse_koji_task_event.__func__, # type: ignore

tests/data/fedmsg/distgit_commit.json

+8-39
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,11 @@
11
{
2-
"topic": "org.fedoraproject.prod.git.receive",
3-
"commit": {
4-
"agent": "rhcontainerbot",
5-
"branch": "main",
6-
"email": "[email protected]",
7-
"message": "buildah-1.12.0-0.73.dev.git1e6a70c\n\n- autobuilt 1e6a70c\n\nSigned-off-by: RH Container Bot <[email protected]>\n",
8-
"name": "Packit",
2+
"agent": "rhcontainerbot",
3+
"branch": "main",
4+
"end_commit": "abcd",
5+
"total_commits": 1,
6+
"repo": {
97
"namespace": "rpms",
10-
"path": "/srv/git/repositories/rpms/buildah.git",
11-
"repo": "buildah",
12-
"rev": "abcd",
13-
"seen": false,
14-
"stats": {
15-
"files": {
16-
".gitignore": {
17-
"additions": 1,
18-
"deletions": 0,
19-
"lines": 1
20-
},
21-
"buildah.spec": {
22-
"additions": 5,
23-
"deletions": 2,
24-
"lines": 7
25-
},
26-
"sources": {
27-
"additions": 1,
28-
"deletions": 1,
29-
"lines": 2
30-
}
31-
},
32-
"total": {
33-
"additions": 7,
34-
"deletions": 3,
35-
"files": 3,
36-
"lines": 10
37-
}
38-
},
39-
"summary": "buildah-1.12.0-0.73.dev.git1e6a70c",
40-
"username": "rhcontainerbot"
41-
}
8+
"name": "buildah"
9+
},
10+
"topic": "org.fedoraproject.prod.pagure.git.receive"
4211
}
+7-48
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,11 @@
11
{
2-
"commit": {
3-
"agent": "pagure",
4-
"branch": "f36",
5-
"email": "[email protected]",
6-
"message": "[packit] 0.50.0 upstream release\n\nUpstream tag: 0.50.0\nUpstream commit: c3667a91\n\nSigned-off-by: Packit <[email protected]>\n",
7-
"name": "Packit",
2+
"agent": "pagure",
3+
"branch": "f36",
4+
"end_commit": "ad0c308af91da45cf40b253cd82f07f63ea9cbbf",
5+
"total_commits": 1,
6+
"repo": {
87
"namespace": "rpms",
9-
"path": "/srv/git/repositories/rpms/packit.git",
10-
"repo": "packit",
11-
"rev": "ad0c308af91da45cf40b253cd82f07f63ea9cbbf",
12-
"seen": false,
13-
"stats": {
14-
"files": {
15-
".gitignore": {
16-
"additions": 1,
17-
"deletions": 0,
18-
"lines": 1
19-
},
20-
"README.packit": {
21-
"additions": 1,
22-
"deletions": 1,
23-
"lines": 2
24-
},
25-
"packit.spec": {
26-
"additions": 9,
27-
"deletions": 1,
28-
"lines": 10
29-
},
30-
"plans/main.fmf": {
31-
"additions": 1,
32-
"deletions": 1,
33-
"lines": 2
34-
},
35-
"sources": {
36-
"additions": 1,
37-
"deletions": 1,
38-
"lines": 2
39-
}
40-
},
41-
"total": {
42-
"additions": 13,
43-
"deletions": 4,
44-
"files": 5,
45-
"lines": 17
46-
}
47-
},
48-
"summary": "[packit] 0.50.0 upstream release",
49-
"username": "pagure"
8+
"name": "packit"
509
},
51-
"topic": "org.fedoraproject.prod.git.receive"
10+
"topic": "org.fedoraproject.prod.pagure.git.receive"
5211
}

tests/integration/test_dg_commit.py

+60-2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ def test_downstream_koji_build_failure_no_issue():
288288
get_web_url=lambda: "https://src.fedoraproject.org/rpms/buildah",
289289
default_branch="main",
290290
)
291+
flexmock(PagureProject).should_receive("get_pr_list").and_return(
292+
[
293+
flexmock(
294+
id=5,
295+
author="author",
296+
head_commit="not-the-same-commit-hash",
297+
status=PRStatus.open,
298+
)
299+
]
300+
)
291301
pagure_project_mock.should_receive("get_files").with_args(
292302
ref="main", filter_regex=r".+\.spec$"
293303
).and_return(["buildah.spec"])
@@ -377,6 +387,16 @@ def test_downstream_koji_build_failure_issue_created():
377387
get_web_url=lambda: "https://src.fedoraproject.org/rpms/buildah",
378388
default_branch="main",
379389
)
390+
flexmock(PagureProject).should_receive("get_pr_list").and_return(
391+
[
392+
flexmock(
393+
id=5,
394+
author="author",
395+
head_commit="not-the-same-commit-hash",
396+
status=PRStatus.open,
397+
)
398+
]
399+
)
380400
pagure_project_mock.should_receive("get_files").with_args(
381401
ref="main", filter_regex=r".+\.spec$"
382402
).and_return(["buildah.spec"])
@@ -472,6 +492,16 @@ def test_downstream_koji_build_failure_issue_comment():
472492
get_web_url=lambda: "https://src.fedoraproject.org/rpms/buildah",
473493
default_branch="main",
474494
)
495+
flexmock(PagureProject).should_receive("get_pr_list").and_return(
496+
[
497+
flexmock(
498+
id=5,
499+
author="author",
500+
head_commit="not-the-same-commit-hash",
501+
status=PRStatus.open,
502+
)
503+
]
504+
)
475505
pagure_project_mock.should_receive("get_files").with_args(
476506
ref="main", filter_regex=r".+\.spec$"
477507
).and_return(["buildah.spec"])
@@ -570,6 +600,16 @@ def test_downstream_koji_build_no_config():
570600
get_web_url=lambda: "https://src.fedoraproject.org/rpms/buildah",
571601
default_branch="main",
572602
)
603+
flexmock(PagureProject).should_receive("get_pr_list").and_return(
604+
[
605+
flexmock(
606+
id=5,
607+
author="author",
608+
head_commit="not-the-same-commit-hash",
609+
status=PRStatus.open,
610+
)
611+
]
612+
)
573613
pagure_project.should_receive("get_files").with_args(
574614
ref="main", filter_regex=r".+\.spec$"
575615
).and_return(["buildah.spec"])
@@ -642,6 +682,16 @@ def test_downstream_koji_build_where_multiple_branches_defined(jobs_config):
642682
f"'jobs': {jobs_config},"
643683
"'downstream_package_name': 'buildah'}"
644684
)
685+
flexmock(PagureProject).should_receive("get_pr_list").and_return(
686+
[
687+
flexmock(
688+
id=5,
689+
author="author",
690+
head_commit="not-the-same-commit-hash",
691+
status=PRStatus.open,
692+
)
693+
]
694+
)
645695
pagure_project = flexmock(
646696
PagureProject,
647697
full_repo_name="rpms/buildah",
@@ -817,6 +867,16 @@ def test_precheck_koji_build_push(
817867
distgit_push_event, push_username, allowed_committers, should_pass
818868
):
819869
distgit_push_event.committer = push_username
870+
flexmock(PagureProject).should_receive("get_pr_list").and_return(
871+
[
872+
flexmock(
873+
id=5,
874+
author="author",
875+
head_commit="not-the-same-commit-hash",
876+
status=PRStatus.open,
877+
)
878+
]
879+
)
820880

821881
flexmock(GitProjectModel).should_receive("get_or_create").with_args(
822882
namespace="rpms",
@@ -884,8 +944,6 @@ def test_precheck_koji_build_push_pr(
884944
allowed_pr_authors,
885945
should_pass,
886946
):
887-
distgit_push_event.committer = "pagure"
888-
889947
flexmock(GitProjectModel).should_receive("get_or_create").with_args(
890948
namespace="rpms",
891949
project_url="https://src.fedoraproject.org/rpms/packit",

tests/unit/test_events.py

-5
Original file line numberDiff line numberDiff line change
@@ -1454,11 +1454,6 @@ def test_distgit_pagure_push(self, distgit_commit):
14541454
assert event_object.git_ref == "main"
14551455
assert event_object.project_url == "https://src.fedoraproject.org/rpms/buildah"
14561456

1457-
def test_distgit_pagure_push_packit(self, distgit_push_packit):
1458-
event_object = Parser.parse_event(distgit_push_packit)
1459-
assert isinstance(event_object, PushPagureEvent)
1460-
assert event_object.committer == "pagure"
1461-
14621457
def test_json_testing_farm_notification(
14631458
self, testing_farm_notification, testing_farm_results
14641459
):

0 commit comments

Comments
 (0)