Skip to content

Commit

Permalink
Ensure PRs are under 101 files changed (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradystroud authored Jun 10, 2024
1 parent eea576d commit 2dcee31
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@ public async Task<HttpResponseData> Run(
var pullRequests =
await gitHubClient.PullRequest.GetAllForRepository(repositoryOwner, repositoryName, request,
apiOptions);
var syncHistory = await context.SyncHistory.GetAll();
var existingCommitHashes = new HashSet<string>(syncHistory.Select(sh => sh.CommitHash));

if (pullRequests == null || !pullRequests.Any())
{
throw new Exception("No Pull Requests found");
}

var syncHistoryHash = await context.SyncHistory.GetAll();
var existingCommitHashes = new HashSet<string>(syncHistoryHash.Select(sh => sh.CommitHash));
HttpClient httpClient = new HttpClient();
var newRules = new List<LatestRules>();
var updatedCount = 0;

foreach (var pr in pullRequests)
{
if (existingCommitHashes.Contains(pr.MergeCommitSha)) break;
if (!pr.Merged) continue;
if (pr.ChangedFiles > 100) continue; // Skips big PRs as these will fail

var files = await gitHubClient.PullRequest.Files(repositoryOwner, repositoryName, pr.Number);
foreach (var file in files)
Expand Down Expand Up @@ -91,7 +99,7 @@ await gitHubClient.PullRequest.GetAllForRepository(repositoryOwner, repositoryNa
_logger.LogInformation($"Updated Latest rules with {updatedCount} new entries.");

return req.CreateJsonResponse(new
{ message = $"Latest rules updated successfully with {updatedCount} new entries." });
{ message = $"Latest rules updated successfully with {updatedCount} new entries." });
}
catch (Exception ex)
{
Expand Down

0 comments on commit 2dcee31

Please sign in to comment.