Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Worklogs by User #68

Open
dipique opened this issue Sep 7, 2021 · 3 comments
Open

Get Worklogs by User #68

dipique opened this issue Sep 7, 2021 · 3 comments

Comments

@dipique
Copy link

dipique commented Sep 7, 2021

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
Copy link
Member

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
Copy link
Author

dipique commented Sep 8, 2021

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
Copy link
Member

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 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants