Skip to content

Commit 1073171

Browse files
authored
TfsWorkItemTypeValidatorTool: fix default excluded WITs handling (#2973)
Fixes #2971 (comment)
2 parents b6090e8 + a36d74c commit 1073171

File tree

8 files changed

+53
-26
lines changed

8 files changed

+53
-26
lines changed

appsettings.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,8 @@
181181
},
182182
"TfsWorkItemTypeValidatorTool": {
183183
"Enabled": true,
184-
"ExcludeWorkItemtypes": [
185-
"Code Review Request",
186-
"Code Review Response",
187-
"Feedback Request",
188-
"Feedback Response",
189-
"Shared Parameter",
190-
"Shared Steps"
191-
],
184+
"ExcludeWorkItemtypes": [],
185+
"ExcludeDefaultWorkItemTypes": true,
192186
"SourceFieldMappings": [],
193187
"FixedTargetFields": []
194188
}

docs/data/classes/reference.tools.tfsworkitemtypevalidatortool.yaml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ configurationSamples:
1111
"CommonTools": {
1212
"TfsWorkItemTypeValidatorTool": {
1313
"Enabled": "True",
14-
"ExcludeWorkItemtypes": [
15-
"Code Review Request",
16-
"Code Review Response",
17-
"Feedback Request",
18-
"Feedback Response",
19-
"Shared Parameter",
20-
"Shared Steps"
21-
],
14+
"ExcludeDefaultWorkItemTypes": "True",
15+
"ExcludeWorkItemtypes": null,
2216
"FixedTargetFields": null,
2317
"SourceFieldMappings": null
2418
}
@@ -60,14 +54,8 @@ configurationSamples:
6054
"$type": "TfsWorkItemTypeValidatorToolOptions",
6155
"Enabled": true,
6256
"IncludeWorkItemtypes": [],
63-
"ExcludeWorkItemtypes": [
64-
"Code Review Request",
65-
"Code Review Response",
66-
"Feedback Request",
67-
"Feedback Response",
68-
"Shared Parameter",
69-
"Shared Steps"
70-
],
57+
"ExcludeWorkItemtypes": [],
58+
"ExcludeDefaultWorkItemTypes": true,
7159
"SourceFieldMappings": {
7260
"User Story": {
7361
"Microsoft.VSTS.Common.Prirucka": "Custom.Prirucka"
@@ -92,6 +80,15 @@ options:
9280
defaultValue: true
9381
isRequired: false
9482
dotNetType: System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
83+
- parameterName: ExcludeDefaultWorkItemTypes
84+
type: Boolean
85+
description: >-
86+
If `true`, some work item types will be automatically added to `ExcludeWorkItemtypes` list.
87+
Work item types excluded by default are: Code Review Request, Code Review Response, Feedback Request,
88+
Feedback Response, Shared Parameter, Shared Steps.
89+
defaultValue: missing XML code comments
90+
isRequired: false
91+
dotNetType: System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
9592
- parameterName: ExcludeWorkItemtypes
9693
type: List
9794
description: List of work item types which will be excluded from validation.

docs/static/schema/configuration.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,10 @@
24682468
"type": "boolean",
24692469
"default": "true"
24702470
},
2471+
"ExcludeDefaultWorkItemTypes": {
2472+
"description": "If `true`, some work item types will be automatically added to `ExcludeWorkItemtypes` list.\r\n Work item types excluded by default are: Code Review Request, Code Review Response, Feedback Request,\r\n Feedback Response, Shared Parameter, Shared Steps.",
2473+
"type": "boolean"
2474+
},
24712475
"ExcludeWorkItemtypes": {
24722476
"description": "List of work item types which will be excluded from validation.",
24732477
"type": "array",

docs/static/schema/schema.tools.tfsworkitemtypevalidatortool.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"type": "boolean",
1111
"default": "true"
1212
},
13+
"ExcludeDefaultWorkItemTypes": {
14+
"description": "If `true`, some work item types will be automatically added to `ExcludeWorkItemtypes` list.\r\n Work item types excluded by default are: Code Review Request, Code Review Response, Feedback Request,\r\n Feedback Response, Shared Parameter, Shared Steps.",
15+
"type": "boolean"
16+
},
1317
"ExcludeWorkItemtypes": {
1418
"description": "List of work item types which will be excluded from validation.",
1519
"type": "array"

src/MigrationTools.Clients.TfsObjectModel/ServiceCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static void AddMigrationToolServicesForClientTfs_Tools(this IServiceColle
2727
context.AddSingleton<TfsTeamSettingsTool>().AddMigrationToolsOptions<TfsTeamSettingsToolOptions>(configuration);
2828
context.AddSingleton<TfsChangeSetMappingTool>().AddMigrationToolsOptions<TfsChangeSetMappingToolOptions>(configuration);
2929
context.AddSingleton<TfsWorkItemTypeValidatorTool>().AddMigrationToolsOptions<TfsWorkItemTypeValidatorToolOptions, TfsWorkItemTypeValidatorToolOptionsValidator>(configuration);
30+
context.PostConfigure<TfsWorkItemTypeValidatorToolOptions>(options => options.Normalize());
3031
}
3132

3233
public static void AddMigrationToolServicesForClientTfs_Processors(this IServiceCollection context)

src/MigrationTools.Clients.TfsObjectModel/Tools/TfsWorkItemTypeValidatorTool.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public TfsWorkItemTypeValidatorTool(
2727
: base(options, services, logger, telemetry)
2828
{
2929
_witMappingTool = witMappingTool ?? throw new ArgumentNullException(nameof(witMappingTool));
30-
Options.Normalize();
3130
}
3231

3332
public bool ValidateReflectedWorkItemIdField(

src/MigrationTools.Clients.TfsObjectModel/Tools/TfsWorkItemTypeValidatorToolOptions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public class TfsWorkItemTypeValidatorToolOptions : ToolOptions
1414

1515
private static readonly StringComparer _normalizedComparer = StringComparer.OrdinalIgnoreCase;
1616
private bool _isNormalized = false;
17+
private static string[] _defaultExcludedWorkItemTypes = [
18+
"Code Review Request",
19+
"Code Review Response",
20+
"Feedback Request",
21+
"Feedback Response",
22+
"Shared Parameter",
23+
"Shared Steps"
24+
];
1725

1826
/// <summary>
1927
/// List of work item types which will be validated. If this list is empty, all work item types will be validated.
@@ -26,6 +34,13 @@ public class TfsWorkItemTypeValidatorToolOptions : ToolOptions
2634
/// </summary>
2735
public List<string> ExcludeWorkItemtypes { get; set; } = [];
2836

37+
/// <summary>
38+
/// If <see langword="true"/>, some work item types will be automatically added to <see cref="ExcludeWorkItemtypes"/> list.
39+
/// Work item types excluded by default are: Code Review Request, Code Review Response, Feedback Request,
40+
/// Feedback Response, Shared Parameter, Shared Steps.
41+
/// </summary>
42+
public bool ExcludeDefaultWorkItemTypes { get; set; } = true;
43+
2944
/// <summary>
3045
/// Field reference name mappings. Key is work item type name, value is dictionary of mapping source filed name to
3146
/// target field name. Target field name can be empty string to indicate that this field will not be validated in target.
@@ -90,6 +105,17 @@ public void Normalize()
90105

91106
IncludeWorkItemtypes ??= [];
92107
ExcludeWorkItemtypes ??= [];
108+
if (ExcludeDefaultWorkItemTypes)
109+
{
110+
foreach (string defaultExcludedWit in _defaultExcludedWorkItemTypes)
111+
{
112+
if (!ExcludeWorkItemtypes.Contains(defaultExcludedWit, _normalizedComparer))
113+
{
114+
ExcludeWorkItemtypes.Add(defaultExcludedWit);
115+
}
116+
}
117+
}
118+
93119
FixedTargetFields = newFixedFields;
94120
SourceFieldMappings = newMappings;
95121
_isNormalized = true;

src/MigrationTools.Clients.TfsObjectModel/Tools/TfsWorkItemTypeValidatorToolOptionsValidator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public ValidateOptionsResult Validate(string name, TfsWorkItemTypeValidatorToolO
1212
if ((includedCount > 0) && (excludedCount > 0))
1313
{
1414
const string msg = $"'{nameof(options.IncludeWorkItemtypes)}' and '{nameof(options.ExcludeWorkItemtypes)}'"
15-
+ $" cannot be set both at the same time.";
15+
+ $" cannot be set both at the same time."
16+
+ $" If '{nameof(options.IncludeWorkItemtypes)}' list is not empty,"
17+
+ $" '{nameof(options.ExcludeDefaultWorkItemTypes)}' must be set to 'false'.";
1618
return ValidateOptionsResult.Fail(msg);
1719
}
1820
return ValidateOptionsResult.Success;

0 commit comments

Comments
 (0)