Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Commit c374bd9

Browse files
authored
Add job details (#16)
1 parent acbbe0b commit c374bd9

3 files changed

Lines changed: 33 additions & 14 deletions

File tree

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = github-workflows-monitoring
3-
version = 0.1.1
3+
version = 0.1.2
44
license-file = LICENSE
55

66
[options]

src/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ def process_workflow_job():
4848
job = request.get_json()
4949

5050
job_id = job["workflow_job"]["id"]
51+
run_id = job["workflow_job"]["run_id"]
52+
job_name = job["workflow_job"]["name"]
5153
workflow = job["workflow_job"]["workflow_name"]
5254
time_start = parse_datetime(job["workflow_job"]["started_at"])
55+
branch = job["workflow_job"].get("head_branch", "")
5356
repository = job["repository"]["full_name"]
5457
repository_private = job["repository"]["private"]
5558
action = job["action"]
@@ -62,7 +65,10 @@ def process_workflow_job():
6265
context_details = {
6366
"action": action,
6467
"repository": repository,
68+
"branch": branch,
6569
"job_id": job_id,
70+
"run_id": run_id,
71+
"job_name": job_name,
6672
"workflow": workflow,
6773
"requestor": requestor,
6874
}
@@ -109,6 +115,7 @@ def process_workflow_job():
109115

110116
context_details = {
111117
**context_details,
118+
"runner_name": runner_name,
112119
"time_to_finish": time_to_finish,
113120
"conclusion": conclusion,
114121
}

tests/tests.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
"action": "",
1010
"workflow_job": {
1111
"id": 0,
12+
"run_id": 10,
1213
"workflow_name": "CI",
14+
"head_branch": "new-feature-branch",
1315
"started_at": "2023-01-27T14:00:00Z",
1416
"conclusion": None,
1517
"labels": [],
1618
"runner_id": None,
1719
"runner_name": None,
1820
"runner_group_id": None,
1921
"runner_group_name": None,
22+
"name": "Build",
2023
},
2124
"repository": {
2225
"name": "foo",
@@ -66,8 +69,9 @@ def test_started_job_not_stored(client, caplog):
6669
assert response.status_code == 200
6770
assert caplog.messages == [
6871
"Job 2 is in_progress but not stored!",
69-
"action=in_progress repository=foo/foo job_id=2 workflow=CI requestor=testerbot "
70-
"runner_name= runner_public=false repository_private=false",
72+
"action=in_progress repository=foo/foo branch=new-feature-branch job_id=2 run_id=10 "
73+
"job_name=Build workflow=CI requestor=testerbot runner_name= runner_public=false "
74+
"repository_private=false",
7175
]
7276

7377

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

8590

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

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

111118

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

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

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

147157

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

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

0 commit comments

Comments
 (0)