Skip to content

Commit

Permalink
Get Team By Name implementation (#2717)
Browse files Browse the repository at this point in the history
* Get Team By Name implementation

* Added GetByName to observable client

* Corrected documentation for Not Found behaviour
  • Loading branch information
dylan-asos committed Jun 22, 2023
1 parent e1d587b commit b4b3534
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Octokit.Reactive/Clients/IObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,19 @@ public interface IObservableTeamsClient
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
IObservable<Unit> RemoveRepositoryFromATeam(string org, string teamSlug, string owner, string repo);

/// <summary>
/// Get a team by slug name
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#get-a-team-by-name">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The organization name. The name is not case sensitive.</param>
/// <param name="teamSlug">The slug of the team name.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <exception cref="NotFoundException">Thrown when the team wasn't found</exception>
/// <returns>A <see cref="Team"/> instance if found, otherwise a <see cref="NotFoundException"/></returns>
IObservable<Team> GetByName(string org, string teamSlug);
}
}
18 changes: 18 additions & 0 deletions Octokit.Reactive/Clients/ObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,5 +523,23 @@ public IObservable<Unit> RemoveRepositoryFromATeam(string org, string teamSlug,
{
return _client.RemoveRepositoryFromATeam(org, teamSlug, owner, repo).ToObservable();
}

/// <summary>
/// Get a team by slug name
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#get-a-team-by-name">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The organization name. The name is not case sensitive.</param>
/// <param name="teamSlug">The slug of the team name.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <exception cref="NotFoundException">Thrown when the team wasn't found</exception>
/// <returns>A <see cref="Team"/> instance if found, otherwise a <see cref="NotFoundException"/></returns>
[ManualRoute("GET", "/orgs/{org}/teams/{teamSlug}")]
public IObservable<Team> GetByName(string org, string teamSlug)
{
return _client.GetByName(org, teamSlug).ToObservable();
}
}
}
16 changes: 16 additions & 0 deletions Octokit.Tests.Integration/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,20 @@ public async Task RemovesRepositoryFromATeam()
}
}
}

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);
}
}
}
}
24 changes: 24 additions & 0 deletions Octokit.Tests/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -618,5 +618,29 @@ public async Task RequestsTheCorrectUrl()
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == expected));
}
}

public class TheGetByNameMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);

client.GetByName("orgName", "teamSlug");

connection.Received().Get<Team>(
Arg.Is<Uri>(u => u.ToString() == "orgs/orgName/teams/teamSlug"));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var teams = new TeamsClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => teams.GetByName(null, "teamSlug"));
await Assert.ThrowsAsync<ArgumentNullException>(() => teams.GetByName("orgName", null));
}
}
}
}
14 changes: 14 additions & 0 deletions Octokit/Clients/ITeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,19 @@ public interface ITeamsClient
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
Task RemoveRepositoryFromATeam(string org, string teamSlug, string owner, string repo);

/// <summary>
/// Get a team by slug name
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#get-a-team-by-name">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The organization name. The name is not case sensitive.</param>
/// <param name="teamSlug">The slug of the team name.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <exception cref="NotFoundException">Thrown when the team wasn't found</exception>
/// <returns>A <see cref="Team"/> instance if found, otherwise a <see cref="NotFoundException"/></returns>
Task<Team> GetByName(string org, string teamSlug);
}
}
22 changes: 22 additions & 0 deletions Octokit/Clients/TeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,5 +686,27 @@ public Task RemoveRepositoryFromATeam(string org, string teamSlug, string owner,

return ApiConnection.Delete(endpoint);
}

/// <summary>
/// Get a team by slug name
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#get-a-team-by-name">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The organization name. The name is not case sensitive.</param>
/// <param name="teamSlug">The slug of the team name.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <exception cref="NotFoundException">Thrown when the team wasn't found</exception>
/// <returns>A <see cref="Team"/> instance if found, otherwise a <see cref="NotFoundException"/></returns>
[ManualRoute("GET", "/orgs/{org}/teams/{teamSlug}")]
public Task<Team> GetByName(string org, string teamSlug)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNullOrEmptyString(teamSlug, nameof(teamSlug));

var endpoint = ApiUrls.TeamsByOrganizationAndSlug(org, teamSlug);
return ApiConnection.Get<Team>(endpoint);
}
}
}

0 comments on commit b4b3534

Please sign in to comment.