Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ 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);
}
}
}
}
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);
}
}
}