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

Scheduled event processing update #7839

Merged
merged 1 commit into from
Mar 8, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ public override Task<int> ProcessPendingUpdates(long repositoryId, int issueOrPu
return Task.FromResult(numUpdates);
}

/// <summary>
/// The mock ProcessPendingScheduledUpdates just returns the number of updates
/// </summary>
/// <returns>integer,the number of pending updates that would be processed</returns>
public override Task<int> ProcessPendingScheduledUpdates()
{
int numUpdates = 0;
Console.WriteLine($"ProcessPendingScheduledUpdates::ProcessPendingUpdates, number of pending comments = {_gitHubComments.Count}");
numUpdates += _gitHubComments.Count;

Console.WriteLine($"ProcessPendingScheduledUpdates::ProcessPendingUpdates, number of pending IssueUpdates = {_gitHubIssuesToUpdate.Count}");
numUpdates += _gitHubIssuesToUpdate.Count;

Console.WriteLine($"ProcessPendingScheduledUpdates::ProcessPendingUpdates, number of issues to Lock = {_gitHubIssuesToLock.Count}");
numUpdates += _gitHubIssuesToLock.Count;

return Task.FromResult(numUpdates);
}

/// <summary>
/// IsUserCollaborator override. Returns IsCollaboratorReturn value
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task TestCloseAddressedIssues(string rule, string payloadFile, Rule
mockGitHubEventClient.CreateSearchIssuesResult(expectedUpdates, scheduledEventPayload.Repository, ItemState.Open);
await ScheduledEventProcessing.CloseAddressedIssues(mockGitHubEventClient, scheduledEventPayload);

var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
var totalUpdates = await mockGitHubEventClient.ProcessPendingScheduledUpdates();
// Verify the RuleCheck
Assert.AreEqual(ruleState == RuleState.On, mockGitHubEventClient.RulesConfiguration.RuleEnabled(rule), $"Rule '{rule}' enabled should have been {ruleState == RuleState.On} but RuleEnabled returned {ruleState != RuleState.On}.'");
if (RuleState.On == ruleState)
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task TestCloseStaleIssues(string rule, string payloadFile, RuleStat
mockGitHubEventClient.CreateSearchIssuesResult(expectedUpdates, scheduledEventPayload.Repository, ItemState.Open);
await ScheduledEventProcessing.CloseStaleIssues(mockGitHubEventClient, scheduledEventPayload);

var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
var totalUpdates = await mockGitHubEventClient.ProcessPendingScheduledUpdates();
// Verify the RuleCheck
Assert.AreEqual(ruleState == RuleState.On, mockGitHubEventClient.RulesConfiguration.RuleEnabled(rule), $"Rule '{rule}' enabled should have been {ruleState == RuleState.On} but RuleEnabled returned {ruleState != RuleState.On}.'");
if (RuleState.On == ruleState)
Expand Down Expand Up @@ -128,7 +128,7 @@ public async Task TestCloseStalePullRequests(string rule, string payloadFile, Ru
mockGitHubEventClient.CreateSearchIssuesResult(expectedUpdates, scheduledEventPayload.Repository, ItemState.Open);
await ScheduledEventProcessing.CloseStalePullRequests(mockGitHubEventClient, scheduledEventPayload);

var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
var totalUpdates = await mockGitHubEventClient.ProcessPendingScheduledUpdates();
// Verify the RuleCheck
Assert.AreEqual(ruleState == RuleState.On, mockGitHubEventClient.RulesConfiguration.RuleEnabled(rule), $"Rule '{rule}' enabled should have been {ruleState == RuleState.On} but RuleEnabled returned {ruleState != RuleState.On}.'");
if (RuleState.On == ruleState)
Expand Down Expand Up @@ -173,7 +173,7 @@ public async Task TestIdentifyStalePullRequests(string rule, string payloadFile,
mockGitHubEventClient.CreateSearchIssuesResult(expectedUpdates, scheduledEventPayload.Repository, ItemState.Open);
await ScheduledEventProcessing.IdentifyStalePullRequests(mockGitHubEventClient, scheduledEventPayload);

var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
var totalUpdates = await mockGitHubEventClient.ProcessPendingScheduledUpdates();
// Verify the RuleCheck
Assert.AreEqual(ruleState == RuleState.On, mockGitHubEventClient.RulesConfiguration.RuleEnabled(rule), $"Rule '{rule}' enabled should have been {ruleState == RuleState.On} but RuleEnabled returned {ruleState != RuleState.On}.'");
if (RuleState.On == ruleState)
Expand Down Expand Up @@ -218,7 +218,7 @@ public async Task TestIdentifyStaleIssues(string rule, string payloadFile, RuleS
mockGitHubEventClient.CreateSearchIssuesResult(expectedUpdates, scheduledEventPayload.Repository, ItemState.Open);
await ScheduledEventProcessing.IdentifyStaleIssues(mockGitHubEventClient, scheduledEventPayload);

var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
var totalUpdates = await mockGitHubEventClient.ProcessPendingScheduledUpdates();
// Verify the RuleCheck
Assert.AreEqual(ruleState == RuleState.On, mockGitHubEventClient.RulesConfiguration.RuleEnabled(rule), $"Rule '{rule}' enabled should have been {ruleState == RuleState.On} but RuleEnabled returned {ruleState != RuleState.On}.'");
if (RuleState.On == ruleState)
Expand Down Expand Up @@ -261,7 +261,7 @@ public async Task TestLockClosedIssues(string rule, string payloadFile, RuleStat
mockGitHubEventClient.CreateSearchIssuesResult(expectedUpdates, scheduledEventPayload.Repository, ItemState.Open);
await ScheduledEventProcessing.LockClosedIssues(mockGitHubEventClient, scheduledEventPayload);

var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
var totalUpdates = await mockGitHubEventClient.ProcessPendingScheduledUpdates();
// Verify the RuleCheck
Assert.AreEqual(ruleState == RuleState.On, mockGitHubEventClient.RulesConfiguration.RuleEnabled(rule), $"Rule '{rule}' enabled should have been {ruleState == RuleState.On} but RuleEnabled returned {ruleState != RuleState.On}.'");
if (RuleState.On == ruleState)
Expand Down Expand Up @@ -303,7 +303,7 @@ public async Task TestEnforceMaxLifeOfIssues(string rule, string payloadFile, Ru
mockGitHubEventClient.CreateSearchIssuesResult(expectedUpdates, scheduledEventPayload.Repository, ItemState.Open);
await ScheduledEventProcessing.EnforceMaxLifeOfIssues(mockGitHubEventClient, scheduledEventPayload);

var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
var totalUpdates = await mockGitHubEventClient.ProcessPendingScheduledUpdates();
// Verify the RuleCheck
Assert.AreEqual(ruleState == RuleState.On, mockGitHubEventClient.RulesConfiguration.RuleEnabled(rule), $"Rule '{rule}' enabled should have been {ruleState == RuleState.On} but RuleEnabled returned {ruleState != RuleState.On}.'");
if (RuleState.On == ruleState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ public class RateLimitConstants
// https://docs.github.com/en/rest/search?apiVersion=2022-11-28#about-search
// The SearchIssues API has a rate limit of 1000 results which resets every 60 seconds
public const int SearchIssuesRateLimit = 1000;
// https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-primary-rate-limits
// There's a 500/hour limit on content creation. In theory, Closing an issue, Locking an issue and
// creating a comment are all considered content creation.
public const int ContentCreationRateLimit = 300;
// The actual rate limit per minute for content creation is 80 but to ensure that scheduled tasks
// don't interfere with Actions processing or people doing things in the GitHub UI.
public const int ScheduledUpdatesPerMinuteRateLimit = 50;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static async Task ProcessScheduledEvent(GitHubEventClient gitHubEventClie
{
// The second argument is IssueOrPullRequestNumber which isn't applicable to scheduled events (cron tasks)
// since they're not going to be changing a single IssueUpdate like rules processing does.
await gitHubEventClient.ProcessPendingUpdates(scheduledEventPayload.Repository.Id);
await gitHubEventClient.ProcessPendingScheduledUpdates();
}
}

Expand Down Expand Up @@ -130,6 +130,7 @@ public static async Task CloseAddressedIssues(GitHubEventClient gitHubEventClien
)
{
Issue issue = result.Items[iCounter++];
// This rule only sets the state
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false);
issueUpdate.State = ItemState.Closed;
issueUpdate.StateReason = ItemStateReason.Completed;
Expand Down Expand Up @@ -211,6 +212,7 @@ public static async Task CloseStaleIssues(GitHubEventClient gitHubEventClient, S
)
{
Issue issue = result.Items[iCounter++];
// This rule only sets the state
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false);
issueUpdate.State = ItemState.Closed;
issueUpdate.StateReason = ItemStateReason.NotPlanned;
Expand Down Expand Up @@ -285,6 +287,7 @@ public static async Task CloseStalePullRequests(GitHubEventClient gitHubEventCli
)
{
Issue issue = result.Items[iCounter++];
// This rule only sets the state
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false);
issueUpdate.State = ItemState.Closed;
issueUpdate.StateReason = ItemStateReason.NotPlanned;
Expand Down Expand Up @@ -366,7 +369,8 @@ public static async Task IdentifyStalePullRequests(GitHubEventClient gitHubEvent
)
{
Issue issue = result.Items[iCounter++];
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false);
// This rule needs to the full IssueUpdate as it's adding a label
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false, false);
issueUpdate.AddLabel(TriageLabelConstants.NoRecentActivity);
gitHubEventClient.AddToIssueUpdateList(scheduledEventPayload.Repository.Id,
issue.Number,
Expand Down Expand Up @@ -451,7 +455,8 @@ public static async Task IdentifyStaleIssues(GitHubEventClient gitHubEventClient
)
{
Issue issue = result.Items[iCounter++];
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false);
// This rule needs to the full IssueUpdate as it's adding a label
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false, false);
issueUpdate.AddLabel(TriageLabelConstants.NoRecentActivity);
gitHubEventClient.AddToIssueUpdateList(scheduledEventPayload.Repository.Id,
issue.Number,
Expand Down Expand Up @@ -597,6 +602,7 @@ public static async Task EnforceMaxLifeOfIssues(GitHubEventClient gitHubEventCli
)
{
Issue issue = result.Items[iCounter++];
// This rule only sets the state
IssueUpdate issueUpdate = gitHubEventClient.GetIssueUpdate(issue, false);
// Close the issue
issueUpdate.State = ItemState.Closed;
Expand Down
Loading