Skip to content

Commit e41e75b

Browse files
author
Jeny Sadadia
committed
Automate incidents creation
Add a subscription module `create_incidents.py` to create incidents automatically when builds and tests objects match with issue patterns. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent fed755c commit e41e75b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
from kcidb.tools import kcidb_match
3+
import kcidb
4+
5+
CLIENT = None
6+
7+
def get_client():
8+
global CLIENT
9+
if not CLIENT:
10+
project_id = os.environ.get('GCP_PROJECT')
11+
topic_name = os.environ.get('KCIDB_LOAD_QUEUE_TOPIC')
12+
if project_id and topic_name:
13+
CLIENT = kcidb.Client(project_id=project_id, topic_name=topic_name)
14+
return CLIENT
15+
16+
17+
def match_test(test):
18+
client = get_client()
19+
if client:
20+
incident_generator = kcidb_match.IncidentGenerator()
21+
incidents = incident_generator.generate_incidents_from_test(test)
22+
client.submit(incidents)
23+
24+
25+
def match_build(build):
26+
client = get_client()
27+
if client:
28+
incident_generator = kcidb_match.IncidentGenerator()
29+
incidents = incident_generator.generate_incidents_from_build(build)
30+
client.submit(incidents)
31+
32+
33+
def match_issue(issue):
34+
incident_generator = kcidb_match.IncidentGenerator()
35+
incident_generator.db.update_patterns(issue)

0 commit comments

Comments
 (0)