Unverified Commit 0cde8da1 authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

Add reporter for JIRA Issue Creation (#401)

* WIP test commit

* Update reporter object

* Testing user id

* Another test

* Update fix

* Update jira logic. Move default configs

* Add issue link; Add reported by in description
parent 70cdf1db
...@@ -28,6 +28,19 @@ class Config: ...@@ -28,6 +28,19 @@ class Config:
# Request Timeout Configurations in Seconds # Request Timeout Configurations in Seconds
REQUEST_SESSION_TIMEOUT_SEC = 3 REQUEST_SESSION_TIMEOUT_SEC = 3
# Frontend Application
FRONTEND_BASE = ''
# Search Service
SEARCHSERVICE_REQUEST_CLIENT = None
SEARCHSERVICE_REQUEST_HEADERS = None
SEARCHSERVICE_BASE = ''
# Metadata Service
METADATASERVICE_REQUEST_CLIENT = None
METADATASERVICE_REQUEST_HEADERS = None
METADATASERVICE_BASE = ''
# Mail Client Features # Mail Client Features
MAIL_CLIENT = None MAIL_CLIENT = None
NOTIFICATIONS_ENABLED = False NOTIFICATIONS_ENABLED = False
...@@ -46,6 +59,15 @@ class Config: ...@@ -46,6 +59,15 @@ class Config:
# Max issues to display at a time # Max issues to display at a time
ISSUE_TRACKER_MAX_RESULTS = None # type: int ISSUE_TRACKER_MAX_RESULTS = None # type: int
# If specified, will be used to generate headers for service-to-service communication
# Please note that if specified, this will ignore following config properties:
# 1. METADATASERVICE_REQUEST_HEADERS
# 2. SEARCHSERVICE_REQUEST_HEADERS
REQUEST_HEADERS_METHOD: Optional[Callable[[Flask], Optional[Dict]]] = None
AUTH_USER_METHOD: Optional[Callable[[Flask], User]] = None
GET_PROFILE_URL = None
class LocalConfig(Config): class LocalConfig(Config):
DEBUG = False DEBUG = False
...@@ -67,31 +89,18 @@ class LocalConfig(Config): ...@@ -67,31 +89,18 @@ class LocalConfig(Config):
PORT=FRONTEND_PORT) PORT=FRONTEND_PORT)
) )
SEARCHSERVICE_REQUEST_CLIENT = None
SEARCHSERVICE_REQUEST_HEADERS = None
SEARCHSERVICE_BASE = os.environ.get('SEARCHSERVICE_BASE', SEARCHSERVICE_BASE = os.environ.get('SEARCHSERVICE_BASE',
'http://{LOCAL_HOST}:{PORT}'.format( 'http://{LOCAL_HOST}:{PORT}'.format(
LOCAL_HOST=LOCAL_HOST, LOCAL_HOST=LOCAL_HOST,
PORT=SEARCH_PORT) PORT=SEARCH_PORT)
) )
METADATASERVICE_REQUEST_CLIENT = None
METADATASERVICE_REQUEST_HEADERS = None
METADATASERVICE_BASE = os.environ.get('METADATASERVICE_BASE', METADATASERVICE_BASE = os.environ.get('METADATASERVICE_BASE',
'http://{LOCAL_HOST}:{PORT}'.format( 'http://{LOCAL_HOST}:{PORT}'.format(
LOCAL_HOST=LOCAL_HOST, LOCAL_HOST=LOCAL_HOST,
PORT=METADATA_PORT) PORT=METADATA_PORT)
) )
# If specified, will be used to generate headers for service-to-service communication
# Please note that if specified, this will ignore following config properties:
# 1. METADATASERVICE_REQUEST_HEADERS
# 2. SEARCHSERVICE_REQUEST_HEADERS
REQUEST_HEADERS_METHOD: Optional[Callable[[Flask], Optional[Dict]]] = None
AUTH_USER_METHOD: Optional[Callable[[Flask], User]] = None
GET_PROFILE_URL = None
class TestConfig(LocalConfig): class TestConfig(LocalConfig):
AUTH_USER_METHOD = get_test_user AUTH_USER_METHOD = get_test_user
......
from jira import JIRA, JIRAError, Issue from jira import JIRA, JIRAError, Issue
from typing import List from typing import List
from flask import current_app as app
from amundsen_application.base.base_issue_tracker_client import BaseIssueTrackerClient from amundsen_application.base.base_issue_tracker_client import BaseIssueTrackerClient
from amundsen_application.proxy.issue_tracker_clients.issue_exceptions import IssueConfigurationException from amundsen_application.proxy.issue_tracker_clients.issue_exceptions import IssueConfigurationException
from amundsen_application.models.data_issue import DataIssue from amundsen_application.models.data_issue import DataIssue
...@@ -67,12 +70,24 @@ class JiraClient(BaseIssueTrackerClient): ...@@ -67,12 +70,24 @@ class JiraClient(BaseIssueTrackerClient):
:return: Metadata about the newly created issue :return: Metadata about the newly created issue
""" """
try: try:
if app.config['AUTH_USER_METHOD']:
user_email = app.config['AUTH_USER_METHOD'](app).email
# We currently cannot use the email directly because of the following issue:
# https://community.atlassian.com/t5/Answers-Developer-Questions/JIRA-Rest-API-find-JIRA-user-based-on-user-s-email-address/qaq-p/532715
jira_id = user_email.split('@')[0]
else:
raise Exception('AUTH_USER_METHOD must be configured to set the JIRA issue reporter')
issue = self.jira_client.create_issue(fields=dict(project={ issue = self.jira_client.create_issue(fields=dict(project={
'id': self.jira_project_id 'id': self.jira_project_id
}, issuetype={ }, issuetype={
'id': ISSUE_TYPE_ID, 'id': ISSUE_TYPE_ID,
'name': ISSUE_TYPE_NAME, 'name': ISSUE_TYPE_NAME,
}, summary=title, description=f'{description} \n Table Key: {table_uri} [PLEASE DO NOT REMOVE]')) }, summary=title,
description=(f'{description} '
f'\n Reported By: {user_email} '
f'\n Table Key: {table_uri} [PLEASE DO NOT REMOVE]'),
reporter={'name': jira_id}))
return self._get_issue_properties(issue=issue) return self._get_issue_properties(issue=issue)
except JIRAError as e: except JIRAError as e:
......
...@@ -157,4 +157,7 @@ class JiraClientTest(unittest.TestCase): ...@@ -157,4 +157,7 @@ class JiraClientTest(unittest.TestCase):
}, issuetype={ }, issuetype={
'id': 1, 'id': 1,
'name': 'Bug', 'name': 'Bug',
}, summary='title', description='desc' + ' \n Table Key: ' + 'key [PLEASE DO NOT REMOVE]')) }, summary='title',
description='desc' + ' \n Reported By: test@email.com' +
' \n Table Key: ' + 'key [PLEASE DO NOT REMOVE]',
reporter={'name': 'test'}))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment