From cbf30d317a9edcdfde861e8bb535070345f624cb Mon Sep 17 00:00:00 2001 From: Dylan Morley Date: Sun, 21 May 2023 18:15:07 +0100 Subject: [PATCH 1/3] Get Team By Name implementation --- .../Clients/TeamsClientTests.cs | 16 +++++++++++++ Octokit.Tests/Clients/TeamsClientTests.cs | 24 +++++++++++++++++++ Octokit/Clients/ITeamsClient.cs | 13 ++++++++++ Octokit/Clients/TeamsClient.cs | 21 ++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index 5cbd7ba8a0..da59b46841 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -682,4 +682,20 @@ await github.Organization.Team.RemoveRepositoryFromATeam( } } } + + public class TheGetByNameMethod + { + [OrganizationTest] + public async Task GetsTeamByNameWhenAuthenticated() + { + var github = Helper.GetAuthenticatedClient(); + + using (var teamContext = await github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team")))) + { + var foundTeam = await github.Organization.Team.GetByName(Helper.Organization, teamContext.TeamName); + + Assert.Equal(foundTeam.Name, teamContext.TeamName); + } + } + } } diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 7f11425840..3a2d032281 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -618,5 +618,29 @@ public async Task RequestsTheCorrectUrl() connection.Received().Delete(Arg.Is(u => u.ToString() == expected)); } } + + public class TheGetByNameMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + + client.GetByName("orgName", "teamSlug"); + + connection.Received().Get( + Arg.Is(u => u.ToString() == "orgs/orgName/teams/teamSlug")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var teams = new TeamsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => teams.GetByName(null, "teamSlug")); + await Assert.ThrowsAsync(() => teams.GetByName("orgName", null)); + } + } } } diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 9507c125e4..5912e336b6 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -354,5 +354,18 @@ public interface ITeamsClient /// Thrown when a general API error occurs. /// Task RemoveRepositoryFromATeam(string org, string teamSlug, string owner, string repo); + + /// + /// Get a team by slug name + /// + /// + /// See the API Documentation + /// for more information. + /// + /// The organization name. The name is not case sensitive. + /// The slug of the team name. + /// Thrown when a general API error occurs. + /// A instance if found, otherwise null + Task GetByName(string org, string teamSlug); } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index af41cc3119..7674ca3db7 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -686,5 +686,26 @@ public Task RemoveRepositoryFromATeam(string org, string teamSlug, string owner, return ApiConnection.Delete(endpoint); } + + /// + /// Get a team by slug name + /// + /// + /// See the API Documentation + /// for more information. + /// + /// The organization name. The name is not case sensitive. + /// The slug of the team name. + /// Thrown when a general API error occurs. + /// A instance if found, otherwise null + [ManualRoute("GET", "/orgs/{org}/teams/{teamSlug}")] + public Task GetByName(string org, string teamSlug) + { + Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); + Ensure.ArgumentNotNullOrEmptyString(teamSlug, nameof(teamSlug)); + + var endpoint = ApiUrls.TeamsByOrganizationAndSlug(org, teamSlug); + return ApiConnection.Get(endpoint); + } } } From bde96ee3581641f8c1995835b586a319d315d475 Mon Sep 17 00:00:00 2001 From: Dylan Morley Date: Sun, 21 May 2023 21:05:42 +0100 Subject: [PATCH 2/3] Added GetByName to observable client --- .../Clients/IObservableTeamsClient.cs | 13 +++++++++++++ .../Clients/ObservableTeamsClient.cs | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index 745aa620e3..ec092a2488 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -362,5 +362,18 @@ public interface IObservableTeamsClient /// Thrown when a general API error occurs. /// IObservable RemoveRepositoryFromATeam(string org, string teamSlug, string owner, string repo); + + /// + /// Get a team by slug name + /// + /// + /// See the API Documentation + /// for more information. + /// + /// The organization name. The name is not case sensitive. + /// The slug of the team name. + /// Thrown when a general API error occurs. + /// A instance if found, otherwise null + IObservable GetByName(string org, string teamSlug); } } diff --git a/Octokit.Reactive/Clients/ObservableTeamsClient.cs b/Octokit.Reactive/Clients/ObservableTeamsClient.cs index f068d468bb..2d0daa0685 100644 --- a/Octokit.Reactive/Clients/ObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableTeamsClient.cs @@ -523,5 +523,22 @@ public IObservable RemoveRepositoryFromATeam(string org, string teamSlug, { return _client.RemoveRepositoryFromATeam(org, teamSlug, owner, repo).ToObservable(); } + + /// + /// Get a team by slug name + /// + /// + /// See the API Documentation + /// for more information. + /// + /// The organization name. The name is not case sensitive. + /// The slug of the team name. + /// Thrown when a general API error occurs. + /// A instance if found, otherwise null + [ManualRoute("GET", "/orgs/{org}/teams/{teamSlug}")] + public IObservable GetByName(string org, string teamSlug) + { + return _client.GetByName(org, teamSlug).ToObservable(); + } } } From d6d3bbd8c3791f2f260805095c372cf0ccc92098 Mon Sep 17 00:00:00 2001 From: Dylan Morley Date: Wed, 24 May 2023 10:40:29 +0100 Subject: [PATCH 3/3] Corrected documentation for Not Found behaviour --- Octokit.Reactive/Clients/IObservableTeamsClient.cs | 3 ++- Octokit.Reactive/Clients/ObservableTeamsClient.cs | 3 ++- Octokit/Clients/ITeamsClient.cs | 3 ++- Octokit/Clients/TeamsClient.cs | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index ec092a2488..1a9f40619b 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -373,7 +373,8 @@ public interface IObservableTeamsClient /// The organization name. The name is not case sensitive. /// The slug of the team name. /// Thrown when a general API error occurs. - /// A instance if found, otherwise null + /// Thrown when the team wasn't found + /// A instance if found, otherwise a IObservable GetByName(string org, string teamSlug); } } diff --git a/Octokit.Reactive/Clients/ObservableTeamsClient.cs b/Octokit.Reactive/Clients/ObservableTeamsClient.cs index 2d0daa0685..00c2b07616 100644 --- a/Octokit.Reactive/Clients/ObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableTeamsClient.cs @@ -534,7 +534,8 @@ public IObservable RemoveRepositoryFromATeam(string org, string teamSlug, /// The organization name. The name is not case sensitive. /// The slug of the team name. /// Thrown when a general API error occurs. - /// A instance if found, otherwise null + /// Thrown when the team wasn't found + /// A instance if found, otherwise a [ManualRoute("GET", "/orgs/{org}/teams/{teamSlug}")] public IObservable GetByName(string org, string teamSlug) { diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 5912e336b6..790d53cb04 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -365,7 +365,8 @@ public interface ITeamsClient /// The organization name. The name is not case sensitive. /// The slug of the team name. /// Thrown when a general API error occurs. - /// A instance if found, otherwise null + /// Thrown when the team wasn't found + /// A instance if found, otherwise a Task GetByName(string org, string teamSlug); } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 7674ca3db7..1c36920d59 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -697,7 +697,8 @@ public Task RemoveRepositoryFromATeam(string org, string teamSlug, string owner, /// The organization name. The name is not case sensitive. /// The slug of the team name. /// Thrown when a general API error occurs. - /// A instance if found, otherwise null + /// Thrown when the team wasn't found + /// A instance if found, otherwise a [ManualRoute("GET", "/orgs/{org}/teams/{teamSlug}")] public Task GetByName(string org, string teamSlug) {