Exemplo n.º 1
0
 public WorkItem GetWorkItem(IssueMigration issueMigration)
 {
     Logger.Debug("Get work item {migration}", (jiraId: issueMigration.IssueId.ToString(), wiId: issueMigration.WorkItemId));
     return(issueMigration.WorkItemId == default
         ? GetWorkItem(issueMigration.IssueId)
         : _workItemStore.GetWorkItem(issueMigration.WorkItemId));
 }
        public string GetMappedValueOrThrow(IssueMigration migration)
        {
            var key = KeyBuildersFromMigration.Select(b => b(migration)).ToCsv();

            if (!_map.TryGetValue(key, out var adoStatus))
            {
                throw new Exception($"mapping not found for {key} in {CsvMapFile}");
            }
            return(adoStatus);
        }
Exemplo n.º 3
0
        private void MapWorkItem(
            IssueMigration migration, Issue issue, WorkItem workItem)
        {
            workItem[_adoContext.ApiSettings.JiraIdField] = issue.Key;

            workItem.Title       = issue.Fields.Summary;
            workItem.Description = issue.Fields.Description;

            workItem.State = _statusMapper.GetMappedValueOrThrow(migration);

            workItem.Fields["System.CreatedDate"].Value = issue.Fields.Created.UtcDateTime;
            workItem.Fields["System.ChangedDate"].Value = issue.Fields.Updated.UtcDateTime;

            var comments = issue.Fields.Comment.Comments;

            if (comments.Any())
            {
                var sb             = new StringBuilder(workItem.Description);
                var headerBar      = new string('-', 50);
                var smallHeaderBar = new string('-', 20);
                sb.AppendLine(
                    $"{Environment.NewLine}{headerBar}{Environment.NewLine}  COMMENTS{Environment.NewLine}{headerBar}{Environment.NewLine}");
                foreach (var comment in comments)
                {
                    sb.AppendLine($"[{comment.Author.DisplayName} @ {comment.Created}]");
                    sb.AppendLine(comment.Body);
                    sb.AppendLine($"{smallHeaderBar}");
                }

                workItem.Description = sb.ToString();
            }

            foreach (var attachmentMigration in migration.Attachments)
            {
                var fullPath = _jiraContext.LocalDirs.GetFullPath(attachmentMigration.File);
                workItem.Attachments.Add(new WiAttachment(fullPath));
                Logger.Debug("Added attachment to {issueId} {file}", issue.Key, fullPath);
                attachmentMigration.Imported = true;
                //_migrationRepository.Save(migration);
            }

            // TODO: map other fields
        }
Exemplo n.º 4
0
 public void Delete(IssueMigration migration)
 {
     Delete(migration.ToEnumerable());
 }
Exemplo n.º 5
0
        public bool TryImport(IssueMigration migration)
        {
            if (migration.ImportComplete)
            {
                if (_force)
                {
                    _migrationRepository.Reset(migration);
                }
                else
                {
                    Logger.Debug("Skipping already imported issue {issue}", migration.IssueId);
                    return(false);
                }
            }

            if (!_issueTypeCsvMapper.TryGetMappedValue(migration, out var workItemTypeKey))
            {
                Logger.Debug("Skipping issue {issue} for unknown type {issueType}", migration.IssueId, migration.IssueType);
                return(false);
            }

            if (!TryGetWorkItemType(workItemTypeKey, out var workItemType))
            {
                throw new Exception($"Unable to find work item type {workItemTypeKey} in {_adoApi.TfsProject.Name}");
            }

            var existingWorkItem = _adoApi.GetWorkItem(migration);

            if (existingWorkItem != null)
            {
                if (_force)
                {
                    Logger.Info("deleteing pre-existing workitem with originalId {originalId}", migration.IssueId);
                    _adoApi.Delete(migration);
                }
                else
                {
                    throw new Exception($"Issue {migration.IssueId} already imported for existing {migration.IssueType}.  TODO: resume migration from last stopping point");
                }
            }

            WorkItem workItem = workItemType.NewWorkItem();

            migration.TempWorkItemId = workItem.TemporaryId;
            _migrationRepository.Save(migration);
            var wiLog = new { Type = workItem.Type.Name, migration.IssueId, TempId = migration.TempWorkItemId };

            Logger.Debug("created Work Item for {wi}", wiLog);

            var issue = _jiraApi.GetIssue(migration.IssueId).Result.ToObject <Issue>();

            MapWorkItem(migration, issue, workItem);
            Logger.Debug("mapped Work Item for {wi}", wiLog);

            workItem.Save();
            migration.WorkItemId    = workItem.Id;
            migration.IssueImported = true;
            _migrationRepository.Save(migration);
            Logger.Info("Imported issue {issue} as work item {workItem}",
                        new { migration.IssueId, migration.IssueType, migration.Status },
                        new { workItem.Id, workItem.Type.Name, workItem.State, TempId = migration.TempWorkItemId });

            return(true);
        }
        public bool TryGetMappedValue(IssueMigration migration, out string value)
        {
            var key = KeyBuildersFromMigration.Select(b => b(migration)).ToCsv();

            return(_map.TryGetValue(key, out value));
        }