Beispiel #1
0
        public void TraslateChangelogToTfs(Issue issue, Tfs tfs, Session session)
        {
            var workItem       = tfs.GetWorkItemByIssueKey(issue.Key);
            var correspondings = _store.GetBug(workItemId: workItem.Id);

            foreach (var history in issue.Changelog.Histories)
            {
                if (_store.IsJiraLogInChanges(history.Id))
                {
                    continue;
                }
                try
                {
                    InnerTranslateChangelogToTfs(issue, tfs, session, history);
                }
                catch (Exception ex)
                {
                    _store.AddSessionChange(new SessionChange
                    {
                        Bug           = correspondings,
                        Session       = session,
                        Date          = DateTime.Now,
                        JiraChangelog = history.Id.ToString(),
                        Operation     = ex.Message,
                        SyncState     = SyncState.Fail
                    });
                }
            }
        }
Beispiel #2
0
        public JiraTfs(IStore store, Jira jira, Tfs tfs)
        {
            _store = store;
            _jira  = jira;
            _tfs   = tfs;

            _timeDifferenceBtwJira = jira.GetServerTime() - DateTime.Now;
            _timeDifferenceBtfTfs  = tfs.GetServerTime() - DateTime.Now;

            global = ConfigurationManager.GetSection("globalConfig") as GlobalConfigurationSection;
        }
Beispiel #3
0
        public WorkItem CreateWorkItem(Tfs tfs, Issue issue)
        {
            var tfsConfig = ConfigurationManager.GetSection("tfs") as TfsConfigSection;
            var workItem  = new WorkItem(tfs.TeamProject.WorkItemTypes["Bug"]);

            SyncFields(workItem, issue);
            workItem.IterationPath = tfsConfig.DefaultIterationPath;
            workItem.Fields["Repro steps"].Value = "См. Исходное замечание";

            workItem.Save(SaveFlags.MergeAll);
            tfs.SyncFields(workItem, this);
            var correspondings = _store.AddBug(workItem.Id, issue.Key);

            logger.WriteInfo(p => p.JMessage(Site.Tfs, Operation.Create, Artifact.WorkItem, workItem.Id.ToString(), workItem.Id.ToString(), issue.Key));
            return(workItem);
        }
Beispiel #4
0
        public void TranslateIssueToTfs(Issue issue, Tfs tfs, Session session)
        {
            issue = GetIssue(issue.Key);
            WorkItem workItem       = tfs.GetWorkItemByIssueKey(issue.Key);
            Bug      correspondings = GetCorrespondings(issue);

            if (workItem == null)
            {
                workItem = CreateWorkItem(tfs, issue);
                //Если появились при создании
                var attachments = LoadAttachments(issue.Key);
                foreach (var attachment in attachments)
                {
                    var path = global.AttachmentsFolder + attachment.Filename;
                    tfs.AttachFileTo(path, workItem);
                }


                AddChangeAtCurrentSession(workItem, issue, session, string.Format("Создан элемент {0}. Количество вложений {1}", workItem.Id, workItem.AttachedFileCount));
            }

            if (!workItem.IsOpen)
            {
                workItem.Open();
            }
            //SyncFields(workItem, issue);

            TraslateChangelogToTfs(issue, tfs, session);

            if (workItem.IsDirty)
            {
                workItem.Save(SaveFlags.MergeAll);
                AddChangeAtCurrentSession(workItem, issue, session, string.Format("Перемещены поля из Jira в TFS ({0} - {1})", issue.Key, workItem.Id));
            }



            //todo: Подписывать, что комментарий изменен
            var issueComments = GetComments(issue).Where(comment => !comment.body.StartsWith("TFS"));
            var tfsComments   = workItem.GetHistory();

            foreach (var issueComment in issueComments)
            {
                if (!_store.IsJiraLogInChanges(issueComment.body) &&
                    !tfsComments.Any(comment => issueComment.renderedBody.RemakeBadTags().EqualToComment(comment)))
                {
                    issueComment.renderedBody = string.Format("Jira |[{3}] {0} пишет:{1}{2}", issueComment.Author.DisplayName,
                                                              Environment.NewLine,
                                                              issueComment.renderedBody, issueComment.UpdatedTime);

                    workItem.Fields["History"].Value = issueComment.renderedBody;
                }
                if (workItem.IsDirty)
                {
                    workItem.Save(SaveFlags.MergeAll);
                    _store.AddSessionChange(
                        new SessionChange
                    {
                        Bug           = correspondings,
                        Session       = session,
                        Date          = DateTime.Now,
                        Operation     = string.Format("Добавлен комментарий  элементу {0}", workItem.Id),
                        JiraChangelog = issueComment.body,
                        TFSRevision   = workItem.Id + "-" + workItem.GetLastRevision().Index,
                        SyncState     = SyncState.Success
                    });
                }
            }
            tfs.SyncFields(workItem, this);
            logger.WriteInfo(p => p.JMessage(Site.Tfs, Operation.Sended, Artifact.WorkItem, issue.Key, issue.Key, workItem.Id.ToString()));
        }
