Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
error = errorMessages
# Catching only 'errors' that are dict. See https://github.com/pycontribs/jira/issues/350
elif (
"errors" in response
and len(response["errors"]) > 0
and isinstance(response["errors"], dict)
):
# JIRA 6.x error messages are found in this array.
error_list = response["errors"].values()
error = ", ".join(error_list)
else:
error = r.text
except ValueError:
error = r.text
raise JIRAError(
r.status_code, error, r.url, request=request, response=r, **kwargs
)
# for debugging weird errors on CI
if r.status_code not in [200, 201, 202, 204]:
raise JIRAError(r.status_code, request=request, response=r, **kwargs)
# testing for the WTH bug exposed on
# https://answers.atlassian.com/questions/11457054/answers/11975162
if (
r.status_code == 200
and len(r.content) == 0
and "X-Seraph-LoginReason" in r.headers
and "AUTHENTICATED_FAILED" in r.headers["X-Seraph-LoginReason"]
):
pass
if parent:
fields['parent'] = {'key': parent.key}
new_issue = target_jira.create_issue(fields=fields)
if not parent:
print('to', new_issue.key, '...', end=' ')
_set_epic_link(new_issue, issue, conf, source_jira, target_jira)
_set_status(new_issue, issue, conf, target_jira)
if issue.fields.comment.comments:
_add_comments(new_issue, target_jira, issue.fields.comment.comments)
if issue.fields.attachment:
try:
_add_attachments(new_issue, target_jira, issue.fields.attachment)
except JIRAError as e:
print('ERROR: attachment import failed with status',
e.status_code, '...', end=' ')
target_jira.add_comment(new_issue, '*Failed to import attachments*')
if issue.fields.subtasks:
subtasks = [source_jira.issue(subtask.key) for subtask in
issue.fields.subtasks]
print('with', len(subtasks), 'subtasks ...', end=' ')
_make_new_issues(source_jira, target_jira, subtasks, conf, result, new_issue)
comment = 'Imported from *[{1}|{0}/browse/{1}]*'.format(
source_jira._options['server'], issue.key)
target_jira.add_comment(new_issue, comment)
if conf.ADD_COMMENT_TO_OLD_ISSUE:
comment = 'Exported to *[{1}|{0}/browse/{1}]*'.format(
target_jira._options['server'], new_issue.key)
source_jira.add_comment(issue, comment)
def _find_for_resource(self, resource_cls, ids, expand=None):
resource = resource_cls(self._options, self._session)
params = {}
if expand is not None:
params['expand'] = expand
resource.find(id=ids, params=params)
if not resource:
raise JIRAError("Unable to find resource %s(%s)", resource_cls, ids)
return resource
``object`` should be a dict containing at least ``url`` to the linked external URL and
``title`` to display for the link inside JIRA.
For definitions of the allowable fields for ``object`` and the keyword arguments ``globalId``, ``application``
and ``relationship``, see https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+for+Remote+Issue+Links.
:param issue: the issue to add the remote link to
:param destination: the link details to add (see the above link for details)
:param globalId: unique ID for the link (see the above link for details)
:param application: application information for the link (see the above link for details)
:param relationship: relationship description for the link (see the above link for details)
"""
try:
applicationlinks = self.applicationlinks()
except JIRAError as e:
applicationlinks = []
# In many (if not most) configurations, non-admin users are
# not allowed to list applicationlinks; if we aren't allowed,
# let's let people try to add remote links anyway, we just
# won't be able to be quite as helpful.
warnings.warn(
"Unable to gather applicationlinks; you will not be able "
"to add links to remote issues: (%s) %s" % (
e.status_code,
e.text),
Warning)
data = {}
if isinstance(destination, Issue):
data['object'] = {
self.__imageproxy_server['host'],
issue.fields.issuetype.iconUrl)
summary = issue.fields.summary.encode('utf8')
return {
'fallback': '{key} - {summary}\n{url}'.format(
key=issue.key,
summary=summary.decode(),
url=issue.permalink()
),
'author_name': issue.key,
'author_link': issue.permalink(),
'author_icon': icon,
'text': summary.decode(),
'color': '#59afe1'
}
except JIRAError as ex:
return self.__get_error_message(ex)
- ``None``: the ticket does not exist.
CLI Example:
.. code-block:: bash
salt '*' jira.issue_closed NE-123
'''
if not issue_key:
return None
jira_ = _get_jira(server=server,
username=username,
password=password)
try:
ticket = jira_.issue(issue_key)
except jira.exceptions.JIRAError:
# Ticket not found
return None
return ticket.fields().status.name == 'Closed'
def _handle_search_issues(jira, jql, field, max_results, args, project, svc_desc):
try:
issues = jira.search_issues(jql,
maxResults=max_results,
json_result=False,
fields=field,
validate_query=True)
except JIRAError as jira_error:
# errors of sections are handled and shown by/in the related checks
msg = "Jira error %s: %s" % (jira_error.status_code, jira_error.text)
if project:
key = project
else:
key = svc_desc
msg_dict = {key: {"error": msg}}
sys.stdout.write("%s\n" % json.dumps(msg_dict))
if args.debug:
raise
else:
return issues
def handle(self, *args, **options):
findings = Finding.objects.exclude(jira_issue__isnull=True)
findings = findings.filter(verified=True, active=True)
# finding = Finding.objects.get(id=1)
for finding in findings:
# try:
JIRAError.log_to_tempfile = False
jira = get_jira_connection(finding)
j_issue = JIRA_Issue.objects.get(finding=finding)
issue = jira.issue(j_issue.jira_id)
# Issue Cloned
print issue.fields.issuelinks[0]
print "Jira Issue: " + str(issue)
print "Resolution: " + str(issue.fields.resolution)
if issue.fields.resolution is not None \
and finding.under_defect_review == False:
# print issue.fields.__dict__
print "Jira Issue: " + str(issue) + " changed status"
# Create Jira Note