Skip to content

Commit bcab381

Browse files
committed
PR 49: Added FieldValuetoTagMapConfig and FieldValuetoTagMap taking a regex for value +semver:minor
- Added FieldValuetoTagMapConfig and FieldValuetoTagMap taking a regex for value
1 parent f8fabf4 commit bcab381

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

TfsWitMigrator.Core/Configuration/EngineConfiguration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public static EngineConfiguration GetDefault()
7070
pattern = @"PRODUCT \d{4}.(\d{1})",
7171
replacement = "$1"
7272
});
73+
ec.FieldMaps.Add(new FieldValuetoTagMapConfig()
74+
{
75+
WorkItemTypeName = "*",
76+
sourceField = "Microsoft.VSTS.CMMI.Blocked",
77+
pattern = @"Yes",
78+
formatExpression = "{0}"
79+
});
7380
ec.FieldMaps.Add(new TreeToTagMapConfig()
7481
{
7582
WorkItemTypeName = "*",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace VSTS.DataBulkEditor.Engine.Configuration.FieldMap
8+
{
9+
public class FieldValuetoTagMapConfig : IFieldMapConfig
10+
{
11+
public string WorkItemTypeName { get; set; }
12+
public string sourceField { get; set; }
13+
public string pattern { get; set; }
14+
public string formatExpression { get; set; }
15+
public Type FieldMap
16+
{
17+
get
18+
{
19+
return typeof(FieldValuetoTagMap);
20+
}
21+
}
22+
}
23+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using Microsoft.TeamFoundation.WorkItemTracking.Client;
3+
using VSTS.DataBulkEditor.Engine.ComponentContext;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Linq;
7+
using VSTS.DataBulkEditor.Engine.Configuration.FieldMap;
8+
using System.Text.RegularExpressions;
9+
10+
namespace VSTS.DataBulkEditor.Engine
11+
{
12+
public class FieldValuetoTagMap : IFieldMap
13+
{
14+
private FieldValuetoTagMapConfig config;
15+
16+
public FieldValuetoTagMap(FieldValuetoTagMapConfig config)
17+
{
18+
this.config = config;
19+
}
20+
21+
public void Execute(WorkItem source, WorkItem target)
22+
{
23+
if (source.Fields.Contains(this.config.sourceField))
24+
{
25+
List<string> newTags = target.Tags.Split(char.Parse(@";")).ToList();
26+
// to tag
27+
if (source.Fields[this.config.sourceField].Value != null)
28+
{
29+
string value = source.Fields[this.config.sourceField].Value.ToString();
30+
if (Regex.IsMatch((string)source.Fields[config.sourceField].Value, config.pattern))
31+
{
32+
if (string.IsNullOrEmpty(config.formatExpression))
33+
{
34+
newTags.Add(value);
35+
}
36+
else
37+
{
38+
newTags.Add(string.Format(config.formatExpression, value));
39+
}
40+
}
41+
42+
target.Tags = string.Join(";", newTags.ToArray());
43+
Trace.WriteLine(string.Format(" [UPDATE] field tagged {0}:{1} to {2}:Tag with foramt of {3}", source.Id, this.config.sourceField, target.Id, config.formatExpression));
44+
}
45+
46+
}
47+
}
48+
}
49+
}

TfsWitMigrator.Core/_VSTS.DataBulkEditor.Engine.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@
258258
<Compile Include="Configuration\EngineConfiguration.cs" />
259259
<Compile Include="Configuration\FieldMap\FieldMapConfigJsonConverter.cs" />
260260
<Compile Include="Configuration\FieldMap\FieldBlankMapConfig.cs" />
261+
<Compile Include="Configuration\FieldMap\FieldValuetoTagMapConfig.cs" />
261262
<Compile Include="Configuration\FieldMap\TreeToTagMapConfig.cs" />
262263
<Compile Include="Configuration\FieldMap\FieldMergeMapConfig.cs" />
263264
<Compile Include="Configuration\FieldMap\RegexFieldMapConfig.cs" />
@@ -292,6 +293,7 @@
292293
<Compile Include="Execution\FieldMaps\FieldMergeMap.cs" />
293294
<Compile Include="Execution\FieldMaps\FieldBlankMap.cs" />
294295
<Compile Include="Execution\FieldMaps\FieldToFieldMap.cs" />
296+
<Compile Include="Execution\FieldMaps\FieldValuetoTagMap.cs" />
295297
<Compile Include="Execution\FieldMaps\FieldValueMap.cs" />
296298
<Compile Include="Execution\FieldMaps\IFieldMap.cs" />
297299
<Compile Include="Execution\ComponentContext\TestManagementContext.cs" />

0 commit comments

Comments
 (0)