christianrondeau / jira-toggl-sync

A simple tool to synchronize Toggl time entries into Atlassian JIRA's work log entries
9 stars 6 forks source link

JiraRestService.GetEntries not working for username that is email address #13

Closed nathaniel-holder closed 6 years ago

nathaniel-holder commented 6 years ago

Not sure if this is a bug with online Jira (vs locally installed), but I had to make this change to JiraRestService.cs to get the dedup functionality to work when using my online Jira account:

diff --git a/JiraTogglSync.Services/JiraRestService..cs b/JiraTogglSync.Services/JiraRestService..cs
index 5c440a1..33c4d05 100644
--- a/JiraTogglSync.Services/JiraRestService..cs
+++ b/JiraTogglSync.Services/JiraRestService..cs
@@ -62,7 +62,7 @@ namespace JiraTogglSync.Services
               _jira.GetWorklogs(new IssueRef() { id = issue.id })
                                   .Where(workLog => workLog.started >= startDate
                                                   && workLog.started.AddSeconds(workLog.timeSpentSeconds) <= endDate
-                                                  && workLog?.author?.name == _username)
+                                                  && (_username.Contains('@') ? workLog?.author?.emailAddress : workLog?.author?.name) == _username)
                                   .Select(wl => new WorkLogEntry(wl, issue.key))
                                   .ToList()

I don't have a local Jira instance to test this fix against. Maybe someone else can?

Thanks!

christianrondeau commented 6 years ago

We're using it with a Jira Cloud account, and didn't hit that issue but your improvement seems sensible. Care to do a PR? Note that I'd check the username first, and fallback to the email rather than the other way around.

vipetrul commented 6 years ago

We are using Jira on premises, and didn't encounter that problem.

nathaniel-holder commented 6 years ago

@christianrondeau I don't think the order matters in the where clause: if _username is an email (contains an @ sign), then compare to email, otherwise compare to name. it could be written like this, but it's logically equivalent as far as I can see: (!_username.Contains('@') ? workLog?.author?.name : workLog?.author?.emailAddress) == _username)

It could also test on either name or email: ((workLog?.author?.name == _username) || (workLog?.author?.emailAddress == _username))

christianrondeau commented 6 years ago

I meant the second, as my username may be an email too (afaik)

christianrondeau commented 6 years ago

That looks good, merged! Thanks :)