From 8693a75e8b60bfe717f7fbdcde6ad0f1d1668797 Mon Sep 17 00:00:00 2001 From: Brook Jeynes Date: Mon, 4 Mar 2024 13:48:01 +1000 Subject: [PATCH 1/2] Archived rules are now filtered out --- SSW.Rules.AzFuncs/Domain/LatestRules.cs | 3 ++- SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs | 3 ++- SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/SSW.Rules.AzFuncs/Domain/LatestRules.cs b/SSW.Rules.AzFuncs/Domain/LatestRules.cs index 0e78764..2c53dc5 100644 --- a/SSW.Rules.AzFuncs/Domain/LatestRules.cs +++ b/SSW.Rules.AzFuncs/Domain/LatestRules.cs @@ -13,4 +13,5 @@ public class LatestRules : BaseEntity public string CreatedBy { get; set; } public string UpdatedBy { get; set; } public string GitHubUsername { get; set; } -} \ No newline at end of file + public string? ArchivedReason { get; set; } +} diff --git a/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs b/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs index e289ac8..74e9afa 100644 --- a/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs +++ b/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs @@ -31,6 +31,7 @@ public async Task Run( r.CreatedBy == githubUsername || r.UpdatedBy == githubUsername) .GroupBy(r => r.RuleGuid) .Select(group => group.First()) + .Where(r => r.ArchivedReason is not null) .OrderByDescending(r => r.UpdatedAt) .Skip(skip) .Take(take); @@ -40,4 +41,4 @@ public async Task Run( ? req.CreateJsonErrorResponse(HttpStatusCode.NotFound, "Not Found") : req.CreateJsonResponse(filteredRules); } -} \ No newline at end of file +} diff --git a/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs b/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs index fa26fbe..1c1b906 100644 --- a/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs +++ b/SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs @@ -91,7 +91,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) { @@ -108,6 +108,7 @@ private void UpdateLatestRule(LatestRules latestRule, PullRequest pr, FrontMatte latestRule.UpdatedAt = pr.UpdatedAt.UtcDateTime; latestRule.UpdatedBy = pr.User.Login; latestRule.GitHubUsername = pr.User.Login; + latestRule.ArchivedReason = string.IsNullOrEmpty(frontMatter.ArchivedReason) ? null : frontMatter.ArchivedReason; context.LatestRules.Update(latestRule); } @@ -124,9 +125,10 @@ private static LatestRules CreateLatestRule(PullRequest pr, FrontMatter frontMat UpdatedAt = pr.UpdatedAt.UtcDateTime, CreatedBy = foundRule?.CreatedByDisplayName ?? pr.User.Location, UpdatedBy = foundRule?.ChangedByDisplayName ?? pr.User.Login, - GitHubUsername = pr.User.Login + GitHubUsername = pr.User.Login, + ArchivedReason = string.IsNullOrEmpty(frontMatter.ArchivedReason) ? null : frontMatter.ArchivedReason, }; return rule; } -} \ No newline at end of file +} From a503c03120e496c046142b0ce6bde652d295ada4 Mon Sep 17 00:00:00 2001 From: Brook Jeynes Date: Tue, 5 Mar 2024 07:36:19 +1000 Subject: [PATCH 2/2] fix null check --- SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs b/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs index b54360b..849b73e 100644 --- a/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs +++ b/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs @@ -31,7 +31,7 @@ public async Task Run( r.CreatedBy == githubUsername || r.UpdatedBy == githubUsername) .GroupBy(r => r.RuleGuid) .Select(group => group.First()) - .Where(r => r.ArchivedReason is not null) + .Where(r => r.ArchivedReason is null) .DistinctBy(r => r.RuleGuid) .OrderByDescending(r => r.UpdatedAt) .Skip(skip)