Example #1
0
 public void Reset(
     [Option(ShortName = "d", LongName = "delete-from-azure", Description = "Removes the work item(s) from Azure DevOps")]
     bool deleteFromAzure,
     [Operand(Description = "The Jira issue id(s) of the migrations to reset (space delimited)")]
     List <IssueId> issueIds)
 {
     issueIds.EnumerateOperation(issueIds.Count, "Reset Migration", _cancellationToken, issueId =>
     {
         var migration = _migrationRepository.Get(issueId);
         if (deleteFromAzure)
         {
             _adoContext.Api.Delete(migration);
         }
         _migrationRepository.Reset(migration);
     });
 }
Example #2
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);
        }