Skip to content

Commit

Permalink
Add job details (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
duhow authored Mar 7, 2023
1 parent acbbe0b commit c374bd9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = github-workflows-monitoring
version = 0.1.1
version = 0.1.2
license-file = LICENSE

[options]
Expand Down
7 changes: 7 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ def process_workflow_job():
job = request.get_json()

job_id = job["workflow_job"]["id"]
run_id = job["workflow_job"]["run_id"]
job_name = job["workflow_job"]["name"]
workflow = job["workflow_job"]["workflow_name"]
time_start = parse_datetime(job["workflow_job"]["started_at"])
branch = job["workflow_job"].get("head_branch", "")
repository = job["repository"]["full_name"]
repository_private = job["repository"]["private"]
action = job["action"]
Expand All @@ -62,7 +65,10 @@ def process_workflow_job():
context_details = {
"action": action,
"repository": repository,
"branch": branch,
"job_id": job_id,
"run_id": run_id,
"job_name": job_name,
"workflow": workflow,
"requestor": requestor,
}
Expand Down Expand Up @@ -109,6 +115,7 @@ def process_workflow_job():

context_details = {
**context_details,
"runner_name": runner_name,
"time_to_finish": time_to_finish,
"conclusion": conclusion,
}
Expand Down
38 changes: 25 additions & 13 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
"action": "",
"workflow_job": {
"id": 0,
"run_id": 10,
"workflow_name": "CI",
"head_branch": "new-feature-branch",
"started_at": "2023-01-27T14:00:00Z",
"conclusion": None,
"labels": [],
"runner_id": None,
"runner_name": None,
"runner_group_id": None,
"runner_group_name": None,
"name": "Build",
},
"repository": {
"name": "foo",
Expand Down Expand Up @@ -66,8 +69,9 @@ def test_started_job_not_stored(client, caplog):
assert response.status_code == 200
assert caplog.messages == [
"Job 2 is in_progress but not stored!",
"action=in_progress repository=foo/foo job_id=2 workflow=CI requestor=testerbot "
"runner_name= runner_public=false repository_private=false",
"action=in_progress repository=foo/foo branch=new-feature-branch job_id=2 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot runner_name= runner_public=false "
"repository_private=false",
]


Expand All @@ -79,7 +83,8 @@ def test_finished_job_not_stored(client, caplog):
assert response.status_code == 200
assert caplog.messages == [
"Job 3 is completed but not stored!",
"action=completed repository=foo/foo job_id=3 workflow=CI requestor=testerbot time_to_finish=0 conclusion=",
"action=completed repository=foo/foo branch=new-feature-branch job_id=3 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot runner_name= time_to_finish=0 conclusion=",
]


Expand All @@ -93,7 +98,8 @@ def test_unknown_action(client, caplog):
response = client.post("/github-webhook", headers=HEADERS, json=body_failed)
assert response.status_code == 200
assert caplog.messages == [
"action=queued repository=foo/foo job_id=4 workflow=CI requestor=testerbot",
"action=queued repository=foo/foo branch=new-feature-branch job_id=4 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot",
"Unknown action failed, removing from memory",
]

Expand All @@ -105,7 +111,8 @@ def test_queued_job(client, caplog):
response = client.post("/github-webhook", headers=HEADERS, json=body_queued)
assert response.status_code == 200
assert caplog.messages == [
"action=queued repository=foo/foo job_id=1 workflow=CI requestor=testerbot"
"action=queued repository=foo/foo branch=new-feature-branch job_id=1 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot"
]


Expand All @@ -118,7 +125,8 @@ def test_logging_flow(client, caplog):
assert response.status_code == 200
assert (
caplog.messages[0]
== "action=queued repository=foo/foo job_id=5 workflow=CI requestor=testerbot"
== "action=queued repository=foo/foo branch=new-feature-branch job_id=5 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot"
)

body_started = BODY.copy()
Expand All @@ -128,8 +136,9 @@ def test_logging_flow(client, caplog):
assert response.status_code == 200
assert (
caplog.messages[1]
== "action=in_progress repository=foo/foo job_id=5 workflow=CI requestor=testerbot "
"runner_name= runner_public=false repository_private=false time_to_start=5"
== "action=in_progress repository=foo/foo branch=new-feature-branch job_id=5 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot runner_name= runner_public=false "
"repository_private=false time_to_start=5"
)

body_completed = BODY.copy()
Expand All @@ -140,8 +149,9 @@ def test_logging_flow(client, caplog):
assert response.status_code == 200
assert (
caplog.messages[2]
== "action=completed repository=foo/foo job_id=5 workflow=CI requestor=testerbot "
"time_to_finish=295 conclusion=success"
== "action=completed repository=foo/foo branch=new-feature-branch job_id=5 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot runner_name= time_to_finish=295 "
"conclusion=success"
)


Expand All @@ -155,7 +165,8 @@ def test_logging_flow_queued_after_in_progress(client, caplog):
assert response.status_code == 200
assert (
caplog.messages[0]
== "action=queued repository=foo/foo job_id=6 workflow=CI requestor=testerbot"
== "action=queued repository=foo/foo branch=new-feature-branch job_id=6 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot"
)

body_started = BODY.copy()
Expand All @@ -167,6 +178,7 @@ def test_logging_flow_queued_after_in_progress(client, caplog):
assert caplog.messages[1] == "Job 6 was in progress before being queued"
assert (
caplog.messages[2]
== "action=in_progress repository=foo/foo job_id=6 workflow=CI"
" requestor=testerbot runner_name= runner_public=false repository_private=false"
== "action=in_progress repository=foo/foo branch=new-feature-branch job_id=6 run_id=10 "
"job_name=Build workflow=CI requestor=testerbot runner_name= runner_public=false "
"repository_private=false"
)

0 comments on commit c374bd9

Please sign in to comment.