Get branch details and sort by modification date
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 2m45s

This commit is contained in:
Robert Marshall 2025-07-05 21:24:30 +01:00
parent 1cc884bec3
commit 5966641b75

View file

@ -5,15 +5,22 @@ using Website.Data;
namespace Website.ViewComponents {
public class ProjectNavigationViewComponent :ViewComponent {
private readonly IGitApi _api;
private readonly IGitApi _gitApi;
public ProjectNavigationViewComponent(IGitApi api) {
_api = api;
public ProjectNavigationViewComponent(IGitApi gitApi) {
_gitApi = gitApi;
}
public async Task<IViewComponentResult> InvokeAsync() {
var repositories = await _api.GetRepositories("rob");
return View(repositories.Take(5));
var repos = await _gitApi.GetRepositories("rob");
var branchTasks = repos.Select(repo => _gitApi.GetBranches("rob", repo));
var branchResults = await Task.WhenAll(branchTasks);
var branches = branchResults.SelectMany(branch => branch);
var sortedBranches = branches.OrderByDescending(branch => branch.Commit.Timestamp);
var sortedRepos = sortedBranches.DistinctBy(branch => branch.Repository).Select(branch => branch.Repository);
return View(sortedRepos.Take(5));
}
}
}