Commit c40145d2 authored by Liam Morland's avatar Liam Morland
Browse files

RT#988316/ISTWCMS-3213: Improve error handling when Jira API is not accessible

parent 69d18ab1
......@@ -105,6 +105,10 @@ function uw_wcms_tools_create_module_update_tickets($module, $version, $depended
require_once 'uw_wcms_tools.jira.inc';
uw_wcms_tools_create_jira_for_rt($id, $links);
if (!isset($jira_ticket->key)) {
drupal_set_message(t('Failed to create corresponding Jira ticket.'), 'error');
}
}
else {
throw new Exception('Failed to create RT ticket.');
......
......@@ -49,7 +49,7 @@ function uw_wcms_tools_jira_api_query($path, stdClass $data = NULL, $method = 'P
}
$url = 'https://' . $jira_username . ':' . $jira_password . '@jira.uwaterloo.ca/rest/api/2/' . $path;
$results = @file_get_contents($url, FALSE, $context);
$results = file_get_contents($url, FALSE, $context);
if ($results) {
return json_decode($results);
}
......@@ -63,8 +63,11 @@ function uw_wcms_tools_jira_api_query($path, stdClass $data = NULL, $method = 'P
* documentation.
*/
function uw_wcms_tools_jira_api_ticket_create(stdClass $jira_ticket) {
foreach (uw_wcms_tools_jira_api_query('issue', $jira_ticket) as $key => $value) {
$jira_ticket->$key = $value;
$result = uw_wcms_tools_jira_api_query('issue', $jira_ticket);
if (is_array($result)) {
foreach ($result as $key => $value) {
$jira_ticket->$key = $value;
}
}
}
......@@ -117,7 +120,9 @@ function uw_wcms_tools_create_jira_for_rt($id, array $links = []) {
uw_wcms_tools_jira_api_ticket_create($jira_ticket);
// Add to the RT ticket a link to the new Jira ticket.
$links['ReferredToBy'] = UW_WCMS_TOOLS_JIRA_URL_PREFIX . $jira_ticket->key;
if (isset($jira_ticket->key)) {
$links['ReferredToBy'] = UW_WCMS_TOOLS_JIRA_URL_PREFIX . $jira_ticket->key;
}
foreach ($links as $relationship => $target) {
$rt->addTicketLink($id, $relationship, $target);
......
......@@ -69,7 +69,7 @@ function uw_wcms_tools_ticket_create_form_submit(array $form, array &$form_state
case 'RT':
$jira = uw_wcms_tools_create_jira_for_rt($ticket_id);
$copy_id = $jira->key;
$copy_id = $jira->key ?? NULL;
break;
}
......@@ -77,7 +77,12 @@ function uw_wcms_tools_ticket_create_form_submit(array $form, array &$form_state
'!copy' => uw_wcms_tools_get_ticket_link($copy_id),
'!original' => uw_wcms_tools_get_ticket_link($ticket_id),
];
drupal_set_message(t('Created !copy for !original.', $args));
if ($copy_id) {
drupal_set_message(t('Created !copy for !original.', $args));
}
else {
drupal_set_message(t('Failed to create corresponding ticket for !original.', $args), 'error');
}
}
/**
......
Supports Markdown
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