Skip to content

Commit

Permalink
Updates to github-event-processor (#7236)
Browse files Browse the repository at this point in the history
* Updates to github-event-processor

* Remove unnecessary ItemGroup VS added to test project and fix a small typo in RemoveLabel

* Remove my initials from the comment section.
  • Loading branch information
JimSuplizio authored Nov 14, 2023
1 parent e15648c commit 02826ab
Show file tree
Hide file tree
Showing 12 changed files with 1,126 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public class MockGitHubEventClient: GitHubEventClient
/// </summary>
public bool UserHasPermissionsReturn { get; set; } = false;

/// <summary>
/// OwnerCanBeAssignedToIssueInRepo will check the list to see if the owner is in there
/// returning true if so, false otherwise
/// </summary>
public List<string> OwnersWithAssignPermission { get; set; } = new List<string>();

/// <summary>
/// IsUserMemberOfOrg value. Defaults to false.
/// </summary>
Expand Down Expand Up @@ -64,14 +70,33 @@ public override Task<int> ProcessPendingUpdates(long repositoryId, int issueOrPu
Console.WriteLine("MockGitHubEventClient::ProcessPendingUpdates, Issue Update is null");
}

// The issue is being assigned. Note, this can only happen for issues, the issueOrPullRequestNumber
// in this case will always be an issue with the way events are processed.
if (_gitHubIssueAssignment != null)
{
Console.WriteLine($"MockGitHubEventClient::ProcessPendingUpdates, Issue Assignment is non-null. Assignees={string.Join(",", _gitHubIssueAssignment.Assignees)}");
numUpdates++;
}
else
{
Console.WriteLine("MockGitHubEventClient::ProcessPendingUpdates, Issue Assignment is null");
}

if (_labelsToAdd.Count > 0)
{
Console.WriteLine($"MockGitHubEventClient::ProcessPendingUpdates, number of labels to add = {_labelsToAdd.Count} (only 1 call)");
Console.WriteLine($"MockGitHubEventClient::ProcessPendingUpdates, number of labels to add = {_labelsToAdd.Count} (only 1 call). Labels={string.Join(",", _labelsToAdd)}");
// Adding labels is a single call to add them all
numUpdates++;
}

Console.WriteLine($"MockGitHubEventClient::ProcessPendingUpdates, number of labels to remove = {_labelsToRemove.Count}");
if (_labelsToRemove.Count > 0)
{
Console.WriteLine($"MockGitHubEventClient::ProcessPendingUpdates, number of labels to remove = {_labelsToRemove.Count} (1 call for each). Labels={string.Join(",", _labelsToRemove)}");
}
else
{
Console.WriteLine("MockGitHubEventClient::ProcessPendingUpdates, number of labels to remove = 0");
}
// Removing labels is a call for each one being removed
numUpdates += _labelsToRemove.Count;

Expand Down Expand Up @@ -125,6 +150,19 @@ public override Task<bool> DoesUserHavePermissions(long repositoryId, string use
return Task.FromResult(UserHasPermissionsReturn);
}


/// <summary>
/// OwnerCanBeAssignedToIssueInRepo override. Returns OwnerCanBeAssignedToIssueInRepoReturn value
/// </summary>
/// <param name="repoOwner">The owner of the repository. Repositories are in the form repoOwner/repoName. Azure/azure-sdk would have Azure as the owner and azure-sdk as the repo.</param>
/// <param name="repoName">The repository name.</param>
/// <param name="assignee">The potential assignee to check..</param>
/// <returns>bool, returns OwnerCanBeAssignedToIssueInRepoReturn for testing</returns>
public override Task<bool> OwnerCanBeAssignedToIssuesInRepo(string repoOwner, string repoName, string assignee)
{
return Task.FromResult(OwnersWithAssignPermission.Contains(assignee, StringComparer.OrdinalIgnoreCase));
}

/// <summary>
/// Mock call that will return a SearchIssuesResult for testing purposes
/// </summary>
Expand Down Expand Up @@ -486,6 +524,11 @@ public List<GitHubIssueToLock> GetGitHubIssuesToLock()
return _gitHubIssuesToLock;
}

public GitHubIssueAssignment GetGitHubIssueAssignment()
{
return _gitHubIssueAssignment;
}

/// <summary>
/// Override for the GitHubEventClient funcion which computes this based upon the repository's core rate limit.
/// Since this isn't necessary for the tests, just return the 100 which is the size of one page.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
################
# FAKE Codeowners file for InitialIssueTriage testing. Each metadata block has a unique ServiceLabel for
# testing different scenarios. The ServiceLabel needs to be returned from the AI Label service mock in order
# for a particular block to be selected.
# Note: FakeUser1 is the owner that opened the issue in the
# Tests.JsonEventPayloads/InitialIssueTriage_issue_opened_no_labels_no_assignee.json file.
################

# This scenario is a ServiceOwners block with no AzureSdkOwners
# ServiceLabel: %FakeLabel1
# ServiceOwners: @FakeUser7 @FakeUser8

# The scenarios here are a ServiceOwners block with a single AzureSdkOwner.
# The first scenario will be that the AzureSdkOwner doesn't have issue assignment permissions
# and the ServiceAttention rule is turned off. The ServiceLabel and NeedsTeamTriage will be added to the issue.
# The second scenario will be that the AzureSdkOwner doesn't have issue assignment permissions
# meaning that the ServiceOwners/ServiceAttention fallback will be executed.
# The third scenario will be that the AzureSdkOwner has issue assignment permissions. This
# will cause the owner to be assigned to the issue without a comment mentioning all AzureSdkOwners
# ServiceLabel: %FakeLabel2
# ServiceOwners: @FakeUser0 @FakeUser9
# AzureSdkOwners: @FakeUser1

