dapplo / Dapplo.Jira

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

Get Worklogs by User #68

Open dipique opened 2 years ago

dipique commented 2 years ago

I would like to see a user's worklogs for the last 7 days.

The issues may not be assigned to the user anymore (or they may never been been assigned since they might have been reviewing).

The only Work method I see for fetching worklogs by Issue Key; I have no way to query by Worklog.

I see that I CAN do the query that I want using issues:

  var startDate = DateTime.Now.AddDays(-7).Date;
  var endDate = DateTime.Now.Date;

  var issues = await jc.Issue.SearchAsync(
      Where.And(
          Where.WorkLogAuthor.IsCurrentUser,
          Where.WorkLogDate.AfterOrOn.DateTime(startDate),
          Where.WorkLogDate.BeforeOrOn.DateTime(endDate)                    
      )
  );

  var worklogTasks = issues.ToDictionary(i => i, i => jc.Work.GetAsync(i.Key));
  Task.WaitAll(worklogTasks.Values.ToArray());
  var userWorklogsByIssue = worklogTasks
      .ToDictionary(i => i.Key,
                    i => i.Value.Result
                      .Where(wl => wl.Author.Name == me.Name)
                      .Where(wl => wl.Started?.DateTime.Date >= startDate)
                      .Where(wl => wl.Started?.DateTime.Date <= endDate)
                      .Where(wl => wl.TimeSpentSeconds > 0)
                      .ToList()
      );

However, shouldn't I be able to query worklogs directly without search issues and then making a separate request for each set of worklogs? Especially since this functionality is available when using the API directly.

Lakritzator commented 2 years ago

Hi!

I'm not 100% sure what API you mean with "Especially since this functionality is available when using the API directly.". In general I would say, what is available in the API is something which is possible to make available via my library.

There is a way to get the changed worklogs, e.g. for the last 7 days, and go from here: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-worklog-updated-get Is that what you mean? It's not available in my project yet but I can probably add that, if you think it helps?

Best wishes, Robin

dipique commented 2 years ago

Hi!

I'm not 100% sure what API you mean with "Especially since this functionality is available when using the API directly.". In general I would say, what is available in the API is something which is possible to make available via my library.

There is a way to get the changed worklogs, e.g. for the last 7 days, and go from here: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-worklog-updated-get Is that what you mean? It's not available in my project yet but I can probably add that, if you think it helps?

Best wishes, Robin

Yes, that's exactly what I mean. Essentially, adding a Work.SearchAsync() method that is analogous to the existing Issue.SearchAsync() method. (I assume there's a good reason that it is Work instead of Worklog, although it is pretty confusing).

All that said, your library has worked perfectly for me, at least once I figured out what to do. Thanks for all your hard work; I've been able to automate a lot of my time logging using this package. And I HATE logging time. :)

Lakritzator commented 2 years ago

Let me see what I can do.

I don't know if there was a good reason to call it work... so might rename it 🤷‍♂️