How can I get the minutes spent from a worklog from an issue using the jira-python library?
Using the jirashell I see that the issue has the attribute issue.fields.worklog, however when I try to access that in my python code I get the error: AttributeError: type object 'PropertyHolder' has no attribute 'worklog'
.
If I create a jira client and do jira_client.worklogs(ticket.key) in my python code, it returns a list of Worklogs and their ids but I don't know what to do with that. I see in the documentation there's a worklog() function that takes in the issue id, and the worklog id, but I don't understand what it returns and how I would use that/if it is what I'm looking for.
I found a roundabout way of doing it through the client.
As I iterate through each issue I get the list of worklogs per ticket and then i iterate through all of the worklog items in the worklogs list (a nested for loop):
worklogs = jira_client.worklogs(issue.key)
for worklog in worklogs:
totaltime += readtime(worklog.timeSpent)
Note: My readtime
function turns the string of timeSpent
into an integer and converts hours to minutes, and is not shown here.
Using the jirashell I accessed a specific worklog of a specific ticket:
wl = jira_client.worklog(<issue key>, <worklog id>)
Then I typed in wl.
and pressed TAB, it listed the following:
wl.author, wl.comment, wl.created, wl.delete, wl.find, wl.id, wl.raw, wl.self, wl.started, wl.timeSpent, wl.timeSpentSeconds, wl.update, wl.updateAuthor, wl.updated
Note: you need to include the period at the end of wl
before pressing TAB.
Running wl.timespent
in the jirashell gave me gave me a Unicode string with the number suffixed by h
for hour or m
for minute (for example: u'6h'
). Then I new that once I generated the worklog object in my loop above, I could access the time by using the timespent
attribute.
The jirashell really helps with trying to find the attributes of the fields, etc.
You need to install package jira-python
in addition to jira
in order to run jirashell.
Also if you installed jira-python
in your virtualenv you need to run env/bin/jirashell
from your command-line once you are in your project's directory.