Skip to content

Commit

Permalink
Add support for delete_attachment.
Browse files Browse the repository at this point in the history
  • Loading branch information
k0ste committed Dec 6, 2016
1 parent 2544eca commit 167aef5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,15 @@ If you would like to list all available attachment, you can do it with through a
filename=attachment.filename, size=attachment.size))
# to read content use `get` method:
print("Content: '{}'".format(attachment.get()))


You can delete attachment by id::

# Find issues with attachments:
query = jira.search_issues(jql_str="attachments is not EMPTY", json_result=True, fields="key, attachment")

# And remove attachments one by one
for i in query['issues']:
for a in i['fields']['attachment']:
print("For issue {0}, found attach: '{1}' [{2}].".format(i['key'], a['filename'], a['id']))
jira.delete_attachment(a['id'])
8 changes: 8 additions & 0 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ def file_stream():
raise JIRAError("Added empty attachment via %s method?!: r: %s\nattachment: %s" % (method, r, attachment))
return attachment

def delete_attachment(self, id):
"""Delete attachment by id.
:param id: ID of the attachment to delete
"""
url = self._get_url('attachment/' + str(id))
return self._session.delete(url)

# Components

def component(self, id):
Expand Down

0 comments on commit 167aef5

Please sign in to comment.