diff --git a/docs/jira.rst b/docs/jira.rst index f78dc8b00..20f5161b1 100644 --- a/docs/jira.rst +++ b/docs/jira.rst @@ -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) diff --git a/examples/jira/jira_download_attachments.py b/examples/jira/jira_download_attachments.py new file mode 100644 index 000000000..bc0719fcf --- /dev/null +++ b/examples/jira/jira_download_attachments.py @@ -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)