jira icon indicating copy to clipboard operation
jira copied to clipboard

jira.worklogs function should return a top level object instead of list of worklogs

Open kadimgh opened this issue 6 years ago • 5 comments

There are two ways to get issue worklogs:

  1. If you obtained issue object through search for example then you can access worklogs by issue.fields.worklog. It has "total" and "maxResults" fields and by comparing those you could tell if you got all the worklogs or not (currently REST API will only return first 20 worklogs). Also it contains worklogs fields with the list of actual worklogs.

  2. Then if there are more than 20 worklogs you can get them by directly calling jira.worklogs(issue_key), this request does not have limitation of 20, however as a result of this call you get list of worklogs, although returned JSON also contains "total" and "maxResults" fields that could be used by calling application to understand if all of the worklogs have been returned.

Actual behavior: jira.worklogs(issue_key) call returns list of worklogs only Expected behavior: jira.worklogs(issue_key) should return worklog object with "total", "maxResults" and "worklogs" fields, as it is in original JSON response. Alternatively there could be additional API that would return the full worklog object, to not break existing jira.worklogs(issue_key) or jira.worklog(issue_key, worklog_id) APIs

I'm referring to the following code

@translate_resource_args
    def worklogs(self, issue):
        """Get a list of worklog Resources from the server for an issue.

        :param issue: ID or key of the issue to get worklogs from
        """
        r_json = self._get_json('issue/' + str(issue) + '/worklog')
        worklogs = [Worklog(self._options, self._session, raw_worklog_json)
                    for raw_worklog_json in r_json['worklogs']]
        return worklogs

kadimgh avatar Aug 16 '18 20:08 kadimgh

The workaround is to compare issue.fields.worklog.total with the length of jira.worklogs(issue_key) list and if list is smaller then not all worklogs were returned

kadimgh avatar Aug 16 '18 21:08 kadimgh

I think a new function would be a good idea. And once that is established we can work to deprecate the other since I'd agree that it's not the best in the current state. Confusing to say the least.

hdost avatar Oct 16 '18 00:10 hdost

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 15 '19 13:10 stale[bot]

refresh

kadimgh avatar Oct 15 '19 17:10 kadimgh

It would be great to have this functionality also in the Issue class as it can be confusing to use the JIRA instance directly to get an Issue's worklogs.

podfran avatar Apr 14 '22 13:04 podfran