Skip to content

Commit

Permalink
🔧 (appsettings.json, TfsTeamProjectAuthentication.cs, TfsEndpointOpti…
Browse files Browse the repository at this point in the history
…ons.cs, TfsWorkItemMigrationProcessorOptions.cs, EndpointOptions.cs, ProcessorOptions.cs): add new configuration fields and improve JSON serialization handling

Add the "ReflectedWorkItemIdField" to multiple sections in appsettings.json to support custom work item ID fields. Improve JSON serialization handling by adding `NullValueHandling.Ignore` and `DefaultValueHandling.Ignore` attributes to various properties in the codebase. This ensures that default values and null properties are not serialized, reducing the size of the configuration files and making them cleaner.

These changes enhance the flexibility and maintainability of the configuration files, allowing for more customized and efficient setups.
  • Loading branch information
MrHinsh committed Sep 24, 2024
1 parent cf9e444 commit 48d5f5c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
24 changes: 7 additions & 17 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Collection": "",
"Project": "",
"AllowCrossProjectLinking": false,
"ReflectedWorkItemIdField": "Custom.ReflectedWorkItemId",
"Authentication": {
"AuthenticationMode": "AccessToken",
"AccessToken": "",
Expand All @@ -36,6 +37,7 @@
"Collection": "",
"Project": "",
"AllowCrossProjectLinking": false,
"ReflectedWorkItemIdField": "Custom.ReflectedWorkItemId",
"Authentication": {
"AuthenticationMode": "AccessToken",
"AccessToken": "",
Expand All @@ -57,6 +59,7 @@
"Collection": "https://dev.azure.com/nkdagility-preview/",
"Project": "migrationSource1",
"AllowCrossProjectLinking": false,
"ReflectedWorkItemIdField": "Custom.ReflectedWorkItemId",
"Authentication": {
"AuthenticationMode": "AccessToken",
"AccessToken": "jklsadhjksahfkjsdhjksahsadjhksadhsad",
Expand All @@ -65,16 +68,13 @@
"Password": "",
"Domain": ""
}
},
"LanguageMaps": {
"AreaPath": "Area",
"IterationPath": "Iteration"
}
},
"TfsEndpoint": {
"Collection": "https://dev.azure.com/nkdagility-preview/",
"Project": "migrationSource1",
"AllowCrossProjectLinking": false,
"ReflectedWorkItemIdField": "Custom.ReflectedWorkItemId",
"Authentication": {
"AuthenticationMode": "AccessToken",
"AccessToken": "jklsadhjksahfkjsdhjksahsadjhksadhsad",
Expand All @@ -93,7 +93,8 @@
"AuthenticationMode": "AccessToken",
"AccessToken": "jklsadhjksahfkjsdhjksahsadjhksadhsad",
"Organisation": "https://dev.azure.com/xxx/",
"Project": "myProject"
"Project": "myProject",
"ReflectedWorkItemIdField": "Custom.ReflectedWorkItemId"
}
},
"CommonTools": {
Expand Down Expand Up @@ -446,21 +447,10 @@
},
"TfsWorkItemMigrationProcessor": {
"Enabled": false,
"UpdateCreatedDate": true,
"UpdateCreatedBy": true,
"WIQLQuery": "SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = @TeamProject AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan','Shared Steps','Shared Parameter','Feedback Request') ORDER BY [System.ChangedDate] desc",
"FixHtmlAttachmentLinks": true,
"WorkItemCreateRetryLimit": 5,
"FilterWorkItemsThatAlreadyExistInTarget": false,
"PauseAfterEachWorkItem": false,
"AttachRevisionHistory": false,
"GenerateMigrationComment": true,
"SourceName": "Source",
"TargetName": "Target",
"WorkItemIDs": [],
"MaxGracefulFailures": 0,
"SkipRevisionWithInvalidIterationPath": false,
"SkipRevisionWithInvalidAreaPath": false
"TargetName": "Target"
},
"ExportUsersForMappingProcessor": {
"Enabled": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TfsAuthenticationOptions : IValidateOptions<TfsAuthenticationOption
[JsonConverter(typeof(StringEnumConverter))]
public AuthenticationMode AuthenticationMode { get; set; }

[JsonProperty( NullValueHandling = NullValueHandling.Ignore)]
public NetworkCredentials NetworkCredentials { get; set; }

[JsonConverter(typeof(DefaultOnlyConverter<string>), "** removed as a secret ***")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ public class TfsEndpointOptions : EndpointOptions
[JsonProperty(Order = -1)]
[Required]
public string ReflectedWorkItemIdField { get; set; }
public bool AllowCrossProjectLinking { get; set; }

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool AllowCrossProjectLinking { get; set; } = false;

[Required]
public TfsLanguageMapOptions LanguageMaps { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public TfsLanguageMapOptions LanguageMaps { get; set; } = new TfsLanguageMapOptions() { AreaPath = "Area", IterationPath = "Iteration" };
}

public class TfsEndpointOptionsValidator : IValidateOptions<TfsEndpointOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Options;
using System.Text.RegularExpressions;
using System.DirectoryServices.AccountManagement;
using Newtonsoft.Json;

namespace MigrationTools.Processors
{
Expand All @@ -21,15 +22,17 @@ public class TfsWorkItemMigrationProcessorOptions : ProcessorOptions, IWorkItemP
/// not the internal create date)
/// </summary>
/// <default>true</default>
public bool UpdateCreatedDate { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool UpdateCreatedDate { get; set; } = true;

/// <summary>
/// If this is enabled the creation process on the target project will create the items with the original creation date.
/// (Important: The item history is always pointed to the date of the migration, it's change only the data column CreateDate,
/// not the internal create date)
/// </summary>
/// <default>true</default>
public bool UpdateCreatedBy { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool UpdateCreatedBy { get; set; } = true;


/// <summary>
Expand All @@ -44,15 +47,17 @@ public class TfsWorkItemMigrationProcessorOptions : ProcessorOptions, IWorkItemP
/// fields as well as discussion comments. You must specify a PersonalAccessToken in the Source project for Azure DevOps;
/// TFS should use integrated authentication.
/// </summary>
/// <default>?</default>
public bool FixHtmlAttachmentLinks { get; set; }
/// <default>true</default>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool FixHtmlAttachmentLinks { get; set; } = true;

/// <summary>
/// **beta** If set to a number greater than 0 work items that fail to save will retry after a number of seconds equal to the retry count.
/// This allows for periodic network glitches not to end the process.
/// </summary>
/// <default>5</default>
public int WorkItemCreateRetryLimit { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public int WorkItemCreateRetryLimit { get; set; } = 5;

/// <summary>
/// This loads all of the work items already saved to the Target and removes them from the Source work item list prior to commencing the run.
Expand All @@ -65,42 +70,49 @@ public class TfsWorkItemMigrationProcessorOptions : ProcessorOptions, IWorkItemP
/// Pause after each work item is migrated
/// </summary>
/// <default>false</default>
public bool PauseAfterEachWorkItem { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool PauseAfterEachWorkItem { get; set; } = false;

/// <summary>
/// This will create a json file with the revision history and attach it to the work item. Best used with `MaxRevisions` or `ReplayRevisions`.
/// </summary>
/// <default>?</default>
public bool AttachRevisionHistory { get; set; }
/// <default>false</default>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool AttachRevisionHistory { get; set; } = false;

/// <summary>
/// If enabled, adds a comment recording the migration
/// </summary>
/// <default>false</default>
public bool GenerateMigrationComment { get; set; }
/// <default>true</default>
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool GenerateMigrationComment { get; set; } = true;

/// <summary>
/// A list of work items to import
/// </summary>
/// <default>[]</default>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public IList<int> WorkItemIDs { get; set; }

/// <summary>
/// The maximum number of failures to tolerate before the migration fails. When set above zero, a work item migration error is logged but the migration will
/// continue until the number of failed items reaches the configured value, after which the migration fails.
/// </summary>
/// <default>0</default>
public int MaxGracefulFailures { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public int MaxGracefulFailures { get; set; } = 0;

/// <summary>
/// This will skip a revision if the source iteration has not been migrated i.e. it was deleted
/// </summary>
public bool SkipRevisionWithInvalidIterationPath { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool SkipRevisionWithInvalidIterationPath { get; set; } = false;

/// <summary>
/// When set to true, this setting will skip a revision if the source area has not been migrated, has been deleted or is somehow invalid, etc.
/// </summary>
public bool SkipRevisionWithInvalidAreaPath { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool SkipRevisionWithInvalidAreaPath { get; set; } = false;


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public abstract class EndpointOptions : IEndpointOptions

[JsonIgnore]
public string Name { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<IEndpointEnricherOptions> EndpointEnrichers { get; set; }

[JsonIgnore]
public bool Enabled { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ public abstract class ProcessorOptions : IProcessorOptions, IValidateOptions<Pro
/// <summary>
/// List of Enrichers that can be used to add more features to this processor. Only works with Native Processors and not legacy Processors.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<IProcessorEnricherOptions> Enrichers { get; set; }

[Required]
public string SourceName { get; set; }
[Required]
public string TargetName { get; set; }

/// <summary>
/// `Refname` will be used in the future to allow for using named Options without the need to copy all of the options.
/// </summary>
[JsonIgnore]
public string RefName { get; set; }

public IProcessorOptions GetSample()
Expand Down

0 comments on commit 48d5f5c

Please sign in to comment.