in dags/eam_workday_netsuite.py [0:0]
def create_jira_ticket(context):
import json
import logging
import requests
from airflow.providers.atlassian.jira.hooks.jira import JiraHook
from requests.auth import HTTPBasicAuth
logger = logging.getLogger(__name__)
logger.info("Creating Jira ticket ...")
conn_id = "eam_jira_connection_id"
conn = JiraHook(
jira_conn_id=conn_id,
).get_connection(conn_id)
log_url = get_airflow_log_link(context)
jira_domain = "mozilla-hub.atlassian.net"
url = f"https://{jira_domain}/rest/api/3/issue"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
auth = HTTPBasicAuth(conn.login, conn.password)
summary = "Workday Netsuite Integration - Airflow Task Issue Exception"
paragraph_text = "Detailed error logging can be found in the link: "
project_key = "ASP"
issue_type_id = "10020" # Issue Type = Bug
assignee_id = "712020:b999000a-67b1-45ff-8b40-42a5ceeee75b" # Julio
payload = json.dumps(
{
"fields": {
"assignee": {"id": assignee_id},
"project": {"key": project_key},
"summary": summary,
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": paragraph_text,
},
{
"type": "text",
"text": "Mozilla-Telemetry log.",
"marks": [
{
"type": "link",
"attrs": {"href": f"{log_url}"},
}
],
},
],
}
],
},
"issuetype": {"id": issue_type_id},
}
}
)
response = requests.post(url, headers=headers, auth=auth, data=payload)
logger.info(f"response.text={response.text}")
if response.status_code == 201:
logger.info("Issue created successfully.")
return response.json()
else:
logger.info(
f"Failed to create issue. Status code:"
f"{response.status_code}, Response: {response.text}"
)
return None