-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Jeny Sadadia
committed
Oct 17, 2024
1 parent
3de95ac
commit 5064d37
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Automate incident creation""" | ||
import os | ||
import kcidb | ||
from kcidb.tools import kcidb_match | ||
|
||
CLIENT = None | ||
|
||
|
||
# pylint: disable=global-statement | ||
def get_client(): | ||
"""Get KCIDB client instance and set it as a global variable""" | ||
global CLIENT | ||
if not CLIENT: | ||
project_id = os.environ.get('GCP_PROJECT') | ||
topic_name = os.environ.get('KCIDB_LOAD_QUEUE_TOPIC') | ||
if project_id and topic_name: | ||
CLIENT = kcidb.Client(project_id=project_id, topic_name=topic_name) | ||
return CLIENT | ||
|
||
|
||
def match_test(test): | ||
"""Generate incident for matching test""" | ||
client = get_client() | ||
if client: | ||
incident_generator = kcidb_match.IncidentGenerator() | ||
incidents = incident_generator.generate_incidents_from_test(test) | ||
client.submit(incidents) | ||
|
||
|
||
def match_build(build): | ||
"""Generate incident for matching build""" | ||
client = get_client() | ||
if client: | ||
incident_generator = kcidb_match.IncidentGenerator() | ||
incidents = incident_generator.generate_incidents_from_build(build) | ||
client.submit(incidents) | ||
|
||
|
||
def match_issue(issue): | ||
"""Match issue and add its pattern to DB""" | ||
incident_generator = kcidb_match.IncidentGenerator() | ||
incident_generator.db.update_patterns(issue) |