예제 #1
0
        public void TranslateItemToJira(WorkItem workItem, Jira jira, Session session)
        {
            var key            = workItem.Fields["ExternalAccountId"].Value.ToString();
            var issue          = jira.GetIssue(key);
            var correspondings = jira.GetCorrespondings(issue);
            var revisions      =
                workItem.Revisions.Cast <Revision>()
                .Where(elem => !_store.IsTfsRevisionInChanges(elem.WorkItem.Id, elem.Index)).OrderBy(elem => elem.Index);

            foreach (Revision revision in revisions)
            {
                try
                {
                    TranslateRevisionToJira(revision, jira, session);
                }
                catch (Exception ex)
                {
                    _store.AddSessionChange(new SessionChange
                    {
                        Bug     = correspondings,
                        Session = session,
                        Date    = DateTime.Now,
                        //JiraChangelog = jira.GetLastChangelogId(key),
                        Operation   = string.Format(ex.ToString()),
                        TFSRevision = revision.WorkItem.Id + "-" + revision.Index,
                        SyncState   = SyncState.Fail
                    });
                }
            }

            Logger.WriteInfo(p => p.JMessage(Site.Jira, Operation.Sended, Artifact.WorkItem, workItem.Fields["ExternalAccountId"].Value.ToString(), partnerId: workItem.Id.ToString()));
        }
예제 #2
0
파일: Jira.cs 프로젝트: Chaliapine/JiraTFS
        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
                    });
                }
            }
        }