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:
# Request Timeout Configurations in Seconds
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 = None
NOTIFICATIONS_ENABLED = False
......@@ -46,6 +59,15 @@ class Config:
# Max issues to display at a time
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):
DEBUG = False
......@@ -67,31 +89,18 @@ class LocalConfig(Config):
PORT=FRONTEND_PORT)
)
SEARCHSERVICE_REQUEST_CLIENT = None
SEARCHSERVICE_REQUEST_HEADERS = None
SEARCHSERVICE_BASE = os.environ.get('SEARCHSERVICE_BASE',
'http://{LOCAL_HOST}:{PORT}'.format(
LOCAL_HOST=LOCAL_HOST,
PORT=SEARCH_PORT)
)
METADATASERVICE_REQUEST_CLIENT = None
METADATASERVICE_REQUEST_HEADERS = None
METADATASERVICE_BASE = os.environ.get('METADATASERVICE_BASE',
'http://{LOCAL_HOST}:{PORT}'.format(
LOCAL_HOST=LOCAL_HOST,
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):
AUTH_USER_METHOD = get_test_user
......
from jira import JIRA, JIRAError, Issue
from typing import List
from flask import current_app as app
from amundsen_application.base.base_issue_tracker_client import BaseIssueTrackerClient
from amundsen_application.proxy.issue_tracker_clients.issue_exceptions import IssueConfigurationException
from amundsen_application.models.data_issue import DataIssue
......@@ -67,12 +70,24 @@ class JiraClient(BaseIssueTrackerClient):
:return: Metadata about the newly created issue
"""
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={
'id': self.jira_project_id
}, issuetype={
'id': ISSUE_TYPE_ID,
'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)
except JIRAError as e:
......
......@@ -157,4 +157,7 @@ class JiraClientTest(unittest.TestCase):
}, issuetype={
'id': 1,
'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