|
| 1 | +from atlassian import Jira |
| 2 | +import os |
| 3 | + |
| 4 | +""" Download the attachments from tickets """ |
| 5 | + |
| 6 | +JIRA_URL = "localhost:8080" |
| 7 | +JIRA_LOGIN = "admin" |
| 8 | +JIRA_TOKEN = "dsadd2c3s" |
| 9 | + |
| 10 | + |
| 11 | +def get_tickets(jql): |
| 12 | + pass |
| 13 | + |
| 14 | + |
| 15 | +if __name__ == "__main__": |
| 16 | + jira = Jira(url=JIRA_URL, username=JIRA_LOGIN, token=JIRA_TOKEN) |
| 17 | + jql = "project = DOC" |
| 18 | + tickets = jira.jql(jql=jql, fields=["key,attachment"], limit=1000).get("issues") |
| 19 | + |
| 20 | + for ticket in tickets: |
| 21 | + mail_folder = "tickets" |
| 22 | + if not os.path.exists(mail_folder): |
| 23 | + os.makedirs(mail_folder) |
| 24 | + key = ticket.get("key") |
| 25 | + attachments = ticket.get("fields").get("attachment") |
| 26 | + |
| 27 | + for attachment in attachments: |
| 28 | + dest_folder = mail_folder + "/" + key |
| 29 | + if not os.path.exists(dest_folder): |
| 30 | + os.makedirs(dest_folder) |
| 31 | + filename = attachment.get("filename") |
| 32 | + author = attachment.get("author").get("emailAddress") |
| 33 | + attachment_id = attachment.get("id") |
| 34 | + content_url = attachment.get("content") |
| 35 | + session = jira._session |
| 36 | + response = session.get(url=content_url) |
| 37 | + |
| 38 | + if response.status_code != 200: |
| 39 | + continue |
| 40 | + with open(dest_folder + "/" + filename, "wb") as f: |
| 41 | + print(f"Saving for {key} the file {filename}") |
| 42 | + f.write(response.content) |
0 commit comments