Skip to content

Commit

Permalink
Merge branch 'main' into fix-more-links
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHinsh authored Nov 20, 2024
2 parents 601cbfe + a766b79 commit f7749b5
Show file tree
Hide file tree
Showing 31 changed files with 85 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace MigrationTools.Endpoints
{
public class AzureDevOpsEndpoint : Endpoint<AzureDevOpsEndpointOptions>
{
[Obsolete("Dont know what this is for")]
public override int Count => 0;

public AzureDevOpsEndpoint(IOptions<AzureDevOpsEndpointOptions> optipons, EndpointEnricherContainer endpointEnrichers, IServiceProvider serviceProvider, ITelemetryLogger telemetry, ILogger<AzureDevOpsEndpoint> logger)
Expand Down Expand Up @@ -208,10 +209,8 @@ public async Task<IEnumerable<DefinitionType>> GetApiDefinitionsAsync<Definition
/// <typeparam name="DefinitionType"></typeparam>
/// <param name="routeParameters">strings that are injected into the route parameters of the definitions url</param>
/// <param name="queryString">additional query string parameters passed to the underlying api call</param>
/// <param name="singleDefinitionQueryString">additional query string parameter passed when pulling the single instance details (ie. $expands, etc)</param>
/// <param name="queryForDetails">a boolean flag to allow caller to skip the calls for each individual definition details</param>
/// <returns></returns>
public async Task<DefinitionType> GetApiDefinitionAsync<DefinitionType>(string[] routeParameters = null, string queryString = "", string singleDefinitionQueryString = "", bool queryForDetails = true)
public async Task<DefinitionType> GetApiDefinitionAsync<DefinitionType>(string[] routeParameters = null, string queryString = "")
where DefinitionType : RestApiDefinition, new()
{
var apiPathAttribute = typeof(DefinitionType).GetCustomAttributes(typeof(ApiPathAttribute), false).OfType<ApiPathAttribute>().FirstOrDefault();
Expand All @@ -235,11 +234,10 @@ public async Task<DefinitionType> GetApiDefinitionAsync<DefinitionType>(string[]
/// <summary>
/// Make HTTP Request to add Revision / Version of Task Group
/// </summary>
/// <param name="targetDefinitions"></param>
/// <param name="rootDefinitions"></param>
/// <param name="updatedDefinitions"></param>
/// <returns>List of Mappings</returns>
public async Task<List<Mapping>> UpdateTaskGroupsAsync(IEnumerable<TaskGroup> targetDefinitions, IEnumerable<TaskGroup> rootDefinitions, IEnumerable<TaskGroup> updatedDefinitions)
public async Task<List<Mapping>> UpdateTaskGroupsAsync(IEnumerable<TaskGroup> rootDefinitions, IEnumerable<TaskGroup> updatedDefinitions)
{
var migratedDefinitions = new List<Mapping>();
foreach (var definitionToBeMigrated in updatedDefinitions)
Expand Down Expand Up @@ -649,4 +647,4 @@ public static void AddToPath(this HttpClient client, string pathToAdd)
client.BaseAddress = new Uri($"https://{client.BaseAddress.Host}:{client.BaseAddress.Port}{client.BaseAddress.LocalPath}{pathToAdd}{client.BaseAddress.Query}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ private IEnumerable<DefinitionType> FilterOutExistingDefinitions<DefinitionType>
/// <summary>
/// Filter incompatible TaskGroups
/// </summary>
/// <param name="filteredTaskGroups"></param>
/// <param name="sourceDefinitions"></param>
/// <param name="availableTasks"></param>
/// <param name="taskGroupMapping"></param>
/// <returns>List of filtered Definitions</returns>
private IEnumerable<BuildDefinition> FilterOutIncompatibleBuildDefinitions(IEnumerable<BuildDefinition> sourceDefinitions, IEnumerable<TaskDefinition> availableTasks, IEnumerable<Mapping> taskGroupMapping)
{
Expand Down Expand Up @@ -631,7 +632,7 @@ private async Task<IEnumerable<Mapping>> CreateTaskGroupDefinitionsAsync()

targetDefinitions = await Target.GetApiDefinitionsAsync<TaskGroup>(queryForDetails: false);
var rootTargetDefinitions = SortDefinitionsByVersion(targetDefinitions).First();
await Target.UpdateTaskGroupsAsync(targetDefinitions, rootTargetDefinitions, updatedSourceDefinitions);
await Target.UpdateTaskGroupsAsync(rootTargetDefinitions, updatedSourceDefinitions);

targetDefinitions = await Target.GetApiDefinitionsAsync<TaskGroup>(queryForDetails: false);
mappings.AddRange(FindExistingMappings(sourceDefinitions, targetDefinitions.Where(d => d.Name != null), mappings));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace MigrationTools.Processors
{

internal class ProcessorModel
{
public Dictionary<string, ProcessDefinitionModel> ProcessDefinitions { get; set; } = new Dictionary<string, ProcessDefinitionModel>();
Expand Down Expand Up @@ -151,7 +151,7 @@ await SourceFields.Values.ParallelForEachAsync(Math.Max(1, Options.MaxDegreeOfPa
catch (Exception ex)
{
Log.LogError(ex, "Failed to synchronize processes.");
throw ex;
throw;
}
}

Expand Down Expand Up @@ -215,7 +215,7 @@ await SyncDefinitionType<WorkItemState>(
foreach (var field in sourceWit.Fields)
{
var existingField = TargetModel.WorkItemFields.Values.FirstOrDefault(x => x.ReferenceName == field.ReferenceName);
//if (existingField == null || (existingField != null && field.Customization != "system")) // I don't think you can modify
//if (existingField == null || (existingField != null && field.Customization != "system")) // I don't think you can modify
//{
await SyncDefinitionType<WorkItemTypeField>(
TargetModel.WorkItemFields,
Expand Down Expand Up @@ -320,7 +320,7 @@ await SyncDefinitionType<WorkItemPage>(
}
else
{

// Its on a different page .. lets move pages
var tempTargetGroup = existingGroup.Value.CloneAsNew();
tempTargetGroup.Id = existingGroup.Value.Id;
Expand Down Expand Up @@ -446,7 +446,7 @@ await SyncDefinitionType<WorkItemPage>(
Log.LogInformation($"Completed sync of work item type [{Source.Options.Name}::{sourceWit.WorkItemType.Name}] in [{Target.Options.Name}::{targetWit.WorkItemType.Name}].");
}



private async Task<DefinitionType> SyncDefinitionType<DefinitionType>(Dictionary<string, DefinitionType> DataDictionary, DefinitionType sourceDef, DefinitionType targetDef, params string[] routeParams)
where DefinitionType : RestApiDefinition, ISynchronizeable<DefinitionType>, new()
Expand All @@ -468,7 +468,7 @@ private async Task<DefinitionType> SyncDefinitionType<DefinitionType>(Dictionary
private async Task BuildModel(ProcessorModel model, AzureDevOpsEndpoint endpoint, bool warnOnMissing)
{
// Grab all the procs, then iterate over them looking for procs user has configured to be
// sync'd. Then grab all Work Item Types for the given process and filter those by the ones user
// sync'd. Then grab all Work Item Types for the given process and filter those by the ones user
// wants to sync.

Log.LogDebug($"Loading model for [{endpoint.Options.Name}].");
Expand Down Expand Up @@ -589,7 +589,7 @@ private async Task LoadWorkItemFields(ProcessorModel model, WorkItemType wit, Az
}
private async Task LoadLayout(ProcessorModel model, WorkItemTypeModel wit, AzureDevOpsEndpoint endpoint, string processId)
{
wit.Layout = (await endpoint.GetApiDefinitionAsync<WorkItemLayout>(new string[] { processId, wit.WorkItemType.ReferenceName }, queryForDetails: false));
wit.Layout = (await endpoint.GetApiDefinitionAsync<WorkItemLayout>(new string[] { processId, wit.WorkItemType.ReferenceName }));
foreach (var page in wit.Layout.Pages)
{
var pageKey = $"{wit.WorkItemType.Name}::{page.Label}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public FileSystemWorkItemEndpoint(IOptions<FileSystemWorkItemEndpointOptions> op
_innerList = new List<WorkItemData>();
}

[Obsolete("Dont know what this is for")]
public override int Count => GetWorkItems().Count();

public void EnsureStore()
Expand Down Expand Up @@ -70,4 +71,4 @@ public void PersistWorkItem(WorkItemData source)
LoadStore();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ public Uri TfsProjectUri
get { return TfsProject.Uri; }
}

[Obsolete("Dont know what this is for")]
public override int Count => 0;




private TfsTeamProjectCollection GetTfsCollection()
{
using (var activity = ActivitySourceProvider.ActivitySource.StartActivity("GetTfsCollection", ActivityKind.Client))
Expand Down Expand Up @@ -191,4 +189,4 @@ private Project GetTfsProject()
return _Project;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ IServiceProvider Services

_workItemClient = ActivatorUtilities.CreateInstance<TfsWorkItemMigrationClient>(Services, this, options);
//networkCredentials IOptions<NetworkCredentialsOptions> networkCredentials,

}

[Obsolete("Dont know what this is for")]
public override int Count => 0;


public IWorkItemMigrationClient WorkItems
{
get
Expand Down Expand Up @@ -177,4 +176,4 @@ public T GetClient<T>() where T : IVssHttpClient
return _collection.GetClient<T>();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private SortedDictionary<int, RevisionItem> GetRevisionItems(RevisionCollection
var dictionary = items.ToDictionary(item => item.Number);
return new SortedDictionary<int, RevisionItem>(dictionary);
}
catch (ArgumentException e)
catch (ArgumentException)
{
Log.Warning("For some Reason there are multiple Revisions on {WorkItemId} with the same System.Rev. We will create a renumbered list...", items[0].WorkItemId);
var currentNumber = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public class TfsExportUsersForMappingProcessorOptions : ProcessorOptions

public string WIQLQuery { get; set; }

/// `OnlyListUsersInWorkItems`
/// <summary>
/// `OnlyListUsersInWorkItems`
/// </summary>
/// <default>true</default>
public bool OnlyListUsersInWorkItems { get; set; } = true;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ public class TfsTestPlansAndSuitesMigrationProcessorOptions : ProcessorOptions

public bool FilterCompleted { get; set; }

/// <inheritdoc />
public bool IsProcessorCompatible(IReadOnlyList<IProcessorConfig> otherProcessors)
{
return true;
}

public TfsTestPlansAndSuitesMigrationProcessorOptions()
{
MigrationDelay = 0;
RemoveAllLinks = false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@ namespace MigrationTools.Processors
{
public class TfsTestVariablesMigrationProcessorOptions : ProcessorOptions
{
/// <inheritdoc />
public bool Enabled { get; set; }

/// <inheritdoc />
public string Processor
{
get { return "TestVariablesMigrationContext"; }
}

/// <inheritdoc />
public bool IsProcessorCompatible(IReadOnlyList<IProcessorConfig> otherProcessors)
{
return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class TfsWorkItemMigrationProcessor : TfsProcessor

private static int _count = 0;
private static int _current = 0;
private static long _elapsedms = 0;
private static int _totalWorkItem = 0;
private static string workItemLogTemplate = "[{sourceWorkItemTypeName,20}][Complete:{currentWorkItem,6}/{totalWorkItems}][sid:{sourceWorkItemId,6}|Rev:{sourceRevisionInt,3}][tid:{targetWorkItemId,6} | ";
private List<string> _ignore;
Expand Down Expand Up @@ -159,12 +158,11 @@ protected override void InternalExecute()

_current = 1;
_count = sourceWorkItems.Count;
_elapsedms = 0;
_totalWorkItem = sourceWorkItems.Count;
ProcessorActivity.SetTag("source_workitems_to_process", sourceWorkItems.Count);
foreach (WorkItemData sourceWorkItemData in sourceWorkItems)
{

var stopwatch = Stopwatch.StartNew();
var sourceWorkItem = TfsExtensions.ToWorkItem(sourceWorkItemData);
workItemLog = contextLog.ForContext("SourceWorkItemId", sourceWorkItem.Id);
Expand Down Expand Up @@ -259,7 +257,7 @@ private void ValidateAllUsersExistOrAreMapped(List<WorkItemData> sourceWorkItems
// } else
// {
// contextLog.Error("nodeStructureEnricher is disabled! Please enable it in the config.");
// }
// }
//}

private void ValidateAllWorkItemTypesHaveReflectedWorkItemIdField(List<WorkItemData> sourceWorkItems)
Expand Down Expand Up @@ -432,7 +430,7 @@ private void PopulateWorkItem(WorkItemData oldWorkItemData, WorkItemData newWork

foreach (Field f in oldWorkItem.Fields)
{
CommonTools.UserMapping.MapUserIdentityField(this, f);
CommonTools.UserMapping.MapUserIdentityField(f);
if (newWorkItem.Fields.Contains(f.ReferenceName) == false)
{
var missedMigratedValue = oldWorkItem.Fields[f.ReferenceName].Value;
Expand Down Expand Up @@ -551,7 +549,7 @@ private async Task ProcessWorkItemAsync(WorkItemData sourceWorkItem, int retryLi
if (revisionsToMigrate.Count == 0)
{
ProcessWorkItemAttachments(sourceWorkItem, targetWorkItem, false);
ProcessWorkItemLinks(Source.WorkItems, Target.WorkItems, sourceWorkItem, targetWorkItem);
ProcessWorkItemLinks(sourceWorkItem, targetWorkItem);
ProcessHTMLFieldAttachements(targetWorkItem);
ProcessWorkItemEmbeddedLinks(sourceWorkItem, targetWorkItem);
TraceWriteLine(LogEventLevel.Information, "Skipping as work item exists and no revisions to sync detected");
Expand Down Expand Up @@ -648,7 +646,7 @@ private void ProcessWorkItemAttachments(WorkItemData sourceWorkItem, WorkItemDat
}
}

private void ProcessWorkItemLinks(IWorkItemMigrationClient sourceStore, IWorkItemMigrationClient targetStore, WorkItemData sourceWorkItem, WorkItemData targetWorkItem)
private void ProcessWorkItemLinks(WorkItemData sourceWorkItem, WorkItemData targetWorkItem)
{
if (targetWorkItem != null && CommonTools.WorkItemLink.Enabled && sourceWorkItem.ToWorkItem().Links.Count > 0)
{
Expand Down Expand Up @@ -834,7 +832,7 @@ private WorkItemData ReplayRevisions(List<RevisionItem> revisionsToMigrate, Work
ProcessWorkItemAttachments(sourceWorkItem, targetWorkItem, false);
if (!string.IsNullOrEmpty(targetWorkItem.Id))
{
ProcessWorkItemLinks(Source.WorkItems, Target.WorkItems, sourceWorkItem, targetWorkItem);
ProcessWorkItemLinks(sourceWorkItem, targetWorkItem);
// The TFS client seems to plainly ignore the ChangedBy field when saving a link, so we need to put this back in place
targetWorkItem.ToWorkItem().Fields["System.ChangedBy"].Value = "Migration";
}
Expand Down Expand Up @@ -960,4 +958,4 @@ private bool ValidateRevisionField(WorkItemData targetWorkItemData, string field
return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public void ProcessAttachemnts(TfsProcessor processer, WorkItemData source, Work
{
string filepath = null;
Directory.CreateDirectory(Path.Combine(_exportWiPath, wia.Id.ToString()));
filepath = ExportAttachment(source.ToWorkItem(), wia, _exportWiPath);
filepath = ExportAttachment(wia, _exportWiPath);
Log.LogDebug("AttachmentMigrationEnricher: Exported {Filename} to disk", Path.GetFileName(filepath));
if (filepath != null)
{
ImportAttachment(target.ToWorkItem(), wia, filepath, save);
ImportAttachment(target.ToWorkItem(), wia, filepath);
Log.LogDebug("AttachmentMigrationEnricher: Imported {Filename} from disk", Path.GetFileName(filepath));
}
}
Expand All @@ -95,14 +95,14 @@ public void CleanUpAfterSave()
Directory.Delete(_exportWiPath, true);
_exportWiPath = null;
}
catch (Exception ex)
catch (Exception)
{
Log.LogWarning(" ERROR: Unable to delete folder {0}! Should be cleaned up at the end.", _exportWiPath);
}
}
}

private string ExportAttachment(WorkItem wi, Attachment wia, string exportpath)
private string ExportAttachment(Attachment wia, string exportpath)
{
string fname = GetSafeFilename(wia.Name);
Log.LogDebug(fname);
Expand Down Expand Up @@ -131,7 +131,7 @@ private string ExportAttachment(WorkItem wi, Attachment wia, string exportpath)
return fpath;
}

private void ImportAttachment(WorkItem targetWorkItem, Attachment wia, string filepath, bool save = true)
private void ImportAttachment(WorkItem targetWorkItem, Attachment wia, string filepath)
{
var filename = Path.GetFileName(filepath);
FileInfo fi = new FileInfo(filepath);
Expand Down Expand Up @@ -184,4 +184,4 @@ private void SetupWorkItemServer(TfsProcessor processer)
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class TfsGitRepositoryTool : Tool<TfsGitRepositoryToolOptions>
{

private bool _save = true;
private bool _filter = true;
private GitRepositoryService sourceRepoService;
private IList<GitRepository> sourceRepos;
private IList<GitRepository> allSourceRepos;
Expand Down Expand Up @@ -57,7 +56,7 @@ private void SetupRepoBits()
targetRepos = targetRepoService.QueryRepositories(_processor.Target.Options.Project);
allTargetRepos = targetRepoService.QueryRepositories("");
}
catch (Exception ex)
catch (Exception)
{
sourceRepoService = null;
}
Expand Down Expand Up @@ -250,4 +249,4 @@ private string GetTargetRepoName(Dictionary<string, string> gitRepoMappings, Tfs
}

}
}
}
Loading

0 comments on commit f7749b5

Please sign in to comment.