Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, issueKey, connection):
self.connection = connection
jira = self.connection.getJiraObject()
if isinstance(issueKey, JiraIssue):
self.obj = issueKey
self.issueKey = self.obj.key
else:
self.obj = jira.issue(issueKey)
self.issueKey = issueKey
self.fields = self.obj.fields
self.issueId = self.obj.id
# These fields will be displayed in normal category style on issue views
self.displayFields = ["summary", "description"]
# These fields will be displayed in the Basic Information section
self.basicInfo = ["status", "reporter", "assignee"]
def get_epic(self, issue):
if issue.fields.issuetype.subtask:
parent = Issue(issue._options, issue._session)
parent.find(issue.fields.parent.key)
issue = parent
epic = Issue(issue._options, issue._session)
epic.find(getattr(issue.fields, self.epic_link_field))
return epic
def delete(self, deleteSubtasks=False):
"""Delete this issue from the server.
:param deleteSubtasks: if the issue has subtasks, this argument must be set to true for the call to succeed.
:type deleteSubtasks: bool
"""
super(Issue, self).delete(params={"deleteSubtasks": deleteSubtasks})
logger.error('Error creating JIRA ticket :%s' % e)
raise forms.ValidationError(u"Error connecting to JIRA ticket, please check the server logs")
try:
jira_ticket = jconn.create_issue(project=project, summary=summary, description=description,
issuetype={'name': issue_type}, components=[{'name': component}])
except Exception as e:
logger.error('Error creating JIRA ticket project=%s, summary=%s, issue_type=%s, description=%s,' % (project,
summary,
issue_type,
description))
logger.error('Server message %s' % e)
msg = u"Error creating JIRA ticket, please check the project name and issue type. If that doesn't work then check the server logs"
raise forms.ValidationError(msg)
if isinstance(jira_ticket, jira.resources.Issue):
return jira_ticket.key
else:
raise forms.ValidationError(u"Error creating JIRA ticket, JIRA server did not return a ticket key.")
def __call__(self, timer, issue):
project_id = self.get_issue_project_id(issue)
# If the issue did not match any explicitly defined project and it is
# a subtask, get the parent issue
if not project_id and issue.fields.issuetype.subtask:
parent = Issue(issue._options, issue._session)
parent.find(issue.fields.parent.key)
project_id = self.get_issue_project_id(parent)
# If no project was found yet, get the default project
if not project_id:
project_id = self._project_ids.get(None)
# At this point, if we didn't get a project, then it's an error
if not project_id:
raise ValueError('Could not find a project ID for issue type "{}"'
.format(issue.fields.issuetype))
return project_id
headers = {'X-ExperimentalApi': 'opt-in'}
if use_old_api:
data = {'usernames': requestParticipants}
else:
data = {'accountIds': requestParticipants}
r = self._session.post(url, headers=headers, json=data)
if r.status_code != status.HTTP_200_OK:
raise JIRAError(r.status_code, request=r)
if prefetch:
return self.issue(raw_issue_json['issueKey'])
else:
return Issue(self._options, self._session, raw=raw_issue_json)
def get_epic(self, issue):
if issue.fields.issuetype.subtask:
parent = Issue(issue._options, issue._session)
parent.find(issue.fields.parent.key)
issue = parent
epic = Issue(issue._options, issue._session)
epic.find(getattr(issue.fields, self.epic_link_field))
return epic
def cached_issue(self):
if not hasattr(self, '_cached_issue'):
try:
issue_path = self.get_metadata_path('issue.json')
with io.open(issue_path, 'r', encoding='utf-8') as _in:
storable = json.loads(_in.read())
self._cached_issue = Issue(
storable['options'],
None,
storable['raw'],
)
except IOError:
self.log(
'Error encountered while loading cached issue!',
level=logging.ERROR,
)
self._cached_issue = self.issue
return self._cached_issue