Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle both started and finished OpenScanHub events #114

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packit_service_fedmsg/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,19 @@ def _openscanhub_task_finished(
packit_user: str,
) -> CallbackResult:
return CallbackResult(
msg=f"[OpenScanHub] OpenScanHub task {event.get('task_id')} finished:"
f" added.js={event.get('added.js')}, fixed.js={event.get('fixed.js')}",
msg=f"[OpenScanHub] OpenScanHub task {event.get('task_id')} "
f"finished with status {event.get('status')}: "
f"added.js={event.get('added.js')}, fixed.js={event.get('fixed.js')}.",
)


def _openscanhub_task_started(
topic: str,
event: dict,
packit_user: str,
) -> CallbackResult:
return CallbackResult(
msg=f"[OpenScanHub] OpenScanHub task {event.get('task_id')} started.",
)


Expand All @@ -204,5 +215,6 @@ def _openscanhub_task_finished(
"org.fedoraproject.prod.pagure.pull-request.closed": _fedora_dg_pr_closed,
"org.fedoraproject.prod.hotness.update.bug.file": _hotness_bugzilla,
"org.release-monitoring.prod.anitya.project.version.update.v2": _anitya_version_update,
"org.fedoraproject.prod.openscanhub.task.finish": _openscanhub_task_finished,
"org.fedoraproject.prod.openscanhub.task.started": _openscanhub_task_started,
"org.fedoraproject.prod.openscanhub.task.finished": _openscanhub_task_finished,
}
16 changes: 8 additions & 8 deletions tests/data/openscanhub_task_finished.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"body": {
"added.js": "http://openscanhub.fedoraproject.org/task/15649/log/added.js?format=raw",
"fixed.js": "http://openscanhub.fedoraproject.org/task/15649/log/fixed.js?format=raw",
"scan-results.js": "http://openscanhub.fedoraproject.org/task/15649/log/gvisor-tap-vsock-0.7.5-1.20241007054606793155.pr405.23.g829aafd6/scan-results.js?format=raw",
"task_id": 15649
"added.js": "http://openscanhub.fedoraproject.org/task/18302/log/added.js?format=raw",
"fixed.js": "http://openscanhub.fedoraproject.org/task/18302/log/fixed.js?format=raw",
"scan-results.js": "http://openscanhub.fedoraproject.org/task/18302/log/podman-5.3.0~dev-1.20241020030546559147.pr24321.1796.24c178f39/scan-results.js?format=raw",
"status": "success",
"task_id": 18302
},
"headers": {
"fedora_messaging_schema": "base.message",
"fedora_messaging_severity": 20,
"priority": 0,
"sent-at": "2024-10-07T06:03:21+00:00",
"task_id": 15649
"sent-at": "2024-10-20T03:44:53+00:00"
},
"id": "631f77b4-74f8-41ca-b3e7-47401e30cc67",
"id": "36b9d2be-5452-467d-8503-d68462e8aa74",
"priority": 0,
"queue": null,
"topic": "org.fedoraproject.prod.openscanhub.task.finish"
"topic": "org.fedoraproject.prod.openscanhub.task.finished"
}
15 changes: 15 additions & 0 deletions tests/data/openscanhub_task_started.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"body": {
"task_id": 18304
},
"headers": {
"fedora_messaging_schema": "base.message",
"fedora_messaging_severity": 20,
"priority": 0,
"sent-at": "2024-10-20T07:58:23+00:00"
},
"id": "39d00df3-a8d0-40be-b555-970e9259fb69",
"priority": 0,
"queue": null,
"topic": "org.fedoraproject.prod.openscanhub.task.started"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
from tests.spellbook import DATA_DIR


def test_task_finished_event():
flexmock(Celery).should_receive("send_task").and_return(flexmock(id="a")).once()
with open(DATA_DIR / "openscanhub_task_finished.json") as outfile:
json_msg = json.load(outfile)
msg = message.loads(json.dumps(json_msg))
c = Consumerino()
c(msg[0])
def test_tasks_events():
flexmock(Celery).should_receive("send_task").and_return(flexmock(id="a")).twice()
for event in ["openscanhub_task_finished", "openscanhub_task_started"]:
with open(DATA_DIR / f"{event}.json") as outfile:
json_msg = json.load(outfile)
msg = message.loads(json.dumps(json_msg))
c = Consumerino()
c(msg[0])
Loading