Hello. There was a thought to automate unloading reports from Jira. Since Python was the favorite tool, the choice fell on a module from JIra that allows you to work with their API. Who cares please in the cat.

Atlassian has official
documentation on the use of their module. The module itself is called “jira”. Traditionally, we will install the module with the command:
pip install jira
Then we import the module directly in the code:
')
from jira import JIRA
In order to connect to the server itself, you need to create a client by passing the required parameters to it:
jira_options = {'server': 'https://project-name.atlassian.net'} jira = JIRA(options=jira_options, basic_auth=(login, api_key))
In order to pass authorization with a password, you can send a password instead of api key. After authorization is completed, we have an active api client that can be accessed.
The possibilities are certainly not limitless, but quite wide. It was necessary for me to pull out tasks for a certain week and to make a report on the hours spent in Excell. You can drag out tasks directly by the project itself, by task number, or by JQL query. Search tools are quite flexible and simple. All information returned by the api client comes in a string, so additional steps are required to work with it.
We make a jql request and pick up tasks for it:
jql = 'project = ' + project_key + ' AND worklogDate >= ' + work_date issues_list = jira.search_issues(jql)
Unfortunately, I did not understand why in those tasks that are obtained through such a query there is no worklog property. After some attempts to understand what is wrong, I politely asked the jira task by number:
issue = jira.issue(issue_key)
In the task returned by this method, the worklog field with a list of worklogs was. As a result, I began to take tasks on jql request, pulled out task numbers and afterwards pulled out the information I needed:
worklogs = issue.fields.worklog.worklogs
Such a line allows you to pull out all time records from a specific task. Each of the records has information about the time both in seconds and in the textual representation (1h, 3d etc).
After that, everything is simple, we drop the records that do not fit the period, in my case the week number does not match:
worklog_date_str = re.search(r'(\d{4}-\d{2}-\d{2})', worklog.started) worklog_date = datetime.strptime(worklog_date_str.group(0), '%Y-%m-%d') if worklog_date.isocalendar()[1] == weak_number:
Since the date is returned in the string, I used a simple regular expression to pick it up, and in the next line I quote the required type. The worklog_date.isocalendar () [1] expression allows you to find out the week number that will be compared with what you need to take. If it matches, we go further and record the rest of the data.
In general, the above module allows you to solve a fairly wide range of tasks, you need only time and desire.
UPD
You can not re-request a task, but simply expand the desired field.
github.com/pycontribs/jira/blob/master/jira/client.py#L2371thanks
HSerg