dapplo / Dapplo.Jira

This is a simple REST based JIRA client, written for Greenshot, by using Dapplo.HttpExtension
MIT License
35 stars 14 forks source link

How to get all worklogs - "/issue/{issueIdOrKey}/worklog" #41

Closed GabrielCoetzee closed 4 years ago

GabrielCoetzee commented 4 years ago

Hi, I am not sure if this is the right place for my question. I recently came across an issue, where I discovered the JIRA API only returns 20 worklogs. I wanted to enquire, how, by using Dapplo.JIRA, I can retrieve all worklogs for an issue?

As per last comment here : https://community.atlassian.com/t5/Answers-Developer-Questions/How-do-I-set-maxResults-for-work-logs/qaq-p/543015

One can call "/issue/{issueIdOrKey}/worklog" to retrieve all worklogs, how can one do this using Dapplo.Jira?

Thanks in advance.

Kind Regards, André

Lakritzator commented 4 years ago

I'm sure this is possible, but I need to find or create an example with multiple workslogs. I currently cannot do so, maybe on monday.

Dapplo.Jira is a client for Jira, and does in fact just do the same as you said, it calls this URI and maps the result to object instances for you. To get more than 20, one normally just needs to pass a limit (maxResults) which is more than 20. But in the link you supplied, it pretty much says there is an issue with this. Although this was years ago, I won't bet on it that Atlassian fixed this!

Currently I don't seem to pass the maxResults: https://github.com/dapplo/Dapplo.Jira/blob/master/src/Dapplo.Jira/WorkExtensions.cs#L50 I will get some test data and try to see if this would work, meaning Atlassian fixed it. If they didn't fix it, it probably won't work....

Lakritzator commented 4 years ago

So the worklog seems to be complete, at least when I use Jira in the Cloud. I currently cannot test it on Jira Server, but if you are not using Jira in the Cloud you will see yourself.

Example code:

var jiraClient = JiraClient.Create(new Uri("https://jira"));
jiraClient.SetBasicAuthentication(username, password); // use API key, instead of your password, for Jira Cloud
var worklogs = await jiraClient.Work.GetAsync(issueKey);
foreach (var workLog in worklogs)
{
    Debug.WriteLine(workLog.Comment);
}

Hope this helps.

GabrielCoetzee commented 4 years ago

Hi Lakritzator.

Thank you for the quick answer, I sincerely appreciate it. That is exactly what I was looking for. It works like a charm, thank you!

Apparently Atlassian decided to not return more than 20 worklogs per issue for performance reasons. So doing this subsequent API call if there are more than 20 worklogs is unfortunately the only way to get around this right now.

Anyway, I`ll go ahead and close this issue. Thanks again Lakritzator!

Lakritzator commented 4 years ago

Great to hear this works for you!

But I'm not sure what you mean with needing a subsequent API call, it's just one call. Are you using my library together with something else? Maybe you can refrain from using the other stuff, most JIRA functionality should be available. If there is something missing let me know.

GabrielCoetzee commented 4 years ago

Hi Lakritzator. Thank you!

Sorry, let me clarify. I mean, in my case, I do initial API call to receive list of issues under a project, and if every issue has 20 worklogs or less, that is fine to just do initial API call. But, if an issue happens to have more than 20 worklogs, I will have to do subsequent API call like above, in order to receive every worklog item under that issue.

So I don`t mean I have to do a subsequent API call every time, just if there are more than 20 worklog items on an issue.

I am only using Dapplo.JIRA. Thanks Lakritzator.