Skip to content

Commit 267667d

Browse files
committed
Add project validation and retrieval functionality
Introduced `GetProjects` method to `IWorkItemMigrationClient` and its implementations, enabling retrieval of project lists. Added `ValidateProject` method in `TfsWorkItemMigrationProcessor` to ensure source and target projects exist before migration. Updated `TfsWorkItemMigrationProcessor` to call `ValidateProject` during execution. Included `System.Collections.Generic` namespace in `TfsWorkItemMigrationClient.cs` to support generic collections. Made minor formatting adjustments to maintain code structure.
1 parent 40c1462 commit 267667d

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

src/MigrationTools.Clients.TfsObjectModel/Clients/TfsWorkItemMigrationClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using Microsoft.Extensions.Options;
77
using Microsoft.TeamFoundation.Client;
8+
using Microsoft.TeamFoundation.Core.WebApi;
89
using Microsoft.TeamFoundation.WorkItemTracking.Client;
910
using MigrationTools._EngineV1.DataContracts;
1011
using MigrationTools.DataContracts;
@@ -344,5 +345,15 @@ private WorkItemStore GetWorkItemStore()
344345
return store;
345346
}
346347
}
348+
349+
public override List<ProjectData> GetProjects()
350+
{
351+
List<ProjectData> projects = new List<ProjectData>();
352+
foreach (Project p in Store.Projects)
353+
{
354+
projects.Add(p?.ToProjectData());
355+
}
356+
return projects;
357+
}
347358
}
348359
}

src/MigrationTools.Clients.TfsObjectModel/Processors/TfsWorkItemMigrationProcessor.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ protected override void InternalExecute()
123123

124124
ValidateWorkItemTypes();
125125

126+
ValidateProject();
127+
126128
CommonTools.NodeStructure.ProcessorExecutionBegin(this);
127129
if (CommonTools.TeamSettings.Enabled)
128130
{
@@ -247,6 +249,45 @@ protected override void InternalExecute()
247249
}
248250
}
249251

252+
private void ValidateProject()
253+
{
254+
Log.LogInformation("[ValidateProject]");
255+
Log.LogInformation("------------------------------------");
256+
Log.LogInformation("Source Project Check");
257+
Log.LogInformation("------------------------------------");
258+
var sourceProjectName = Source.Options.Project;
259+
var sourceProjects = Source.WorkItems.GetProjects();
260+
var foundSourceProject = sourceProjects.FirstOrDefault(p => p.Name.Equals(sourceProjectName, StringComparison.OrdinalIgnoreCase));
261+
if (foundSourceProject == null)
262+
{
263+
Log.LogError("Source project '{ProjectName}' not found!", sourceProjectName);
264+
Log.LogInformation("Available projects are: {@sourceProjects}", string.Join(", ", sourceProjects.Select(p => p.Name)));
265+
Environment.Exit(-1);
266+
}
267+
else
268+
{
269+
Log.LogInformation("Found source project as {@sourceProject}", foundSourceProject.Name);
270+
}
271+
Log.LogInformation("------------------------------------");
272+
Log.LogInformation("Target Project Check");
273+
Log.LogInformation("------------------------------------");
274+
var targetProjectName = Target.Options.Project;
275+
var targetProjects = Target.WorkItems.GetProjects();
276+
var foundTargetProject = targetProjects.FirstOrDefault(p => p.Name.Equals(targetProjectName, StringComparison.OrdinalIgnoreCase));
277+
if (foundTargetProject == null)
278+
{
279+
Log.LogError("Target project '{ProjectName}' not found!", targetProjectName);
280+
Log.LogInformation("Available projects are: {@targetProjects}", string.Join(", ", targetProjects.Select(p => p.Name)));
281+
Environment.Exit(-1);
282+
}
283+
else
284+
{
285+
Log.LogInformation("Found target project as {@targetProject}", foundTargetProject.Name);
286+
}
287+
288+
Log.LogInformation("[/ValidateProject]");
289+
}
290+
250291
private void ValidateWorkItemTypes()
251292
{
252293
Log.LogInformation("[ValidateWorkItemTypes]");

src/MigrationTools.Tests/Core/Clients/WorkItemMigrationClientMock.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,10 @@ ReflectedWorkItemId IWorkItemMigrationClient.GetReflectedWorkItemId(WorkItemData
165165
{
166166
throw new System.NotImplementedException();
167167
}
168+
169+
public List<ProjectData> GetProjects()
170+
{
171+
throw new System.NotImplementedException();
172+
}
168173
}
169-
}
174+
}

src/MigrationTools/_EngineV1/Clients/IWorkItemMigrationClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public interface IWorkItemMigrationClient
1414

1515
ProjectData GetProject();
1616

17+
List<ProjectData> GetProjects();
18+
1719
List<WorkItemData> GetWorkItems();
1820

1921
WorkItemData GetWorkItem(string id, bool stopOnError = true);
@@ -40,4 +42,4 @@ public interface IWorkItemMigrationClient
4042

4143
ReflectedWorkItemId GetReflectedWorkItemId(WorkItemData workItem);
4244
}
43-
}
45+
}

src/MigrationTools/_EngineV1/Clients/WorkItemMigrationClientBase.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,10 @@ protected WorkItemData GetFromCache(ReflectedWorkItemId reflectedWorkItemId)
7979
}
8080
return null;
8181
}
82+
83+
public abstract List<ProjectData> GetProjects();
84+
85+
86+
8287
}
83-
}
88+
}

0 commit comments

Comments
 (0)