Skip to content

Commit c01e741

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 c440369 commit c01e741

File tree

1 file changed

+36
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)