# The scenarios here are a ServiceOwners block with a multiple AzureSdkOwners.
# The first scenario is that none of the AzureSdkOwners will have issue assignment permissions
# meaning that the ServiceOwners/ServiceAttention fallback will be executed.
# The second scenario is that only 1 of the AzureSdkOwners will have issue assignment permissions.
# This will cause the owner with permissions to be assigned to the issue and both owners will be
# in the at mention.
# ServiceOwners block with multiple AzureSdkOwners
# ServiceLabel: %FakeLabel3
# ServiceOwners: @FakeUser3 @FakeUser4
# AzureSdkOwners: @FakeUser1 @FakeUser5

# AzureSdkOwners and ServiceOwners pulled from source path/owners.
# The first scenario will test with both AzureSdkOwners having issue assignment permission
# The second scenario will test both AzureSdkOwners not having issue assignment permission
# ServiceLabel: %FakeLabel4
# AzureSdkOwners:
/files/filePath0/ @FakeUser5 @FakeUser6

Original file line number Diff line number Diff line change
@@ -1,24 +1,101 @@
{
"action": "opened",
"action": "labeled",
"issue": {
"active_lock_reason": null,
"assignee": null,
"assignees": [],
"assignee": {
"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"
},
"assignees": [
{
"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"
}
],
"author_association": "OWNER",
"body": null,
"closed_at": null,
"comments": 0,
"comments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/15/comments",
"created_at": "2023-01-30T18:59:03Z",
"events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/15/events",
"html_url": "https://github.com/Azure/azure-sdk-fake/issues/15",
"id": 1563022437,
"labels": [],
"labels_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/15/labels{/name}",
"comments_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/14/comments",
"created_at": "2023-01-27T17:01:30Z",
"events_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/14/events",
"html_url": "https://github.com/Azure/azure-sdk-fake/issues/14",
"id": 1560095682,
"labels": [
{
"color": "d73a4a",
"default": true,
"description": "Something isn't working",
"id": 4273699693,
"name": "bug",
"node_id": "LA_kwDOHkcrQs7-u3tt",
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels/bug"
},
{
"color": "F75BB2",
"default": false,
"description": "",
"id": 5095715984,
"name": "Service Attention",
"node_id": "LA_kwDOHkcrQs8AAAABL7p0kA",
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels/Service%20Attention"
},
{
"color": "9C7082",
"default": false,
"description": "fake label for testing",
"id": 5095712487,
"name": "FakeLabel1",
"node_id": "LA_kwDOHkcrQs8AAAABL7pm5w",
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels/FakeLabel1"
},
{
"color": "9C7082",
"default": false,
"description": "fake label for testing",
"id": 5095712487,
"name": "FakeLabel9",
"node_id": "LA_kwDOHkcrQs8AAAABL7pm5w",
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels/FakeLabel9"
}
],
"labels_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/14/labels{/name}",
"locked": false,
"milestone": null,
"node_id": "I_kwDOHkcrQs5dKdRl",
"number": 15,
"node_id": "I_kwDOHkcrQs5c_SvC",
"number": 14,
"performed_via_github_app": null,
"reactions": {
"+1": 0,
Expand All @@ -30,15 +107,15 @@
"laugh": 0,
"rocket": 0,
"total_count": 0,
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/15/reactions"
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/14/reactions"
},
"repository_url": "https://api.github.com/repos/Azure/azure-sdk-fake",
"state": "open",
"state_reason": null,
"timeline_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/15/timeline",
"title": "Another new issue to generate test payloads",
"updated_at": "2023-01-30T18:59:03Z",
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/15",
"timeline_url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/14/timeline",
"title": "New test issue to generate event payloads",
"updated_at": "2023-01-30T16:16:54Z",
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/issues/14",
"user": {
"avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4",
"events_url": "https://api.github.com/users/FakeUser1/events{/privacy}",
Expand All @@ -60,6 +137,15 @@
"url": "https://api.github.com/users/FakeUser1"
}
},
"label": {
"color": "9C7082",
"default": false,
"description": "fake label for testing",
"id": 5095712487,
"name": "FakeLabel4",
"node_id": "LA_kwDOHkcrQs8AAAABL7pm5w",
"url": "https://api.github.com/repos/Azure/azure-sdk-fake/labels/FakeLabel4"
},
"repository": {
"allow_forking": true,
"archive_url": "https://api.github.com/repos/Azure/azure-sdk-fake/{archive_format}{/ref}",
Expand Down Expand Up @@ -121,8 +207,8 @@
"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,
"open_issues": 6,
"open_issues_count": 6,
"owner": {
"avatar_url": "https://avatars.githubusercontent.com/u/13556087?v=4",
"events_url": "https://api.github.com/users/FakeUser1/events{/privacy}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\code-owners-parser\CodeOwnersParser\Azure.Sdk.Tools.CodeOwnersParser.csproj" />
<ProjectReference Include="..\..\codeowners-utils\Azure.Sdk.Tools.CodeownersUtils\Azure.Sdk.Tools.CodeownersUtils.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 02826ab

Please sign in to comment.