diff --git a/src/AzureDevOps/MigrationPlatform.CLI.Migration/Commands/Discovery/InventoryCommand.cs b/src/AzureDevOps/MigrationPlatform.CLI.Migration/Commands/Discovery/InventoryCommand.cs index 334364d..c7ef956 100644 --- a/src/AzureDevOps/MigrationPlatform.CLI.Migration/Commands/Discovery/InventoryCommand.cs +++ b/src/AzureDevOps/MigrationPlatform.CLI.Migration/Commands/Discovery/InventoryCommand.cs @@ -60,10 +60,14 @@ await AnsiConsole.Live(table) ctx.UpdateTarget(RenderTable(summaries)); } - //// Repos (pseudo-code) - //summary.TotalRepos = await _catalogService.CountReposAsync(project.Name); - //summary.IsRepoComplete = true; - //ctx.UpdateTarget(RenderTable(summaries)); + // Repos + await foreach (var repoStat in catalogService.CountRepositoriesAsync(settings.Organisation, project, settings.Token)) + { + summary.ReposCount = repoStat.ReposCount; + summary.IsRepoComplete = repoStat.IsRepoComplete; + summary.LastUpdatedUtc = repoStat.LastUpdatedUtc; + ctx.UpdateTarget(RenderTable(summaries)); + } //// Pipelines (pseudo-code) //summary.TotalPipelines = await _catalogService.CountPipelinesAsync(project.Name); diff --git a/src/AzureDevOps/MigrationPlatform.Infrastructure.AzureDevOps/Services/CatalogService.cs b/src/AzureDevOps/MigrationPlatform.Infrastructure.AzureDevOps/Services/CatalogService.cs index 23e2833..8de1e97 100644 --- a/src/AzureDevOps/MigrationPlatform.Infrastructure.AzureDevOps/Services/CatalogService.cs +++ b/src/AzureDevOps/MigrationPlatform.Infrastructure.AzureDevOps/Services/CatalogService.cs @@ -1,4 +1,5 @@ using Microsoft.TeamFoundation.Core.WebApi; +using Microsoft.TeamFoundation.SourceControl.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi; using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; using Microsoft.VisualStudio.Services.Common; @@ -83,6 +84,27 @@ public async IAsyncEnumerable<ProjectDiscoverySummary> CountAllWorkItemsAsync( } while (batchCount == maxPerBatch); } - + public async IAsyncEnumerable<ProjectDiscoverySummary> CountRepositoriesAsync( + string orgUrl, + string project, + string pat, + [EnumeratorCancellation] CancellationToken cancellationToken = default) + { + var credentials = new VssBasicCredential(string.Empty, pat); + var connection = new VssConnection(new Uri(orgUrl), credentials); + var gitClient = connection.GetClient<GitHttpClient>(); + + ProjectDiscoverySummary repoStats = new ProjectDiscoverySummary(); + + // Get all repositories for the project + var repositories = await gitClient.GetRepositoriesAsync(project, cancellationToken: cancellationToken); + + // Set the repository count + repoStats.ReposCount = repositories.Count; + repoStats.IsRepoComplete = true; + repoStats.LastUpdatedUtc = DateTime.UtcNow; + + yield return repoStats; + } } } diff --git a/src/Common/MigrationPlatform.Abstractions/Services/ICatalogService.cs b/src/Common/MigrationPlatform.Abstractions/Services/ICatalogService.cs index a332281..8ea5797 100644 --- a/src/Common/MigrationPlatform.Abstractions/Services/ICatalogService.cs +++ b/src/Common/MigrationPlatform.Abstractions/Services/ICatalogService.cs @@ -5,7 +5,7 @@ namespace MigrationPlatform.Abstractions.Services public interface ICatalogService { IAsyncEnumerable<ProjectDiscoverySummary> CountAllWorkItemsAsync(string orgUrl, string project, string pat, CancellationToken cancellationToken = default); + IAsyncEnumerable<ProjectDiscoverySummary> CountRepositoriesAsync(string orgUrl, string project, string pat, CancellationToken cancellationToken = default); Task<IReadOnlyList<string>> GetProjectsAsync(string orgUrl, string pat); - } }