Skip to content

Commit

Permalink
Add example with attachments downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
gonchik committed Aug 9, 2022
1 parent d95ee12 commit c0dcfcc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/jira.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Manage projects
# Follow the documentation of /notificationscheme/{id} resource for all details about returned value.
# Use 'expand' to get details (default is None) possible values are notificationSchemeEvents,user,group,projectRole,field,all
jira.get_priority_scheme_of_project(project_key_or_id, expand=None)
# Returns a list of active users who have browse permission for a project that matches the search string for username.
# Using " " string (space) for username gives All the active users who have browse permission for a project
jira.get_users_with_browse_permission_to_a_project(self, username, issue_key=None, project_key=None, start=0, limit=100)
Expand Down
42 changes: 42 additions & 0 deletions examples/jira/jira_download_attachments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from atlassian import Jira
import os

""" Download the attachments from tickets """

JIRA_URL = "localhost:8080"
JIRA_LOGIN = "admin"
JIRA_TOKEN = "dsadd2c3s"


def get_tickets(jql):
pass


if __name__ == "__main__":
jira = Jira(url=JIRA_URL, username=JIRA_LOGIN, token=JIRA_TOKEN)
jql = "project = DOC"
tickets = jira.jql(jql=jql, fields=["key,attachment"], limit=1000).get("issues")

for ticket in tickets:
mail_folder = "tickets"
if not os.path.exists(mail_folder):
os.makedirs(mail_folder)
key = ticket.get("key")
attachments = ticket.get("fields").get("attachment")

for attachment in attachments:
dest_folder = mail_folder + "/" + key
if not os.path.exists(dest_folder):
os.makedirs(dest_folder)
filename = attachment.get("filename")
author = attachment.get("author").get("emailAddress")
attachment_id = attachment.get("id")
content_url = attachment.get("content")
session = jira._session
response = session.get(url=content_url)

if response.status_code != 200:
continue
with open(dest_folder + "/" + filename, "wb") as f:
print(f"Saving for {key} the file {filename}")
f.write(response.content)

0 comments on commit c0dcfcc

Please sign in to comment.