Merge pull request #181 from hahmed/org-teams

Github Teams Api
This commit is contained in:
Phil Haack
2013-11-08 09:27:36 -08:00
17 changed files with 449 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
{
/// <summary>
/// Client tests mostly just need to make sure they call the IApiConnection with the correct
/// relative Uri. No need to fake up the response. All *those* tests are in ApiConnectionTests.cs.
/// </summary>
public class TeamsClientTests
{
public class TheConstructor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new TeamsClient(null));
}
}
public class TheGetAllMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);
client.GetAllTeams("orgName");
connection.Received().GetAll<TeamItem>(Arg.Is<Uri>(u => u.ToString() == "orgs/orgName/teams"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var teams = new TeamsClient(Substitute.For<IApiConnection>());
AssertEx.Throws<ArgumentNullException>(async () => await teams.GetAllTeams(null));
}
}
public class TheCreateTeamMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);
var team = new NewTeam("Octokittens");
client.CreateTeam("orgName", team);
connection.Received().Post<Team>(Arg.Is<Uri>(u => u.ToString() == "orgs/orgName/teams"), team);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);
AssertEx.Throws<ArgumentNullException>(async () => await
client.CreateTeam("", new NewTeam("superstars")));
AssertEx.Throws<ArgumentException>(async () => await
client.CreateTeam("name", null));
}
}
public class TheUpdateTeamMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);
var team = new UpdateTeam("Octokittens");
client.UpdateTeam(1, team);
connection.Received().Patch<Team>(Arg.Is<Uri>(u => u.ToString() == "teams/1"), team);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);
AssertEx.Throws<ArgumentNullException>(async () => await
client.UpdateTeam(1, null));
}
}
public class TheDeleteTeamMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);
client.DeleteTeam(1);
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "teams/1"));
}
}
}
}
@@ -106,6 +106,7 @@
<Compile Include="Clients\RepositoriesClientTests.cs" />
<Compile Include="SimpleJsonSerializerTests.cs" />
<Compile Include="Clients\UsersClientTests.cs" />
<Compile Include="Clients\TeamsClientTests.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Fixtures\user_full.json" />
+1
View File
@@ -66,6 +66,7 @@
<Compile Include="Clients\AssigneesClientTests.cs" />
<Compile Include="Clients\CommitsClientTests.cs" />
<Compile Include="Clients\CommitStatusClientTests.cs" />
<Compile Include="Clients\TeamsClientTests.cs" />
<Compile Include="Clients\GitDatabaseClientTests.cs" />
<Compile Include="Clients\OrganizationMembersClientTests.cs" />
<Compile Include="Clients\TagsClientTests.cs" />
+5
View File
@@ -19,6 +19,11 @@ namespace Octokit
/// </summary>
IOrganizationMembersClient Member { get; }
/// <summary>
/// Returns a client to manage teams of an organization.
/// </summary>
ITeamsClient Team { get; }
/// <summary>
/// Returns the specified <see cref="Organization"/>.
/// </summary>
+46
View File
@@ -0,0 +1,46 @@
#if NET_45
using System.Collections.Generic;
#endif
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Org Teams API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Orgs API documentation</a> for more information.
/// </remarks>
public interface ITeamsClient
{
/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="TeamItem"/>s.</returns>
Task<IReadOnlyList<TeamItem>> GetAllTeams(string org);
/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>Newly created <see cref="Team"/></returns>
Task<Team> CreateTeam(string org, NewTeam team);
/// <summary>
/// Returns updated <see cref="Team" /> for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>Updated <see cref="Team"/></returns>
Task<Team> UpdateTeam(int id, UpdateTeam team);
/// <summary>
/// Delte a team - must have owner permissions to this
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
Task DeleteTeam(int id);
}
}
+6
View File
@@ -21,10 +21,16 @@ namespace Octokit
public OrganizationsClient(IApiConnection apiConnection) : base(apiConnection)
{
Member = new OrganizationMembersClient(apiConnection);
Team = new TeamsClient(apiConnection);
}
public IOrganizationMembersClient Member { get; private set; }
/// <summary>
/// Returns a client to manage teams of an organization.
/// </summary>
public ITeamsClient Team { get; private set; }
/// <summary>
/// Returns the specified <see cref="Organization"/>.
/// </summary>
+81
View File
@@ -0,0 +1,81 @@
#if NET_45
using System.Collections.Generic;
#endif
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Org Teams API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Orgs API documentation</a> for more information.
/// </remarks>
public class TeamsClient : ApiClient, ITeamsClient
{
/// <summary>
/// Initializes a new GitHub Orgs Team API client.
/// </summary>
/// <param name="apiConnection">An API connection.</param>
public TeamsClient(IApiConnection apiConnection)
: base(apiConnection)
{
}
/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
public Task<IReadOnlyList<TeamItem>> GetAllTeams(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
var endpoint = "orgs/{0}/teams".FormatUri(org);
return ApiConnection.GetAll<TeamItem>(endpoint);
}
/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>Newly created <see cref="Team"/></returns>
public Task<Team> CreateTeam(string org, NewTeam team)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNull(team, "team");
var endpoint = "orgs/{0}/teams".FormatUri(org);
return ApiConnection.Post<Team>(endpoint, team);
}
/// <summary>
/// Returns updated <see cref="Team" /> for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>Updated <see cref="Team"/></returns>
public Task<Team> UpdateTeam(int id, UpdateTeam team)
{
Ensure.ArgumentNotNull(team, "team");
var endpoint = "teams/{0}".FormatUri(id);
return ApiConnection.Patch<Team>(endpoint, team);
}
/// <summary>
/// Delte a team - must have owner permissions to this
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public Task DeleteTeam(int id)
{
var endpoint = "teams/{0}".FormatUri(id);
return ApiConnection.Delete(endpoint);
}
}
}
+34
View File
@@ -0,0 +1,34 @@
using Octokit.Internal;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
public class NewTeam
{
public NewTeam(string name)
{
Name = name;
RepoNames = new Collection<string>();
Permission = Octokit.Permission.Pull;
}
/// <summary>
/// team name
/// </summary>
public string Name { get; set; }
/// <summary>
/// permission associated to this team
/// </summary>
public Permission Permission { get; set; }
/// <summary>
/// array of repo_names this team has permissions to
/// </summary>
public Collection<string> RepoNames { get; private set; }
}
}
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
public enum Permission
{
/// <summary>
/// team members can pull, push and administer these repositories.
/// </summary>
Admin,
/// <summary>
/// team members can pull and push, but not administer these repositories
/// </summary>
Push,
/// <summary>
/// team members can pull, but not push to or administer these repositories
/// </summary>
Pull
}
}
+31
View File
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
public class UpdateTeam
{
public UpdateTeam(string team)
{
Name = team;
}
public UpdateTeam(string team, Permission permission)
{
Name = team;
Permission = permission;
}
/// <summary>
/// team name
/// </summary>
public string Name { get; set; }
/// <summary>
/// permission for this team
/// </summary>
public Permission? Permission { get; set; }
}
}
+48
View File
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
/// <summary>
/// organization teams
/// </summary>
public class Team
{
/// <summary>
/// url for this team
/// </summary>
public Uri Url { get; set; }
/// <summary>
/// team id
/// </summary>
public int Id { get; set; }
/// <summary>
/// team name
/// </summary>
public string Name { get; set; }
/// <summary>
/// permission attached to this team
/// </summary>
public Permission Permission { get; set; }
/// <summary>
/// how many members in this team
/// </summary>
public int MembersCount { get; set; }
/// <summary>
/// how many repo this team has access to
/// </summary>
public int ReposCount { get; set; }
/// <summary>
/// who this team belongs to
/// </summary>
public Organization Organization { get; set; }
}
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
/// <summary>
/// organization teams - used for the list
/// </summary>
public class TeamItem
{
/// <summary>
/// team id
/// </summary>
public int Id { get; set; }
/// <summary>
/// team name
/// </summary>
public string Name { get; set; }
}
}
+7
View File
@@ -58,9 +58,11 @@
<Compile Include="Clients\IssuesClient.cs" />
<Compile Include="Clients\IssuesEventsClient.cs" />
<Compile Include="Clients\ITagsClient.cs" />
<Compile Include="Clients\ITeamsClient.cs" />
<Compile Include="Clients\MilestonesClient.cs" />
<Compile Include="Clients\OrganizationMembersClient.cs" />
<Compile Include="Clients\TagsClient.cs" />
<Compile Include="Clients\TeamsClient.cs" />
<Compile Include="Exceptions\NotFoundException.cs" />
<Compile Include="Clients\IAssigneesClient.cs" />
<Compile Include="Clients\IIssuesClient.cs" />
@@ -72,7 +74,10 @@
<Compile Include="Models\Request\NewCommitStatus.cs" />
<Compile Include="Models\Request\NewMilestone.cs" />
<Compile Include="Models\Request\NewTag.cs" />
<Compile Include="Models\Request\NewTeam.cs" />
<Compile Include="Models\Request\Permission.cs" />
<Compile Include="Models\Request\RequestParameters.cs" />
<Compile Include="Models\Request\UpdateTeam.cs" />
<Compile Include="Models\Response\Commit.cs" />
<Compile Include="Models\Response\Activity.cs" />
<Compile Include="Models\Response\CommitStatus.cs" />
@@ -94,6 +99,8 @@
<Compile Include="Models\Request\MilestoneRequest.cs" />
<Compile Include="Models\Response\Signature.cs" />
<Compile Include="Models\Response\TagObject.cs" />
<Compile Include="Models\Response\Team.cs" />
<Compile Include="Models\Response\TeamItem.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Exceptions\TwoFactorChallengeFailedException.cs" />
<Compile Include="Exceptions\TwoFactorRequiredException.cs" />
+7
View File
@@ -206,6 +206,13 @@
<Compile Include="SimpleJson.cs" />
<Compile Include="Models\Request\NewRepository.cs" />
<Compile Include="Clients\UsersClient.cs" />
<Compile Include="Clients\TeamsClient.cs" />
<Compile Include="Clients\ITeamsClient.cs" />
<Compile Include="Models\Request\NewTeam.cs" />
<Compile Include="Models\Request\Permission.cs" />
<Compile Include="Models\Request\UpdateTeam.cs" />
<Compile Include="Models\Response\Team.cs" />
<Compile Include="Models\Response\TeamItem.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
+7
View File
@@ -201,6 +201,13 @@
<Compile Include="SimpleJson.cs" />
<Compile Include="Models\Request\NewRepository.cs" />
<Compile Include="Clients\UsersClient.cs" />
<Compile Include="Clients\TeamsClient.cs" />
<Compile Include="Clients\ITeamsClient.cs" />
<Compile Include="Models\Request\NewTeam.cs" />
<Compile Include="Models\Request\Permission.cs" />
<Compile Include="Models\Request\UpdateTeam.cs" />
<Compile Include="Models\Response\Team.cs" />
<Compile Include="Models\Response\TeamItem.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+7
View File
@@ -79,6 +79,7 @@
<Compile Include="Clients\IssuesClient.cs" />
<Compile Include="Clients\ITagsClient.cs" />
<Compile Include="Clients\IssuesEventsClient.cs" />
<Compile Include="Clients\ITeamsClient.cs" />
<Compile Include="Clients\IUsersClient.cs" />
<Compile Include="Clients\MilestonesClient.cs" />
<Compile Include="Clients\MiscellaneousClient.cs" />
@@ -89,6 +90,7 @@
<Compile Include="Clients\RepositoriesClient.cs" />
<Compile Include="Clients\SshKeysClient.cs" />
<Compile Include="Clients\TagsClient.cs" />
<Compile Include="Clients\TeamsClient.cs" />
<Compile Include="Clients\UsersClient.cs" />
<Compile Include="Exceptions\ApiException.cs" />
<Compile Include="Exceptions\ApiValidationException.cs" />
@@ -152,10 +154,13 @@
<Compile Include="Models\Request\NewMilestone.cs" />
<Compile Include="Models\Request\NewRepository.cs" />
<Compile Include="Models\Request\NewTag.cs" />
<Compile Include="Models\Request\NewTeam.cs" />
<Compile Include="Models\Request\Permission.cs" />
<Compile Include="Models\Request\ReleaseUpdate.cs" />
<Compile Include="Models\Request\RepositoryIssueRequest.cs" />
<Compile Include="Models\Request\RequestParameters.cs" />
<Compile Include="Models\Request\SshKeyUpdate.cs" />
<Compile Include="Models\Request\UpdateTeam.cs" />
<Compile Include="Models\Request\UserUpdate.cs" />
<Compile Include="Models\Response\Account.cs" />
<Compile Include="Models\Response\Activity.cs" />
@@ -189,6 +194,8 @@
<Compile Include="Models\Response\SshKey.cs" />
<Compile Include="Models\Response\SshKeyInfo.cs" />
<Compile Include="Models\Response\TagObject.cs" />
<Compile Include="Models\Response\Team.cs" />
<Compile Include="Models\Response\TeamItem.cs" />
<Compile Include="Models\Response\User.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helpers\StringExtensions.cs" />
+7
View File
@@ -59,6 +59,8 @@
<Compile Include="Clients\AssigneesClient.cs" />
<Compile Include="Clients\CommitsClient.cs" />
<Compile Include="Clients\CommitStatusClient.cs" />
<Compile Include="Clients\TeamsClient.cs" />
<Compile Include="Clients\ITeamsClient.cs" />
<Compile Include="Clients\GitDatabaseClient.cs" />
<Compile Include="Clients\ICommitsClient.cs" />
<Compile Include="Clients\IEventsClient.cs" />
@@ -80,6 +82,8 @@
<Compile Include="Clients\IMilestonesClient.cs" />
<Compile Include="Helpers\ParameterAttribute.cs" />
<Compile Include="Helpers\ReflectionExtensions.cs" />
<Compile Include="Models\Request\NewTeam.cs" />
<Compile Include="Models\Request\UpdateTeam.cs" />
<Compile Include="Models\Request\MilestoneUpdate.cs" />
<Compile Include="Models\Request\NewCommit.cs" />
<Compile Include="Models\Request\NewCommitStatus.cs" />
@@ -87,6 +91,9 @@
<Compile Include="Models\Request\RequestParameters.cs" />
<Compile Include="Models\Response\Commit.cs" />
<Compile Include="Models\Response\CommitStatus.cs" />
<Compile Include="Models\Request\Permission.cs" />
<Compile Include="Models\Response\TeamItem.cs" />
<Compile Include="Models\Response\Team.cs" />
<Compile Include="Models\Response\EventInfo.cs" />
<Compile Include="Models\Response\GitReference.cs" />
<Compile Include="Models\Response\Issue.cs" />