Beispiel #5
0
        private void InnerTranslateChangelogToTfs(Issue issue, Tfs tfs, Session session, History history)
        {
            var workItem       = tfs.GetWorkItemByIssueKey(issue.Key);
            var correspondings = _store.GetBug(workItemId: workItem.Id);

            if (!workItem.IsOpen)
            {
                workItem.Open();
            }
            foreach (var item in history.Items)
            {
                switch (item.Field)
                {
                case "status":
                    var fromStatus   = item.FromString;
                    var toStatus     = item.ToString;
                    var stateChanges = _store.ReadProgram(Tracker.Jira, fromStatus, toStatus);
                    IEnumerable <StateChangedCommand> stateChangedCommands = Enumerable.Empty <StateChangedCommand>();
                    if (stateChanges.Count() == 1)
                    {
                        stateChangedCommands = _store.ReadCommands(stateChanges.FirstOrDefault().Id);
                    }
                    else
                    {
                        foreach (var stateChange in stateChanges)
                        {
                            if (stateChange.Condition == Condition.WorkIsDone && stateChange.ConditionValue == tfs.SomeWorkIsDone(workItem))
                            {
                                stateChangedCommands = _store.ReadCommands(stateChange.Id);
                                break;
                            }
                        }
                    }

                    foreach (var stateChangedCommand in stateChangedCommands)
                    {
                        switch (stateChangedCommand.Command)
                        {
                        case Command.ChangeState:
                            workItem.Fields[stateChangedCommand.FieldName].Value =
                                stateChangedCommand.ChangeTo;
                            if (workItem.IsDirty)
                            {
                                logger.Info(
                                    "Изменение статуса элемента {0} на {1}. Изменился статус запроса {2} с {3} на {4}. Команда {5}",
                                    workItem.Id, stateChangedCommand.ChangeTo, issue.Key, fromStatus,
                                    toStatus,
                                    JsonConvert.SerializeObject(stateChangedCommand));
                                logger.WriteInfo(
                                    p =>
                                    p.JMessage(Site.Jira, Operation.Changed, Artifact.WorkItem,
                                               workItem.Id.ToString(),
                                               workItem.Id.ToString(), issue.Key));
                                workItem.Save(SaveFlags.MergeAll);
                                _store.AddSessionChange(new SessionChange
                                {
                                    Bug           = correspondings,
                                    Session       = session,
                                    Date          = DateTime.Now,
                                    JiraChangelog = history.Id.ToString(),
                                    Operation     =
                                        string.Format("Измение статуса на {0}",
                                                      stateChangedCommand.ChangeTo),
                                    TFSRevision = workItem.Id + "-" + workItem.GetLastRevision().Index,
                                    SyncState   = SyncState.Success
                                });
                            }
                            break;
                        }
                    }

                    break;

                case "Attachment":
                    if (item.FromString == null)
                    {
                        var attachmentName = item.ToString;
                        if (issue.Fields.Attachment.Any(elem => elem.Filename == attachmentName) &&
                            workItem.Attachments.Cast <TfsAttachment>().All(elem => elem.Name != attachmentName))
                        {
                            LoadAttachment(issue, attachmentName);
                            tfs.AttachFileTo(global.AttachmentsFolder + attachmentName, workItem);
                        }
                    }
                    else
                    {
                        var attachmentToDelete =
                            workItem.Attachments.Cast <TfsAttachment>()
                            .FirstOrDefault(elem => elem.Name == item.FromString);
                        if (attachmentToDelete != null)
                        {
                            workItem.Attachments.Remove(attachmentToDelete);
                        }
                    }
                    break;
                }

                if (workItem.IsDirty)
                {
                    workItem.Save(SaveFlags.MergeAll);
                    var attachmentsFolder = new DirectoryInfo(global.AttachmentsFolder);
                    attachmentsFolder.ClearFolder();
                    _store.AddSessionChange(new SessionChange
                    {
                        Bug           = correspondings,
                        Session       = session,
                        Date          = DateTime.Now,
                        JiraChangelog = history.Id.ToString(),
                        Operation     = "Добавлены вложения",
                        TFSRevision   = workItem.Id + "-" + workItem.GetLastRevision().Index,
                        SyncState     = SyncState.Success
                    });
                }
            }
        }