Skip to content

Commit

Permalink
Migrate to org.fedoraproject.prod.pagure.git.receive
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarcziova committed Feb 16, 2024
1 parent 3f4773e commit d29df6e
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 66 deletions.
18 changes: 6 additions & 12 deletions packit_service_fedmsg/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,17 @@ def _koji(topic: str, event: dict, packit_user: str) -> CallbackResult:


def _fedora_dg_push(topic: str, event: dict, packit_user: str) -> CallbackResult:
if (
getenv("PROJECT", "").startswith("packit")
# skip the specfile changed check for commits from PRs
and nested_get(event, "commit", "agent") != "pagure"
and not specfile_changed(
event,
)
if getenv("PROJECT", "").startswith("packit") and not specfile_changed(
event,
):
return CallbackResult(
msg="[Fedora DG] No specfile change, ignoring the push.",
pass_to_service=False,
)

if commit := event.get("commit"):
what = f"{commit.get('repo')} {commit.get('rev')}@{commit.get('branch')}"
else:
what = "Couldn't get commit out of the event."
repo_name = nested_get(event, "repo", "name")

what = f"{repo_name} {event.get('end_commit')}@{event.get('branch')}"

return CallbackResult(msg=f"[Fedora DG] Passing push: {what}")

Expand Down Expand Up @@ -173,7 +167,7 @@ def _anitya_version_update(topic: str, event: dict, packit_user: str) -> Callbac
"org.fedoraproject.prod.copr.build.start": _copr,
"org.fedoraproject.prod.buildsys.task.state.change": _koji,
"org.fedoraproject.prod.buildsys.build.state.change": _koji,
"org.fedoraproject.prod.git.receive": _fedora_dg_push,
"org.fedoraproject.prod.pagure.git.receive": _fedora_dg_push,
"org.fedoraproject.prod.pagure.pull-request.flag.added": _fedora_dg_pr_flag,
"org.fedoraproject.prod.pagure.pull-request.flag.updated": _fedora_dg_pr_flag,
"org.fedoraproject.prod.pagure.pull-request.comment.added": _fedora_dg_pr_comment,
Expand Down
7 changes: 1 addition & 6 deletions packit_service_fedmsg/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from functools import reduce
from typing import Any


Expand Down Expand Up @@ -41,11 +40,7 @@ def specfile_changed(body: dict) -> bool:
Returns:
`True` if the specfile has changed, `False` otherwise.
"""
files = reduce(
lambda val, key: val.get(key) if val else None,
["commit", "stats", "files"],
body,
)
files = body.get("changed_files")
file_names = files.keys() if files else []

return any(file_name.endswith(".spec") for file_name in file_names)
107 changes: 107 additions & 0 deletions tests/data/git_receive.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"body": {
"agent": "cathay4t",
"authors": [
{
"fullname": "Packit",
"name": null,
"url_path": null
},
{
"full_url": "https://src.fedoraproject.org/user/yselkowitz",
"fullname": "Yaakov Selkowitz",
"name": "yselkowitz",
"url_path": "user/yselkowitz"
}
],
"branch": "1.2.17-rawhide-update-pull_from_upstream",
"changed_files": {
"nispor.spec": "M"
},
"end_commit": "e134a94872e6cdf0b421667bef35843ffc2e2794",
"forced": true,
"old_commit": "04c956ebf012f0e053dced9275d5c8ebdd080edd",
"repo": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": [],
"collaborator": [],
"commit": ["cathay4t", "ffmancera"],
"owner": ["packit"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1695187712",
"date_modified": "1701990754",
"description": "The nispor package\n",
"full_url": "https://src.fedoraproject.org/fork/packit/rpms/nispor",
"fullname": "forks/packit/rpms/nispor",
"id": 66339,
"milestones": {},
"name": "nispor",
"namespace": "rpms",
"parent": {
"access_groups": {
"admin": [],
"collaborator": [],
"commit": [],
"ticket": []
},
"access_users": {
"admin": ["ffmancera"],
"collaborator": [],
"commit": [],
"owner": ["cathay4t"],
"ticket": []
},
"close_status": [],
"custom_keys": [],
"date_created": "1599236259",
"date_modified": "1603815379",
"description": "The nispor package\n",
"full_url": "https://src.fedoraproject.org/rpms/nispor",
"fullname": "rpms/nispor",
"id": 45300,
"milestones": {},
"name": "nispor",
"namespace": "rpms",
"parent": null,
"priorities": {},
"tags": [],
"url_path": "rpms/nispor",
"user": {
"full_url": "https://src.fedoraproject.org/user/cathay4t",
"fullname": "Gris Ge",
"name": "cathay4t",
"url_path": "user/cathay4t"
}
},
"priorities": {},
"tags": [],
"url_path": "fork/packit/rpms/nispor",
"user": {
"full_url": "https://src.fedoraproject.org/user/packit",
"fullname": "Packit Bot",
"name": "packit",
"url_path": "user/packit"
}
},
"start_commit": "a80772d8fdc093a2080bda050daf4e66bff585eb",
"total_commits": 2
},
"headers": {
"fedora_messaging_schema": "pagure.git.receive",
"fedora_messaging_severity": 20,
"fedora_messaging_user_cathay4t": true,
"sent-at": "2024-02-08T07:29:14+00:00"
},
"id": "d98e4f3f-2e6a-4634-b86b-8abbae9c54d3",
"queue": null,
"topic": "org.fedoraproject.prod.pagure.git.receive"
}
17 changes: 17 additions & 0 deletions tests/test_git_receive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json

from celery import Celery
from fedora_messaging import message
from flexmock import flexmock

from packit_service_fedmsg.consumer import Consumerino
from tests.spellbook import DATA_DIR


def test_git_receive():
flexmock(Celery).should_receive("send_task").and_return(flexmock(id="a")).once()
with open(DATA_DIR / "git_receive.json") as outfile:
json_msg = json.load(outfile)
msg = message.loads(json.dumps(json_msg))
c = Consumerino()
c(msg[0])
53 changes: 5 additions & 48 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,23 @@
("body", "expected"),
[
pytest.param(
{
"commit": {
"stats": {
"files": {
".gitignore": {"additions": 1, "deletions": 0, "lines": 1},
"buildah.spec": {
"additions": 5,
"deletions": 2,
"lines": 7,
},
"sources": {"additions": 1, "deletions": 1, "lines": 2},
},
"total": {
"additions": 7,
"deletions": 3,
"files": 3,
"lines": 10,
},
},
"summary": "buildah-1.12.0-0.73.dev.git1e6a70c",
"username": "rhcontainerbot",
},
},
{"changed_files": {"nispor.spec": "M"}},
True,
),
pytest.param(
{
"commit": {
"stats": {
"files": {
".gitignore": {"additions": 1, "deletions": 0, "lines": 1},
"sources": {"additions": 1, "deletions": 1, "lines": 2},
},
"total": {
"additions": 7,
"deletions": 3,
"files": 3,
"lines": 10,
},
},
"summary": "buildah-1.12.0-0.73.dev.git1e6a70c",
"username": "rhcontainerbot",
},
},
False,
{"changed_files": {"README.packit": "M", "nispor.spec": "M"}},
True,
),
pytest.param({}, False),
pytest.param(
{
"commit": {
"stats": {},
"summary": "buildah-1.12.0-0.73.dev.git1e6a70c",
"username": "rhcontainerbot",
},
"changed_files": {"README.md": "M"},
},
False,
),
pytest.param(
{
"commit": {},
"changed_files": {},
},
False,
),
Expand Down

0 comments on commit d29df6e

Please sign in to comment.