Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archived rules are now filtered out #51

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SSW.Rules.AzFuncs/Domain/LatestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public class LatestRules : BaseEntity
public string CreatedBy { get; set; }
public string UpdatedBy { get; set; }
public string GitHubUsername { get; set; }
public string? ArchivedReason { get; set; }
}
1 change: 1 addition & 0 deletions SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public async Task<HttpResponseData> Run(
r.CreatedBy == githubUsername || r.UpdatedBy == githubUsername)
.GroupBy(r => r.RuleGuid)
.Select(group => group.First())
.Where(r => r.ArchivedReason is null)
.DistinctBy(r => r.RuleGuid)
.OrderByDescending(r => r.UpdatedAt)
.Skip(skip)
Expand Down
8 changes: 5 additions & 3 deletions SSW.Rules.AzFuncs/Functions/Widget/UpdateLatestRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -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;
}
}
}
Loading