Пример #1
0
 public UserWorklogReportRow(JiraIssue <UserWorklogReportFields> i, JiraWorklog w)
 {
     IssueKey       = i.Key;
     Date           = w.Started;
     Worklog        = w.TimeSpentSeconds;
     WorklogSummary = w.Comment;
     IssueSummary   = i.Fields?.Summary ?? "";
 }
        public async Task <JiraWorklog> GetJiraWorkLog(string issueId, string workLogId)
        {
            string resultQuery = "rest/api/latest/issue/" + issueId + "/worklog/" + workLogId;

            logger.Info("JiraApiUrl: " + jiraApiUrl);
            logger.Info("GetJiraWorkLog: " + resultQuery);
            JiraWorklog jiraWorklog = await JiraConnection.RestClient.ExecuteRequestAsync <JiraWorklog>(Method.GET, resultQuery);

            return(jiraWorklog);
        }
Пример #3
0
 public static Worklog FromWorklog(JiraWorklog jiraWorklog, string user)
 {
     return(new Worklog
     {
         User = user,
         Category = jiraWorklog.Category,
         Date = jiraWorklog.Started.Date,
         Hours = Convert.ToDecimal(jiraWorklog.Duration.TotalHours),
         IssueKey = jiraWorklog.IssueKey,
         ProjectKey = jiraWorklog.ProjectKey
     });
 }
Пример #4
0
 private void SyncronizeWorklog(JiraWorklog worklog, IEnumerable <WorkEntry> entriesForIssue)
 {
     foreach (WorkEntry wEntry in entriesForIssue)
     {
         JiraWorkEntry jEntry = wEntry.FindMatchingEntry(worklog);
         if (jEntry == null)
         {
             Jira.AddWorkEntry(wEntry);
         }
         else if (jEntry.TimeSpentSeconds != (wEntry.DurationInMinutes * 60))
         {
             Jira.SyncWorkEntry(jEntry, wEntry);
         }
         else
         {
             Logger.DebugFormat("Entry {0} in {1} already correct", wEntry.TogglId, wEntry.IssueId);
         }
     }
 }
Пример #5
0
        private void SyncTogglEntries(IEnumerable <TogglEntry> togglEntries, DateTime startSyncTime)
        {
            bool succeeded                = true;
            bool changedIssue             = false;
            IList <WorkEntry> workEntries = TranslateEntries(togglEntries);

            IEnumerable <IGrouping <string, WorkEntry> > groupedEntries = from e in workEntries
                                                                          where e.Updated > _lastSyncTime
                                                                          group e by e.IssueId into eg
                                                                          select eg;

            JiraClient jiraClient = Jira;

            foreach (IGrouping <string, WorkEntry> entriesForIssue in groupedEntries)
            {
                // TODO: Handle when issues aren't editable
                JiraWorklog worklog = jiraClient.GetIssueWorklog(entriesForIssue.Key);
                if (worklog != null)
                {
                    Logger.DebugFormat("Syncronizing worklog for {0}", entriesForIssue.Key);
                    SyncronizeWorklog(worklog, entriesForIssue);
                    changedIssue = true;
                }
                else
                {
                    AlertStatusChange("Failed to get Jira issue worklog", Logger.Warn);
                    Logger.ErrorFormat("Unable to get worklog for {0}", entriesForIssue.Key);
                    succeeded = false;
                }
            }

            if (succeeded)
            {
                if (changedIssue)
                {
                    AlertStatusChange("Syncronized successfully", Logger.Info);
                }
                Logger.Debug("Successfully syncronized systems");
                _lastSyncTime = startSyncTime;
            }
        }
