diff --git a/src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/PullRequestController.cs b/src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/PullRequestController.cs index b465926d7..5c238af1f 100644 --- a/src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/PullRequestController.cs +++ b/src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/PullRequestController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.ApiVersioning; using Microsoft.AspNetCore.ApiVersioning.Swashbuckle; using Microsoft.AspNetCore.Mvc; +using Microsoft.DotNet.DarcLib.Helpers; using Microsoft.EntityFrameworkCore; using ProductConstructionService.Common; using ProductConstructionService.DependencyFlow; @@ -74,25 +75,35 @@ public async Task GetTrackedPullRequests() .Include(s => s.Channel) .ToListAsync(); + var sampleSub = subscriptions.FirstOrDefault(); + + string? org = null; + string? repoName = null; + if (sampleSub != null) + { + if (GitRepoUrlParser.ParseTypeFromUri(sampleSub.TargetRepository) == GitRepoType.AzureDevOps) + { + (repoName, org) = GitRepoUrlParser.GetRepoNameAndOwner(sampleSub.TargetRepository); + } + } + var updates = subscriptions .Select(update => new PullRequestUpdate( - update.SourceRepository, + TurnApiUrlToWebsite(update.SourceRepository, org, repoName), pr.ContainedSubscriptions.First(s => s.SubscriptionId == update.Id).BuildId)) .ToList(); - var sampleSub = subscriptions.FirstOrDefault(); - prs.Add(new TrackedPullRequest( - TurnApiUrlToWebsite(pr.Url), - sampleSub?.Channel?.Name ?? "N/A", - sampleSub?.TargetBranch ?? "N/A", + TurnApiUrlToWebsite(pr.Url, org, repoName), + sampleSub?.Channel?.Name, + sampleSub?.TargetBranch, updates)); } return Ok(prs.AsQueryable()); } - private static string TurnApiUrlToWebsite(string url) + private static string TurnApiUrlToWebsite(string url, string? orgName, string? repoName) { var match = GitHubApiPrUrlRegex().Match(url); if (match.Success) @@ -103,6 +114,12 @@ private static string TurnApiUrlToWebsite(string url) match = AzdoApiPrUrlRegex().Match(url); if (match.Success) { + // If we have the repo name, use it to replace the repo GUID in the URL + if (repoName != null) + { + WellKnownIds[match.Groups["repo"].Value] = orgName + "-" +repoName; + } + var org = ResolveWellKnownIds(match.Groups["org"].Value); var project = ResolveWellKnownIds(match.Groups["project"].Value); var repo = ResolveWellKnownIds(match.Groups["repo"].Value); @@ -114,8 +131,8 @@ private static string TurnApiUrlToWebsite(string url) private record TrackedPullRequest( string Url, - string Channel, - string TargetBranch, + string? Channel, + string? TargetBranch, List Updates); private record PullRequestUpdate( diff --git a/src/ProductConstructionService/ProductConstructionService.BarViz/Layout/MainLayout.razor b/src/ProductConstructionService/ProductConstructionService.BarViz/Layout/MainLayout.razor index 0b3c853c9..e1594118e 100644 --- a/src/ProductConstructionService/ProductConstructionService.BarViz/Layout/MainLayout.razor +++ b/src/ProductConstructionService/ProductConstructionService.BarViz/Layout/MainLayout.razor @@ -9,6 +9,10 @@ + + Tracked pull requests + +
diff --git a/src/ProductConstructionService/ProductConstructionService.BarViz/Pages/PullRequests.razor b/src/ProductConstructionService/ProductConstructionService.BarViz/Pages/PullRequests.razor index ce1eac713..9251d700a 100644 --- a/src/ProductConstructionService/ProductConstructionService.BarViz/Pages/PullRequests.razor +++ b/src/ProductConstructionService/ProductConstructionService.BarViz/Pages/PullRequests.razor @@ -8,26 +8,60 @@ - - + + @context.Url - @context.Channel + @if (context.Channel != null) + { + @context.Channel + } + else + { + + + + } - @context.TargetBranch + @if (context.TargetBranch != null) + { + @context.TargetBranch + } + else + { + + + + } @code { - IQueryable? TrackedPullRequests = null; + Timer? _timer; protected override async Task OnInitializedAsync() + { + await LoadDataAsync(); + _timer = new Timer(async _ => await LoadDataAsync(), null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); + } + + private async Task LoadDataAsync() { TrackedPullRequests = (await api.PullRequest.GetTrackedPullRequestsAsync()).AsQueryable(); + await InvokeAsync(StateHasChanged); + } + + public void Dispose() + { + _timer?.Dispose(); } }