Skip to content

Commit 0a1babc

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 fd26a9b commit 0a1babc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Automate incident creation"""
2+
import os
3+
from kcidb.tools import kcidb_match
4+
import kcidb
5+
6+
CLIENT = None
7+
8+
9+
# pylint: disable=global-statement
10+
def get_client():
11+
"""Get KCIDB client instance and set it as a global variable"""
12+
global CLIENT
13+
if not CLIENT:
14+
project_id = os.environ.get('GCP_PROJECT')
15+
topic_name = os.environ.get('KCIDB_LOAD_QUEUE_TOPIC')
16+
if project_id and topic_name:
17+
CLIENT = kcidb.Client(project_id=project_id, topic_name=topic_name)
18+
return CLIENT
19+
20+
21+
def match_test(test):
22+
"""Generate incident for matching test"""
23+
client = get_client()
24+
if client:
25+
incident_generator = kcidb_match.IncidentGenerator()
26+
incidents = incident_generator.generate_incidents_from_test(test)
27+
client.submit(incidents)
28+
29+
30+
def match_build(build):
31+
"""Generate incident for matching build"""
32+
client = get_client()
33+
if client:
34+
incident_generator = kcidb_match.IncidentGenerator()
35+
incidents = incident_generator.generate_incidents_from_build(build)
36+
client.submit(incidents)
37+
38+
39+
def match_issue(issue):
40+
"""Match issue and add its pattern to DB"""
41+
incident_generator = kcidb_match.IncidentGenerator()
42+
incident_generator.db.update_patterns(issue)

0 commit comments

Comments
 (0)