mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-02 19:00:47 +00:00
Get Team By Name implementation (#2717)
* Get Team By Name implementation * Added GetByName to observable client * Corrected documentation for Not Found behaviour
This commit is contained in:
@@ -362,5 +362,19 @@ namespace Octokit.Reactive
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,5 +523,23 @@ namespace Octokit.Reactive
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -682,4 +682,20 @@ public class TeamsClientTests
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,5 +618,29 @@ namespace Octokit.Tests.Clients
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,5 +354,19 @@ namespace Octokit
|
||||
/// <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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,5 +686,27 @@ namespace Octokit
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user