"""Returns a property of this instance"""
return self.info().get(param, default)
+ def getAttachments(self, key):
+ """Get a dict of attachments
+
+ The keys are the filenames, the values are another dict containing:
+ - id: The file ID on the Tracker
+ - filename: The file name
+ - URL: The URL to download the file
+ - date: A datetime object representing the date at which the file was created
+ - mimetype: The mimetype of the file
+ - size: The size of the file in bytes
+ - author: The username of the author of the file
+ """
+ issueInfo = self.getIssue(key, fields='attachment')
+ results = issueInfo.get('fields').get('attachment', [])
+ attachments = {}
+ for attachment in results:
+ attachments[attachment.get('filename')] = {
+ 'id': attachment.get('id'),
+ 'filename': attachment.get('filename'),
+ 'url': attachment.get('content'),
+ 'date': Jira.parseDate(attachment.get('created')),
+ 'mimetype': attachment.get('mimeType'),
+ 'size': attachment.get('size'),
+ 'author': attachment.get('author', {}).get('name'),
+ }
+ return attachments
+
def getIssue(self, key, fields='*all,-comment'):
"""Load the issue info from the jira server using a rest api call.
@staticmethod
def parseDate(value):
- """Parse a date returned by Jira API"""
+ """Parse a date returned by Jira API and returns a datetime object."""
# Strips the timezone information because of some issues with %z.
value = re.sub(r'[+-]\d+$', '', value)
return datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%f')