Show status of Jira ticket when analyze the testrun
PRODX-39015
Change-Id: Ibf6c97b388738cb66846f9fcb3d5fa8d13dd1fc1
diff --git a/testrail_bot/.env b/testrail_bot/.env
index b90eb6d..e0556fc 100644
--- a/testrail_bot/.env
+++ b/testrail_bot/.env
@@ -10,3 +10,5 @@
TESTRAIL_EMAIL=mosqa-eng@mirantis.com
TESTRAIL_PASSWORD=mosqa-eng496F
FLOWER_UNAUTHENTICATED_API=true
+JIRA_USER=jira-qa@mirantis.com
+JIRA_PASSWORD=ATATT3xFfGF0wVa9fMFtKb9TX09GMRuIBRa6dSzy8Gtz9j3sSZHos8j0pppNw8CXq5t3ppxgEnTQp-4twhYX1WlJCo0ojQIBIYoh1twsJc4qsnL9EmWWYMZH0Ba8v1LJ-LkO406Hv04xOG9S8tPaYcjieTVn60wm1Zmib5m1WVQ-fuda8N2dM3c=EEDBD607
\ No newline at end of file
diff --git a/testrail_bot/control/celery_tasks/testrail_pipeline.py b/testrail_bot/control/celery_tasks/testrail_pipeline.py
index af2b59b..aaaa172 100644
--- a/testrail_bot/control/celery_tasks/testrail_pipeline.py
+++ b/testrail_bot/control/celery_tasks/testrail_pipeline.py
@@ -10,6 +10,7 @@
from .enums import StatusEnum
from . import test_rail_api
from .. import models
+from ..jira_manager import JiraIssue
__all__ = ("process_test_run",)
@@ -244,8 +245,9 @@
f.flush()
return False
- prod_link = "<a href=https://mirantis.jira.com/browse/{defect}>" \
- "{defect}</a>".format(defect=sim_result["defects"])
+ prod_link = "None" \
+ if str(sim_result["defects"]) == "None" \
+ else JiraIssue(sim_result["defects"]).html()
test_link = test_rail_api.html_link('test',
sim_result["test_id"],
str(sim_result["test_id"]))
@@ -282,7 +284,9 @@
f"{test_link} with similarity {per}% and "
f"{StatusEnum(status_id).name} status and {prod_link} "
f"defect\n"
- f"<i>Pushing to TestRail {update_dict}</i>\n\n")
+ f"<i style='color:ForestGreen;'>Pushing to TestRail "
+ f"{update_dict}"
+ f"</i>\n\n")
f.flush()
test_rail_api.add_result(test["id"], update_dict)
return True
diff --git a/testrail_bot/control/jira_manager.py b/testrail_bot/control/jira_manager.py
new file mode 100644
index 0000000..e61ecfa
--- /dev/null
+++ b/testrail_bot/control/jira_manager.py
@@ -0,0 +1,30 @@
+from django.conf import settings
+from jira import JIRA, Issue
+
+jira = JIRA(server=settings.JIRA_SERVER,
+ basic_auth=(settings.JIRA_USER, settings.JIRA_PASSWORD))
+
+
+class JiraIssue:
+ def __init__(self, key: str):
+ self.key = key
+ self._issue = None
+
+ @property
+ def issue(self) -> Issue:
+ if self._issue:
+ return self._issue
+ self._issue = jira.issue(self.key)
+ return self._issue
+
+ def get_link(self) -> str:
+ return f"{settings.JIRA_SERVER}/browse/{self.issue.key}"
+
+ def html(self) -> str:
+ return f"<div style='display:inline-block;border:1px solid;" \
+ f"background-color:aliceblue;border-color:CornflowerBlue;" \
+ f"border-radius:5px;padding:2px;'>" \
+ f"<a href='{self.get_link()}'>" \
+ f"{self.key}: {self.issue.fields.summary[:50]}</a>" \
+ f"<b> {self.issue.fields.status.name}</b>" \
+ f"</div>"
diff --git a/testrail_bot/requirements.txt b/testrail_bot/requirements.txt
index 727ea37..3518d14 100644
--- a/testrail_bot/requirements.txt
+++ b/testrail_bot/requirements.txt
@@ -12,3 +12,4 @@
click==8.1.7
python-jenkins==1.7.0
matplotlib==3.3.2
+jira[cli]==3.5.2
diff --git a/testrail_bot/testrail_bot/settings.py b/testrail_bot/testrail_bot/settings.py
index ca79a12..240f9df 100644
--- a/testrail_bot/testrail_bot/settings.py
+++ b/testrail_bot/testrail_bot/settings.py
@@ -156,3 +156,10 @@
# TestRail configs
TESTRAIL_EMAIL = os.environ.get("TESTRAIL_EMAIL", default="123")
TESTRAIL_PASSWORD = os.environ.get("TESTRAIL_PASSWORD", default="123")
+
+# Jira settings
+JIRA_USER = os.environ.get("JIRA_USER")
+JIRA_PASSWORD = os.environ.get("JIRA_PASSWORD")
+JIRA_SERVER = os.environ.get("JIRA_SERVER",
+ default="https://mirantis.jira.com")
+