From 2dcee31bafcb36c80a3097b24a3f3e8d44962ad3 Mon Sep 17 00:00:00 2001 From: "Brady Stroud [SSW]" Date: Mon, 10 Jun 2024 09:46:27 +0930 Subject: [PATCH] Ensure PRs are under 101 files changed (#52) --- .../Functions/Widget/UpdateLatestRules.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs b/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs index fa26fbe..9d0dfa1 100644 --- a/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs +++ b/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs @@ -39,15 +39,23 @@ public async Task Run( var pullRequests = await gitHubClient.PullRequest.GetAllForRepository(repositoryOwner, repositoryName, request, apiOptions); - var syncHistory = await context.SyncHistory.GetAll(); - var existingCommitHashes = new HashSet(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(syncHistoryHash.Select(sh => sh.CommitHash)); HttpClient httpClient = new HttpClient(); var newRules = new List(); 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) @@ -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) {