From c44b18e947e3a928009e026313246c37c5a3a0a1 Mon Sep 17 00:00:00 2001 From: haroon Date: Tue, 5 Nov 2013 11:15:11 +0000 Subject: [PATCH 01/23] prepping teams api client --- Octokit.Tests/Clients/TeamsClientTests.cs | 46 +++++++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + Octokit/Clients/ITeamsClient.cs | 24 ++++++++++++ Octokit/Clients/TeamsClient.cs | 41 ++++++++++++++++++++ Octokit/Models/Request/Permission.cs | 25 ++++++++++++ Octokit/Models/Response/Team.cs | 23 ++++++++++++ Octokit/Octokit.csproj | 6 ++- SolutionInfo.cs | 7 ++-- 8 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 Octokit.Tests/Clients/TeamsClientTests.cs create mode 100644 Octokit/Clients/ITeamsClient.cs create mode 100644 Octokit/Clients/TeamsClient.cs create mode 100644 Octokit/Models/Request/Permission.cs create mode 100644 Octokit/Models/Response/Team.cs diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs new file mode 100644 index 00000000..9eb687d8 --- /dev/null +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Tests.Helpers; +using Xunit; + +namespace Octokit.Tests.Clients +{ + /// + /// 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. + /// + public class TeamsClientTests + { + public class TheConstructor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new TeamsClient(null)); + } + } + + public class TheGetAllMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var client = Substitute.For(); + var orgs = new TeamsClient(client); + + orgs.GetAllTeams("username"); + + client.Received().GetAll(Arg.Is(u => u.ToString() == "users/username/orgs")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var teams = new TeamsClient(Substitute.For()); + + AssertEx.Throws(async () => await teams.GetAllTeams(null)); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 7434fab8..a8ae1f0f 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -64,6 +64,7 @@ + diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs new file mode 100644 index 00000000..a902e029 --- /dev/null +++ b/Octokit/Clients/ITeamsClient.cs @@ -0,0 +1,24 @@ +#if NET_45 +using System.Collections.Generic; +#endif +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Org Teams API. + /// + /// + /// See the Orgs API documentation for more information. + /// + public interface ITeamsClient + { + /// + /// Returns all s for the current org. + /// + /// Thrown when a general API error occurs. + /// A list of the orgs's teams s. + Task> GetAllTeams(string org); + } +} diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs new file mode 100644 index 00000000..029f5f43 --- /dev/null +++ b/Octokit/Clients/TeamsClient.cs @@ -0,0 +1,41 @@ +#if NET_45 +using System.Collections.Generic; +#endif +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + + /// + /// A client for GitHub's Org Teams API. + /// + /// + /// See the Orgs API documentation for more information. + /// + public class TeamsClient : ApiClient, ITeamsClient + { + /// + /// Initializes a new GitHub Orgs Team API client. + /// + /// An API connection. + public TeamsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Returns all s for the current org. + /// + /// Thrown when a general API error occurs. + /// A list of the orgs's teams s. + public Task> GetAllTeams(string org) + { + Ensure.ArgumentNotNullOrEmptyString(org, "org"); + + var endpoint = "orgs/{0}/teams".FormatUri(org); + + return ApiConnection.GetAll(endpoint); + } + } +} diff --git a/Octokit/Models/Request/Permission.cs b/Octokit/Models/Request/Permission.cs new file mode 100644 index 00000000..4e630967 --- /dev/null +++ b/Octokit/Models/Request/Permission.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + public enum Permission + { + /// + /// team members can pull, push and administer these repositories. + /// + Admin, + + /// + /// team members can pull and push, but not administer these repositories + /// + Push, + + /// + /// team members can pull, but not push to or administer these repositories + /// + Pull + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/Team.cs b/Octokit/Models/Response/Team.cs new file mode 100644 index 00000000..ed997812 --- /dev/null +++ b/Octokit/Models/Response/Team.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + /// + /// organization teams + /// + public class Team + { + /// + /// team id + /// + public int Id { get; set; } + + /// + /// team name + /// + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 27dcf08c..08fc7266 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -52,6 +52,8 @@ + + @@ -66,6 +68,8 @@ + + @@ -198,4 +202,4 @@ --> - + \ No newline at end of file diff --git a/SolutionInfo.cs b/SolutionInfo.cs index 79e54730..af1a4021 100644 --- a/SolutionInfo.cs +++ b/SolutionInfo.cs @@ -4,6 +4,7 @@ using System.Reflection; [assembly: AssemblyProductAttribute("Octokit")] [assembly: AssemblyVersionAttribute("0.1.2")] [assembly: AssemblyFileVersionAttribute("0.1.2")] - -class AssemblyVersionInformation { public const string Version = "0.1.2"; } - +class AssemblyVersionInformation { + AssemblyVersionInformation() { } + public const string Version = "0.1.2"; +} From e0cf9ff1ba91f0b5da43932e2e99f68c903a840a Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 00:19:50 +0000 Subject: [PATCH 02/23] add teams client to orgclient --- Octokit/Clients/IOrganizationsClient.cs | 2 ++ Octokit/Clients/OrganizationsClient.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Octokit/Clients/IOrganizationsClient.cs b/Octokit/Clients/IOrganizationsClient.cs index 01d8c94b..38c6e34b 100644 --- a/Octokit/Clients/IOrganizationsClient.cs +++ b/Octokit/Clients/IOrganizationsClient.cs @@ -16,6 +16,8 @@ namespace Octokit { IOrganizationMembersClient Member { get; } + ITeamsClient Team { get; } + /// /// Returns the specified . /// diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index 243e115f..55c51b3a 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -21,10 +21,13 @@ namespace Octokit public OrganizationsClient(IApiConnection apiConnection) : base(apiConnection) { Member = new OrganizationMembersClient(apiConnection); + Team = new TeamsClient(apiConnection); } public IOrganizationMembersClient Member { get; private set; } + public ITeamsClient Team { get; private set; } + /// /// Returns the specified . /// From d5226534cce6aecbe08bccce61e32d80c8743701 Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 12:53:33 +0000 Subject: [PATCH 03/23] add create and update methods --- Octokit/Clients/ITeamsClient.cs | 14 ++++++++++++++ Octokit/Clients/TeamsClient.cs | 21 +++++++++++++++++++++ Octokit/Models/Request/NewTeam.cs | 25 +++++++++++++++++++++++++ Octokit/Models/Request/UpdateTeam.cs | 20 ++++++++++++++++++++ Octokit/Octokit.csproj | 2 ++ 5 files changed, 82 insertions(+) create mode 100644 Octokit/Models/Request/NewTeam.cs create mode 100644 Octokit/Models/Request/UpdateTeam.cs diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index a902e029..5061bb7f 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -20,5 +20,19 @@ namespace Octokit /// Thrown when a general API error occurs. /// A list of the orgs's teams s. Task> GetAllTeams(string org); + + /// + /// Returns newly created for the current org. + /// + /// Thrown when a general API error occurs. + /// Newly created + Task CreateTeam(string org, NewTeam team); + + /// + /// Returns updated for the current org. + /// + /// Thrown when a general API error occurs. + /// Updated + Task UpdateTeam(string org, int id, UpdateTeam team); } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 029f5f43..e9838930 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -37,5 +37,26 @@ namespace Octokit return ApiConnection.GetAll(endpoint); } + + + /// + /// Returns newly created for the current org. + /// + /// Thrown when a general API error occurs. + /// Newly created + public Task CreateTeam(string org, NewTeam team) + { + throw new System.NotImplementedException(); + } + + /// + /// Returns updated for the current org. + /// + /// Thrown when a general API error occurs. + /// Updated + public Task UpdateTeam(string org, int id, UpdateTeam team) + { + throw new System.NotImplementedException(); + } } } diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs new file mode 100644 index 00000000..484a5892 --- /dev/null +++ b/Octokit/Models/Request/NewTeam.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + public class NewTeam + { + /// + /// team name + /// + public string Name { get; set; } + + /// + /// permission associated to this team + /// + public Permission Permission { get; set; } + + /// + /// array of repo_names this team has permissions to + /// + public string[] RepoNames { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Request/UpdateTeam.cs b/Octokit/Models/Request/UpdateTeam.cs new file mode 100644 index 00000000..587d53b7 --- /dev/null +++ b/Octokit/Models/Request/UpdateTeam.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + public class UpdateTeam + { + /// + /// team name + /// + public string Name { get; set; } + + /// + /// permission for this team + /// + public Permission Permission { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 5971e516..0dcc8b20 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -75,6 +75,8 @@ + + From 375cc244de5a3a500b38b8b7963c2baf02fc46d4 Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 12:55:08 +0000 Subject: [PATCH 04/23] split out teamitem from teams looking at github api only id and name is returned for the list. --- Octokit/Clients/ITeamsClient.cs | 4 ++-- Octokit/Clients/TeamsClient.cs | 4 ++-- Octokit/Models/Response/TeamItem.cs | 23 +++++++++++++++++++++++ Octokit/Octokit.csproj | 1 + 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 Octokit/Models/Response/TeamItem.cs diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 5061bb7f..2c711394 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -18,8 +18,8 @@ namespace Octokit /// Returns all s for the current org. /// /// Thrown when a general API error occurs. - /// A list of the orgs's teams s. - Task> GetAllTeams(string org); + /// A list of the orgs's teams s. + Task> GetAllTeams(string org); /// /// Returns newly created for the current org. diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index e9838930..d0a37d21 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -29,13 +29,13 @@ namespace Octokit /// /// Thrown when a general API error occurs. /// A list of the orgs's teams s. - public Task> GetAllTeams(string org) + public Task> GetAllTeams(string org) { Ensure.ArgumentNotNullOrEmptyString(org, "org"); var endpoint = "orgs/{0}/teams".FormatUri(org); - return ApiConnection.GetAll(endpoint); + return ApiConnection.GetAll(endpoint); } diff --git a/Octokit/Models/Response/TeamItem.cs b/Octokit/Models/Response/TeamItem.cs new file mode 100644 index 00000000..7d3343a8 --- /dev/null +++ b/Octokit/Models/Response/TeamItem.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + /// + /// organization teams - used for the list + /// + public class TeamItem + { + /// + /// team id + /// + public int Id { get; set; } + + /// + /// team name + /// + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 0dcc8b20..88d4be99 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -83,6 +83,7 @@ + From 6793ef7a0bdeecd13dad4ca1f4fc7c202aafd79a Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 13:04:44 +0000 Subject: [PATCH 05/23] implement new team method --- Octokit/Clients/TeamsClient.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index d0a37d21..8a1f6965 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -46,7 +46,12 @@ namespace Octokit /// Newly created public Task CreateTeam(string org, NewTeam team) { - throw new System.NotImplementedException(); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); + Ensure.ArgumentNotNull(team, "team"); + + var endpoint = "orgs/{0}/teams".FormatUri(org); + + return ApiConnection.Post(endpoint, team); } /// From 70598b36696b2e1e98f4705a397a677db6b9cceb Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 13:05:29 +0000 Subject: [PATCH 06/23] suppress it! shut up crazy code analysis --- Octokit/Models/Request/NewTeam.cs | 1 + Octokit/Models/Request/Permission.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs index 484a5892..afaef248 100644 --- a/Octokit/Models/Request/NewTeam.cs +++ b/Octokit/Models/Request/NewTeam.cs @@ -20,6 +20,7 @@ namespace Octokit /// /// array of repo_names this team has permissions to /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] public string[] RepoNames { get; set; } } } \ No newline at end of file diff --git a/Octokit/Models/Request/Permission.cs b/Octokit/Models/Request/Permission.cs index 4e630967..4a858a2a 100644 --- a/Octokit/Models/Request/Permission.cs +++ b/Octokit/Models/Request/Permission.cs @@ -5,6 +5,7 @@ using System.Globalization; namespace Octokit { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] public enum Permission { /// From 88fab030fa3d8cbe85c62125c602c4066e03e3cf Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 13:06:03 +0000 Subject: [PATCH 07/23] Fix up the test to return correct type --- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 9eb687d8..7bbb9396 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -31,7 +31,7 @@ namespace Octokit.Tests.Clients orgs.GetAllTeams("username"); - client.Received().GetAll(Arg.Is(u => u.ToString() == "users/username/orgs")); + client.Received().GetAll(Arg.Is(u => u.ToString() == "users/username/orgs")); } [Fact] From 3e62cbcc56eb8088c10fa90f5007338633ecf90b Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 15:14:27 +0000 Subject: [PATCH 08/23] compile.include netcore45 and mono --- Octokit/Octokit-Mono.csproj | 7 +++++++ Octokit/Octokit-netcore45.csproj | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 7f71fdcf..5be26ed9 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -53,9 +53,11 @@ + + @@ -66,7 +68,10 @@ + + + @@ -85,6 +90,8 @@ + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index eb937726..e7716a3b 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -73,6 +73,7 @@ + @@ -83,6 +84,7 @@ + @@ -145,10 +147,13 @@ + + + @@ -179,6 +184,8 @@ + + From ee293d500e76ea8787babffa7b6cb843a71b1ee8 Mon Sep 17 00:00:00 2001 From: Haroon Date: Wed, 6 Nov 2013 18:31:21 +0000 Subject: [PATCH 09/23] better names... --- Octokit.Tests/Clients/TeamsClientTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 7bbb9396..17b53940 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -26,12 +26,12 @@ namespace Octokit.Tests.Clients [Fact] public void RequestsTheCorrectUrl() { - var client = Substitute.For(); - var orgs = new TeamsClient(client); + var connection = Substitute.For(); + var client = new TeamsClient(connection); - orgs.GetAllTeams("username"); + client.GetAllTeams("orgName"); - client.Received().GetAll(Arg.Is(u => u.ToString() == "users/username/orgs")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/username/teams")); } [Fact] From c0d33a027489311bdbfb1096acc39a34ac0cd382 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 09:03:10 +0000 Subject: [PATCH 10/23] fixed broken test - invalid name --- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 17b53940..7824d72f 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -31,7 +31,7 @@ namespace Octokit.Tests.Clients client.GetAllTeams("orgName"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/username/teams")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/orgName/teams")); } [Fact] From 782dde9c3f4e8f7c0cbcdc227e4fb23f9dda0c7b Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 09:27:43 +0000 Subject: [PATCH 11/23] test for create team --- Octokit.Tests/Clients/TeamsClientTests.cs | 28 +++++++++++++++++++++++ Octokit/Clients/TeamsClient.cs | 7 +++++- Octokit/Models/Request/NewTeam.cs | 7 ++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 7824d72f..dd351fb7 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -42,5 +42,33 @@ namespace Octokit.Tests.Clients AssertEx.Throws(async () => await teams.GetAllTeams(null)); } } + + public class TheCreateTeamMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + var team = new NewTeam("Octokittens"); + + client.CreateTeam("orgName", team); + + connection.Received().Post(Arg.Is(u => u.ToString() == "orgs/orgName/teams"), team); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + + AssertEx.Throws(async () => await + client.CreateTeam("", new NewTeam("superstars"))); + AssertEx.Throws(async () => await + client.CreateTeam("name", null)); + } + } + } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 8a1f6965..1887ca23 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -61,7 +61,12 @@ namespace Octokit /// Updated public Task UpdateTeam(string org, int id, UpdateTeam team) { - throw new System.NotImplementedException(); + Ensure.ArgumentNotNullOrEmptyString(org, "org"); + Ensure.ArgumentNotNull(team, "team"); + + var endpoint = "orgs/{0}/teams/{1}".FormatUri(org,id); + + return ApiConnection.Put(endpoint, team); } } } diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs index afaef248..e6087f63 100644 --- a/Octokit/Models/Request/NewTeam.cs +++ b/Octokit/Models/Request/NewTeam.cs @@ -1,3 +1,4 @@ +using Octokit.Internal; using System; using System.Collections.Generic; using System.Diagnostics; @@ -7,6 +8,11 @@ namespace Octokit { public class NewTeam { + public NewTeam(string name) + { + Name = name; + } + /// /// team name /// @@ -21,6 +27,7 @@ namespace Octokit /// array of repo_names this team has permissions to /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] + //[Parameter(Key="repo_names")] public string[] RepoNames { get; set; } } } \ No newline at end of file From ab25e9140ab4729f70ea52e58bd209f6ad8b75a6 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 09:46:35 +0000 Subject: [PATCH 12/23] update_team test fixed ctor for updateTeam class, fixed method params for UpdateTeam to take in only the id and the UpdateTeam class. Now Putting to the correct url. --- Octokit.Tests/Clients/TeamsClientTests.cs | 25 +++++++++++++++++++++++ Octokit/Clients/ITeamsClient.cs | 2 +- Octokit/Clients/TeamsClient.cs | 6 ++---- Octokit/Models/Request/UpdateTeam.cs | 13 +++++++++++- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index dd351fb7..d3ce8509 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -70,5 +70,30 @@ namespace Octokit.Tests.Clients } } + public class TheUpdateTeamMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + var team = new UpdateTeam("Octokittens"); + + client.UpdateTeam(1, team); + + connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1"), team); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + + AssertEx.Throws(async () => await + client.UpdateTeam(1, null)); + } + } + } } diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 2c711394..07f6cda7 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -33,6 +33,6 @@ namespace Octokit /// /// Thrown when a general API error occurs. /// Updated - Task UpdateTeam(string org, int id, UpdateTeam team); + Task UpdateTeam(int id, UpdateTeam team); } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 1887ca23..3ea2c17c 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -59,13 +59,11 @@ namespace Octokit /// /// Thrown when a general API error occurs. /// Updated - public Task UpdateTeam(string org, int id, UpdateTeam team) + public Task UpdateTeam(int id, UpdateTeam team) { - Ensure.ArgumentNotNullOrEmptyString(org, "org"); Ensure.ArgumentNotNull(team, "team"); - var endpoint = "orgs/{0}/teams/{1}".FormatUri(org,id); - + var endpoint = "teams/{0}".FormatUri(id); return ApiConnection.Put(endpoint, team); } } diff --git a/Octokit/Models/Request/UpdateTeam.cs b/Octokit/Models/Request/UpdateTeam.cs index 587d53b7..1ef7c728 100644 --- a/Octokit/Models/Request/UpdateTeam.cs +++ b/Octokit/Models/Request/UpdateTeam.cs @@ -7,6 +7,17 @@ namespace Octokit { public class UpdateTeam { + public UpdateTeam(string team) + { + Name = team; + } + + public UpdateTeam(string team, Permission permission) + { + Name = team; + Permission = permission; + } + /// /// team name /// @@ -15,6 +26,6 @@ namespace Octokit /// /// permission for this team /// - public Permission Permission { get; set; } + public Permission? Permission { get; set; } } } \ No newline at end of file From 5676bb27b7276d1d7aebf41c1345c71be8534def Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 09:47:17 +0000 Subject: [PATCH 13/23] Github wants us to Patch --- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- Octokit/Clients/TeamsClient.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index d3ce8509..bd5884a6 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -81,7 +81,7 @@ namespace Octokit.Tests.Clients client.UpdateTeam(1, team); - connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1"), team); + connection.Received().Patch(Arg.Is(u => u.ToString() == "teams/1"), team); } [Fact] diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 3ea2c17c..aea55915 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -64,7 +64,7 @@ namespace Octokit Ensure.ArgumentNotNull(team, "team"); var endpoint = "teams/{0}".FormatUri(id); - return ApiConnection.Put(endpoint, team); + return ApiConnection.Patch(endpoint, team); } } } From df006163e0314c037e5593c1103c2e8000c64683 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 09:57:07 +0000 Subject: [PATCH 14/23] make it into a collection --- Octokit/Models/Request/NewTeam.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs index e6087f63..944a0a54 100644 --- a/Octokit/Models/Request/NewTeam.cs +++ b/Octokit/Models/Request/NewTeam.cs @@ -1,6 +1,7 @@ using Octokit.Internal; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; @@ -11,6 +12,7 @@ namespace Octokit public NewTeam(string name) { Name = name; + RepoNames = new Collection(); } /// @@ -26,8 +28,7 @@ namespace Octokit /// /// array of repo_names this team has permissions to /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] //[Parameter(Key="repo_names")] - public string[] RepoNames { get; set; } + public Collection RepoNames { get; private set; } } } \ No newline at end of file From eec50c99462d1bdd5f80a99650cec012c5fe23a3 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 09:59:55 +0000 Subject: [PATCH 15/23] add default permissions --- Octokit/Models/Request/NewTeam.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs index 944a0a54..dc4265b8 100644 --- a/Octokit/Models/Request/NewTeam.cs +++ b/Octokit/Models/Request/NewTeam.cs @@ -13,6 +13,7 @@ namespace Octokit { Name = name; RepoNames = new Collection(); + Permission = Octokit.Permission.Pull; } /// From e0c9a77fba9e22737d91c5158a66e96c2171d571 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 10:00:50 +0000 Subject: [PATCH 16/23] fix param name to match api --- Octokit/Models/Request/NewTeam.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs index dc4265b8..e4474ea4 100644 --- a/Octokit/Models/Request/NewTeam.cs +++ b/Octokit/Models/Request/NewTeam.cs @@ -29,7 +29,7 @@ namespace Octokit /// /// array of repo_names this team has permissions to /// - //[Parameter(Key="repo_names")] + [Parameter(Key="repo_names")] public Collection RepoNames { get; private set; } } } \ No newline at end of file From 53393054fc1bb80ac3066d72343001b91f7e21d7 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 10:08:29 +0000 Subject: [PATCH 17/23] added more props --- Octokit/Models/Response/Team.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Octokit/Models/Response/Team.cs b/Octokit/Models/Response/Team.cs index ed997812..f92eec68 100644 --- a/Octokit/Models/Response/Team.cs +++ b/Octokit/Models/Response/Team.cs @@ -10,6 +10,11 @@ namespace Octokit /// public class Team { + /// + /// url for this team + /// + public Uri Url { get; set; } + /// /// team id /// @@ -19,5 +24,25 @@ namespace Octokit /// team name /// public string Name { get; set; } + + /// + /// permission attached to this team + /// + public Permission Permission { get; set; } + + /// + /// how many members in this team + /// + public int MembersCount { get; set; } + + /// + /// how many repo this team has access to + /// + public int ReposCount { get; set; } + + /// + /// who this team belongs to + /// + public User Organization { get; set; } } } \ No newline at end of file From 518fd7d8f59a591fbc5fbf7e704e554e584c3577 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 10:21:56 +0000 Subject: [PATCH 18/23] delete team with test --- Octokit.Tests/Clients/TeamsClientTests.cs | 13 +++++++++++++ Octokit/Clients/ITeamsClient.cs | 8 ++++++++ Octokit/Clients/TeamsClient.cs | 11 +++++++++++ 3 files changed, 32 insertions(+) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index bd5884a6..fa224636 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -95,5 +95,18 @@ namespace Octokit.Tests.Clients } } + public class TheDeleteTeamMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + client.DeleteTeam(1); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "teams/1")); + } + } + } } diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 07f6cda7..3737e484 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -34,5 +34,13 @@ namespace Octokit /// Thrown when a general API error occurs. /// Updated Task UpdateTeam(int id, UpdateTeam team); + + /// + /// Delte a team - must have owner permissions to this + /// + /// Thrown when a general API error occurs. + /// + Task DeleteTeam(int id); + } } diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index aea55915..3cd08ba9 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -66,5 +66,16 @@ namespace Octokit var endpoint = "teams/{0}".FormatUri(id); return ApiConnection.Patch(endpoint, team); } + + /// + /// Delte a team - must have owner permissions to this + /// + /// Thrown when a general API error occurs. + /// + public Task DeleteTeam(int id) + { + var endpoint = "teams/{0}".FormatUri(id); + return ApiConnection.Delete(endpoint); + } } } From 2d9219a98049242c413d1fc5a2f7f6ff8e31dd54 Mon Sep 17 00:00:00 2001 From: Haroon Date: Thu, 7 Nov 2013 10:28:00 +0000 Subject: [PATCH 19/23] include test in netcore45 --- Octokit.Tests/OctoKit.Tests-NetCore45.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Octokit.Tests/OctoKit.Tests-NetCore45.csproj b/Octokit.Tests/OctoKit.Tests-NetCore45.csproj index 9604328c..d47c2b85 100644 --- a/Octokit.Tests/OctoKit.Tests-NetCore45.csproj +++ b/Octokit.Tests/OctoKit.Tests-NetCore45.csproj @@ -104,6 +104,7 @@ + From a1650f978dd54f30eed54014f23fc7460d921f53 Mon Sep 17 00:00:00 2001 From: Haroon Date: Fri, 8 Nov 2013 08:30:42 +0000 Subject: [PATCH 20/23] doc comment added --- Octokit/Clients/IOrganizationsClient.cs | 3 +++ Octokit/Clients/OrganizationsClient.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Octokit/Clients/IOrganizationsClient.cs b/Octokit/Clients/IOrganizationsClient.cs index 19381fa6..546e5cd2 100644 --- a/Octokit/Clients/IOrganizationsClient.cs +++ b/Octokit/Clients/IOrganizationsClient.cs @@ -19,6 +19,9 @@ namespace Octokit /// IOrganizationMembersClient Member { get; } + /// + /// Returns a client to manage teams of an organization. + /// ITeamsClient Team { get; } /// diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index b6d4ce08..ba7f7c5f 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -26,6 +26,9 @@ namespace Octokit public IOrganizationMembersClient Member { get; private set; } + /// + /// Returns a client to manage teams of an organization. + /// public ITeamsClient Team { get; private set; } /// From 05b929d5d88dcab6278f3daf1ba6dc78956b162e Mon Sep 17 00:00:00 2001 From: Haroon Date: Fri, 8 Nov 2013 08:33:59 +0000 Subject: [PATCH 21/23] remove paramattribute - not valid for requests --- Octokit/Models/Request/NewTeam.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Octokit/Models/Request/NewTeam.cs b/Octokit/Models/Request/NewTeam.cs index e4474ea4..64e1ed58 100644 --- a/Octokit/Models/Request/NewTeam.cs +++ b/Octokit/Models/Request/NewTeam.cs @@ -29,7 +29,6 @@ namespace Octokit /// /// array of repo_names this team has permissions to /// - [Parameter(Key="repo_names")] public Collection RepoNames { get; private set; } } } \ No newline at end of file From 0e34b454c81618ce2b7903e53598842323249774 Mon Sep 17 00:00:00 2001 From: Haroon Date: Fri, 8 Nov 2013 17:10:55 +0000 Subject: [PATCH 22/23] org not user --- Octokit/Models/Response/Team.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Models/Response/Team.cs b/Octokit/Models/Response/Team.cs index f92eec68..9d8ce0ef 100644 --- a/Octokit/Models/Response/Team.cs +++ b/Octokit/Models/Response/Team.cs @@ -43,6 +43,6 @@ namespace Octokit /// /// who this team belongs to /// - public User Organization { get; set; } + public Organization Organization { get; set; } } } \ No newline at end of file From 8b65725128914a675f7ef3ad5c672c298431a67a Mon Sep 17 00:00:00 2001 From: Haroon Date: Fri, 8 Nov 2013 17:20:29 +0000 Subject: [PATCH 23/23] update driod and touch projs include necessary files --- Octokit/Octokit-MonoAndroid.csproj | 7 +++++++ Octokit/Octokit-Monotouch.csproj | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 556fe0dd..0847f4a8 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -206,6 +206,13 @@ + + + + + + + diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 43a8e561..37824954 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -201,6 +201,13 @@ + + + + + + +