From 10cea07daf392c8b3ec7bbfc9b33c05070388379 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 10:16:30 +0200 Subject: [PATCH 01/18] add TeamRepositoryUpdate model --- Octokit/Clients/ITeamsClient.cs | 8 ++++ Octokit/Clients/TeamsClient.cs | 18 ++++++++ .../Models/Request/TeamRepositoryUpdate.cs | 42 +++++++++++++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-Portable.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 9 files changed, 74 insertions(+) create mode 100644 Octokit/Models/Request/TeamRepositoryUpdate.cs diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 4249acafff..e4699ce984 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -159,6 +159,14 @@ public interface ITeamsClient /// Task AddRepository(int id, string organization, string repoName); + /// + /// Add a repository to the team + /// + /// The permission to grant the team on this repository + /// Thrown when a general API error occurs. + /// + Task AddRepository(int id, string organization, string repoName, PermissionType permission); + /// /// Remove a repository from the team /// diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 3ec477ac1d..cc267bc3cd 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -317,6 +317,24 @@ public async Task AddRepository(int id, string organization, string repoNa } } + public async Task AddRepository(int id, string organization, string repoName, PermissionType permission) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName"); + + var endpoint = ApiUrls.TeamRepository(id, organization, repoName); + + try + { + var httpStatusCode = await ApiConnection.Connection.Put(endpoint).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } + /// /// Remove a repository from the team /// diff --git a/Octokit/Models/Request/TeamRepositoryUpdate.cs b/Octokit/Models/Request/TeamRepositoryUpdate.cs new file mode 100644 index 0000000000..1106572fa1 --- /dev/null +++ b/Octokit/Models/Request/TeamRepositoryUpdate.cs @@ -0,0 +1,42 @@ +using Octokit.Internal; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + public enum PermissionType + { + [Parameter(Value = "pull")] + Pull, + [Parameter(Value = "push")] + Push, + [Parameter(Value = "admin")] + Admin + } + + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class TeamRepositoryUpdate + { + /// + /// Used to add or update a team repository. + /// + public TeamRepositoryUpdate(PermissionType permission) + { + Permission = permission; + } + + /// + /// The permission to grant the team on this repository. + /// + [Parameter(Key = "permission")] + public PermissionType Permission { get; private set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, "Permission: {}", Permission); + } + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 2370eca2ce..a2638babd8 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -466,6 +466,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index f7fadcd7f4..b4a0a2930d 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -477,6 +477,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index d99d397908..50fdde6d90 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -473,6 +473,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 4c2c15744b..44aa78eb46 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -463,6 +463,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 841d4088a1..c459ed446b 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -470,6 +470,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 2f5bac2953..afd1dc39c1 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -144,6 +144,7 @@ + From 41ba20813166cad5c49aa1dc944d55233abc3ada Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 11:47:21 +0200 Subject: [PATCH 02/18] add methods to set permission for team repositories --- .../Clients/IObservableTeamsClient.cs | 14 ++++++++++++++ .../Clients/ObservableTeamsClient.cs | 19 +++++++++++++++++++ Octokit/Clients/ITeamsClient.cs | 4 ++-- Octokit/Clients/TeamsClient.cs | 10 ++++++++-- Octokit/Http/Connection.cs | 17 ++++++++++++++++- Octokit/Http/IConnection.cs | 8 ++++++++ .../Models/Request/TeamRepositoryUpdate.cs | 2 +- 7 files changed, 68 insertions(+), 6 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index 0ca0a385bf..7acad62111 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -171,6 +171,20 @@ public interface IObservableTeamsClient /// if the repository was added to the team; otherwise. IObservable AddRepository(int id, string organization, string repoName); + /// + /// Adds a to a . + /// + /// The team identifier. + /// Org to associate the repo with. + /// Name of the repo. + /// The permission to grant the team on this repository. + /// Thrown if you attempt to add a repository to a team that is not owned by the organization. + /// + /// See the API documentation for more information. + /// + /// if the repository was added to the team; otherwise. + IObservable AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission); + /// /// Gets whether or not the given repository is managed by the given team. /// diff --git a/Octokit.Reactive/Clients/ObservableTeamsClient.cs b/Octokit.Reactive/Clients/ObservableTeamsClient.cs index 31f9b7aaeb..1649472bc7 100644 --- a/Octokit.Reactive/Clients/ObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableTeamsClient.cs @@ -246,6 +246,25 @@ public IObservable AddRepository(int id, string organization, string repoN return _client.AddRepository(id, organization, repoName).ToObservable(); } + /// + /// Adds a to a . + /// + /// The team identifier. + /// Org to associate the repo with. + /// Name of the repo. + /// The permission to grant the team on this repository. + /// Thrown if you attempt to add a repository to a team that is not owned by the organization. + /// + /// See the API documentation for more information. + /// + /// if the repository was added to the team; otherwise. + public IObservable AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission) + { + Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); + Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName"); + + return _client.AddRepository(id, organization, repoName, permission).ToObservable(); + } /// /// Remove a repository from the team diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index e4699ce984..1925dba95e 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -162,10 +162,10 @@ public interface ITeamsClient /// /// Add a repository to the team /// - /// The permission to grant the team on this repository + /// The permission to grant the team on this repository. /// Thrown when a general API error occurs. /// - Task AddRepository(int id, string organization, string repoName, PermissionType permission); + Task AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission); /// /// Remove a repository from the team diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index cc267bc3cd..5e244336f1 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -317,7 +317,13 @@ public async Task AddRepository(int id, string organization, string repoNa } } - public async Task AddRepository(int id, string organization, string repoName, PermissionType permission) + /// + /// Add a repository to the team + /// + /// The permission to grant the team on this repository. + /// Thrown when a general API error occurs. + /// + public async Task AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName"); @@ -326,7 +332,7 @@ public async Task AddRepository(int id, string organization, string repoNa try { - var httpStatusCode = await ApiConnection.Connection.Put(endpoint).ConfigureAwait(false); + var httpStatusCode = await ApiConnection.Connection.Put(endpoint, permission).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 8f7412e130..229849f777 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -404,6 +404,21 @@ public async Task Put(Uri uri) return response.HttpResponse.StatusCode; } + /// + /// Performs an asynchronous HTTP PUT request that expects an empty response. + /// + /// URI endpoint to send request to + /// The object to serialize as the body of the request + /// The returned + public async Task Put(Uri uri, object body) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(body, "body"); + + var response = await SendData(uri, HttpMethod.Put, body, null, null, CancellationToken.None).ConfigureAwait(false); + return response.HttpResponse.StatusCode; + } + /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. /// @@ -466,7 +481,7 @@ public async Task Delete(Uri uri, object data) /// The object to serialize as the body of the request /// Specifies accept response media type /// The returned - public async Task Delete(Uri uri,object data, string accepts) + public async Task Delete(Uri uri, object data, string accepts) { Ensure.ArgumentNotNull(uri, "uri"); Ensure.ArgumentNotNull(accepts, "accepts"); diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 39ddac533c..d89c22c350 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -197,6 +197,14 @@ public interface IConnection : IApiInfoProvider /// The returned Task Put(Uri uri); + /// + /// Performs an asynchronous HTTP PUT request that expects an empty response. + /// + /// URI endpoint to send request to + /// The object to serialize as the body of the request + /// The returned + Task Put(Uri uri, object body); + /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. /// diff --git a/Octokit/Models/Request/TeamRepositoryUpdate.cs b/Octokit/Models/Request/TeamRepositoryUpdate.cs index 1106572fa1..e5a64b6fa3 100644 --- a/Octokit/Models/Request/TeamRepositoryUpdate.cs +++ b/Octokit/Models/Request/TeamRepositoryUpdate.cs @@ -35,7 +35,7 @@ internal string DebuggerDisplay { get { - return string.Format(CultureInfo.InvariantCulture, "Permission: {}", Permission); + return string.Format(CultureInfo.InvariantCulture, "Permission: {0}", Permission); } } } From a0a85c860e3ba2c60153b0c82eb7db61e6f2ddd8 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 13:07:40 +0200 Subject: [PATCH 03/18] add method for unit test --- Octokit.Tests/Clients/TeamsClientTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index f41c3abecd..66cba182bd 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -300,6 +300,18 @@ public void RequestsTheCorrectUrl() connection.Connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1/repos/org/repo")); } + [Fact] + public void AddOrUpdatePermission() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + var newPermission = new TeamRepositoryUpdate(PermissionType.Admin); + + client.AddRepository(1, "org", "repo", newPermission); + + connection.Connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1/repos/org/repo"), Arg.Any()); + } + [Fact] public void EnsureNonNullOrg() { From dfccb51e5f4c9d800b7235eb03e56794074670ea Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 15:05:28 +0200 Subject: [PATCH 04/18] remove PemissionType enum; --- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- Octokit/Models/Request/TeamRepositoryUpdate.cs | 17 +++-------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 66cba182bd..c08c640a8b 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -305,7 +305,7 @@ public void AddOrUpdatePermission() { var connection = Substitute.For(); var client = new TeamsClient(connection); - var newPermission = new TeamRepositoryUpdate(PermissionType.Admin); + var newPermission = new TeamRepositoryUpdate(Permission.Admin); client.AddRepository(1, "org", "repo", newPermission); diff --git a/Octokit/Models/Request/TeamRepositoryUpdate.cs b/Octokit/Models/Request/TeamRepositoryUpdate.cs index e5a64b6fa3..6f5af1f88e 100644 --- a/Octokit/Models/Request/TeamRepositoryUpdate.cs +++ b/Octokit/Models/Request/TeamRepositoryUpdate.cs @@ -4,32 +4,21 @@ namespace Octokit { - public enum PermissionType - { - [Parameter(Value = "pull")] - Pull, - [Parameter(Value = "push")] - Push, - [Parameter(Value = "admin")] - Admin - } - [DebuggerDisplay("{DebuggerDisplay,nq}")] public class TeamRepositoryUpdate { /// /// Used to add or update a team repository. /// - public TeamRepositoryUpdate(PermissionType permission) + public TeamRepositoryUpdate(Permission permission) { Permission = permission; } /// /// The permission to grant the team on this repository. - /// - [Parameter(Key = "permission")] - public PermissionType Permission { get; private set; } + /// + public Permission Permission { get; private set; } internal string DebuggerDisplay { From 67f71e4dc6788de1955cc7e99ff7434290030341 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 15:07:45 +0200 Subject: [PATCH 05/18] add accept header for organization permissions --- Octokit/Helpers/AcceptHeaders.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 3d448fb77d..7e158e8285 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -21,5 +21,7 @@ public static class AcceptHeaders public const string SquashCommitPreview = "application/vnd.github.polaris-preview+json"; public const string MigrationsApiPreview = " application/vnd.github.wyandotte-preview+json"; + + public const string OrganizationPermissionsPreview = "application/vnd.github.ironman-preview+json"; } } From a3fafe90c130fdec28afacc06bf9ab78dcf13b44 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 15:26:07 +0200 Subject: [PATCH 06/18] update xml comments --- Octokit/Clients/ITeamsClient.cs | 3 +++ Octokit/Clients/TeamsClient.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 1925dba95e..f1680ce2bc 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -162,6 +162,9 @@ public interface ITeamsClient /// /// Add a repository to the team /// + /// The team identifier. + /// Org to associate the repo with. + /// Name of the repo. /// The permission to grant the team on this repository. /// Thrown when a general API error occurs. /// diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 5e244336f1..25d986e9f3 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -320,6 +320,9 @@ public async Task AddRepository(int id, string organization, string repoNa /// /// Add a repository to the team /// + /// The team identifier. + /// Org to associate the repo with. + /// Name of the repo. /// The permission to grant the team on this repository. /// Thrown when a general API error occurs. /// From 3ed011dfd4f704946eb7f91b141dba6030cbe73e Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 15:50:14 +0200 Subject: [PATCH 07/18] add accept header for teams client --- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- Octokit/Clients/TeamsClient.cs | 4 ++-- Octokit/Http/Connection.cs | 15 --------------- Octokit/Http/IConnection.cs | 8 -------- 4 files changed, 3 insertions(+), 26 deletions(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index c08c640a8b..31806b0c40 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -309,7 +309,7 @@ public void AddOrUpdatePermission() client.AddRepository(1, "org", "repo", newPermission); - connection.Connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1/repos/org/repo"), Arg.Any()); + connection.Connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1/repos/org/repo"), Arg.Any(), "application/vnd.github.ironman-preview+json"); } [Fact] diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 25d986e9f3..e23f3ba243 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -335,8 +335,8 @@ public async Task AddRepository(int id, string organization, string repoNa try { - var httpStatusCode = await ApiConnection.Connection.Put(endpoint, permission).ConfigureAwait(false); - return httpStatusCode == HttpStatusCode.NoContent; + var httpStatusCode = await ApiConnection.Connection.Put(endpoint, permission, "", AcceptHeaders.OrganizationPermissionsPreview).ConfigureAwait(false); + return httpStatusCode.HttpResponse.StatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) { diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 229849f777..7a8a203f18 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -404,21 +404,6 @@ public async Task Put(Uri uri) return response.HttpResponse.StatusCode; } - /// - /// Performs an asynchronous HTTP PUT request that expects an empty response. - /// - /// URI endpoint to send request to - /// The object to serialize as the body of the request - /// The returned - public async Task Put(Uri uri, object body) - { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(body, "body"); - - var response = await SendData(uri, HttpMethod.Put, body, null, null, CancellationToken.None).ConfigureAwait(false); - return response.HttpResponse.StatusCode; - } - /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. /// diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index d89c22c350..39ddac533c 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -197,14 +197,6 @@ public interface IConnection : IApiInfoProvider /// The returned Task Put(Uri uri); - /// - /// Performs an asynchronous HTTP PUT request that expects an empty response. - /// - /// URI endpoint to send request to - /// The object to serialize as the body of the request - /// The returned - Task Put(Uri uri, object body); - /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. /// From a1eb0aa94664acd656aea421924b09b08e41997b Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 16:34:15 +0200 Subject: [PATCH 08/18] fix unit test --- Octokit.Tests/Clients/TeamsClientTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 31806b0c40..d1d6a37f19 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using NSubstitute; using Xunit; +using System.Net; namespace Octokit.Tests.Clients { @@ -309,7 +310,7 @@ public void AddOrUpdatePermission() client.AddRepository(1, "org", "repo", newPermission); - connection.Connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1/repos/org/repo"), Arg.Any(), "application/vnd.github.ironman-preview+json"); + connection.Connection.Received().Put(Arg.Is(u => u.ToString() == "teams/1/repos/org/repo"), Arg.Any(), "", "application/vnd.github.ironman-preview+json"); } [Fact] From 11b1d756cc673d98ad0681f4b6faef2355156a47 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 6 Jun 2016 16:45:53 +0200 Subject: [PATCH 09/18] add new request --- Octokit.Reactive/Clients/IObservableTeamsClient.cs | 2 +- Octokit.Reactive/Clients/ObservableTeamsClient.cs | 2 +- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- Octokit/Clients/ITeamsClient.cs | 2 +- Octokit/Clients/TeamsClient.cs | 2 +- ...TeamRepositoryUpdate.cs => RepositoryPermissionRequest.cs} | 4 ++-- Octokit/Octokit-Mono.csproj | 2 +- Octokit/Octokit-MonoAndroid.csproj | 2 +- Octokit/Octokit-Monotouch.csproj | 2 +- Octokit/Octokit-Portable.csproj | 2 +- Octokit/Octokit-netcore45.csproj | 2 +- Octokit/Octokit.csproj | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) rename Octokit/Models/Request/{TeamRepositoryUpdate.cs => RepositoryPermissionRequest.cs} (86%) diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index 7acad62111..908960b903 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -183,7 +183,7 @@ public interface IObservableTeamsClient /// See the API documentation for more information. /// /// if the repository was added to the team; otherwise. - IObservable AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission); + IObservable AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission); /// /// Gets whether or not the given repository is managed by the given team. diff --git a/Octokit.Reactive/Clients/ObservableTeamsClient.cs b/Octokit.Reactive/Clients/ObservableTeamsClient.cs index 1649472bc7..2b4bd0ec1b 100644 --- a/Octokit.Reactive/Clients/ObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableTeamsClient.cs @@ -258,7 +258,7 @@ public IObservable AddRepository(int id, string organization, string repoN /// See the API documentation for more information. /// /// if the repository was added to the team; otherwise. - public IObservable AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission) + public IObservable AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName"); diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index d1d6a37f19..3144cd98a3 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -306,7 +306,7 @@ public void AddOrUpdatePermission() { var connection = Substitute.For(); var client = new TeamsClient(connection); - var newPermission = new TeamRepositoryUpdate(Permission.Admin); + var newPermission = new RepositoryPermissionRequest(Permission.Admin); client.AddRepository(1, "org", "repo", newPermission); diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index f1680ce2bc..c07d646738 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -168,7 +168,7 @@ public interface ITeamsClient /// The permission to grant the team on this repository. /// Thrown when a general API error occurs. /// - Task AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission); + Task AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission); /// /// Remove a repository from the team diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index e23f3ba243..c928e6a164 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -326,7 +326,7 @@ public async Task AddRepository(int id, string organization, string repoNa /// The permission to grant the team on this repository. /// Thrown when a general API error occurs. /// - public async Task AddRepository(int id, string organization, string repoName, TeamRepositoryUpdate permission) + public async Task AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName"); diff --git a/Octokit/Models/Request/TeamRepositoryUpdate.cs b/Octokit/Models/Request/RepositoryPermissionRequest.cs similarity index 86% rename from Octokit/Models/Request/TeamRepositoryUpdate.cs rename to Octokit/Models/Request/RepositoryPermissionRequest.cs index 6f5af1f88e..9475b01195 100644 --- a/Octokit/Models/Request/TeamRepositoryUpdate.cs +++ b/Octokit/Models/Request/RepositoryPermissionRequest.cs @@ -5,12 +5,12 @@ namespace Octokit { [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class TeamRepositoryUpdate + public class RepositoryPermissionRequest { /// /// Used to add or update a team repository. /// - public TeamRepositoryUpdate(Permission permission) + public RepositoryPermissionRequest(Permission permission) { Permission = permission; } diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index a2638babd8..bb98c8a898 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -466,7 +466,7 @@ - + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index b4a0a2930d..cf0aa9e720 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -477,7 +477,7 @@ - + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 50fdde6d90..cbb7347e06 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -473,7 +473,7 @@ - + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 44aa78eb46..d5cc1c6eaf 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -463,7 +463,7 @@ - + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index c459ed446b..b6714a9baa 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -470,7 +470,7 @@ - + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index afd1dc39c1..24dad5da12 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -144,7 +144,7 @@ - + From f04b643d84d0236381a4233d04711021c50b0936 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Tue, 7 Jun 2016 15:14:01 +0200 Subject: [PATCH 10/18] [WIP] add integration test for add or update team repositories --- .../Clients/TeamsClientTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index a80a6da040..0abde10be2 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; using Xunit; public class TeamsClientTests @@ -119,4 +120,28 @@ public async Task GetsAllMembersWhenAuthenticated() Assert.Contains(Helper.UserName, members.Select(u => u.Login)); } } + + public class TheAddOrUpdateTeamRepositoryMethod + { + readonly Team team; + + [OrganizationTest] + public async Task CanAddRepository() + { + var github = Helper.GetAuthenticatedClient(); + + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + var team = github.Organization.Team.GetAll(Helper.Organization).Result.First(); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var createdRepository = context.Repository; + + var addRepo = await github.Organization.Team.AddRepository(team.Id, team.Organization.Name, createdRepository.Name, new RepositoryPermissionRequest(Permission.Admin)); + + Assert.NotNull(addRepo); + } + } + } } From 71f992a478791569b516d0c413f5c9406d8567f7 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Wed, 8 Jun 2016 10:15:41 +0200 Subject: [PATCH 11/18] rename EnterpriseTeamContext to TeamContext --- .../Clients/Enterprise/EnterpriseLdapClientTests.cs | 2 +- Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs | 4 ++-- .../Helpers/ObservableGithubClientExtensions.cs | 4 ++-- .../Helpers/{EnterpriseTeamContext.cs => TeamContext.cs} | 4 ++-- Octokit.Tests.Integration/Octokit.Tests.Integration.csproj | 2 +- .../Enterprise/ObservableEnterpriseLdapClientTests.cs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) rename Octokit.Tests.Integration/Helpers/{EnterpriseTeamContext.cs => TeamContext.cs} (82%) diff --git a/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs index 5fbac3728e..1b8a99311a 100644 --- a/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs +++ b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs @@ -13,7 +13,7 @@ public class EnterpriseLdapClientTests : IDisposable readonly string _testUser = "test-user"; readonly string _distinguishedNameUser = "uid=test-user,ou=users,dc=company,dc=com"; - readonly EnterpriseTeamContext _context; + readonly TeamContext _context; readonly string _distinguishedNameTeam = "cn=test-team,ou=groups,dc=company,dc=com"; public EnterpriseLdapClientTests() diff --git a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs index 8f982e43c4..91dfc2a7e0 100644 --- a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs @@ -26,11 +26,11 @@ internal static async Task CreateRepositoryContext(this IGitH return new RepositoryContext(repo); } - internal static async Task CreateEnterpriseTeamContext(this IGitHubClient client, string organization, NewTeam newTeam) + internal static async Task CreateEnterpriseTeamContext(this IGitHubClient client, string organization, NewTeam newTeam) { var team = await client.Organization.Team.Create(organization, newTeam); - return new EnterpriseTeamContext(team); + return new TeamContext(team); } internal static async Task CreateEnterpriseUserContext(this IGitHubClient client, NewUser newUser) diff --git a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs index f455608a95..4a864c3d38 100644 --- a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs @@ -28,11 +28,11 @@ internal static async Task CreateRepositoryContext(this IObse return new RepositoryContext(repo); } - internal static async Task CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam) + internal static async Task CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam) { var team = await client.Organization.Team.Create(organization, newTeam); - return new EnterpriseTeamContext(team); + return new TeamContext(team); } internal static async Task CreateEnterpriseUserContext(this IObservableGitHubClient client, NewUser newUser) diff --git a/Octokit.Tests.Integration/Helpers/EnterpriseTeamContext.cs b/Octokit.Tests.Integration/Helpers/TeamContext.cs similarity index 82% rename from Octokit.Tests.Integration/Helpers/EnterpriseTeamContext.cs rename to Octokit.Tests.Integration/Helpers/TeamContext.cs index 3b910a2af3..967aebb2f6 100644 --- a/Octokit.Tests.Integration/Helpers/EnterpriseTeamContext.cs +++ b/Octokit.Tests.Integration/Helpers/TeamContext.cs @@ -6,9 +6,9 @@ namespace Octokit.Tests.Integration.Helpers { - internal sealed class EnterpriseTeamContext : IDisposable + internal sealed class TeamContext : IDisposable { - internal EnterpriseTeamContext(Team team) + internal TeamContext(Team team) { Team = team; TeamId = team.Id; diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index be61279eb1..afe0511eb7 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -127,7 +127,7 @@ - + diff --git a/Octokit.Tests.Integration/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs b/Octokit.Tests.Integration/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs index 948a52a65a..01441e963b 100644 --- a/Octokit.Tests.Integration/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/Enterprise/ObservableEnterpriseLdapClientTests.cs @@ -15,7 +15,7 @@ public class ObservableEnterpriseLdapClientTests : IDisposable readonly string _testUser = "test-user"; readonly string _distinguishedNameUser = "uid=test-user,ou=users,dc=company,dc=com"; - readonly EnterpriseTeamContext _context; + readonly TeamContext _context; readonly string _distinguishedNameTeam = "cn=test-team,ou=groups,dc=company,dc=com"; public ObservableEnterpriseLdapClientTests() From 6e03a81e220a5dbbee6674ca68768af40b52fac6 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Wed, 8 Jun 2016 10:28:46 +0200 Subject: [PATCH 12/18] rename enterprise team context methods --- .../Clients/Enterprise/EnterpriseLdapClientTests.cs | 2 +- .../Clients/UserAdministrationClientTests.cs | 12 ++++++------ .../Helpers/GithubClientExtensions.cs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs index 1b8a99311a..9548a2b16e 100644 --- a/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs +++ b/Octokit.Tests.Integration/Clients/Enterprise/EnterpriseLdapClientTests.cs @@ -21,7 +21,7 @@ public EnterpriseLdapClientTests() _github = EnterpriseHelper.GetAuthenticatedClient(); NewTeam newTeam = new NewTeam(Helper.MakeNameWithTimestamp("test-team")) { Description = "Test Team" }; - _context = _github.CreateEnterpriseTeamContext(EnterpriseHelper.Organization, newTeam).Result; + _context = _github.CreateTeamContext(EnterpriseHelper.Organization, newTeam).Result; } [GitHubEnterpriseTest] diff --git a/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs b/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs index 0a68edd27a..34e4c52389 100644 --- a/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs +++ b/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs @@ -67,7 +67,7 @@ public async Task CanRename() { string renamedUsername = Helper.MakeNameWithTimestamp("user-renamed"); // Create a disposable user for the test - using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) { var response = await _github.User.Administration.Rename( context.UserLogin, @@ -86,7 +86,7 @@ public async Task CanRename() public async Task CanAddAndDeleteImpersonationToken() { // Create a disposable user for the test - using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) { // Create Impersonation token var token = await _github.User.Administration.CreateImpersonationToken( @@ -109,7 +109,7 @@ public async Task CanPromoteAndDemote() User checkUser = null; // Create a disposable user for the test - using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) { // Ensure user is not site admin checkUser = await _github.User.Get(context.UserLogin); @@ -137,7 +137,7 @@ public async Task CanSuspendAndUnsuspend() User checkUser = null; // Create a disposable user for the test - using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) { // Ensure user is not suspended checkUser = await _github.User.Get(context.UserLogin); @@ -163,7 +163,7 @@ public async Task CanSuspendAndUnsuspend() public async Task CanListAllPublicKeys() { // Create a disposable user for the test - using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) { // Ensure user has a key //var key = await _github.User.Keys.Create(new NewPublicKey("title", "key")); @@ -183,7 +183,7 @@ public async Task CanListAllPublicKeys() public async Task CanDeletePublicKey() { // Create a disposable user for the test - using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) { // Ensure user has a key //var key = await _github.User.Keys.Create(new NewPublicKey("title", "key")); diff --git a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs index 91dfc2a7e0..5c892c43b6 100644 --- a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs @@ -26,14 +26,14 @@ internal static async Task CreateRepositoryContext(this IGitH return new RepositoryContext(repo); } - internal static async Task CreateEnterpriseTeamContext(this IGitHubClient client, string organization, NewTeam newTeam) + internal static async Task CreateTeamContext(this IGitHubClient client, string organization, NewTeam newTeam) { var team = await client.Organization.Team.Create(organization, newTeam); return new TeamContext(team); } - internal static async Task CreateEnterpriseUserContext(this IGitHubClient client, NewUser newUser) + internal static async Task CreateUserContext(this IGitHubClient client, NewUser newUser) { var user = await client.User.Administration.Create(newUser); From 82dce21a35deee1cea8061d862a77fb778324cb5 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Wed, 8 Jun 2016 10:53:19 +0200 Subject: [PATCH 13/18] finish integration tests --- .../Clients/TeamsClientTests.cs | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index 0abde10be2..fb5ab9e930 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -123,24 +123,37 @@ public async Task GetsAllMembersWhenAuthenticated() public class TheAddOrUpdateTeamRepositoryMethod { - readonly Team team; + private readonly TeamContext _teamContext; + private readonly IGitHubClient _github; + + public TheAddOrUpdateTeamRepositoryMethod() + { + _github = EnterpriseHelper.GetAuthenticatedClient(); + var newTeam = new NewTeam(Guid.NewGuid().ToString()); + _teamContext = _github.CreateTeamContext(EnterpriseHelper.Organization, newTeam).Result; + } [OrganizationTest] public async Task CanAddRepository() { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - var team = github.Organization.Team.GetAll(Helper.Organization).Result.First(); + var team = _teamContext.Team; - using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + using (var context = await _github.CreateRepositoryContext(new NewRepository(repoName))) { var createdRepository = context.Repository; - var addRepo = await github.Organization.Team.AddRepository(team.Id, team.Organization.Name, createdRepository.Name, new RepositoryPermissionRequest(Permission.Admin)); + var addRepo = await _github.Organization.Team.AddRepository(team.Id, team.Organization.Name, createdRepository.Name, new RepositoryPermissionRequest(Permission.Admin)); + + Assert.True(addRepo); + + var addedRepo = await _github.Organization.Team.GetAllRepositories(team.Id); + + //Check if permission was correctly applied + Assert.True(addedRepo.First(x => x.Id == createdRepository.Id).Permissions.Admin == true); + - Assert.NotNull(addRepo); } } } From e83ca0d0d1f4a184af750ed46218e67e02614fcc Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Wed, 8 Jun 2016 11:19:04 +0200 Subject: [PATCH 14/18] change integration tests --- .../Clients/TeamsClientTests.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index fb5ab9e930..7971c14302 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -121,16 +121,16 @@ public async Task GetsAllMembersWhenAuthenticated() } } - public class TheAddOrUpdateTeamRepositoryMethod + public class TheAddOrUpdateTeamRepositoryMethod : IDisposable { - private readonly TeamContext _teamContext; private readonly IGitHubClient _github; + private Repository _repository; + private Team _team; public TheAddOrUpdateTeamRepositoryMethod() { _github = EnterpriseHelper.GetAuthenticatedClient(); - var newTeam = new NewTeam(Guid.NewGuid().ToString()); - _teamContext = _github.CreateTeamContext(EnterpriseHelper.Organization, newTeam).Result; + } [OrganizationTest] @@ -138,23 +138,31 @@ public async Task CanAddRepository() { var repoName = Helper.MakeNameWithTimestamp("public-repo"); - var team = _teamContext.Team; + var newTeam = new NewTeam(Guid.NewGuid().ToString()); - using (var context = await _github.CreateRepositoryContext(new NewRepository(repoName))) + using (RepositoryContext context = await _github.CreateRepositoryContext(new NewRepository(repoName))) + using (TeamContext teamContext = _github.CreateTeamContext(EnterpriseHelper.Organization, newTeam).Result) { - var createdRepository = context.Repository; + _team = teamContext.Team; + + _repository = context.Repository; - var addRepo = await _github.Organization.Team.AddRepository(team.Id, team.Organization.Name, createdRepository.Name, new RepositoryPermissionRequest(Permission.Admin)); + var addRepo = await _github.Organization.Team.AddRepository(_team.Id, _team.Organization.Name, _repository.Name, new RepositoryPermissionRequest(Permission.Admin)); Assert.True(addRepo); - var addedRepo = await _github.Organization.Team.GetAllRepositories(team.Id); + var addedRepo = await _github.Organization.Team.GetAllRepositories(_team.Id); //Check if permission was correctly applied - Assert.True(addedRepo.First(x => x.Id == createdRepository.Id).Permissions.Admin == true); - + Assert.True(addedRepo.First(x => x.Id == _repository.Id).Permissions.Admin == true); } } + + public void Dispose() + { + EnterpriseHelper.DeleteRepo(_repository); + EnterpriseHelper.DeleteTeam(_team); + } } } From 7fa1faa5c46de777cab11130ca7fb808c1885709 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 8 Jun 2016 21:46:25 +1000 Subject: [PATCH 15/18] integration helper context classes now work against github.com or github enterprise, by using the IConnection used to create the context, to delete it in Dispose() update CreateContext extension methods to pass in the IConnection --- Octokit.Tests.Integration/EnterpriseHelper.cs | 42 +++---------------- Octokit.Tests.Integration/Helper.cs | 37 +++++++++++----- .../Helpers/EnterpriseUserContext.cs | 6 ++- .../Helpers/GithubClientExtensions.cs | 14 +++---- .../ObservableGithubClientExtensions.cs | 12 +++--- .../Helpers/PublicKeyContext.cs | 6 ++- .../Helpers/RepositoryContext.cs | 7 +++- .../Helpers/TeamContext.cs | 8 ++-- 8 files changed, 63 insertions(+), 69 deletions(-) diff --git a/Octokit.Tests.Integration/EnterpriseHelper.cs b/Octokit.Tests.Integration/EnterpriseHelper.cs index baf16c9a33..deae6e0e88 100644 --- a/Octokit.Tests.Integration/EnterpriseHelper.cs +++ b/Octokit.Tests.Integration/EnterpriseHelper.cs @@ -108,50 +108,18 @@ public static string ClientSecret get { return Environment.GetEnvironmentVariable("OCTOKIT_GHE_CLIENTSECRET"); } } - public static void DeleteRepo(Repository repository) - { - if (repository != null) - DeleteRepo(repository.Owner.Login, repository.Name); - } - - public static void DeleteRepo(string owner, string name) - { - var api = GetAuthenticatedClient(); - try - { - api.Repository.Delete(owner, name).Wait(TimeSpan.FromSeconds(15)); - } - catch { } - } - - public static void DeleteTeam(Team team) - { - if (team != null) - DeleteTeam(team.Id); - } - - public static void DeleteTeam(int teamId) - { - var api = GetAuthenticatedClient(); - try - { - api.Organization.Team.Delete(teamId).Wait(TimeSpan.FromSeconds(15)); - } - catch { } - } - - public static void DeleteUser(User user) + public static void DeleteUser(IConnection connection, User user) { if (user != null) - DeleteUser(user.Login); + DeleteUser(connection, user.Login); } - public static void DeleteUser(string username) + public static void DeleteUser(IConnection connection, string username) { - var api = GetAuthenticatedClient(); try { - api.User.Administration.Delete(username).Wait(TimeSpan.FromSeconds(15)); + var client = new GitHubClient(connection); + client.User.Administration.Delete(username).Wait(TimeSpan.FromSeconds(15)); } catch { } } diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 52eaeb8cb6..f383d37724 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using Octokit.Reactive; namespace Octokit.Tests.Integration { @@ -110,34 +111,50 @@ public static string ClientSecret get { return Environment.GetEnvironmentVariable("OCTOKIT_CLIENTSECRET"); } } - public static void DeleteRepo(Repository repository) + public static void DeleteRepo(IConnection connection, Repository repository) { if (repository != null) - DeleteRepo(repository.Owner.Login, repository.Name); + DeleteRepo(connection, repository.Owner.Login, repository.Name); } - public static void DeleteRepo(string owner, string name) + public static void DeleteRepo(IConnection connection, string owner, string name) { - var api = GetAuthenticatedClient(); try { - api.Repository.Delete(owner, name).Wait(TimeSpan.FromSeconds(15)); + var client = new GitHubClient(connection); + client.Repository.Delete(owner, name).Wait(TimeSpan.FromSeconds(15)); } catch { } } - public static void DeleteKey(PublicKey key) + public static void DeleteTeam(IConnection connection, Team team) + { + if (team != null) + DeleteTeam(connection, team.Id); + } + + public static void DeleteTeam(IConnection connection, int teamId) + { + try + { + var client = new GitHubClient(connection); + client.Organization.Team.Delete(teamId).Wait(TimeSpan.FromSeconds(15)); + } + catch { } + } + + public static void DeleteKey(IConnection connection, PublicKey key) { if (key != null) - DeleteKey(key.Id); + DeleteKey(connection, key.Id); } - public static void DeleteKey(int keyId) + public static void DeleteKey(IConnection connection, int keyId) { - var api = GetAuthenticatedClient(); try { - api.User.Keys.Delete(keyId).Wait(TimeSpan.FromSeconds(15)); + var client = new GitHubClient(connection); + client.User.Keys.Delete(keyId).Wait(TimeSpan.FromSeconds(15)); } catch { } } diff --git a/Octokit.Tests.Integration/Helpers/EnterpriseUserContext.cs b/Octokit.Tests.Integration/Helpers/EnterpriseUserContext.cs index 496fb52d3c..177a8c6902 100644 --- a/Octokit.Tests.Integration/Helpers/EnterpriseUserContext.cs +++ b/Octokit.Tests.Integration/Helpers/EnterpriseUserContext.cs @@ -8,14 +8,16 @@ namespace Octokit.Tests.Integration.Helpers { internal sealed class EnterpriseUserContext : IDisposable { - internal EnterpriseUserContext(User user) + internal EnterpriseUserContext(IConnection connection, User user) { + _connection = connection; User = user; UserId = user.Id; UserLogin = user.Login; UserEmail = user.Email; } + private IConnection _connection; internal int UserId { get; private set; } internal string UserLogin { get; private set; } internal string UserEmail { get; private set; } @@ -24,7 +26,7 @@ internal EnterpriseUserContext(User user) public void Dispose() { - EnterpriseHelper.DeleteUser(User); + EnterpriseHelper.DeleteUser(_connection, User.Login); } } } diff --git a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs index 5c892c43b6..18604004ee 100644 --- a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs @@ -9,35 +9,35 @@ internal static async Task CreateRepositoryContext(this IGitH var repoName = Helper.MakeNameWithTimestamp(repositoryName); var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - return new RepositoryContext(repo); + return new RepositoryContext(client.Connection, repo); } internal static async Task CreateRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository) { var repo = await client.Repository.Create(organizationLogin, newRepository); - return new RepositoryContext(repo); + return new RepositoryContext(client.Connection, repo); } internal static async Task CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository) { var repo = await client.Repository.Create(newRepository); - return new RepositoryContext(repo); + return new RepositoryContext(client.Connection, repo); } internal static async Task CreateTeamContext(this IGitHubClient client, string organization, NewTeam newTeam) { var team = await client.Organization.Team.Create(organization, newTeam); - return new TeamContext(team); + return new TeamContext(client.Connection, team); } - internal static async Task CreateUserContext(this IGitHubClient client, NewUser newUser) + internal static async Task CreateEnterpriseUserContext(this IGitHubClient client, NewUser newUser) { var user = await client.User.Administration.Create(newUser); - return new EnterpriseUserContext(user); + return new EnterpriseUserContext(client.Connection, user); } internal static async Task CreatePublicKeyContext(this IGitHubClient client) @@ -48,7 +48,7 @@ internal static async Task CreatePublicKeyContext(this IGitHub var key = await client.User.Keys.Create(new NewPublicKey(keyTitle, keyData)); - return new PublicKeyContext(key); + return new PublicKeyContext(client.Connection, key); } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs index 4a864c3d38..12ab85f23b 100644 --- a/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs +++ b/Octokit.Tests.Integration/Helpers/ObservableGithubClientExtensions.cs @@ -11,35 +11,35 @@ internal static async Task CreateRepositoryContext(this IObse var repoName = Helper.MakeNameWithTimestamp(repositoryName); var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true }); - return new RepositoryContext(repo); + return new RepositoryContext(client.Connection, repo); } internal static async Task CreateRepositoryContext(this IObservableGitHubClient client, string organizationLogin, NewRepository newRepository) { var repo = await client.Repository.Create(organizationLogin, newRepository); - return new RepositoryContext(repo); + return new RepositoryContext(client.Connection, repo); } internal static async Task CreateRepositoryContext(this IObservableGitHubClient client, NewRepository newRepository) { var repo = await client.Repository.Create(newRepository); - return new RepositoryContext(repo); + return new RepositoryContext(client.Connection, repo); } internal static async Task CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam) { var team = await client.Organization.Team.Create(organization, newTeam); - return new TeamContext(team); + return new TeamContext(client.Connection, team); } internal static async Task CreateEnterpriseUserContext(this IObservableGitHubClient client, NewUser newUser) { var user = await client.User.Administration.Create(newUser); - return new EnterpriseUserContext(user); + return new EnterpriseUserContext(client.Connection, user); } internal static async Task CreatePublicKeyContext(this IObservableGitHubClient client) @@ -50,7 +50,7 @@ internal static async Task CreatePublicKeyContext(this IObserv var key = await client.User.Keys.Create(new NewPublicKey(keyTitle, keyData)); - return new PublicKeyContext(key); + return new PublicKeyContext(client.Connection, key); } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Helpers/PublicKeyContext.cs b/Octokit.Tests.Integration/Helpers/PublicKeyContext.cs index 30fbaac79c..bf4b2d3292 100644 --- a/Octokit.Tests.Integration/Helpers/PublicKeyContext.cs +++ b/Octokit.Tests.Integration/Helpers/PublicKeyContext.cs @@ -8,14 +8,16 @@ namespace Octokit.Tests.Integration.Helpers { internal sealed class PublicKeyContext : IDisposable { - internal PublicKeyContext(PublicKey key) + internal PublicKeyContext(IConnection connection, PublicKey key) { + _connection = connection; Key = key; KeyId = key.Id; KeyTitle = key.Title; KeyData = key.Key; } + private IConnection _connection; internal int KeyId { get; private set; } internal string KeyTitle { get; private set; } internal string KeyData { get; private set; } @@ -24,7 +26,7 @@ internal PublicKeyContext(PublicKey key) public void Dispose() { - Helper.DeleteKey(Key); + Helper.DeleteKey(_connection, Key); } } } diff --git a/Octokit.Tests.Integration/Helpers/RepositoryContext.cs b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs index d16afd36de..509cba7a3a 100644 --- a/Octokit.Tests.Integration/Helpers/RepositoryContext.cs +++ b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs @@ -3,18 +3,21 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Octokit.Reactive; namespace Octokit.Tests.Integration.Helpers { internal sealed class RepositoryContext : IDisposable { - internal RepositoryContext(Repository repo) + internal RepositoryContext(IConnection connection, Repository repo) { + _connection = connection; Repository = repo; RepositoryOwner = repo.Owner.Login; RepositoryName = repo.Name; } + private IConnection _connection; internal string RepositoryOwner { get; private set; } internal string RepositoryName { get; private set; } @@ -22,7 +25,7 @@ internal RepositoryContext(Repository repo) public void Dispose() { - Helper.DeleteRepo(Repository); + Helper.DeleteRepo(_connection, Repository); } } } diff --git a/Octokit.Tests.Integration/Helpers/TeamContext.cs b/Octokit.Tests.Integration/Helpers/TeamContext.cs index 967aebb2f6..07f20525e6 100644 --- a/Octokit.Tests.Integration/Helpers/TeamContext.cs +++ b/Octokit.Tests.Integration/Helpers/TeamContext.cs @@ -8,21 +8,23 @@ namespace Octokit.Tests.Integration.Helpers { internal sealed class TeamContext : IDisposable { - internal TeamContext(Team team) + internal TeamContext(IConnection connection, Team team) { + _connection = connection; Team = team; TeamId = team.Id; TeamName = team.Name; } + private IConnection _connection; internal int TeamId { get; private set; } internal string TeamName { get; private set; } - + internal Team Team { get; private set; } public void Dispose() { - EnterpriseHelper.DeleteTeam(Team); + Helper.DeleteTeam(_connection, Team); } } } From acbc3fec006cbb5ba850a1864796f5788f9ec7ee Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 8 Jun 2016 21:46:39 +1000 Subject: [PATCH 16/18] Update impacted tests to use new Context creation and Delete helper methods --- .../Clients/RepositoriesClientTests.cs | 2 +- .../Clients/RepositoryForksClientTests.cs | 4 ++-- .../Clients/UserAdministrationClientTests.cs | 14 +++++++------- .../ObservableRepositoryDeployKeysClientTests.cs | 2 +- .../ObservableUserAdministrationClientTests.cs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index cb715f0bf9..f0bf997226 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -433,7 +433,7 @@ public async Task UpdatesHasWiki() public void Dispose() { - Helper.DeleteRepo(_repository); + Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, _repository); } } diff --git a/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs index 3f7c5af777..c1b64c6b88 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs @@ -43,7 +43,7 @@ public async Task ForkCreatedForUserLoggedIn() // The fork is created asynchronously by github and therefore it cannot // be certain that the repo exists when the test ends. It is therefore deleted // before the test starts instead of after. - Helper.DeleteRepo(Helper.Credentials.Login, "octokit.net"); + Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, Helper.Credentials.Login, "octokit.net"); var github = Helper.GetAuthenticatedClient(); @@ -60,7 +60,7 @@ public async Task ForkCreatedForOrganization() // The fork is created asynchronously by github and therefore it cannot // be certain that the repo exists when the test ends. It is therefore deleted // before the test starts. - Helper.DeleteRepo(Helper.Organization, "octokit.net"); + Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, Helper.Organization, "octokit.net"); var github = Helper.GetAuthenticatedClient(); diff --git a/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs b/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs index 34e4c52389..08554c5bee 100644 --- a/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs +++ b/Octokit.Tests.Integration/Clients/UserAdministrationClientTests.cs @@ -67,7 +67,7 @@ public async Task CanRename() { string renamedUsername = Helper.MakeNameWithTimestamp("user-renamed"); // Create a disposable user for the test - using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) { var response = await _github.User.Administration.Rename( context.UserLogin, @@ -79,14 +79,14 @@ public async Task CanRename() } // Remove user if it was already renamed - EnterpriseHelper.DeleteUser(renamedUsername); + EnterpriseHelper.DeleteUser(_github.Connection, renamedUsername); } [GitHubEnterpriseTest] public async Task CanAddAndDeleteImpersonationToken() { // Create a disposable user for the test - using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) { // Create Impersonation token var token = await _github.User.Administration.CreateImpersonationToken( @@ -109,7 +109,7 @@ public async Task CanPromoteAndDemote() User checkUser = null; // Create a disposable user for the test - using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) { // Ensure user is not site admin checkUser = await _github.User.Get(context.UserLogin); @@ -137,7 +137,7 @@ public async Task CanSuspendAndUnsuspend() User checkUser = null; // Create a disposable user for the test - using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) { // Ensure user is not suspended checkUser = await _github.User.Get(context.UserLogin); @@ -163,7 +163,7 @@ public async Task CanSuspendAndUnsuspend() public async Task CanListAllPublicKeys() { // Create a disposable user for the test - using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) { // Ensure user has a key //var key = await _github.User.Keys.Create(new NewPublicKey("title", "key")); @@ -183,7 +183,7 @@ public async Task CanListAllPublicKeys() public async Task CanDeletePublicKey() { // Create a disposable user for the test - using (var context = _github.CreateUserContext(GenerateNewUserDetails()).Result) + using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result) { // Ensure user has a key //var key = await _github.User.Keys.Create(new NewPublicKey("title", "key")); diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs index 1cf8b6067e..5a6ba833c6 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs @@ -101,6 +101,6 @@ public async Task CanRemoveADeployKey() public void Dispose() { - Helper.DeleteRepo(_repository); + Helper.DeleteRepo(Helper.GetAuthenticatedClient().Connection, _repository); } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs index ad15c40233..eb2f8a9a4e 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableUserAdministrationClientTests.cs @@ -82,7 +82,7 @@ public async Task CanRename() } // Remove user if it was already renamed - EnterpriseHelper.DeleteUser(renamedUsername); + EnterpriseHelper.DeleteUser(_github.Connection, renamedUsername); } [GitHubEnterpriseTest] From e2ee4feb38b9b2d0a513146850d86ed8d2b57e3f Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 8 Jun 2016 21:49:32 +1000 Subject: [PATCH 17/18] Fix AddPermission test - use Helper not EnterpriseHelper - use team.Organization.Login rather than .Name --- .../Clients/TeamsClientTests.cs | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index 7971c14302..91b812a85e 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -121,48 +121,33 @@ public async Task GetsAllMembersWhenAuthenticated() } } - public class TheAddOrUpdateTeamRepositoryMethod : IDisposable + public class TheAddOrUpdateTeamRepositoryMethod { private readonly IGitHubClient _github; - private Repository _repository; - private Team _team; public TheAddOrUpdateTeamRepositoryMethod() { - _github = EnterpriseHelper.GetAuthenticatedClient(); - + _github = Helper.GetAuthenticatedClient(); } [OrganizationTest] public async Task CanAddRepository() { - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - - var newTeam = new NewTeam(Guid.NewGuid().ToString()); - - using (RepositoryContext context = await _github.CreateRepositoryContext(new NewRepository(repoName))) - using (TeamContext teamContext = _github.CreateTeamContext(EnterpriseHelper.Organization, newTeam).Result) + using (var teamContext = await _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team")))) + using (var repoContext = await _github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("team-repository")))) { - _team = teamContext.Team; - - _repository = context.Repository; + var team = teamContext.Team; + var repo = repoContext.Repository; - var addRepo = await _github.Organization.Team.AddRepository(_team.Id, _team.Organization.Name, _repository.Name, new RepositoryPermissionRequest(Permission.Admin)); + var addRepo = await _github.Organization.Team.AddRepository(team.Id, team.Organization.Login, repo.Name, new RepositoryPermissionRequest(Permission.Admin)); Assert.True(addRepo); - var addedRepo = await _github.Organization.Team.GetAllRepositories(_team.Id); + var addedRepo = await _github.Organization.Team.GetAllRepositories(team.Id); //Check if permission was correctly applied - Assert.True(addedRepo.First(x => x.Id == _repository.Id).Permissions.Admin == true); - + Assert.True(addedRepo.First(x => x.Id == repo.Id).Permissions.Admin == true); } } - - public void Dispose() - { - EnterpriseHelper.DeleteRepo(_repository); - EnterpriseHelper.DeleteTeam(_team); - } } } From aabc8da9638cb4fd338a4b9aa3faa1caffcd86c9 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Wed, 8 Jun 2016 21:55:42 +1000 Subject: [PATCH 18/18] Fix whitespace --- Octokit.Tests.Integration/Helpers/TeamContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Helpers/TeamContext.cs b/Octokit.Tests.Integration/Helpers/TeamContext.cs index 07f20525e6..c1479c4c4d 100644 --- a/Octokit.Tests.Integration/Helpers/TeamContext.cs +++ b/Octokit.Tests.Integration/Helpers/TeamContext.cs @@ -19,7 +19,7 @@ internal TeamContext(IConnection connection, Team team) private IConnection _connection; internal int TeamId { get; private set; } internal string TeamName { get; private set; } - + internal Team Team { get; private set; } public void Dispose()