Skip to content

Commit 18d05ca

Browse files
authored
Update PR triage rule for PRs created by BOTs (#8941)
* Update PR triage rule for PRs created by BOTs * fix mistype of label
1 parent 65dbdb2 commit 18d05ca

File tree

4 files changed

+551
-28
lines changed

4 files changed

+551
-28
lines changed

tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Static/PullRequestProcessingTests.cs

+25-12
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ public class PullRequestProcessingTests : ProcessingTestBase
3535
/// <param name="hasWriteOrAdmin">Whether or not the PR creator has write or admin permissions</param>
3636
[Category("static")]
3737
[NonParallelizable]
38-
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, true)]
39-
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.Off, false, false)]
40-
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, false)]
41-
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, true)]
42-
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, false)]
43-
public async Task TestPullRequestTriage(string rule, string payloadFile, RuleState ruleState, bool isMemberOfOrg, bool hasWriteOrAdmin)
38+
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, true, false)]
39+
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.Off, false, false, false)]
40+
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, false, false)]
41+
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, true, false)]
42+
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, false, false)]
43+
[TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_by_bot_no_labels.json", RuleState.On, false, false, true)]
44+
public async Task TestPullRequestTriage(string rule, string payloadFile, RuleState ruleState, bool isMemberOfOrg, bool hasWriteOrAdmin, bool prCreatedByBot)
4445
{
4546
var mockGitHubEventClient = new MockGitHubEventClient(OrgConstants.ProductHeaderName);
4647
mockGitHubEventClient.RulesConfiguration.Rules[rule] = ruleState;
@@ -68,13 +69,17 @@ public async Task TestPullRequestTriage(string rule, string payloadFile, RuleSta
6869
var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(prEventPayload.Repository.Id, prEventPayload.PullRequest.Number);
6970
if (RuleState.On == ruleState)
7071
{
71-
// Regardless of whether or not the user has Write or Admin permissions, the prFiles should cause 4 labels to get added
72-
// which means an issueUpdate will be created
72+
// Regardless of whether or not the user has Write or Admin permissions, or the PR is created by a BOT, the prFiles should
73+
// cause 4 labels to get added which means an issueUpdate will be created
7374
int expectedUpdates = 1;
74-
75-
if (hasWriteOrAdmin || isMemberOfOrg)
75+
if (prCreatedByBot)
76+
{
77+
// There should be one update, an IssueUpdate with the PR labels for files in the PR
78+
Assert.AreEqual(expectedUpdates, totalUpdates, $"The number of updates for a PR created by a BOT user should have been {expectedUpdates} but was instead, {totalUpdates}");
79+
}
80+
else if (hasWriteOrAdmin || isMemberOfOrg)
7681
{
77-
// There should be one update, an IssueUpdate with the NoRecentActivity label removed
82+
// There should be one update, an IssueUpdate with the PR labels for files in the PR
7883
Assert.AreEqual(expectedUpdates, totalUpdates, $"The number of updates for a user having Write or Admin permission or being a member of Azure org should have been {expectedUpdates} but was instead, {totalUpdates}");
7984
}
8085
// If the user doesn't have Write or Admin permissions then "customer-reported" and "Community Contribution" labels
@@ -92,9 +97,17 @@ public async Task TestPullRequestTriage(string rule, string payloadFile, RuleSta
9297
Assert.True(mockGitHubEventClient.GetLabelsToAdd().Contains(label), $"Labels to add should contain {label} which should have been added because of the file paths in the PR but was not.");
9398
}
9499

100+
// If the PR was created by a bot, CustomerReported and CommunityContribution labels and commend should not be added
101+
if (prCreatedByBot)
102+
{
103+
Assert.False(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CustomerReported), $"User that created the PR was a BOT, IssueUpdate should not contain {TriageLabelConstants.CustomerReported}.");
104+
Assert.False(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CommunityContribution), $"User that created the PR was a BOT, IssueUpdate should not contain {TriageLabelConstants.CommunityContribution}.");
105+
Assert.AreEqual(0, mockGitHubEventClient.GetComments().Count, "User that created the PR was a BOT, there should not have been a comment added.");
106+
107+
}
95108
// If the user is not part of the Azure org AND they don't have write or admin collaborator permissions
96109
// then customer-reported and community-contribution labels should have been added along with a comment
97-
if (!isMemberOfOrg && !hasWriteOrAdmin)
110+
else if (!isMemberOfOrg && !hasWriteOrAdmin)
98111
{
99112
Assert.True(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CustomerReported), $"User does not have write or admin permission, IssueUpdate should contain {TriageLabelConstants.CustomerReported}.");
100113
Assert.True(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CommunityContribution), $"User does not have write or admin permission, IssueUpdate should contain {TriageLabelConstants.CommunityContribution}.");

0 commit comments

Comments
 (0)