From 956aeb00dd3079027c5d506fa5b3208fac79cd27 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Mon, 9 Sep 2024 08:55:30 -0700 Subject: [PATCH 1/2] Update PR triage rule for PRs created by BOTs --- .../Static/PullRequestProcessingTests.cs | 37 +- ...uestTriage_pr_opened_by_bot_no_labels.json | 503 ++++++++++++++++++ .../EventProcessing/PullRequestProcessing.cs | 26 +- tools/github-event-processor/RULES.md | 13 +- 4 files changed, 551 insertions(+), 28 deletions(-) create mode 100644 tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Tests.JsonEventPayloads/PullRequestTriage_pr_opened_by_bot_no_labels.json diff --git a/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Static/PullRequestProcessingTests.cs b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Static/PullRequestProcessingTests.cs index 59bb1a68ac3..1a48ed3ca68 100644 --- a/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Static/PullRequestProcessingTests.cs +++ b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Static/PullRequestProcessingTests.cs @@ -35,12 +35,13 @@ public class PullRequestProcessingTests : ProcessingTestBase /// Whether or not the PR creator has write or admin permissions [Category("static")] [NonParallelizable] - [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, true)] - [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.Off, false, false)] - [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, false)] - [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, true)] - [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, false)] - public async Task TestPullRequestTriage(string rule, string payloadFile, RuleState ruleState, bool isMemberOfOrg, bool hasWriteOrAdmin) + [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, true, false)] + [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.Off, false, false, false)] + [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, true, false, false)] + [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, true, false)] + [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_no_labels.json", RuleState.On, false, false, false)] + [TestCase(RulesConstants.PullRequestTriage, "Tests.JsonEventPayloads/PullRequestTriage_pr_opened_by_bot_no_labels.json", RuleState.On, false, false, true)] + public async Task TestPullRequestTriage(string rule, string payloadFile, RuleState ruleState, bool isMemberOfOrg, bool hasWriteOrAdmin, bool prCreatedByBot) { var mockGitHubEventClient = new MockGitHubEventClient(OrgConstants.ProductHeaderName); mockGitHubEventClient.RulesConfiguration.Rules[rule] = ruleState; @@ -68,13 +69,17 @@ public async Task TestPullRequestTriage(string rule, string payloadFile, RuleSta var totalUpdates = await mockGitHubEventClient.ProcessPendingUpdates(prEventPayload.Repository.Id, prEventPayload.PullRequest.Number); if (RuleState.On == ruleState) { - // Regardless of whether or not the user has Write or Admin permissions, the prFiles should cause 4 labels to get added - // which means an issueUpdate will be created + // Regardless of whether or not the user has Write or Admin permissions, or the PR is created by a BOT, the prFiles should + // cause 4 labels to get added which means an issueUpdate will be created int expectedUpdates = 1; - - if (hasWriteOrAdmin || isMemberOfOrg) + if (prCreatedByBot) + { + // There should be one update, an IssueUpdate with the PR labels for files in the PR + Assert.AreEqual(expectedUpdates, totalUpdates, $"The number of updates for a PR created by a BOT user should have been {expectedUpdates} but was instead, {totalUpdates}"); + } + else if (hasWriteOrAdmin || isMemberOfOrg) { - // There should be one update, an IssueUpdate with the NoRecentActivity label removed + // There should be one update, an IssueUpdate with the PR labels for files in the PR 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}"); } // 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 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."); } + // If the PR was created by a bot, CustomerReported and CommunityContribution labels and commend should not be added + if (prCreatedByBot) + { + Assert.False(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CustomerReported), $"User that created the PR was a BOT, IssueUpdate should not contain {TriageLabelConstants.CustomerReported}."); + Assert.False(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CommunityContribution), $"User that created the PR was a BOT, IssueUpdate should not contain {TriageLabelConstants.CommunityContribution}."); + Assert.AreEqual(0, mockGitHubEventClient.GetComments().Count, "User that created the PR was a BOT, there should not have been a comment added."); + + } // If the user is not part of the Azure org AND they don't have write or admin collaborator permissions // then customer-reported and community-contribution labels should have been added along with a comment - if (!isMemberOfOrg && !hasWriteOrAdmin) + else if (!isMemberOfOrg && !hasWriteOrAdmin) { Assert.True(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CustomerReported), $"User does not have write or admin permission, IssueUpdate should contain {TriageLabelConstants.CustomerReported}."); Assert.True(mockGitHubEventClient.GetLabelsToAdd().Contains(TriageLabelConstants.CommunityContribution), $"User does not have write or admin permission, IssueUpdate should contain {TriageLabelConstants.CommunityContribution}."); diff --git a/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Tests.JsonEventPayloads/PullRequestTriage_pr_opened_by_bot_no_labels.json b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Tests.JsonEventPayloads/PullRequestTriage_pr_opened_by_bot_no_labels.json new file mode 100644 index 00000000000..5dfd3c17fb1 --- /dev/null +++ b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor.Tests/Tests.JsonEventPayloads/PullRequestTriage_pr_opened_by_bot_no_labels.json @@ -0,0 +1,503 @@ +{ + "action": "opened", + "number": 8, + "pull_request": { + "_links": { + "comments": { + "href": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/8/comments" + }, + "commits": { + "href": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/8/commits" + }, + "html": { + "href": "https://github.com/Azure/azure-sdk-fake/pull/8" + }, + "issue": { + "href": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/8" + }, + "review_comment": { + "href": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/comments{/number}" + }, + "review_comments": { + "href": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/8/comments" + }, + "self": { + "href": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/8" + }, + "statuses": { + "href": "https://api.github.com/repos/Azure/azure-sdk-fake/statuses/827307d6715561ecea6ec0d5d64e5fb2578a6165" + } + }, + "active_lock_reason": null, + "additions": 1, + "assignee": null, + "assignees": [], + "author_association": "OWNER", + "auto_merge": null, + "base": { + "label": "FakeUser1:main", + "ref": "main", + "repo": { + "allow_auto_merge": false, + "allow_forking": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/Azure/azure-sdk-fake/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/Azure/azure-sdk-fake/assignees{/user}", + "blobs_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/Azure/azure-sdk-fake/branches{/branch}", + "clone_url": "https://github.com/Azure/azure-sdk-fake.git", + "collaborators_url": "https://api.github.com/repos/Azure/azure-sdk-fake/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/comments{/number}", + "commits_url": "https://api.github.com/repos/Azure/azure-sdk-fake/commits{/sha}", + "compare_url": "https://api.github.com/repos/Azure/azure-sdk-fake/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/Azure/azure-sdk-fake/contents/{+path}", + "contributors_url": "https://api.github.com/repos/Azure/azure-sdk-fake/contributors", + "created_at": "2022-06-27T16:19:29Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/deployments", + "description": "Tools repository leveraged by the Azure SDK team.", + "disabled": false, + "downloads_url": "https://api.github.com/repos/Azure/azure-sdk-fake/downloads", + "events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/events", + "fork": true, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/Azure/azure-sdk-fake/forks", + "full_name": "Azure/azure-sdk-fake", + "git_commits_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/tags{/sha}", + "git_url": "git://github.com/Azure/azure-sdk-fake.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/Azure/azure-sdk-fake/hooks", + "html_url": "https://github.com/Azure/azure-sdk-fake", + "id": 507980610, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/events{/number}", + "issues_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues{/number}", + "keys_url": "https://api.github.com/repos/Azure/azure-sdk-fake/keys{/key_id}", + "labels_url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels{/name}", + "language": "C#", + "languages_url": "https://api.github.com/repos/Azure/azure-sdk-fake/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "MDc6TGljZW5zZTEz", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/Azure/azure-sdk-fake/merges", + "milestones_url": "https://api.github.com/repos/Azure/azure-sdk-fake/milestones{/number}", + "mirror_url": null, + "name": "azure-sdk-fake", + "node_id": "R_kgDOHkcrQg", + "notifications_url": "https://api.github.com/repos/Azure/azure-sdk-fake/notifications{?since,all,participating}", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4", + "events_url": "https://api.github.com/users/FakeUser1/events{/privacy}", + "followers_url": "https://api.github.com/users/FakeUser1/followers", + "following_url": "https://api.github.com/users/FakeUser1/following{/other_user}", + "gists_url": "https://api.github.com/users/FakeUser1/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/FakeUser1", + "id": 13556087, + "login": "FakeUser1", + "node_id": "MDQ6VXNlcjEzNTU2MDg3", + "organizations_url": "https://api.github.com/users/FakeUser1/orgs", + "received_events_url": "https://api.github.com/users/FakeUser1/received_events", + "repos_url": "https://api.github.com/users/FakeUser1/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/FakeUser1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/FakeUser1/subscriptions", + "type": "User", + "url": "https://api.github.com/users/FakeUser1" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls{/number}", + "pushed_at": "2022-11-01T20:27:41Z", + "releases_url": "https://api.github.com/repos/Azure/azure-sdk-fake/releases{/id}", + "size": 28964, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:Azure/azure-sdk-fake.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/Azure/azure-sdk-fake/stargazers", + "statuses_url": "https://api.github.com/repos/Azure/azure-sdk-fake/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/Azure/azure-sdk-fake/subscribers", + "subscription_url": "https://api.github.com/repos/Azure/azure-sdk-fake/subscription", + "svn_url": "https://github.com/Azure/azure-sdk-fake", + "tags_url": "https://api.github.com/repos/Azure/azure-sdk-fake/tags", + "teams_url": "https://api.github.com/repos/Azure/azure-sdk-fake/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/trees{/sha}", + "updated_at": "2022-10-31T16:54:20Z", + "url": "https://api.github.com/repos/Azure/azure-sdk-fake", + "use_squash_pr_title_as_default": false, + "visibility": "public", + "watchers": 0, + "watchers_count": 0, + "web_commit_signoff_required": false + }, + "sha": "36aab176cf9055be3bbac44a4134875dbb5e6319", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4", + "events_url": "https://api.github.com/users/FakeUser1/events{/privacy}", + "followers_url": "https://api.github.com/users/FakeUser1/followers", + "following_url": "https://api.github.com/users/FakeUser1/following{/other_user}", + "gists_url": "https://api.github.com/users/FakeUser1/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/FakeUser1", + "id": 13556087, + "login": "FakeUser1", + "node_id": "MDQ6VXNlcjEzNTU2MDg3", + "organizations_url": "https://api.github.com/users/FakeUser1/orgs", + "received_events_url": "https://api.github.com/users/FakeUser1/received_events", + "repos_url": "https://api.github.com/users/FakeUser1/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/FakeUser1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/FakeUser1/subscriptions", + "type": "User", + "url": "https://api.github.com/users/FakeUser1" + } + }, + "body": "test comment", + "changed_files": 1, + "closed_at": null, + "comments": 0, + "comments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/8/comments", + "commits": 1, + "commits_url": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/8/commits", + "created_at": "2022-11-01T20:27:41Z", + "deletions": 0, + "diff_url": "https://github.com/Azure/azure-sdk-fake/pull/8.diff", + "draft": false, + "head": { + "label": "FakeUser1:TestBranch2", + "ref": "TestBranch2", + "repo": { + "allow_auto_merge": false, + "allow_forking": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/Azure/azure-sdk-fake/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/Azure/azure-sdk-fake/assignees{/user}", + "blobs_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/Azure/azure-sdk-fake/branches{/branch}", + "clone_url": "https://github.com/Azure/azure-sdk-fake.git", + "collaborators_url": "https://api.github.com/repos/Azure/azure-sdk-fake/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/comments{/number}", + "commits_url": "https://api.github.com/repos/Azure/azure-sdk-fake/commits{/sha}", + "compare_url": "https://api.github.com/repos/Azure/azure-sdk-fake/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/Azure/azure-sdk-fake/contents/{+path}", + "contributors_url": "https://api.github.com/repos/Azure/azure-sdk-fake/contributors", + "created_at": "2022-06-27T16:19:29Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/deployments", + "description": "Tools repository leveraged by the Azure SDK team.", + "disabled": false, + "downloads_url": "https://api.github.com/repos/Azure/azure-sdk-fake/downloads", + "events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/events", + "fork": true, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/Azure/azure-sdk-fake/forks", + "full_name": "Azure/azure-sdk-fake", + "git_commits_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/tags{/sha}", + "git_url": "git://github.com/Azure/azure-sdk-fake.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/Azure/azure-sdk-fake/hooks", + "html_url": "https://github.com/Azure/azure-sdk-fake", + "id": 507980610, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/events{/number}", + "issues_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues{/number}", + "keys_url": "https://api.github.com/repos/Azure/azure-sdk-fake/keys{/key_id}", + "labels_url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels{/name}", + "language": "C#", + "languages_url": "https://api.github.com/repos/Azure/azure-sdk-fake/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "MDc6TGljZW5zZTEz", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/Azure/azure-sdk-fake/merges", + "milestones_url": "https://api.github.com/repos/Azure/azure-sdk-fake/milestones{/number}", + "mirror_url": null, + "name": "azure-sdk-fake", + "node_id": "R_kgDOHkcrQg", + "notifications_url": "https://api.github.com/repos/Azure/azure-sdk-fake/notifications{?since,all,participating}", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4", + "events_url": "https://api.github.com/users/FakeUser1/events{/privacy}", + "followers_url": "https://api.github.com/users/FakeUser1/followers", + "following_url": "https://api.github.com/users/FakeUser1/following{/other_user}", + "gists_url": "https://api.github.com/users/FakeUser1/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/FakeUser1", + "id": 13556087, + "login": "FakeUser1", + "node_id": "MDQ6VXNlcjEzNTU2MDg3", + "organizations_url": "https://api.github.com/users/FakeUser1/orgs", + "received_events_url": "https://api.github.com/users/FakeUser1/received_events", + "repos_url": "https://api.github.com/users/FakeUser1/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/FakeUser1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/FakeUser1/subscriptions", + "type": "User", + "url": "https://api.github.com/users/FakeUser1" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls{/number}", + "pushed_at": "2022-11-01T20:27:41Z", + "releases_url": "https://api.github.com/repos/Azure/azure-sdk-fake/releases{/id}", + "size": 28964, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:Azure/azure-sdk-fake.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/Azure/azure-sdk-fake/stargazers", + "statuses_url": "https://api.github.com/repos/Azure/azure-sdk-fake/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/Azure/azure-sdk-fake/subscribers", + "subscription_url": "https://api.github.com/repos/Azure/azure-sdk-fake/subscription", + "svn_url": "https://github.com/Azure/azure-sdk-fake", + "tags_url": "https://api.github.com/repos/Azure/azure-sdk-fake/tags", + "teams_url": "https://api.github.com/repos/Azure/azure-sdk-fake/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/trees{/sha}", + "updated_at": "2022-10-31T16:54:20Z", + "url": "https://api.github.com/repos/Azure/azure-sdk-fake", + "use_squash_pr_title_as_default": false, + "visibility": "public", + "watchers": 0, + "watchers_count": 0, + "web_commit_signoff_required": false + }, + "sha": "827307d6715561ecea6ec0d5d64e5fb2578a6165", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4", + "events_url": "https://api.github.com/users/FakeUser1/events{/privacy}", + "followers_url": "https://api.github.com/users/FakeUser1/followers", + "following_url": "https://api.github.com/users/FakeUser1/following{/other_user}", + "gists_url": "https://api.github.com/users/FakeUser1/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/FakeUser1", + "id": 13556087, + "login": "FakeUser1", + "node_id": "MDQ6VXNlcjEzNTU2MDg3", + "organizations_url": "https://api.github.com/users/FakeUser1/orgs", + "received_events_url": "https://api.github.com/users/FakeUser1/received_events", + "repos_url": "https://api.github.com/users/FakeUser1/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/FakeUser1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/FakeUser1/subscriptions", + "type": "User", + "url": "https://api.github.com/users/FakeUser1" + } + }, + "html_url": "https://github.com/Azure/azure-sdk-fake/pull/8", + "id": 1107290828, + "issue_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/8", + "labels": [], + "locked": false, + "maintainer_can_modify": false, + "merge_commit_sha": null, + "mergeable": null, + "mergeable_state": "unknown", + "merged": false, + "merged_at": null, + "merged_by": null, + "milestone": null, + "node_id": "PR_kwDOHkcrQs5B_-rM", + "number": 8, + "patch_url": "https://github.com/Azure/azure-sdk-fake/pull/8.patch", + "rebaseable": null, + "requested_reviewers": [], + "requested_teams": [], + "review_comment_url": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/comments{/number}", + "review_comments": 0, + "review_comments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/8/comments", + "state": "open", + "statuses_url": "https://api.github.com/repos/Azure/azure-sdk-fake/statuses/827307d6715561ecea6ec0d5d64e5fb2578a6165", + "title": "This is just a test", + "updated_at": "2022-11-01T20:27:41Z", + "url": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls/8", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4", + "events_url": "https://api.github.com/users/FakeUser1/events{/privacy}", + "followers_url": "https://api.github.com/users/FakeUser1/followers", + "following_url": "https://api.github.com/users/FakeUser1/following{/other_user}", + "gists_url": "https://api.github.com/users/FakeUser1/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/FakeUser1", + "id": 13556087, + "login": "FakeUser1", + "node_id": "MDQ6VXNlcjEzNTU2MDg3", + "organizations_url": "https://api.github.com/users/FakeUser1/orgs", + "received_events_url": "https://api.github.com/users/FakeUser1/received_events", + "repos_url": "https://api.github.com/users/FakeUser1/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/FakeUser1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/FakeUser1/subscriptions", + "type": "User", + "url": "https://api.github.com/users/FakeUser1" + } + }, + "repository": { + "allow_forking": true, + "archive_url": "https://api.github.com/repos/Azure/azure-sdk-fake/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/Azure/azure-sdk-fake/assignees{/user}", + "blobs_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/Azure/azure-sdk-fake/branches{/branch}", + "clone_url": "https://github.com/Azure/azure-sdk-fake.git", + "collaborators_url": "https://api.github.com/repos/Azure/azure-sdk-fake/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/comments{/number}", + "commits_url": "https://api.github.com/repos/Azure/azure-sdk-fake/commits{/sha}", + "compare_url": "https://api.github.com/repos/Azure/azure-sdk-fake/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/Azure/azure-sdk-fake/contents/{+path}", + "contributors_url": "https://api.github.com/repos/Azure/azure-sdk-fake/contributors", + "created_at": "2022-06-27T16:19:29Z", + "default_branch": "main", + "deployments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/deployments", + "description": "Tools repository leveraged by the Azure SDK team.", + "disabled": false, + "downloads_url": "https://api.github.com/repos/Azure/azure-sdk-fake/downloads", + "events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/events", + "fork": true, + "forks": 0, + "forks_count": 0, + "forks_url": "https://api.github.com/repos/Azure/azure-sdk-fake/forks", + "full_name": "Azure/azure-sdk-fake", + "git_commits_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/tags{/sha}", + "git_url": "git://github.com/Azure/azure-sdk-fake.git", + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/Azure/azure-sdk-fake/hooks", + "html_url": "https://github.com/Azure/azure-sdk-fake", + "id": 507980610, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/events{/number}", + "issues_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues{/number}", + "keys_url": "https://api.github.com/repos/Azure/azure-sdk-fake/keys{/key_id}", + "labels_url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels{/name}", + "language": "C#", + "languages_url": "https://api.github.com/repos/Azure/azure-sdk-fake/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "MDc6TGljZW5zZTEz", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merges_url": "https://api.github.com/repos/Azure/azure-sdk-fake/merges", + "milestones_url": "https://api.github.com/repos/Azure/azure-sdk-fake/milestones{/number}", + "mirror_url": null, + "name": "azure-sdk-fake", + "node_id": "R_kgDOHkcrQg", + "notifications_url": "https://api.github.com/repos/Azure/azure-sdk-fake/notifications{?since,all,participating}", + "open_issues": 7, + "open_issues_count": 7, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4", + "events_url": "https://api.github.com/users/FakeUser1/events{/privacy}", + "followers_url": "https://api.github.com/users/FakeUser1/followers", + "following_url": "https://api.github.com/users/FakeUser1/following{/other_user}", + "gists_url": "https://api.github.com/users/FakeUser1/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/FakeUser1", + "id": 13556087, + "login": "FakeUser1", + "node_id": "MDQ6VXNlcjEzNTU2MDg3", + "organizations_url": "https://api.github.com/users/FakeUser1/orgs", + "received_events_url": "https://api.github.com/users/FakeUser1/received_events", + "repos_url": "https://api.github.com/users/FakeUser1/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/FakeUser1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/FakeUser1/subscriptions", + "type": "User", + "url": "https://api.github.com/users/FakeUser1" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/Azure/azure-sdk-fake/pulls{/number}", + "pushed_at": "2022-11-01T20:27:41Z", + "releases_url": "https://api.github.com/repos/Azure/azure-sdk-fake/releases{/id}", + "size": 28964, + "ssh_url": "git@github.com:Azure/azure-sdk-fake.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/Azure/azure-sdk-fake/stargazers", + "statuses_url": "https://api.github.com/repos/Azure/azure-sdk-fake/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/Azure/azure-sdk-fake/subscribers", + "subscription_url": "https://api.github.com/repos/Azure/azure-sdk-fake/subscription", + "svn_url": "https://github.com/Azure/azure-sdk-fake", + "tags_url": "https://api.github.com/repos/Azure/azure-sdk-fake/tags", + "teams_url": "https://api.github.com/repos/Azure/azure-sdk-fake/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/Azure/azure-sdk-fake/git/trees{/sha}", + "updated_at": "2022-10-31T16:54:20Z", + "url": "https://api.github.com/repos/Azure/azure-sdk-fake", + "visibility": "public", + "watchers": 0, + "watchers_count": 0, + "web_commit_signoff_required": false + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4", + "events_url": "https://api.github.com/users/FakeUser1/events{/privacy}", + "followers_url": "https://api.github.com/users/FakeUser1/followers", + "following_url": "https://api.github.com/users/FakeUser1/following{/other_user}", + "gists_url": "https://api.github.com/users/FakeUser1/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/FakeUser1", + "id": 13556087, + "login": "FakeUser1", + "node_id": "MDQ6VXNlcjEzNTU2MDg3", + "organizations_url": "https://api.github.com/users/FakeUser1/orgs", + "received_events_url": "https://api.github.com/users/FakeUser1/received_events", + "repos_url": "https://api.github.com/users/FakeUser1/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/FakeUser1/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/FakeUser1/subscriptions", + "type": "Bot", + "url": "https://api.github.com/users/FakeUser1" + } +} \ No newline at end of file diff --git a/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs index 19ebae14786..eb4521da140 100644 --- a/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs +++ b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs @@ -33,7 +33,8 @@ public static async Task ProcessPullRequestEvent(GitHubEventClient gitHubEventCl /// Conditions: Pull request has no labels /// Resulting Action: /// Evaluate the path for each file in the PR, if the path has a label, add the label to the issue - /// If the sender is not a Collaborator OR, if they are a collaborator without Write/Admin permissions + /// If the sender is not a known bot + /// If the sender is not a Collaborator OR, if they are a collaborator without Write/Admin permissions /// Add "customer-reported" label /// Add "Community Contribution" label /// Create issue comment: "Thank you for your contribution @{issueAuthor} ! We will review the pull request and get back to you soon." @@ -59,17 +60,22 @@ public static async Task PullRequestTriage(GitHubEventClient gitHubEventClient, } } - // If the user is not a member of the Azure Org AND the user does not have write or admin collaborator permission - bool isMemberOfOrg = await gitHubEventClient.IsUserMemberOfOrg(OrgConstants.Azure, prEventPayload.PullRequest.User.Login); - if (!isMemberOfOrg) + // There are PRs coming from bots, specifically the microsoft-github-policy-service bot. + // Don't add the triage lables or comment if the PR was created by a bot. + if (prEventPayload.Sender.Type != AccountType.Bot) { - bool hasAdminOrWritePermission = await gitHubEventClient.DoesUserHaveAdminOrWritePermission(prEventPayload.Repository.Id, prEventPayload.PullRequest.User.Login); - if (!hasAdminOrWritePermission) + // If the user is not a member of the Azure Org AND the user does not have write or admin collaborator permission + bool isMemberOfOrg = await gitHubEventClient.IsUserMemberOfOrg(OrgConstants.Azure, prEventPayload.PullRequest.User.Login); + if (!isMemberOfOrg) { - gitHubEventClient.AddLabel(TriageLabelConstants.CustomerReported); - gitHubEventClient.AddLabel(TriageLabelConstants.CommunityContribution); - string prComment = $"Thank you for your contribution @{prEventPayload.PullRequest.User.Login}! We will review the pull request and get back to you soon."; - gitHubEventClient.CreateComment(prEventPayload.Repository.Id, prEventPayload.PullRequest.Number, prComment); + bool hasAdminOrWritePermission = await gitHubEventClient.DoesUserHaveAdminOrWritePermission(prEventPayload.Repository.Id, prEventPayload.PullRequest.User.Login); + if (!hasAdminOrWritePermission) + { + gitHubEventClient.AddLabel(TriageLabelConstants.CustomerReported); + gitHubEventClient.AddLabel(TriageLabelConstants.CommunityContribution); + string prComment = $"Thank you for your contribution @{prEventPayload.PullRequest.User.Login}! We will review the pull request and get back to you soon."; + gitHubEventClient.CreateComment(prEventPayload.Repository.Id, prEventPayload.PullRequest.Number, prComment); + } } } } diff --git a/tools/github-event-processor/RULES.md b/tools/github-event-processor/RULES.md index 2b0ca8c3b41..d693cbfbf55 100644 --- a/tools/github-event-processor/RULES.md +++ b/tools/github-event-processor/RULES.md @@ -426,12 +426,13 @@ OR - Determine if this is a community contribution: ```text - IF the user is NOT a member of the Azure Org - IF the user does not have Admin or Write Collaborator permission - - Add "customer-reported" label - - Add "Community Contribution" label - - Create the following comment - - "Thank you for your contribution @{issueAuthor}! We will review the pull request and get back to you soon." + If the user is NOT a known bot + IF the user is NOT a member of the Azure Org + IF the user does not have Admin or Write Collaborator permission + - Add "customer-reported" label + - Add "Community Contribution" label + - Create the following comment + - "Thank you for your contribution @{issueAuthor}! We will review the pull request and get back to you soon." ``` ## Reset pull request activity From c148690867b731e4a7eccd45358c310307acc312 Mon Sep 17 00:00:00 2001 From: James Suplizio Date: Mon, 9 Sep 2024 08:57:39 -0700 Subject: [PATCH 2/2] fix mistype of label --- .../EventProcessing/PullRequestProcessing.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs index eb4521da140..b5d28df53e6 100644 --- a/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs +++ b/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor/EventProcessing/PullRequestProcessing.cs @@ -61,7 +61,7 @@ public static async Task PullRequestTriage(GitHubEventClient gitHubEventClient, } // There are PRs coming from bots, specifically the microsoft-github-policy-service bot. - // Don't add the triage lables or comment if the PR was created by a bot. + // Don't add the triage labels or comment if the PR was created by a bot. if (prEventPayload.Sender.Type != AccountType.Bot) { // If the user is not a member of the Azure Org AND the user does not have write or admin collaborator permission