Skip to content

Commit

Permalink
Port changes of Maestro's Incoming page to PCS (#3874)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Aug 23, 2024
1 parent 7b4a8c8 commit 3f0709e
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ public async Task<IActionResult> OnGet(int channelId, string owner, string repo)
}
IncomingRepositories = incoming;

CurrentRateLimit = _github.GetLastApiInfo().RateLimit;
CurrentRateLimit = _github.GetLastApiInfo()?.RateLimit;

return Page();
}

private async Task<Build?> GetOldestUnconsumedBuild(int lastConsumedBuildOfDependencyId)
{
// Note: We fetch `build` again here so that it will have channel information, which it doesn't when coming from the graph :(
var build = await _context.Builds.FindAsync(lastConsumedBuildOfDependencyId);
var build = await _context.Builds.Where(b => b.Id == lastConsumedBuildOfDependencyId)
.Include(b => b.BuildChannels)
.ThenInclude(bc => bc.Channel)
.FirstOrDefaultAsync();

if (build == null)
{
Expand All @@ -125,9 +128,11 @@ public async Task<IActionResult> OnGet(int channelId, string owner, string repo)

var channelId = build.BuildChannels.FirstOrDefault(bc => bc.Channel.Classification == "product" || bc.Channel.Classification == "tools")?.ChannelId;
var publishedBuildsOfDependency = await _context.Builds
.Include(b => b.BuildChannels)
.Where(b => b.GitHubRepository == build.GitHubRepository &&
b.DateProduced >= build.DateProduced.AddSeconds(-5) &&
b.BuildChannels.Any(bc => bc.ChannelId == channelId))
.OrderByDescending(b => b.DateProduced)
.ToListAsync();

var last = publishedBuildsOfDependency.LastOrDefault();
Expand Down Expand Up @@ -169,7 +174,7 @@ public string GetBuildUrl(Build? build)
? "(unknown)"
: $"https://dev.azure.com/{build.AzureDevOpsAccount}/{build.AzureDevOpsProject}/_build/results?buildId={build.AzureDevOpsBuildId}&view=results";

private bool IncludeRepo(GitHubInfo? gitHubInfo)
private static bool IncludeRepo(GitHubInfo? gitHubInfo)
{
if (string.Equals(gitHubInfo?.Owner, "dotnet", StringComparison.OrdinalIgnoreCase) &&
string.Equals(gitHubInfo?.Repo, "blazor", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -212,8 +217,11 @@ public string GetDateProduced(Build? build)
}
catch (NotFoundException)
{
_logger.LogWarning("Failed to compare commit history for '{0}/{1}' between '{2}' and '{3}'.", gitHubInfo.Owner, gitHubInfo.Repo,
build.Commit, build.GitHubBranch);
_logger.LogWarning("Failed to compare commit history for '{owner}/{repo}' between '{commit}' and '{branch}'.",
gitHubInfo.Owner,
gitHubInfo.Repo,
build.Commit,
build.GitHubBranch);
return null;
}
}
Expand Down

0 comments on commit 3f0709e

Please sign in to comment.