Пример #6
0
        public virtual Worklogs GetWorklogs(IEnumerable <string> users, DateTime from, DateTime till)
        {
            Worklogs results = new Worklogs();

            ConcurrentBag <dynamic> issuesJsons = new ConcurrentBag <dynamic>();
            dynamic   firstIssuesJson           = GetIssuesWithWorklogs(users, from, till, 0);
            PagingJob issuesPagingJob           = new PagingJob(firstIssuesJson.issues.Count, firstIssuesJson.total.Value);

            issuesJsons.Add(firstIssuesJson);

            if (issuesPagingJob.IsPagingNecessary)
            {
                Parallel.ForEach(issuesPagingJob.GetPageStarts(), new ParallelOptions {
                    MaxDegreeOfParallelism = 1
                }, pageStart =>
                {
                    issuesJsons.Add(GetIssuesWithWorklogs(users, from, till, pageStart));
                });
            }

            ConcurrentBag <dynamic>           worklogsJsons      = new ConcurrentBag <dynamic>();
            ConcurrentBag <WorklogsPagingJob> worklogsPagingJobs = new ConcurrentBag <WorklogsPagingJob>();

            foreach (dynamic issuesJson in issuesJsons)
            {
                Parallel.ForEach(issuesJson.issues, new ParallelOptions {
                    MaxDegreeOfParallelism = 1
                }, (Action <dynamic>)(issueJson =>
                {
                    if (issueJson.fields != null && issueJson.fields.worklog != null)
                    {
                        List <string> labels = new List <string>();
                        if (issueJson.fields.parent != null)
                        {
                            dynamic issueParent = GetIssue((string)issueJson.fields.parent.key, "labels");
                            foreach (dynamic label in issueParent.fields.labels)
                            {
                                labels.Add((string)label);
                            }
                        }
                        else if (issueJson.fields.labels != null)
                        {
                            foreach (dynamic label in issueJson.fields.labels)
                            {
                                labels.Add((string)label);
                            }
                        }

                        dynamic firstWorklogsJson           = issueJson.fields.worklog;
                        WorklogsPagingJob worklogsPagingJob = new WorklogsPagingJob(issueJson.key.Value, labels, firstWorklogsJson.worklogs.Count, firstWorklogsJson.total.Value);
                        if (worklogsPagingJob.IsPagingNecessary)
                        {
                            worklogsPagingJobs.Add(worklogsPagingJob);
                        }
                        else
                        {
                            firstWorklogsJson.issueKey = issueJson.key;
                            firstWorklogsJson.labels   = String.Join("||", labels);
                            worklogsJsons.Add(firstWorklogsJson);
                        }
                    }
                    else
                    {
                        worklogsPagingJobs.Add(new WorklogsPagingJob(issueJson.key.Value, Enumerable.Empty <string>(), 0, 1000));
                    }
                }));
            }

            Parallel.ForEach(worklogsPagingJobs, new ParallelOptions {
                MaxDegreeOfParallelism = 1
            }, x =>
            {
                dynamic worklogsJson  = GetWorklogsForIssue(x.IssueKey, 0);
                worklogsJson.issueKey = x.IssueKey;
                worklogsJson.labels   = String.Join("||", x.Labels);
                worklogsJsons.Add(worklogsJson);
            });

            foreach (dynamic worklogJsons in worklogsJsons)
            {
                string issueKey = worklogJsons.issueKey;
                string labels   = worklogJsons.labels ?? String.Empty;
                foreach (dynamic worklogJson in worklogJsons.worklogs)
                {
                    DateTime startTime            = worklogJson.started.Value;
                    string   workLoggedByUserName = worklogJson.author.displayName.Value;
                    string   workLoggedByUser     = users.SingleOrDefault(x => x == workLoggedByUserName);
                    if (startTime >= from && startTime <= till && workLoggedByUser != null)
                    {
                        JiraWorklog jiraWorklog = new JiraWorklog
                        {
                            IssueKey = issueKey,
                            Labels   = labels.Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries),
                            Started  = startTime,
                            Duration = TimeSpan.FromSeconds(Convert.ToDouble(worklogJson.timeSpentSeconds.Value))
                        };
                        results.AddWorklogForUser(workLoggedByUser, jiraWorklog);
                    }
                }
            }

            return(results);
        }
Пример #7
0
 internal JiraWorkEntry FindMatchingEntry(JiraWorklog worklog)
 {
     return(worklog.Entries.FirstOrDefault(e => e.Comment.Contains(LogMarker)));
 }