Skip to content

Commit

Permalink
Fix PipelineProcessor (nkdAgility#887)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Hinshelwood nkdAgility.com <martin@nkdagility.com>
  • Loading branch information
tomfrenzel and MrHinsh authored Mar 26, 2021
1 parent 5e75586 commit bc57209
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ private UriBuilder GetUriBuilderBasedOnEndpointAndType<DefinitionType>()
}
else
{
builder.Query = "api-version=5.1-preview.1";
builder.Query = "api-version=5.1-preview";
}
return builder;
}

/// <summary>
/// Generic Method to get API Definitions (Taskgroups, Variablegroups, Build- or Release Pipelines)
/// </summary>
/// <typeparam name="DefinitionType">Type of Definition. Can be: Taskgroup, Build- or Release Pipeline</typeparam>
/// <returns>List of API Definitions </returns>
/// <typeparam name="DefinitionType">
/// Type of Definition. Can be: Taskgroup, Build- or Release Pipeline
/// </typeparam>
/// <returns>List of API Definitions</returns>
public async Task<IEnumerable<DefinitionType>> GetApiDefinitionsAsync<DefinitionType>()
where DefinitionType : RestApiDefinition, new()
{
Expand Down Expand Up @@ -169,7 +171,7 @@ public async Task<List<Mapping>> CreateApiDefinitionsAsync<DefinitionType>(IEnum
var responseContent = await result.Content.ReadAsStringAsync();
if (result.StatusCode != HttpStatusCode.OK)
{
Log.LogError("Error migrating {DefinitionType} {DefinitionName}. Please migrate it manually. {ErrorText}", typeof(DefinitionType).Name, definitionToBeMigrated.Name, responseContent);
Log.LogError("Error migrating {DefinitionType}: {DefinitionName}. Please migrate it manually. {ErrorText}", typeof(DefinitionType).Name, definitionToBeMigrated.Name, responseContent);
continue;
}
else
Expand All @@ -181,7 +183,6 @@ public async Task<List<Mapping>> CreateApiDefinitionsAsync<DefinitionType>(IEnum
SourceId = definitionToBeMigrated.Id,
TargetId = targetObject.Id
});

}
}
Log.LogInformation("{MigratedCount} of {TriedToMigrate} {DefinitionType}(s) got migrated..", migratedDefinitions.Count, definitionsToBeMigrated.Count(), typeof(DefinitionType).Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ private void EnsureConfigured()
}

/// <summary>
/// Executes Method for migrating Taskgroups, Variablegroups or Pipelines, depinding on what is set in the config.
/// Executes Method for migrating Taskgroups, Variablegroups or Pipelines, depinding on what
/// is set in the config.
/// </summary>
private async System.Threading.Tasks.Task MigratePipelinesAsync()
{
Expand Down Expand Up @@ -111,8 +112,9 @@ private async System.Threading.Tasks.Task MigratePipelinesAsync()
private IEnumerable<Mapping> FindExistingMappings<DefintionType>(IEnumerable<DefintionType> sourceDefinitions, IEnumerable<DefintionType> targetDefinitions, List<Mapping> newMappings)
where DefintionType : RestApiDefinition, new()
{
// This is not safe, because the target project can have a taskgroup with the same name but with different content
// To make this save we must add a local storage option for the mappings (sid, tid)
// This is not safe, because the target project can have a taskgroup with the same name
// but with different content To make this save we must add a local storage option for
// the mappings (sid, tid)
var alreadyMigratedMappings = new List<Mapping>();
var alreadyMigratedDefintions = targetDefinitions.Where(t => newMappings.Any(m => m.TargetId == t.Id) == false).ToList();
foreach (var item in alreadyMigratedDefintions)
Expand Down Expand Up @@ -187,7 +189,7 @@ private async Task<IEnumerable<Mapping>> CreateBuildPipelinesAsync(IEnumerable<M
}
}

if (VariableGroupMapping is not null)
if (VariableGroupMapping is not null && definitionToBeMigrated.VariableGroups is not null)
{
foreach (var variableGroup in definitionToBeMigrated.VariableGroups)
{
Expand All @@ -206,7 +208,6 @@ private async Task<IEnumerable<Mapping>> CreateBuildPipelinesAsync(IEnumerable<M
}
}
}

}
var mappings = await Target.CreateApiDefinitionsAsync<BuildDefinition>(definitionsToBeMigrated.ToList());
mappings.AddRange(FindExistingMappings(sourceDefinitions, targetDefinitions, mappings));
Expand Down Expand Up @@ -348,14 +349,14 @@ private void UpdateTaskGroupId(ReleaseDefinition definitionToBeMigrated, IEnumer
{
foreach (var WorkflowTask in deployPhase.WorkflowTasks)
{
if (WorkflowTask.DefinitionType.ToLower() != "metaTask".ToLower())
if (WorkflowTask.DefinitionType != null && WorkflowTask.DefinitionType.ToLower() != "metaTask".ToLower())
{
continue;
}
var mapping = TaskGroupMapping.FirstOrDefault(d => d.SourceId == WorkflowTask.TaskId.ToString());
if (mapping == null)
{
Log.LogWarning("Can't find taskgroup {TaskGroupId} in the target collection.", WorkflowTask.TaskId);
Log.LogWarning("Can't find taskgroup {TaskGroupName} in the target collection.", WorkflowTask.Name);
}
else
{
Expand Down

0 comments on commit bc57209

Please sign in to comment.