From 7bd3b37a283b5e5b39ccf34d88186f035a861ccd Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 30 Jun 2016 13:33:12 +0200 Subject: [PATCH 01/47] add invitations accept header --- Octokit/Helpers/AcceptHeaders.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index dfb37c0ec3..a258c7082f 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -34,5 +34,7 @@ public static class AcceptHeaders public const string GpgKeysPreview = "application/vnd.github.cryptographer-preview"; public const string DeploymentApiPreview = "application/vnd.github.ant-man-preview+json"; + + public const string InvitationsApiPreview = "application/vnd.github.swamp-thing-preview+json"; } } From 9f9c5e0f48d7d8a85e3ce60e0a4fad3a32a01892 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 30 Jun 2016 14:26:54 +0200 Subject: [PATCH 02/47] create class RepositoryInvitation --- .../Models/Response/RepositoryInvitation.cs | 45 +++++++++++++++++++ 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 + 7 files changed, 51 insertions(+) create mode 100644 Octokit/Models/Response/RepositoryInvitation.cs diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs new file mode 100644 index 0000000000..8f738a791e --- /dev/null +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -0,0 +1,45 @@ +using System; + +namespace Octokit +{ + public enum RepositoryInvitationPermissions + { + Read, + Write, + Admin + } + public class RepositoryInvitation + { + public RepositoryInvitation() + { + } + + public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, RepositoryInvitationPermissions permissions, DateTimeOffset createdAt, string url, string htmlUrl) + { + Id = id; + Repository = repository; + Invitee = invitee; + Inviter = inviter; + Permissions = permissions; + CreatedAt = createdAt; + Url = url; + HtmlUrl = htmlUrl; + } + + public int Id { get; protected set; } + + public Repository Repository { get; protected set; } + + public User Invitee { get; protected set; } + + public User Inviter { get; protected set; } + + public RepositoryInvitationPermissions Permissions { get; protected set; } + + public DateTimeOffset CreatedAt { get; set; } + + public string Url { get; protected set; } + + public string HtmlUrl { get; protected set; } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 7c6a3564f6..1f8e24d319 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -485,6 +485,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 8b66b03d30..e542efa331 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -496,6 +496,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 68b0e6ff83..284c0bcd70 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -492,6 +492,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index c7a7f4fa47..4ac5b02697 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -482,6 +482,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 3d7d9a74d8..9c6f174132 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -489,6 +489,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 29da34ce5c..a350f0311c 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -203,6 +203,7 @@ + From dcdfbc6f8b7b333ff61f0d4be0aa02c5f1ef3a14 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 30 Jun 2016 15:02:54 +0200 Subject: [PATCH 03/47] add repository invitations client --- .../Clients/IRepositoryInvitationsClient.cs | 82 ++++++++++++++++ .../Clients/RepositoryInvitationsClient.cs | 95 +++++++++++++++++++ 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 + 8 files changed, 189 insertions(+) create mode 100644 Octokit/Clients/IRepositoryInvitationsClient.cs create mode 100644 Octokit/Clients/RepositoryInvitationsClient.cs diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs new file mode 100644 index 0000000000..cf3fa91b3d --- /dev/null +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -0,0 +1,82 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Invitations on a Repository. + /// + /// + /// See the Invitations API documentation for more details. + /// + public interface IRepositoryInvitationsClient + { + /// + /// Accept a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + Task Accept(int id); + + /// + /// Decline a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + Task Decline(int id); + + /// + /// Deletes a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + Task Delete(int repoId, int invitationId); + + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Thrown when a general API error occurs. + /// A of . + Task> GetAllForCurrent(int id); + + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Thrown when a general API error occurs. + /// A of . + Task> GetAllForRepository(int id); + + /// + /// Updates a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + Task Update(int repoId, int invitationId); + } +} diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs new file mode 100644 index 0000000000..e7cdbda617 --- /dev/null +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class RepositoryInvitationsClient : IRepositoryInvitationsClient + { + /// + /// Accept a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + public Task Accept(int id) + { + throw new NotImplementedException(); + } + + /// + /// Decline a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + public Task Decline(int id) + { + throw new NotImplementedException(); + } + + /// + /// Deletes a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + public Task Delete(int repoId, int invitationId) + { + throw new NotImplementedException(); + } + + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Thrown when a general API error occurs. + /// A of . + public Task> GetAllForCurrent(int id) + { + throw new NotImplementedException(); + } + + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Thrown when a general API error occurs. + /// A of . + public Task> GetAllForRepository(int id) + { + throw new NotImplementedException(); + } + + /// + /// Updates a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + /// Thrown when a general API error occurs. + /// + public Task Update(int repoId, int invitationId) + { + throw new NotImplementedException(); + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 1f8e24d319..0a01d8ae45 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -486,6 +486,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index e542efa331..a7b37edb29 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -497,6 +497,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 284c0bcd70..e642793d81 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -493,6 +493,8 @@ + + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 4ac5b02697..e62cd9e4a0 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -483,6 +483,8 @@ + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 9c6f174132..8d9ea0f0be 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -490,6 +490,8 @@ + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index a350f0311c..58889b16e4 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -62,6 +62,7 @@ + @@ -101,6 +102,7 @@ + From f8e7899b6c87e811b098374f5ba280cc4c9e9a04 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 30 Jun 2016 15:26:06 +0200 Subject: [PATCH 04/47] add api urls for invitations --- Octokit/Helpers/ApiUrls.cs | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index ca28659dff..a14fda6b65 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -2959,5 +2959,45 @@ public static Uri Reactions(int number) { return "reactions/{0}".FormatUri(number); } + + /// + /// Returns the for repository invitations. + /// + /// The id of the repository + /// The for repository invitations. + public static Uri RepositoryInvitations(int repositoryId) + { + return "repositories/{0}/invitations".FormatUri(repositoryId); + } + + /// + /// Returns the for repository invitations. + /// + /// The id of the repository + /// The id of the invitation + /// The for repository invitations. + public static Uri RepositoryInvitations(int repositoryId, int invitationId) + { + return "repositories/{0}/invitations/{1}".FormatUri(repositoryId, invitationId); + } + + /// + /// Returns the for invitations for the current user. + /// + /// The for invitations for the current user. + public static Uri UserInvitations() + { + return "user/repository_invitations".FormatUri(); + } + + /// + /// Returns the for invitations for the current user. + /// + /// The id of the invitation + /// The for invitations for the current user. + public static Uri UserInvitations(int invitationId) + { + return "user/repository_invitations/{0}".FormatUri(invitationId); + } } } From 6fbfa0e7cae04b62630c503589584bff29d8b84c Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 30 Jun 2016 16:16:20 +0200 Subject: [PATCH 05/47] [WIP] --- .../Clients/IRepositoryInvitationsClient.cs | 10 +++---- .../Clients/RepositoryInvitationsClient.cs | 27 +++++++++++-------- Octokit/Http/ApiConnection.cs | 13 +++++++++ Octokit/Http/Connection.cs | 14 ++++++++++ Octokit/Http/IApiConnection.cs | 8 ++++++ Octokit/Http/IConnection.cs | 8 ++++++ Octokit/Models/Request/InvitationUpdate.cs | 18 +++++++++++++ Octokit/Octokit.csproj | 1 + 8 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 Octokit/Models/Request/InvitationUpdate.cs diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index cf3fa91b3d..a4ddaa5150 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -39,11 +39,11 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. /// - Task Delete(int repoId, int invitationId); + Task Delete(int repositoryId, int invitationId); /// /// Gets all invitations for the current user. @@ -51,7 +51,7 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the invitation /// Thrown when a general API error occurs. /// A of . Task> GetAllForCurrent(int id); @@ -73,10 +73,10 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. /// - Task Update(int repoId, int invitationId); + Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions); } } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index e7cdbda617..83cfb5a356 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -4,8 +4,13 @@ namespace Octokit { - public class RepositoryInvitationsClient : IRepositoryInvitationsClient + public class RepositoryInvitationsClient : ApiClient, IRepositoryInvitationsClient { + public RepositoryInvitationsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + /// /// Accept a repository invitation. /// @@ -17,7 +22,7 @@ public class RepositoryInvitationsClient : IRepositoryInvitationsClient /// public Task Accept(int id) { - throw new NotImplementedException(); + return ApiConnection.Patch(ApiUrls.UserInvitations(id), AcceptHeaders.InvitationsApiPreview); } /// @@ -31,7 +36,7 @@ public Task Accept(int id) /// public Task Decline(int id) { - throw new NotImplementedException(); + return ApiConnection.Delete(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -40,13 +45,13 @@ public Task Decline(int id) /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. /// - public Task Delete(int repoId, int invitationId) + public Task Delete(int repositoryId, int invitationId) { - throw new NotImplementedException(); + return ApiConnection.Delete(ApiUrls.RepositoryInvitations(repositoryId, invitationId), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -55,12 +60,12 @@ public Task Delete(int repoId, int invitationId) /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the invitation /// Thrown when a general API error occurs. /// A of . public Task> GetAllForCurrent(int id) { - throw new NotImplementedException(); + return ApiConnection.GetAll(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -74,7 +79,7 @@ public Task> GetAllForCurrent(int id) /// A of . public Task> GetAllForRepository(int id) { - throw new NotImplementedException(); + return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(id), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -87,9 +92,9 @@ public Task> GetAllForRepository(int id) /// The id of the invitation /// Thrown when a general API error occurs. /// - public Task Update(int repoId, int invitationId) + public Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { - throw new NotImplementedException(); + return ApiConnection.Patch(ApiUrls.RepositoryInvitations(repositoryId, invitationId), permissions, AcceptHeaders.InvitationsApiPreview); } } } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 30c9634c8b..593617fc76 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -387,6 +387,19 @@ public Task Patch(Uri uri) return Connection.Patch(uri); } + /// + /// Updates the API resource at the specified URI. + /// + /// URI of the API resource to patch + /// A for the request's execution. + public Task Patch(Uri uri, string accepts) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(accepts, "accepts"); + + return Connection.Patch(uri, accepts); + } + /// /// Updates the API resource at the specified URI. /// diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 7a8a203f18..38fd4bba13 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -385,6 +385,20 @@ public async Task Patch(Uri uri) return response.HttpResponse.StatusCode; } + /// + /// Performs an asynchronous HTTP PATCH request. + /// + /// URI endpoint to send request to + /// representing the received HTTP response + public async Task Patch(Uri uri, string accepts) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(accepts, "accepts"); + + var response = await SendData(uri, new HttpMethod("PATCH"), null, accepts, null, CancellationToken.None).ConfigureAwait(false); + return response.HttpResponse.StatusCode; + } + /// /// Performs an asynchronous HTTP PUT request that expects an empty response. /// diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index 0444e3dd36..72c4f742b7 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -259,6 +259,14 @@ public interface IApiConnection /// A for the request's execution. Task Patch(Uri uri); + /// + /// Updates the API resource at the specified URI. + /// + /// URI of the API resource to patch + /// Accept header to use for the API request + /// A for the request's execution. + Task Patch(Uri uri, string accepts); + /// /// Updates the API resource at the specified URI. /// diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 39ddac533c..1cfaa4e9b5 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -63,6 +63,14 @@ public interface IConnection : IApiInfoProvider /// representing the received HTTP response Task Patch(Uri uri); + /// + /// Performs an asynchronous HTTP PATCH request. + /// + /// URI endpoint to send request to + /// Specifies accepted response media types. + /// representing the received HTTP response + Task Patch(Uri uri, string accepts); + /// /// Performs an asynchronous HTTP PATCH request. /// Attempts to map the response body to an object of type diff --git a/Octokit/Models/Request/InvitationUpdate.cs b/Octokit/Models/Request/InvitationUpdate.cs new file mode 100644 index 0000000000..0596865bf9 --- /dev/null +++ b/Octokit/Models/Request/InvitationUpdate.cs @@ -0,0 +1,18 @@ +using System.Diagnostics; + +namespace Octokit +{ + /// + /// Used to update a gist and its contents. + /// + /// + /// Note: All files from the previous version of the gist are carried over by default if not included in the + /// object. Deletes can be performed by including the filename with a null object. + /// API docs: https://developer.github.com/v3/gists/ + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class InvitationUpdate + { + + } +} diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 58889b16e4..29ec176558 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -134,6 +134,7 @@ + From 58d90c127fa0419a6167709f16747058538e4aca Mon Sep 17 00:00:00 2001 From: lrz-hal Date: Thu, 30 Jun 2016 17:53:37 +0200 Subject: [PATCH 06/47] add methods to repository invitations client --- .../Clients/IRepositoryInvitationsClient.cs | 10 +++--- .../Clients/RepositoryInvitationsClient.cs | 27 ++++++++------- Octokit/Http/ApiConnection.cs | 13 ++++++++ Octokit/Http/Connection.cs | 14 ++++++++ Octokit/Http/IApiConnection.cs | 8 +++++ Octokit/Http/IConnection.cs | 8 +++++ Octokit/Models/Request/InvitationUpdate.cs | 33 +++++++++++++++++++ .../Models/Response/RepositoryInvitation.cs | 6 ++-- 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 + 14 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 Octokit/Models/Request/InvitationUpdate.cs diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index cf3fa91b3d..a4ddaa5150 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -39,11 +39,11 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. /// - Task Delete(int repoId, int invitationId); + Task Delete(int repositoryId, int invitationId); /// /// Gets all invitations for the current user. @@ -51,7 +51,7 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the invitation /// Thrown when a general API error occurs. /// A of . Task> GetAllForCurrent(int id); @@ -73,10 +73,10 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. /// - Task Update(int repoId, int invitationId); + Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions); } } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index e7cdbda617..83cfb5a356 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -4,8 +4,13 @@ namespace Octokit { - public class RepositoryInvitationsClient : IRepositoryInvitationsClient + public class RepositoryInvitationsClient : ApiClient, IRepositoryInvitationsClient { + public RepositoryInvitationsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + /// /// Accept a repository invitation. /// @@ -17,7 +22,7 @@ public class RepositoryInvitationsClient : IRepositoryInvitationsClient /// public Task Accept(int id) { - throw new NotImplementedException(); + return ApiConnection.Patch(ApiUrls.UserInvitations(id), AcceptHeaders.InvitationsApiPreview); } /// @@ -31,7 +36,7 @@ public Task Accept(int id) /// public Task Decline(int id) { - throw new NotImplementedException(); + return ApiConnection.Delete(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -40,13 +45,13 @@ public Task Decline(int id) /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. /// - public Task Delete(int repoId, int invitationId) + public Task Delete(int repositoryId, int invitationId) { - throw new NotImplementedException(); + return ApiConnection.Delete(ApiUrls.RepositoryInvitations(repositoryId, invitationId), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -55,12 +60,12 @@ public Task Delete(int repoId, int invitationId) /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the invitation /// Thrown when a general API error occurs. /// A of . public Task> GetAllForCurrent(int id) { - throw new NotImplementedException(); + return ApiConnection.GetAll(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -74,7 +79,7 @@ public Task> GetAllForCurrent(int id) /// A of . public Task> GetAllForRepository(int id) { - throw new NotImplementedException(); + return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(id), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -87,9 +92,9 @@ public Task> GetAllForRepository(int id) /// The id of the invitation /// Thrown when a general API error occurs. /// - public Task Update(int repoId, int invitationId) + public Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { - throw new NotImplementedException(); + return ApiConnection.Patch(ApiUrls.RepositoryInvitations(repositoryId, invitationId), permissions, AcceptHeaders.InvitationsApiPreview); } } } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 30c9634c8b..593617fc76 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -387,6 +387,19 @@ public Task Patch(Uri uri) return Connection.Patch(uri); } + /// + /// Updates the API resource at the specified URI. + /// + /// URI of the API resource to patch + /// A for the request's execution. + public Task Patch(Uri uri, string accepts) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(accepts, "accepts"); + + return Connection.Patch(uri, accepts); + } + /// /// Updates the API resource at the specified URI. /// diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 7a8a203f18..38fd4bba13 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -385,6 +385,20 @@ public async Task Patch(Uri uri) return response.HttpResponse.StatusCode; } + /// + /// Performs an asynchronous HTTP PATCH request. + /// + /// URI endpoint to send request to + /// representing the received HTTP response + public async Task Patch(Uri uri, string accepts) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(accepts, "accepts"); + + var response = await SendData(uri, new HttpMethod("PATCH"), null, accepts, null, CancellationToken.None).ConfigureAwait(false); + return response.HttpResponse.StatusCode; + } + /// /// Performs an asynchronous HTTP PUT request that expects an empty response. /// diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index 0444e3dd36..72c4f742b7 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -259,6 +259,14 @@ public interface IApiConnection /// A for the request's execution. Task Patch(Uri uri); + /// + /// Updates the API resource at the specified URI. + /// + /// URI of the API resource to patch + /// Accept header to use for the API request + /// A for the request's execution. + Task Patch(Uri uri, string accepts); + /// /// Updates the API resource at the specified URI. /// diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 39ddac533c..1cfaa4e9b5 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -63,6 +63,14 @@ public interface IConnection : IApiInfoProvider /// representing the received HTTP response Task Patch(Uri uri); + /// + /// Performs an asynchronous HTTP PATCH request. + /// + /// URI endpoint to send request to + /// Specifies accepted response media types. + /// representing the received HTTP response + Task Patch(Uri uri, string accepts); + /// /// Performs an asynchronous HTTP PATCH request. /// Attempts to map the response body to an object of type diff --git a/Octokit/Models/Request/InvitationUpdate.cs b/Octokit/Models/Request/InvitationUpdate.cs new file mode 100644 index 0000000000..eae85bed4b --- /dev/null +++ b/Octokit/Models/Request/InvitationUpdate.cs @@ -0,0 +1,33 @@ +using System.Diagnostics; +using System.Globalization; + + +namespace Octokit +{ + /// + /// Used to update a gist and its contents. + /// + /// + /// Note: All files from the previous version of the gist are carried over by default if not included in the + /// object. Deletes can be performed by including the filename with a null object. + /// API docs: https://developer.github.com/v3/gists/ + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class InvitationUpdate + { + public InvitationUpdate(RepositoryInvitationPermission permission) + { + Permissions = permission; + } + + public RepositoryInvitationPermission Permissions { get; private set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, "Permission: {0}", Permissions); + } + } + } +} diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs index 8f738a791e..fcdf46dbfa 100644 --- a/Octokit/Models/Response/RepositoryInvitation.cs +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -2,7 +2,7 @@ namespace Octokit { - public enum RepositoryInvitationPermissions + public enum RepositoryInvitationPermission { Read, Write, @@ -14,7 +14,7 @@ public RepositoryInvitation() { } - public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, RepositoryInvitationPermissions permissions, DateTimeOffset createdAt, string url, string htmlUrl) + public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, RepositoryInvitationPermission permissions, DateTimeOffset createdAt, string url, string htmlUrl) { Id = id; Repository = repository; @@ -34,7 +34,7 @@ public RepositoryInvitation(int id, Repository repository, User invitee, User in public User Inviter { get; protected set; } - public RepositoryInvitationPermissions Permissions { get; protected set; } + public RepositoryInvitationPermission Permissions { get; protected set; } public DateTimeOffset CreatedAt { get; set; } diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 0a01d8ae45..58c0d0bf96 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -488,6 +488,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index a7b37edb29..10aa240a88 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -499,6 +499,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index e642793d81..59d075b4b7 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -495,6 +495,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index e62cd9e4a0..e7c3362501 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -485,6 +485,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 8d9ea0f0be..0b57edf8d7 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -492,6 +492,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 58889b16e4..29ec176558 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -134,6 +134,7 @@ + From 0a67ae0081815fcc97da7585a5eb7955511f533e Mon Sep 17 00:00:00 2001 From: lrz-hal Date: Thu, 30 Jun 2016 18:19:10 +0200 Subject: [PATCH 07/47] add invite method to repo collaborators client need to add some new overload to post method in apiconnection --- Octokit/Clients/IRepoCollaboratorsClient.cs | 10 ++++++++++ Octokit/Clients/RepoCollaboratorsClient.cs | 9 +++++++++ Octokit/Clients/RepositoryInvitationsClient.cs | 2 +- Octokit/Http/ApiConnection.cs | 14 ++++++++++++++ Octokit/Http/IApiConnection.cs | 8 ++++++++ Octokit/Http/IConnection.cs | 8 ++++++++ 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index d0513cc506..a989295cf6 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -58,6 +58,16 @@ public interface IRepoCollaboratorsClient /// Task Add(string owner, string repo, string user); + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// Thrown when a general API error occurs. + /// + Task Invite(string owner, string repo, string user); + /// /// Deletes a collaborator from the repo /// diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index cf1f5a3550..47f03cdafe 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -118,5 +118,14 @@ public Task Delete(string owner, string repo, string user) return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, repo, user)); } + + public Task Invite(string owner, string repo, string user) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), AcceptHeaders.InvitationsApiPreview); + } } } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 83cfb5a356..48733cbb11 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -88,7 +88,7 @@ public Task> GetAllForRepository(int id) /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. /// diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 593617fc76..22db9834f6 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -317,6 +317,20 @@ public Task Put(Uri uri) return Connection.Put(uri); } + /// + /// Creates or replaces the API resource at the specified URI + /// + /// URI of the API resource to put + /// Accept header to use for the API request + /// A for the request's execution. + public Task Put(Uri uri, string accepts) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(accepts, "accpets"); + + return Connection.Put(uri, accepts); + } + /// /// Creates or replaces the API resource at the specified URI. /// diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index 72c4f742b7..44eb0a38e4 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -218,6 +218,14 @@ public interface IApiConnection /// A for the request's execution. Task Put(Uri uri); + /// + /// Creates or replaces the API resource at the specified URI + /// + /// URI of the API resource to put + /// Accept header to use for the API request + /// A for the request's execution. + Task Put(Uri uri, string accepts); + /// /// Creates or replaces the API resource at the specified URI. /// diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 1cfaa4e9b5..223897814c 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -205,6 +205,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 + /// Specifies accepted response media types. + /// The returned + Task Put(Uri uri, string accepts); + /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. /// From 9471562b61f949803e8ebf2daf3027c58f572f99 Mon Sep 17 00:00:00 2001 From: lrz-hal Date: Thu, 30 Jun 2016 19:04:12 +0200 Subject: [PATCH 08/47] some changes --- .../RepositoryCollaboratorClientTests.cs | 22 +++++++++++++++++++ Octokit/Clients/IRepoCollaboratorsClient.cs | 2 +- Octokit/Clients/RepoCollaboratorsClient.cs | 10 ++++----- Octokit/Http/ApiConnection.cs | 14 ------------ Octokit/Http/IApiConnection.cs | 8 ------- Octokit/Http/IConnection.cs | 8 ------- Octokit/Models/Request/InvitationUpdate.cs | 4 ++-- .../Models/Response/RepositoryInvitation.cs | 6 ++--- 8 files changed, 33 insertions(+), 41 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index 1035ab35ad..a7f227bb63 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -136,4 +136,26 @@ public async Task ReturnsTrueIfUserIsCollaborator() } } } + + public class TheInviteNewCollaboratorMethod + { + [IntegrationTest] + public async Task CanInviteNewCollaborator() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "maddin2016"); + + var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + Assert.True(isCollab); + } + } + } } \ No newline at end of file diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index a989295cf6..4b08814353 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -66,7 +66,7 @@ public interface IRepoCollaboratorsClient /// /// Thrown when a general API error occurs. /// - Task Invite(string owner, string repo, string user); + Task Invite(string owner, string repo, string user); /// /// Deletes a collaborator from the repo diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 47f03cdafe..98f48419cd 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -73,7 +73,7 @@ public async Task IsCollaborator(string owner, string repo, string user) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - + try { var response = await Connection.Get(ApiUrls.RepoCollaborator(owner, repo, user), null, null).ConfigureAwait(false); @@ -98,7 +98,7 @@ public Task Add(string owner, string repo, string user) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user)); } @@ -115,17 +115,17 @@ public Task Delete(string owner, string repo, string user) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - + return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, repo, user)); } - public Task Invite(string owner, string repo, string user) + public Task Invite(string owner, string repo, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), AcceptHeaders.InvitationsApiPreview); + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), new object(), null, AcceptHeaders.InvitationsApiPreview); } } } diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 22db9834f6..593617fc76 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -317,20 +317,6 @@ public Task Put(Uri uri) return Connection.Put(uri); } - /// - /// Creates or replaces the API resource at the specified URI - /// - /// URI of the API resource to put - /// Accept header to use for the API request - /// A for the request's execution. - public Task Put(Uri uri, string accepts) - { - Ensure.ArgumentNotNull(uri, "uri"); - Ensure.ArgumentNotNull(accepts, "accpets"); - - return Connection.Put(uri, accepts); - } - /// /// Creates or replaces the API resource at the specified URI. /// diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index 44eb0a38e4..72c4f742b7 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -218,14 +218,6 @@ public interface IApiConnection /// A for the request's execution. Task Put(Uri uri); - /// - /// Creates or replaces the API resource at the specified URI - /// - /// URI of the API resource to put - /// Accept header to use for the API request - /// A for the request's execution. - Task Put(Uri uri, string accepts); - /// /// Creates or replaces the API resource at the specified URI. /// diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 223897814c..1cfaa4e9b5 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -205,14 +205,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 - /// Specifies accepted response media types. - /// The returned - Task Put(Uri uri, string accepts); - /// /// Performs an asynchronous HTTP DELETE request that expects an empty response. /// diff --git a/Octokit/Models/Request/InvitationUpdate.cs b/Octokit/Models/Request/InvitationUpdate.cs index eae85bed4b..8aa395a04f 100644 --- a/Octokit/Models/Request/InvitationUpdate.cs +++ b/Octokit/Models/Request/InvitationUpdate.cs @@ -15,12 +15,12 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class InvitationUpdate { - public InvitationUpdate(RepositoryInvitationPermission permission) + public InvitationUpdate(InvitationPermissionType permission) { Permissions = permission; } - public RepositoryInvitationPermission Permissions { get; private set; } + public InvitationPermissionType Permissions { get; private set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs index fcdf46dbfa..3b96d34b3e 100644 --- a/Octokit/Models/Response/RepositoryInvitation.cs +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -2,7 +2,7 @@ namespace Octokit { - public enum RepositoryInvitationPermission + public enum InvitationPermissionType { Read, Write, @@ -14,7 +14,7 @@ public RepositoryInvitation() { } - public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, RepositoryInvitationPermission permissions, DateTimeOffset createdAt, string url, string htmlUrl) + public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, InvitationPermissionType permissions, DateTimeOffset createdAt, string url, string htmlUrl) { Id = id; Repository = repository; @@ -34,7 +34,7 @@ public RepositoryInvitation(int id, Repository repository, User invitee, User in public User Inviter { get; protected set; } - public RepositoryInvitationPermission Permissions { get; protected set; } + public InvitationPermissionType Permissions { get; protected set; } public DateTimeOffset CreatedAt { get; set; } From a0eb6db5987c8f6f3b072d6bc274bf94648efd51 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 09:24:51 +0200 Subject: [PATCH 09/47] add observable client --- .../IObservableRepoCollaboratorsClient.cs | 9 ++ .../IObservableRepositoryInvitationsClient.cs | 64 +++++++++++++ .../ObservableRepoCollaboratorsClient.cs | 18 +++- .../ObservableRepositoryInvitationsClient.cs | 93 +++++++++++++++++++ Octokit.Reactive/Octokit.Reactive.csproj | 2 + Octokit/Clients/IRepositoriesClient.cs | 8 ++ Octokit/Clients/RepositoriesClient.cs | 9 ++ 7 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs diff --git a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs index 3d5d09d067..b30a585856 100644 --- a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs @@ -40,6 +40,15 @@ public interface IObservableRepoCollaboratorsClient /// IObservable Add(string owner, string repo, string user); + /// + /// Invites a user as a collaborator to a repository. + /// + /// The owner of the repository + /// The name of the repository + /// Username of the prospective collaborator + /// + IObservable Invite(string owner, string repo, string user); + /// /// Removes a user as a collaborator for a repository. /// diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs new file mode 100644 index 0000000000..66f19e28e7 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -0,0 +1,64 @@ +using System; +using System.Reactive; + +namespace Octokit.Reactive +{ + public interface IObservableRepositoryInvitationsClient + { + /// + /// Accept a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + IObservable Accept(int id); + + /// + /// Decline a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + IObservable Decline(int id); + + /// + /// Deletes a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + IObservable Delete(int repositoryId, int invitationId); + + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + IObservable GetAllForCurrent(int id); + + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + IObservable GetAllForRepository(int id); + + /// + /// Updates a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions); + } +} diff --git a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs index 800b976fdf..dcaa514155 100644 --- a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs @@ -44,7 +44,7 @@ public IObservable GetAll(string owner, string repo, ApiOptions options) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNull(options, "options"); - + return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, repo), options); } @@ -72,6 +72,22 @@ public IObservable Add(string owner, string repo, string user) return _client.Add(owner, repo, user).ToObservable(); } + /// + /// Invites a user as a collaborator to a repository. + /// + /// The owner of the repository + /// The name of the repository + /// Username of the prospective collaborator + /// + public IObservable Invite(string owner, string repo, string user) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return _client.Invite(owner, repo, user).ToObservable(); + } + /// /// Removes a user as a collaborator for a repository. /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs new file mode 100644 index 0000000000..a2e42a3f07 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -0,0 +1,93 @@ +using Octokit.Reactive.Internal; +using System; +using System.Reactive; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + public class ObservableRepositoryInvitationsClient : IObservableRepositoryInvitationsClient + { + readonly IRepositoryInvitationsClient _client; + readonly IConnection _connection; + + public ObservableRepositoryInvitationsClient(IGitHubClient client) + { + _client = client.Repository.Invitation; + _connection = client.Connection; + } + + /// + /// Accept a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + public IObservable Accept(int id) + { + return _client.Accept(id).ToObservable(); + } + + /// + /// Decline a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + public IObservable Decline(int id) + { + return _client.Decline(id).ToObservable(); + } + + /// + /// Deletes a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + public IObservable Delete(int repositoryId, int invitationId) + { + return _client.Delete(repositoryId, invitationId).ToObservable(); + } + + /// + /// Updates a repository invitation. + /// + /// + /// See the API documentation for more information. + /// + /// The id ot the repository + /// The id of the invitation + public IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions) + { + return _client.Edit(repositoryId, invitationId, permissions).ToObservable(); + } + + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the invitation + public IObservable GetAllForCurrent(int id) + { + return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview, null); + } + + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + public IObservable GetAllForRepository(int id) + { + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(id), null, AcceptHeaders.InvitationsApiPreview, null); + } + } +} diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index fc0a2dfa7a..1dcc302081 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -100,6 +100,7 @@ + @@ -134,6 +135,7 @@ + diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 5ae6b1decc..7b3e632f0f 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -668,5 +668,13 @@ public interface IRepositoriesClient /// See the Repository Pages API documentation for more information. /// IRepositoryPagesClient Page { get; } + + /// + /// A client for GitHub's Repository Invitations API. + /// + /// + /// See the Repository Invitations API documentation for more information. + /// + IRepositoryInvitationsClient Invitation { get; } } } diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 8508e4db17..de0a1d94dc 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -45,6 +45,7 @@ public RepositoriesClient(IApiConnection apiConnection) : base(apiConnection) Merging = new MergingClient(apiConnection); Content = new RepositoryContentsClient(apiConnection); Page = new RepositoryPagesClient(apiConnection); + Invitation = new RepositoryInvitationsClient(apiConnection); } /// @@ -989,5 +990,13 @@ public Task GetBranch(string owner, string name, string branchName) /// See the Repository Pages API documentation for more information. /// public IRepositoryPagesClient Page { get; private set; } + + /// + /// A client for GitHub's Repository Invitations API. + /// + /// + /// See the Repository Invitations API documentation for more information. + /// + public IRepositoryInvitationsClient Invitation { get; private set; } } } From abc4b08a2067ab4f06a5145f74ec07c4b942ef08 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 09:52:30 +0200 Subject: [PATCH 10/47] add dependings --- Octokit.Reactive/Octokit.Reactive-Mono.csproj | 2 ++ Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj | 2 ++ Octokit.Reactive/Octokit.Reactive-Monotouch.csproj | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 8d12e95177..88aeccc945 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -192,6 +192,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index 67daf9d4bb..d660fefdce 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -208,6 +208,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index 52fc933fe4..227135c78b 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -204,6 +204,8 @@ + + From cd95700ed8aa0debd6d2bae69f2d2c931713a3d2 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 10:00:22 +0200 Subject: [PATCH 11/47] add missing observable client --- .../Clients/IObservableRepositoriesClient.cs | 9 +++++++++ Octokit.Reactive/Clients/ObservableRepositoriesClient.cs | 9 +++++++++ Octokit/Models/Request/InvitationUpdate.cs | 7 ++----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs index 952dd82a61..4bab6da42b 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs @@ -597,6 +597,7 @@ public interface IObservableRepositoriesClient /// See the Repository Deploy Keys API documentation for more information. /// IObservableRepositoryDeployKeysClient DeployKeys { get; } + /// /// A client for GitHub's Repository Pages API. /// @@ -604,5 +605,13 @@ public interface IObservableRepositoriesClient /// See the Repository Pages API documentation for more information. /// IObservableRepositoryPagesClient Page { get; } + + /// + /// A client for GitHub's Repository Invitations API. + /// + /// + /// See the Repository Invitations API documentation for more information. + /// + IObservableRepositoryInvitationsClient Invitation { get; } } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs index c4839ea021..fa6f1f7c28 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs @@ -42,6 +42,7 @@ public ObservableRepositoriesClient(IGitHubClient client) Content = new ObservableRepositoryContentsClient(client); Merging = new ObservableMergingClient(client); Page = new ObservableRepositoryPagesClient(client); + Invitation = new ObservableRepositoryInvitationsClient(client); } /// @@ -900,5 +901,13 @@ public IObservable Compare(string owner, string name, string @bas /// See the Repository Pages API documentation for more information. /// public IObservableRepositoryPagesClient Page { get; private set; } + + /// + /// A client for GitHub's Repository Invitations API. + /// + /// + /// See the Repository Invitations API documentation for more information. + /// + public IObservableRepositoryInvitationsClient Invitation { get; private set; } } } diff --git a/Octokit/Models/Request/InvitationUpdate.cs b/Octokit/Models/Request/InvitationUpdate.cs index 8aa395a04f..82c4a1b5e9 100644 --- a/Octokit/Models/Request/InvitationUpdate.cs +++ b/Octokit/Models/Request/InvitationUpdate.cs @@ -5,12 +5,9 @@ namespace Octokit { /// - /// Used to update a gist and its contents. + /// Used to update a invitation. /// - /// - /// Note: All files from the previous version of the gist are carried over by default if not included in the - /// object. Deletes can be performed by including the filename with a null object. - /// API docs: https://developer.github.com/v3/gists/ + /// /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class InvitationUpdate From aba86536aac8cb119ba4831a883f09aa0fa2ec8d Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 10:22:47 +0200 Subject: [PATCH 12/47] add missing xml params --- .../Clients/IObservableRepositoryInvitationsClient.cs | 3 ++- .../Clients/ObservableRepositoryInvitationsClient.cs | 3 ++- Octokit/Clients/IRepositoryInvitationsClient.cs | 1 + Octokit/Clients/RepositoryInvitationsClient.cs | 1 + Octokit/Http/ApiConnection.cs | 1 + Octokit/Http/Connection.cs | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index 66f19e28e7..051386db08 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -58,7 +58,8 @@ public interface IObservableRepositoryInvitationsClient /// See the API documentation for more information. /// /// The id ot the repository - /// The id of the invitation + /// The id of the invitation + /// The permission for the collsborator IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index a2e42a3f07..d1455d3c5f 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -60,7 +60,8 @@ public IObservable Delete(int repositoryId, int invitationId) /// See the API documentation for more information. /// /// The id ot the repository - /// The id of the invitation + /// The id of the invitation + /// The permission for the collsborator public IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { return _client.Edit(repositoryId, invitationId, permissions).ToObservable(); diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index a4ddaa5150..b48cb62c69 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -75,6 +75,7 @@ public interface IRepositoryInvitationsClient /// /// The id ot the repository /// The id of the invitation + /// The permission for the collsborator /// Thrown when a general API error occurs. /// Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions); diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 48733cbb11..b0897f064d 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -90,6 +90,7 @@ public Task> GetAllForRepository(int id) /// /// The id ot the repository /// The id of the invitation + /// The permission for the collsborator /// Thrown when a general API error occurs. /// public Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions) diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 593617fc76..988d7f0d32 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -391,6 +391,7 @@ public Task Patch(Uri uri) /// Updates the API resource at the specified URI. /// /// URI of the API resource to patch + /// Accept header to use for the API request /// A for the request's execution. public Task Patch(Uri uri, string accepts) { diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 38fd4bba13..c98b76e3ed 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -389,6 +389,7 @@ public async Task Patch(Uri uri) /// Performs an asynchronous HTTP PATCH request. /// /// URI endpoint to send request to + /// Specifies accept response media type /// representing the received HTTP response public async Task Patch(Uri uri, string accepts) { From eb79e6ad529a69bc18f6b635308551fe7f4cfd19 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 10:46:52 +0200 Subject: [PATCH 13/47] check client --- .../Clients/ObservableRepositoryInvitationsClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index d1455d3c5f..49b43ccd17 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -12,6 +12,8 @@ public class ObservableRepositoryInvitationsClient : IObservableRepositoryInvita public ObservableRepositoryInvitationsClient(IGitHubClient client) { + Ensure.ArgumentNotNull(client, "client"); + _client = client.Repository.Invitation; _connection = client.Connection; } From a1b0fcbc94d21cb54717958b67a7aee1b1c2b316 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 11:05:45 +0200 Subject: [PATCH 14/47] change repository invitation model --- .../Clients/RepoCollaboratorsClientTests.cs | 26 +++++++++++++++ .../Models/Response/RepositoryInvitation.cs | 33 ++++++++++++------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index d79c82a806..474e6aa779 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -146,6 +146,32 @@ public async Task EnsuresNonNullArguments() } } + public class TheInviteMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + client.Invite("owner", "test", "user1"); + connection.Received().Put(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Any(), Arg.Any(), Arg.Is("application/vnd.github.swamp-thing-preview+json")); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepoCollaboratorsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Invite(null, "test", "user1")); + await Assert.ThrowsAsync(() => client.Invite("", "test", "user1")); + await Assert.ThrowsAsync(() => client.Invite("owner", null, "user1")); + await Assert.ThrowsAsync(() => client.Invite("owner", "", "user1")); + await Assert.ThrowsAsync(() => client.Invite("owner", "test", "")); + await Assert.ThrowsAsync(() => client.Invite("owner", "test", null)); + } + } + public class TheDeleteMethod { [Fact] diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs index 3b96d34b3e..b4c48f623b 100644 --- a/Octokit/Models/Response/RepositoryInvitation.cs +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.Globalization; namespace Octokit { @@ -8,12 +10,10 @@ public enum InvitationPermissionType Write, Admin } + + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RepositoryInvitation { - public RepositoryInvitation() - { - } - public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, InvitationPermissionType permissions, DateTimeOffset createdAt, string url, string htmlUrl) { Id = id; @@ -26,20 +26,29 @@ public RepositoryInvitation(int id, Repository repository, User invitee, User in HtmlUrl = htmlUrl; } - public int Id { get; protected set; } + public int Id { get; private set; } - public Repository Repository { get; protected set; } + public Repository Repository { get; private set; } - public User Invitee { get; protected set; } + public User Invitee { get; private set; } - public User Inviter { get; protected set; } + public User Inviter { get; private set; } - public InvitationPermissionType Permissions { get; protected set; } + public InvitationPermissionType Permissions { get; private set; } - public DateTimeOffset CreatedAt { get; set; } + public DateTimeOffset CreatedAt { get; private set; } - public string Url { get; protected set; } + public string Url { get; private set; } - public string HtmlUrl { get; protected set; } + public string HtmlUrl { get; private set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, + "Repository Invitation: Id: {0} Permissions: {1}", Id, Permissions); + } + } } } From 721ab95f2484bf9b33bb30c348980519baaa2357 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 12:34:17 +0200 Subject: [PATCH 15/47] [WIP] tests --- .../ObservableRepoCollaboratorsClientTests.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs index 97ee4cf9dc..b19410204c 100644 --- a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs @@ -170,6 +170,71 @@ public void CallsCreateOnRegularDeploymentsClient() } } + public class TheInviteMethod + { + private readonly IGitHubClient _githubClient; + private IObservableRepoCollaboratorsClient _client; + + public TheInviteMethod() + { + _githubClient = Substitute.For(); + } + + private void SetupWithoutNonReactiveClient() + { + _client = new ObservableRepoCollaboratorsClient(_githubClient); + } + + private void SetupWithNonReactiveClient() + { + var collaboratorsClient = new RepoCollaboratorsClient(Substitute.For()); + _githubClient.Repository.Collaborator.Returns(collaboratorsClient); + _client = new ObservableRepoCollaboratorsClient(_githubClient); + } + + [Fact] + public void EnsuresNonNullArguments() + { + SetupWithNonReactiveClient(); + + Assert.Throws(() => _client.Invite(null, "repo", "user")); + Assert.Throws(() => _client.Invite("owner", null, "user")); + Assert.Throws(() => _client.Invite("owner", "repo", null)); + } + + [Fact] + public void EnsuresNonEmptyArguments() + { + SetupWithNonReactiveClient(); + + Assert.Throws(() => _client.Invite("", "repo", "user")); + Assert.Throws(() => _client.Invite("owner", "", "user")); + } + + [Fact] + public async Task EnsuresNonWhitespaceArguments() + { + SetupWithNonReactiveClient(); + + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.Invite(whitespace, "repo", "user")); + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.Invite("owner", whitespace, "user")); + } + + [Fact] + public void CallsCreateOnRegularDeploymentsClient() + { + SetupWithoutNonReactiveClient(); + + _client.Invite("owner", "repo", "user"); + + _githubClient.Repository.Collaborator.Received(1).Invite(Arg.Is("owner"), + Arg.Is("repo"), + Arg.Is("user")); + } + } + public class TheCtor { [Fact] From 6727c4e4f006746dd345c4f9ae3d3ff792eb5415 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 15:51:06 +0200 Subject: [PATCH 16/47] [WIP] tests; fix overloads for client --- .../RepositoryCollaboratorClientTests.cs | 4 +--- .../RepositoryInvitationsClientTests.cs | 24 +++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + .../Clients/IRepositoryInvitationsClient.cs | 4 ++-- .../Clients/RepositoryInvitationsClient.cs | 8 +++---- 5 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index a7f227bb63..cfc16b22a3 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -152,9 +152,7 @@ public async Task CanInviteNewCollaborator() // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "maddin2016"); - var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - - Assert.True(isCollab); + Assert.Equal("maddin2016", response.Invitee.Login); } } } diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs new file mode 100644 index 0000000000..0022fb9b37 --- /dev/null +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -0,0 +1,24 @@ +using NSubstitute; +using Octokit; +using System; +using System.Threading.Tasks; +using Xunit; + +public class RepositoryInvitationsClientTests +{ + public class TheGetAllForRepositoryMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + + await client.GetAllForRepository(1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/invitations"), "application/vnd.github.swamp-thing-preview+json"); + } + } + +} + diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index ba16b864df..e6f638c83b 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -104,6 +104,7 @@ + diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index b48cb62c69..8d4bd2bf6e 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -53,7 +53,7 @@ public interface IRepositoryInvitationsClient /// /// The id of the invitation /// Thrown when a general API error occurs. - /// A of . + /// A of . Task> GetAllForCurrent(int id); /// @@ -64,7 +64,7 @@ public interface IRepositoryInvitationsClient /// /// The id of the repository /// Thrown when a general API error occurs. - /// A of . + /// A of . Task> GetAllForRepository(int id); /// diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index b0897f064d..48a88e9ebd 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -62,10 +62,10 @@ public Task Delete(int repositoryId, int invitationId) /// /// The id of the invitation /// Thrown when a general API error occurs. - /// A of . + /// A of . public Task> GetAllForCurrent(int id) { - return ApiConnection.GetAll(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview); + return ApiConnection.GetAll(ApiUrls.UserInvitations(id), AcceptHeaders.InvitationsApiPreview); } /// @@ -76,10 +76,10 @@ public Task> GetAllForCurrent(int id) /// /// The id of the repository /// Thrown when a general API error occurs. - /// A of . + /// A of . public Task> GetAllForRepository(int id) { - return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(id), null, AcceptHeaders.InvitationsApiPreview); + return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(id), AcceptHeaders.InvitationsApiPreview); } /// From ffa599988a06e0f02e848eef510dbd8198a0dac9 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 16:12:11 +0200 Subject: [PATCH 17/47] change GetAllForCurrent; suppress message --- .../IObservableRepositoryInvitationsClient.cs | 7 ++++--- .../ObservableRepositoryInvitationsClient.cs | 5 ++--- .../Clients/RepositoryInvitationsClientTests.cs | 14 ++++++++++++++ Octokit/Clients/IRepositoryInvitationsClient.cs | 5 +++-- Octokit/Clients/RepositoryInvitationsClient.cs | 5 ++--- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index 051386db08..df2a0f0da0 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Reactive; namespace Octokit.Reactive @@ -38,9 +39,9 @@ public interface IObservableRepositoryInvitationsClient /// /// /// See the API documentation for more information. - /// - /// The id of the invitation - IObservable GetAllForCurrent(int id); + /// + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + IObservable GetAllForCurrent(); /// /// Gets all the invitations on a repository. diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index 49b43ccd17..e164a45154 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -75,10 +75,9 @@ public IObservable Edit(int repositoryId, int invitationId /// /// See the API documentation for more information. /// - /// The id of the invitation - public IObservable GetAllForCurrent(int id) + public IObservable GetAllForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview, null); + return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, null); } /// diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs index 0022fb9b37..08909acc88 100644 --- a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -20,5 +20,19 @@ public async Task RequestsCorrectUrl() } } + public class TheGetAllForCurrentMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + + await client.GetAllForCurrent(); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/repository_invitations"), "application/vnd.github.swamp-thing-preview+json"); + } + } + } diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index 8d4bd2bf6e..87b07d338a 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace Octokit @@ -51,10 +52,10 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the invitation /// Thrown when a general API error occurs. /// A of . - Task> GetAllForCurrent(int id); + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + Task> GetAllForCurrent(); /// /// Gets all the invitations on a repository. diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 48a88e9ebd..d2effd018c 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -60,12 +60,11 @@ public Task Delete(int repositoryId, int invitationId) /// /// See the API documentation for more information. /// - /// The id of the invitation /// Thrown when a general API error occurs. /// A of . - public Task> GetAllForCurrent(int id) + public Task> GetAllForCurrent() { - return ApiConnection.GetAll(ApiUrls.UserInvitations(id), AcceptHeaders.InvitationsApiPreview); + return ApiConnection.GetAll(ApiUrls.UserInvitations(), AcceptHeaders.InvitationsApiPreview); } /// From e81dde8100c7aa1112c4eaf553b49d8f740dd107 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 1 Jul 2016 16:32:06 +0200 Subject: [PATCH 18/47] some more tests --- .../RepositoryInvitationsClientTests.cs | 57 +++++++++++++++++++ .../Clients/RepositoryInvitationsClient.cs | 4 +- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs index 08909acc88..d672ee04ab 100644 --- a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -34,5 +34,62 @@ public async Task RequestsCorrectUrl() } } + public class TheAcceptMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + + await client.Accept(1); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "user/repository_invitations/1"), "application/vnd.github.swamp-thing-preview+json"); + } + } + + public class TheDeclineMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + + await client.Decline(1); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "user/repository_invitations/1"), Arg.Any(), "application/vnd.github.swamp-thing-preview+json"); + } + } + + public class TheDeleteMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + + await client.Delete(1, 2); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/invitations/2"), Arg.Any(), "application/vnd.github.swamp-thing-preview+json"); + } + } + + public class TheEditMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + var updatedInvitation = new InvitationUpdate(InvitationPermissionType.Read); + + await client.Edit(1, 2, updatedInvitation); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repositories/1/invitations/2"), Arg.Is(updatedInvitation), "application/vnd.github.swamp-thing-preview+json"); + } + } + } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index d2effd018c..8ed923c79a 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -36,7 +36,7 @@ public Task Accept(int id) /// public Task Decline(int id) { - return ApiConnection.Delete(ApiUrls.UserInvitations(id), null, AcceptHeaders.InvitationsApiPreview); + return ApiConnection.Delete(ApiUrls.UserInvitations(id), new object(), AcceptHeaders.InvitationsApiPreview); } /// @@ -51,7 +51,7 @@ public Task Decline(int id) /// public Task Delete(int repositoryId, int invitationId) { - return ApiConnection.Delete(ApiUrls.RepositoryInvitations(repositoryId, invitationId), null, AcceptHeaders.InvitationsApiPreview); + return ApiConnection.Delete(ApiUrls.RepositoryInvitations(repositoryId, invitationId), new object(), AcceptHeaders.InvitationsApiPreview); } /// From 7b7d60e1b2545174211d6f6b3a6b2a0bdf45ce5f Mon Sep 17 00:00:00 2001 From: lrz-hal Date: Sun, 3 Jul 2016 17:46:54 +0200 Subject: [PATCH 19/47] [WIP] --- .../Clients/IObservableRepositoryInvitationsClient.cs | 2 +- .../Clients/ObservableRepositoryInvitationsClient.cs | 6 +++--- .../Clients/RepositoryCollaboratorClientTests.cs | 2 +- .../Clients/RepositoryInvitationsClientTests.cs | 9 +++++++++ Octokit/Clients/IRepositoryInvitationsClient.cs | 4 ++-- Octokit/Clients/RepositoryInvitationsClient.cs | 6 +++--- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index df2a0f0da0..dff54087dc 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -50,7 +50,7 @@ public interface IObservableRepositoryInvitationsClient /// See the API documentation for more information. /// /// The id of the repository - IObservable GetAllForRepository(int id); + IObservable GetAllForRepository(int repositroyId); /// /// Updates a repository invitation. diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index e164a45154..f722462d7c 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -86,10 +86,10 @@ public IObservable GetAllForCurrent() /// /// See the API documentation for more information. /// - /// The id of the repository - public IObservable GetAllForRepository(int id) + /// The id of the repository + public IObservable GetAllForRepository(int repositoryId) { - return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(id), null, AcceptHeaders.InvitationsApiPreview, null); + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, null); } } } diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index cfc16b22a3..53ed6aa3bf 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -150,7 +150,7 @@ public async Task CanInviteNewCollaborator() var fixture = github.Repository.Collaborator; // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "maddin2016"); + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "lrz-hal"); Assert.Equal("maddin2016", response.Invitee.Login); } diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs index d672ee04ab..db07275e8f 100644 --- a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -6,6 +6,15 @@ public class RepositoryInvitationsClientTests { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new RepositoryInvitationsClient(null)); + } + } + public class TheGetAllForRepositoryMethod { [Fact] diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index 87b07d338a..0f8df95747 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -63,10 +63,10 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the repository /// Thrown when a general API error occurs. /// A of . - Task> GetAllForRepository(int id); + Task> GetAllForRepository(int repositoryId); /// /// Updates a repository invitation. diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 8ed923c79a..065c225a17 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -73,12 +73,12 @@ public Task> GetAllForCurrent() /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the repository /// Thrown when a general API error occurs. /// A of . - public Task> GetAllForRepository(int id) + public Task> GetAllForRepository(int repositoryId) { - return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(id), AcceptHeaders.InvitationsApiPreview); + return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(repositoryId), AcceptHeaders.InvitationsApiPreview); } /// From 29b6f07a3a61eabb74c29910643dc7b5507fd2fc Mon Sep 17 00:00:00 2001 From: lrz-hal Date: Sun, 3 Jul 2016 20:46:36 +0200 Subject: [PATCH 20/47] [WIP] --- .../Clients/IObservableRepositoryInvitationsClient.cs | 5 ++++- .../Clients/RepositoryCollaboratorClientTests.cs | 4 ++-- .../Reactive/ObservableRepoCollaboratorsClientTests.cs | 5 ++++- Octokit/Clients/IRepoCollaboratorsClient.cs | 2 +- Octokit/Clients/IRepositoryInvitationsClient.cs | 6 +++--- Octokit/Clients/RepositoryInvitationsClient.cs | 6 +++--- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index dff54087dc..5537c1cfd8 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -40,6 +40,7 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// + /// /// A of . [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAllForCurrent(); @@ -49,7 +50,8 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the repository + /// A of . IObservable GetAllForRepository(int repositroyId); /// @@ -61,6 +63,7 @@ public interface IObservableRepositoryInvitationsClient /// The id ot the repository /// The id of the invitation /// The permission for the collsborator + /// IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions); } } diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index 53ed6aa3bf..8d0b211ff2 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -137,7 +137,7 @@ public async Task ReturnsTrueIfUserIsCollaborator() } } - public class TheInviteNewCollaboratorMethod + public class TheInviteMethod { [IntegrationTest] public async Task CanInviteNewCollaborator() @@ -152,7 +152,7 @@ public async Task CanInviteNewCollaborator() // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "lrz-hal"); - Assert.Equal("maddin2016", response.Invitee.Login); + Assert.Equal("lrz-hal", response.Invitee.Login); } } } diff --git a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs index b19410204c..3b8dc124ed 100644 --- a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs @@ -209,6 +209,7 @@ public void EnsuresNonEmptyArguments() Assert.Throws(() => _client.Invite("", "repo", "user")); Assert.Throws(() => _client.Invite("owner", "", "user")); + Assert.Throws(() => _client.Invite("owner", "repo", "")); } [Fact] @@ -220,10 +221,12 @@ await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.Invite(whitespace, "repo", "user")); await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.Invite("owner", whitespace, "user")); + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.Invite("owner", "repo", whitespace)); } [Fact] - public void CallsCreateOnRegularDeploymentsClient() + public void CallsInviteOnRegularDeploymentsClient() { SetupWithoutNonReactiveClient(); diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 4b08814353..829a7e8bc1 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -65,7 +65,7 @@ public interface IRepoCollaboratorsClient /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// + /// Task Invite(string owner, string repo, string user); /// diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index 0f8df95747..b8a184d2e8 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -53,7 +53,7 @@ public interface IRepositoryInvitationsClient /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// A of . + /// A of . [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] Task> GetAllForCurrent(); @@ -65,7 +65,7 @@ public interface IRepositoryInvitationsClient /// /// The id of the repository /// Thrown when a general API error occurs. - /// A of . + /// A of . Task> GetAllForRepository(int repositoryId); /// @@ -78,7 +78,7 @@ public interface IRepositoryInvitationsClient /// The id of the invitation /// The permission for the collsborator /// Thrown when a general API error occurs. - /// + /// Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions); } } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 065c225a17..2f511eb839 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -61,7 +61,7 @@ public Task Delete(int repositoryId, int invitationId) /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// A of . + /// A of . public Task> GetAllForCurrent() { return ApiConnection.GetAll(ApiUrls.UserInvitations(), AcceptHeaders.InvitationsApiPreview); @@ -75,7 +75,7 @@ public Task> GetAllForCurrent() /// /// The id of the repository /// Thrown when a general API error occurs. - /// A of . + /// A of . public Task> GetAllForRepository(int repositoryId) { return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(repositoryId), AcceptHeaders.InvitationsApiPreview); @@ -91,7 +91,7 @@ public Task> GetAllForRepository(int reposit /// The id of the invitation /// The permission for the collsborator /// Thrown when a general API error occurs. - /// + /// public Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { return ApiConnection.Patch(ApiUrls.RepositoryInvitations(repositoryId, invitationId), permissions, AcceptHeaders.InvitationsApiPreview); From 24920c9e9f988434a7d5f2ccb7b312af044240c7 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 08:35:52 +0200 Subject: [PATCH 21/47] add collaborator request model --- Octokit/Models/Request/CollaboratorRequest.cs | 24 +++++++++++++++++++ Octokit/Octokit.csproj | 1 + 2 files changed, 25 insertions(+) create mode 100644 Octokit/Models/Request/CollaboratorRequest.cs diff --git a/Octokit/Models/Request/CollaboratorRequest.cs b/Octokit/Models/Request/CollaboratorRequest.cs new file mode 100644 index 0000000000..7f21d7625c --- /dev/null +++ b/Octokit/Models/Request/CollaboratorRequest.cs @@ -0,0 +1,24 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CollaboratorRequest + { + public CollaboratorRequest(Permission permissions) + { + Permissions = permissions; + } + + public Permission Permissions { get; private set; } + + internal string DebuggerDisplay + { + get + { + return string.Format(CultureInfo.InvariantCulture, "Permission: {0}", Permissions); + } + } + } +} diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 29ec176558..062bd93198 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -134,6 +134,7 @@ + From 3eb7bd4ebc2e6274bfcef83aeda9df0574b56912 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 09:26:26 +0200 Subject: [PATCH 22/47] change return types change return types for invitation methods. add permission attribute for repository collaborators invite method. --- .../IObservableRepositoryInvitationsClient.cs | 20 ++++---- .../ObservableRepositoryInvitationsClient.cs | 24 ++++----- Octokit/Clients/IRepoCollaboratorsClient.cs | 12 +++-- .../Clients/IRepositoryInvitationsClient.cs | 12 ++--- Octokit/Clients/RepoCollaboratorsClient.cs | 18 +++++-- .../Clients/RepositoryInvitationsClient.cs | 51 +++++++++++++++---- Octokit/Models/Request/CollaboratorRequest.cs | 11 ++-- 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 + 12 files changed, 101 insertions(+), 52 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index 5537c1cfd8..8daf0a8278 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -12,8 +12,8 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the invitation - IObservable Accept(int id); + /// The id of the invitation. + IObservable Accept(int invitationId); /// /// Decline a repository invitation. @@ -21,8 +21,8 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the invitation - IObservable Decline(int id); + /// The id of the invitation. + IObservable Decline(int invitationId); /// /// Deletes a repository invitation. @@ -30,8 +30,8 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository - /// The id of the invitation + /// The id ot the repository. + /// The id of the invitation. IObservable Delete(int repositoryId, int invitationId); /// @@ -40,7 +40,7 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// /// A of . + /// A of . [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAllForCurrent(); @@ -60,9 +60,9 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository - /// The id of the invitation - /// The permission for the collsborator + /// The id ot the repository. + /// The id of the invitation. + /// The permission to set. /// IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions); } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index f722462d7c..7bd6026107 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -24,10 +24,10 @@ public ObservableRepositoryInvitationsClient(IGitHubClient client) /// /// See the API documentation for more information. /// - /// The id of the invitation - public IObservable Accept(int id) + /// The id of the invitation. + public IObservable Accept(int invitationId) { - return _client.Accept(id).ToObservable(); + return _client.Accept(invitationId).ToObservable(); } /// @@ -36,10 +36,10 @@ public IObservable Accept(int id) /// /// See the API documentation for more information. /// - /// The id of the invitation - public IObservable Decline(int id) + /// The id of the invitation. + public IObservable Decline(int invitationId) { - return _client.Decline(id).ToObservable(); + return _client.Decline(invitationId).ToObservable(); } /// @@ -48,9 +48,9 @@ public IObservable Decline(int id) /// /// See the API documentation for more information. /// - /// The id ot the repository - /// The id of the invitation - public IObservable Delete(int repositoryId, int invitationId) + /// The id ot the repository. + /// The id of the invitation. + public IObservable Delete(int repositoryId, int invitationId) { return _client.Delete(repositoryId, invitationId).ToObservable(); } @@ -61,9 +61,9 @@ public IObservable Delete(int repositoryId, int invitationId) /// /// See the API documentation for more information. /// - /// The id ot the repository - /// The id of the invitation - /// The permission for the collsborator + /// The id ot the repository. + /// The id of the invitatio.n + /// The permission to set. public IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { return _client.Edit(repositoryId, invitationId, permissions).ToObservable(); diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 829a7e8bc1..03c3f54a48 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -54,8 +54,7 @@ public interface IRepoCollaboratorsClient /// /// See the API documentation for more information. /// - /// Thrown when a general API error occurs. - /// + /// Thrown when a general API error occurs. Task Add(string owner, string repo, string user); /// @@ -64,9 +63,13 @@ public interface IRepoCollaboratorsClient /// /// See the API documentation for more information. /// + /// The owner of the repository. + /// The name of the repository. + /// The name of the user to invite. + /// The permission to set. /// Thrown when a general API error occurs. - /// - Task Invite(string owner, string repo, string user); + /// + Task Invite(string owner, string repo, string user, CollaboratorRequest permission); /// /// Deletes a collaborator from the repo @@ -75,7 +78,6 @@ public interface IRepoCollaboratorsClient /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// Task Delete(string owner, string repo, string user); } } diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index b8a184d2e8..c5d8405e9a 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -18,10 +18,9 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the invitation + /// The id of the invitation /// Thrown when a general API error occurs. - /// - Task Accept(int id); + Task Accept(int invitationId); /// /// Decline a repository invitation. @@ -29,10 +28,10 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the invitation + /// The id of the invitation /// Thrown when a general API error occurs. /// - Task Decline(int id); + Task Decline(int invitationId); /// /// Deletes a repository invitation. @@ -43,8 +42,7 @@ public interface IRepositoryInvitationsClient /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. - /// - Task Delete(int repositoryId, int invitationId); + Task Delete(int repositoryId, int invitationId); /// /// Gets all invitations for the current user. diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 98f48419cd..20e2d1e520 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -92,7 +92,6 @@ public async Task IsCollaborator(string owner, string repo, string user) /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// public Task Add(string owner, string repo, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -109,7 +108,6 @@ public Task Add(string owner, string repo, string user) /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// public Task Delete(string owner, string repo, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -119,13 +117,25 @@ public Task Delete(string owner, string repo, string user) return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, repo, user)); } - public Task Invite(string owner, string repo, string user) + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository. + /// The name of the repository. + /// The name of the user to invite. + /// The permission to set. + /// Thrown when a general API error occurs. + /// + public Task Invite(string owner, string repo, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), new object(), null, AcceptHeaders.InvitationsApiPreview); + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), permission, null, AcceptHeaders.InvitationsApiPreview); } } } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 2f511eb839..18802814f0 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; namespace Octokit @@ -17,12 +18,22 @@ public RepositoryInvitationsClient(IApiConnection apiConnection) /// /// See the API documentation for more information. /// - /// The id of the invitation + /// The id of the invitation /// Thrown when a general API error occurs. /// - public Task Accept(int id) + public async Task Accept(int invitationId) { - return ApiConnection.Patch(ApiUrls.UserInvitations(id), AcceptHeaders.InvitationsApiPreview); + var endpoint = ApiUrls.UserInvitations(invitationId); + + try + { + var httpStatusCode = await ApiConnection.Connection.Patch(endpoint, AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch + { + return false; + } } /// @@ -31,12 +42,21 @@ public Task Accept(int id) /// /// See the API documentation for more information. /// - /// The id of the invitation - /// Thrown when a general API error occurs. - /// - public Task Decline(int id) + /// The id of the invitation + /// Thrown when a general API error occurs. + public async Task Decline(int invitationId) { - return ApiConnection.Delete(ApiUrls.UserInvitations(id), new object(), AcceptHeaders.InvitationsApiPreview); + var endpoint = ApiUrls.UserInvitations(invitationId); + + try + { + var httpStatusCode = await ApiConnection.Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch + { + return false; + } } /// @@ -48,10 +68,19 @@ public Task Decline(int id) /// The id ot the repository /// The id of the invitation /// Thrown when a general API error occurs. - /// - public Task Delete(int repositoryId, int invitationId) + public async Task Delete(int repositoryId, int invitationId) { - return ApiConnection.Delete(ApiUrls.RepositoryInvitations(repositoryId, invitationId), new object(), AcceptHeaders.InvitationsApiPreview); + var endpoint = ApiUrls.RepositoryInvitations(repositoryId, invitationId); + + try + { + var httpStatusCode = await ApiConnection.Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch + { + return false; + } } /// diff --git a/Octokit/Models/Request/CollaboratorRequest.cs b/Octokit/Models/Request/CollaboratorRequest.cs index 7f21d7625c..b4b2a424fc 100644 --- a/Octokit/Models/Request/CollaboratorRequest.cs +++ b/Octokit/Models/Request/CollaboratorRequest.cs @@ -6,18 +6,23 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class CollaboratorRequest { + public CollaboratorRequest() + { + Permission = Permission.Push; + } + public CollaboratorRequest(Permission permissions) { - Permissions = permissions; + Permission = permissions; } - public Permission Permissions { get; private set; } + public Permission Permission { get; private set; } internal string DebuggerDisplay { get { - return string.Format(CultureInfo.InvariantCulture, "Permission: {0}", Permissions); + return string.Format(CultureInfo.InvariantCulture, "Permission: {0}", Permission); } } } diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 58c0d0bf96..03ec21b2ea 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -489,6 +489,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 10aa240a88..95fdfeef52 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -500,6 +500,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 59d075b4b7..6f6c6b5e62 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -496,6 +496,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index e7c3362501..5569e3027a 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -486,6 +486,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 0b57edf8d7..dc6ca4da58 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -493,6 +493,7 @@ + From e65d596dc122e499d79d8aef5203a53c13fe19ab Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 10:10:28 +0200 Subject: [PATCH 23/47] add some more tests --- .../IObservableRepoCollaboratorsClient.cs | 5 +- .../IObservableRepositoryInvitationsClient.cs | 10 +- .../ObservableRepoCollaboratorsClient.cs | 8 +- .../ObservableRepositoryInvitationsClient.cs | 5 +- .../RepositoryCollaboratorClientTests.cs | 4 +- .../Clients/RepoCollaboratorsClientTests.cs | 22 ++-- Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableRepoCollaboratorsClientTests.cs | 28 +++-- ...ervableRepositoryInvitationsClientTests.cs | 104 ++++++++++++++++++ 9 files changed, 154 insertions(+), 33 deletions(-) create mode 100644 Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs index b30a585856..6501963915 100644 --- a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs @@ -45,9 +45,10 @@ public interface IObservableRepoCollaboratorsClient /// /// The owner of the repository /// The name of the repository - /// Username of the prospective collaborator + /// The username of the prospective collaborator + /// The permission to set /// - IObservable Invite(string owner, string repo, string user); + IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission); /// /// Removes a user as a collaborator for a repository. diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index 8daf0a8278..fc06372aee 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -13,7 +13,7 @@ public interface IObservableRepositoryInvitationsClient /// See the API documentation for more information. /// /// The id of the invitation. - IObservable Accept(int invitationId); + IObservable Accept(int invitationId); /// /// Decline a repository invitation. @@ -22,7 +22,7 @@ public interface IObservableRepositoryInvitationsClient /// See the API documentation for more information. /// /// The id of the invitation. - IObservable Decline(int invitationId); + IObservable Decline(int invitationId); /// /// Deletes a repository invitation. @@ -32,7 +32,7 @@ public interface IObservableRepositoryInvitationsClient /// /// The id ot the repository. /// The id of the invitation. - IObservable Delete(int repositoryId, int invitationId); + IObservable Delete(int repositoryId, int invitationId); /// /// Gets all invitations for the current user. @@ -50,9 +50,9 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the repository + /// The id of the repository /// A of . - IObservable GetAllForRepository(int repositroyId); + IObservable GetAllForRepository(int repositoryId); /// /// Updates a repository invitation. diff --git a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs index dcaa514155..e705d1c652 100644 --- a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs @@ -77,15 +77,17 @@ public IObservable Add(string owner, string repo, string user) /// /// The owner of the repository /// The name of the repository - /// Username of the prospective collaborator + /// The username of the prospective collaborator + /// The permission to set /// - public IObservable Invite(string owner, string repo, string user) + public IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "psermission"); - return _client.Invite(owner, repo, user).ToObservable(); + return _client.Invite(owner, repo, user, permission).ToObservable(); } /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index 7bd6026107..55de284e51 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -1,5 +1,6 @@ using Octokit.Reactive.Internal; using System; +using System.Collections.Generic; using System.Reactive; using System.Reactive.Threading.Tasks; @@ -77,7 +78,7 @@ public IObservable Edit(int repositoryId, int invitationId /// public IObservable GetAllForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, null); + return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, ApiOptions.None); } /// @@ -89,7 +90,7 @@ public IObservable GetAllForCurrent() /// The id of the repository public IObservable GetAllForRepository(int repositoryId) { - return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, null); + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, ApiOptions.None); } } } diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index 8d0b211ff2..062eca0c55 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -148,11 +148,13 @@ public async Task CanInviteNewCollaborator() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(); // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "lrz-hal"); + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "lrz-hal", permission); Assert.Equal("lrz-hal", response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); } } } diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 474e6aa779..a97c63955f 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -154,21 +154,25 @@ public void RequestsCorrectUrl() var connection = Substitute.For(); var client = new RepoCollaboratorsClient(connection); - client.Invite("owner", "test", "user1"); - connection.Received().Put(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Any(), Arg.Any(), Arg.Is("application/vnd.github.swamp-thing-preview+json")); + var permission = new CollaboratorRequest(); + + client.Invite("owner", "test", "user1", permission); + connection.Received().Put(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Is(permission), Arg.Any(), Arg.Is("application/vnd.github.swamp-thing-preview+json")); } [Fact] public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For()); - - await Assert.ThrowsAsync(() => client.Invite(null, "test", "user1")); - await Assert.ThrowsAsync(() => client.Invite("", "test", "user1")); - await Assert.ThrowsAsync(() => client.Invite("owner", null, "user1")); - await Assert.ThrowsAsync(() => client.Invite("owner", "", "user1")); - await Assert.ThrowsAsync(() => client.Invite("owner", "test", "")); - await Assert.ThrowsAsync(() => client.Invite("owner", "test", null)); + var permission = new CollaboratorRequest(); + + await Assert.ThrowsAsync(() => client.Invite(null, "test", "user1", permission)); + await Assert.ThrowsAsync(() => client.Invite("", "test", "user1", permission)); + await Assert.ThrowsAsync(() => client.Invite("owner", null, "user1", permission)); + await Assert.ThrowsAsync(() => client.Invite("owner", "", "user1", permission)); + await Assert.ThrowsAsync(() => client.Invite("owner", "test", "", permission)); + await Assert.ThrowsAsync(() => client.Invite("owner", "test", null, permission)); + await Assert.ThrowsAsync(() => client.Invite("owner", "test", "user1", null)); } } diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index e6f638c83b..0bc6520d8b 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -244,6 +244,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs index 3b8dc124ed..d3de26440e 100644 --- a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs @@ -196,45 +196,51 @@ private void SetupWithNonReactiveClient() public void EnsuresNonNullArguments() { SetupWithNonReactiveClient(); + var permission = new CollaboratorRequest(); - Assert.Throws(() => _client.Invite(null, "repo", "user")); - Assert.Throws(() => _client.Invite("owner", null, "user")); - Assert.Throws(() => _client.Invite("owner", "repo", null)); + Assert.Throws(() => _client.Invite(null, "repo", "user", permission)); + Assert.Throws(() => _client.Invite("owner", null, "user", permission)); + Assert.Throws(() => _client.Invite("owner", "repo", null, permission)); + Assert.Throws(() => _client.Invite("owner", "repo", "user", null)); } [Fact] public void EnsuresNonEmptyArguments() { SetupWithNonReactiveClient(); + var permission = new CollaboratorRequest(); - Assert.Throws(() => _client.Invite("", "repo", "user")); - Assert.Throws(() => _client.Invite("owner", "", "user")); - Assert.Throws(() => _client.Invite("owner", "repo", "")); + Assert.Throws(() => _client.Invite("", "repo", "user", permission)); + Assert.Throws(() => _client.Invite("owner", "", "user", permission)); + Assert.Throws(() => _client.Invite("owner", "repo", "", permission)); } [Fact] public async Task EnsuresNonWhitespaceArguments() { SetupWithNonReactiveClient(); + var permission = new CollaboratorRequest(); await AssertEx.ThrowsWhenGivenWhitespaceArgument( - async whitespace => await _client.Invite(whitespace, "repo", "user")); + async whitespace => await _client.Invite(whitespace, "repo", "user", permission)); await AssertEx.ThrowsWhenGivenWhitespaceArgument( - async whitespace => await _client.Invite("owner", whitespace, "user")); + async whitespace => await _client.Invite("owner", whitespace, "user", permission)); await AssertEx.ThrowsWhenGivenWhitespaceArgument( - async whitespace => await _client.Invite("owner", "repo", whitespace)); + async whitespace => await _client.Invite("owner", "repo", whitespace, permission)); } [Fact] public void CallsInviteOnRegularDeploymentsClient() { SetupWithoutNonReactiveClient(); + var permission = new CollaboratorRequest(); - _client.Invite("owner", "repo", "user"); + _client.Invite("owner", "repo", "user", permission); _githubClient.Repository.Collaborator.Received(1).Invite(Arg.Is("owner"), Arg.Is("repo"), - Arg.Is("user")); + Arg.Is("user"), + Arg.Is(permission)); } } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs new file mode 100644 index 0000000000..53ead6caa6 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs @@ -0,0 +1,104 @@ +using NSubstitute; +using Octokit.Reactive; +using System; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableRepositoryInvitationsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableRepositoryInvitationsClient(null)); + } + } + + public class TheGetAllForRepositoryMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + client.GetAllForRepository(42); + + gitHub.Received().Repository.Invitation.GetAllForRepository(42); + } + } + + public class TheGetAllForCurrentMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + client.GetAllForCurrent(); + + gitHub.Received().Repository.Invitation.GetAllForCurrent(); + } + } + + public class TheAcceptMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + client.Accept(42); + + gitHub.Received().Repository.Invitation.Accept(42); + } + } + + public class TheDeclineMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + client.Decline(42); + + gitHub.Received().Repository.Invitation.Decline(42); + } + } + + public class TheDeleteMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + client.Delete(42, 43); + + gitHub.Received().Repository.Invitation.Delete(42, 43); + } + } + + public class TheEditMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + var update = new InvitationUpdate(InvitationPermissionType.Write); + + client.Edit(42, 43, update); + + gitHub.Received().Repository.Invitation.Edit(42, 43, update); + } + } + } +} \ No newline at end of file From 7536d96762d948f2bdd8de2bec24c6daa5e7a056 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 10:23:47 +0200 Subject: [PATCH 24/47] fix xml doc --- .../Clients/IObservableRepositoryInvitationsClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index fc06372aee..0a97b97947 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -1,6 +1,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Reactive; +using System.Collections.Generic; namespace Octokit.Reactive { From 7451528838d9d7db9f714f1dc894bc9b3aec1746 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 10:37:05 +0200 Subject: [PATCH 25/47] check for null arguments --- .../Clients/ObservableRepositoryInvitationsClient.cs | 2 ++ .../Clients/RepositoryInvitationsClientTests.cs | 8 ++++++++ .../ObservableRepositoryInvitationsClientTests.cs | 9 +++++++++ Octokit/Clients/RepoCollaboratorsClient.cs | 1 + Octokit/Clients/RepositoryInvitationsClient.cs | 2 ++ 5 files changed, 22 insertions(+) diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index 55de284e51..61cc769e8d 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -67,6 +67,8 @@ public IObservable Delete(int repositoryId, int invitationId) /// The permission to set. public IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { + Ensure.ArgumentNotNull(permissions, "persmissions"); + return _client.Edit(repositoryId, invitationId, permissions).ToObservable(); } diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs index db07275e8f..bc874c8f65 100644 --- a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -98,6 +98,14 @@ public async Task RequestsCorrectUrl() connection.Received().Patch(Arg.Is(u => u.ToString() == "repositories/1/invitations/2"), Arg.Is(updatedInvitation), "application/vnd.github.swamp-thing-preview+json"); } + + [Fact] + public async Task EnsureNonNullArguments() + { + var client = new RepositoryInvitationsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.Edit(1, 2, null)); + } } } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs index 53ead6caa6..2a7d9bfe83 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs @@ -99,6 +99,15 @@ public void RequestsCorrectUrl() gitHub.Received().Repository.Invitation.Edit(42, 43, update); } + + [Fact] + public void EnsureNonNullArguments() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + Assert.Throws(() => client.Edit(1, 2, null)); + } } } } \ No newline at end of file diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 20e2d1e520..49663b6ad0 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -134,6 +134,7 @@ public Task Invite(string owner, string repo, string user, Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "permission"); return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), permission, null, AcceptHeaders.InvitationsApiPreview); } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 18802814f0..9026701801 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -123,6 +123,8 @@ public Task> GetAllForRepository(int reposit /// public Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { + Ensure.ArgumentNotNull(permissions, "permissions"); + return ApiConnection.Patch(ApiUrls.RepositoryInvitations(repositoryId, invitationId), permissions, AcceptHeaders.InvitationsApiPreview); } } From 7d8e520ad497eb3079c6f5170edfcaf4bc9536a6 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 11:08:28 +0200 Subject: [PATCH 26/47] fix tests --- Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs index bc874c8f65..374ce74826 100644 --- a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -53,7 +53,7 @@ public async Task RequestsCorrectUrl() await client.Accept(1); - connection.Received().Patch(Arg.Is(u => u.ToString() == "user/repository_invitations/1"), "application/vnd.github.swamp-thing-preview+json"); + connection.Connection.Received().Patch(Arg.Is(u => u.ToString() == "user/repository_invitations/1"), "application/vnd.github.swamp-thing-preview+json"); } } @@ -67,7 +67,7 @@ public async Task RequestsCorrectUrl() await client.Decline(1); - connection.Received().Delete(Arg.Is(u => u.ToString() == "user/repository_invitations/1"), Arg.Any(), "application/vnd.github.swamp-thing-preview+json"); + connection.Connection.Received().Delete(Arg.Is(u => u.ToString() == "user/repository_invitations/1"), Arg.Any(), "application/vnd.github.swamp-thing-preview+json"); } } @@ -81,7 +81,7 @@ public async Task RequestsCorrectUrl() await client.Delete(1, 2); - connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/invitations/2"), Arg.Any(), "application/vnd.github.swamp-thing-preview+json"); + connection.Connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/invitations/2"), Arg.Any(), "application/vnd.github.swamp-thing-preview+json"); } } From 1566f69f3ac6fe7d2f7d40ccbb4b7f3b9b825271 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Mon, 4 Jul 2016 13:37:33 +0200 Subject: [PATCH 27/47] some fixes from @ryangribble --- .../Clients/IObservableRepoCollaboratorsClient.cs | 1 - .../Clients/IObservableRepositoryInvitationsClient.cs | 10 ++++------ .../Clients/ObservableRepoCollaboratorsClient.cs | 1 - .../Clients/ObservableRepositoryInvitationsClient.cs | 4 ++-- .../Clients/RepositoryCollaboratorClientTests.cs | 4 ++-- Octokit.sln | 5 ++++- Octokit/Clients/IRepoCollaboratorsClient.cs | 3 +-- Octokit/Clients/IRepositoryInvitationsClient.cs | 10 +++------- Octokit/Clients/RepositoryInvitationsClient.cs | 8 ++------ Octokit/Helpers/ApiUrls.cs | 4 ++-- 10 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs index 6501963915..2d6ec1264b 100644 --- a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs @@ -56,7 +56,6 @@ public interface IObservableRepoCollaboratorsClient /// The owner of the repository /// The name of the repository /// Username of the prospective collaborator - /// IObservable Delete(string owner, string repo, string user); } } diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index 0a97b97947..b2e9910978 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -30,7 +30,7 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository. + /// The id of the repository. /// The id of the invitation. IObservable Delete(int repositoryId, int invitationId); @@ -39,8 +39,7 @@ public interface IObservableRepositoryInvitationsClient /// /// /// See the API documentation for more information. - /// - /// A of . + /// [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAllForCurrent(); @@ -50,8 +49,7 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id of the repository - /// A of . + /// The id of the repository IObservable GetAllForRepository(int repositoryId); /// @@ -60,7 +58,7 @@ public interface IObservableRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository. + /// The id of the repository. /// The id of the invitation. /// The permission to set. /// diff --git a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs index e705d1c652..049f24cedb 100644 --- a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs @@ -79,7 +79,6 @@ public IObservable Add(string owner, string repo, string user) /// The name of the repository /// The username of the prospective collaborator /// The permission to set - /// public IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index 61cc769e8d..c1c19215db 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -49,7 +49,7 @@ public IObservable Decline(int invitationId) /// /// See the API documentation for more information. /// - /// The id ot the repository. + /// The id of the repository. /// The id of the invitation. public IObservable Delete(int repositoryId, int invitationId) { @@ -62,7 +62,7 @@ public IObservable Delete(int repositoryId, int invitationId) /// /// See the API documentation for more information. /// - /// The id ot the repository. + /// The id of the repository. /// The id of the invitatio.n /// The permission to set. public IObservable Edit(int repositoryId, int invitationId, InvitationUpdate permissions) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index 062eca0c55..e65d6a0c97 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -151,9 +151,9 @@ public async Task CanInviteNewCollaborator() var permission = new CollaboratorRequest(); // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "lrz-hal", permission); + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "maddin2016", permission); - Assert.Equal("lrz-hal", response.Invitee.Login); + Assert.Equal("maddin2016", response.Invitee.Login); Assert.Equal(InvitationPermissionType.Write, response.Permissions); } } diff --git a/Octokit.sln b/Octokit.sln index 18068f4c0a..207fab8235 100644 --- a/Octokit.sln +++ b/Octokit.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Octokit", "Octokit\Octokit.csproj", "{08DD4305-7787-4823-A53F-4D0F725A07F3}" EndProject @@ -96,4 +96,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {397C742D-291E-46BD-99A5-57BB6902FA7B} = {CEC9D451-6291-4EDF-971A-D398144FBF96} + EndGlobalSection EndGlobal diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 03c3f54a48..2413dfd344 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -67,8 +67,7 @@ public interface IRepoCollaboratorsClient /// The name of the repository. /// The name of the user to invite. /// The permission to set. - /// Thrown when a general API error occurs. - /// + /// Thrown when a general API error occurs. Task Invite(string owner, string repo, string user, CollaboratorRequest permission); /// diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index c5d8405e9a..ace7a49ccc 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -29,8 +29,7 @@ public interface IRepositoryInvitationsClient /// See the API documentation for more information. /// /// The id of the invitation - /// Thrown when a general API error occurs. - /// + /// Thrown when a general API error occurs. Task Decline(int invitationId); /// @@ -39,7 +38,7 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id of the repository /// The id of the invitation /// Thrown when a general API error occurs. Task Delete(int repositoryId, int invitationId); @@ -51,7 +50,6 @@ public interface IRepositoryInvitationsClient /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// A of . [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] Task> GetAllForCurrent(); @@ -63,7 +61,6 @@ public interface IRepositoryInvitationsClient /// /// The id of the repository /// Thrown when a general API error occurs. - /// A of . Task> GetAllForRepository(int repositoryId); /// @@ -72,11 +69,10 @@ public interface IRepositoryInvitationsClient /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id of the repository /// The id of the invitation /// The permission for the collsborator /// Thrown when a general API error occurs. - /// Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions); } } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 9026701801..799059c7da 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -20,7 +20,6 @@ public RepositoryInvitationsClient(IApiConnection apiConnection) /// /// The id of the invitation /// Thrown when a general API error occurs. - /// public async Task Accept(int invitationId) { var endpoint = ApiUrls.UserInvitations(invitationId); @@ -65,7 +64,7 @@ public async Task Decline(int invitationId) /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id of the repository /// The id of the invitation /// Thrown when a general API error occurs. public async Task Delete(int repositoryId, int invitationId) @@ -90,7 +89,6 @@ public async Task Delete(int repositoryId, int invitationId) /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// A of . public Task> GetAllForCurrent() { return ApiConnection.GetAll(ApiUrls.UserInvitations(), AcceptHeaders.InvitationsApiPreview); @@ -104,7 +102,6 @@ public Task> GetAllForCurrent() /// /// The id of the repository /// Thrown when a general API error occurs. - /// A of . public Task> GetAllForRepository(int repositoryId) { return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(repositoryId), AcceptHeaders.InvitationsApiPreview); @@ -116,11 +113,10 @@ public Task> GetAllForRepository(int reposit /// /// See the API documentation for more information. /// - /// The id ot the repository + /// The id of the repository /// The id of the invitation /// The permission for the collsborator /// Thrown when a general API error occurs. - /// public Task Edit(int repositoryId, int invitationId, InvitationUpdate permissions) { Ensure.ArgumentNotNull(permissions, "permissions"); diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index a14fda6b65..54c5a416eb 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -2961,7 +2961,7 @@ public static Uri Reactions(int number) } /// - /// Returns the for repository invitations. + /// Returns the for a single repository invitation. /// /// The id of the repository /// The for repository invitations. @@ -2991,7 +2991,7 @@ public static Uri UserInvitations() } /// - /// Returns the for invitations for the current user. + /// Returns the for a single invitation of the current user. /// /// The id of the invitation /// The for invitations for the current user. From a21b3a1dc0158a7d4146408ac097d0c969e3d594 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Tue, 5 Jul 2016 15:41:16 +0200 Subject: [PATCH 28/47] add parameterless constructor for RepositoryInvitation --- Octokit/Models/Response/RepositoryInvitation.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs index b4c48f623b..fbfe0754df 100644 --- a/Octokit/Models/Response/RepositoryInvitation.cs +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -14,6 +14,10 @@ public enum InvitationPermissionType [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RepositoryInvitation { + public RepositoryInvitation() + { + } + public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, InvitationPermissionType permissions, DateTimeOffset createdAt, string url, string htmlUrl) { Id = id; From 8d98235a1f8a491032323e569db80dc40baeccab Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Tue, 5 Jul 2016 15:56:46 +0200 Subject: [PATCH 29/47] change setter --- Octokit/Models/Response/RepositoryInvitation.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs index fbfe0754df..feb69b51f9 100644 --- a/Octokit/Models/Response/RepositoryInvitation.cs +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -30,21 +30,21 @@ public RepositoryInvitation(int id, Repository repository, User invitee, User in HtmlUrl = htmlUrl; } - public int Id { get; private set; } + public int Id { get; protected set; } - public Repository Repository { get; private set; } + public Repository Repository { get; protected set; } - public User Invitee { get; private set; } + public User Invitee { get; protected set; } - public User Inviter { get; private set; } + public User Inviter { get; protected set; } - public InvitationPermissionType Permissions { get; private set; } + public InvitationPermissionType Permissions { get; protected set; } - public DateTimeOffset CreatedAt { get; private set; } + public DateTimeOffset CreatedAt { get; protected set; } - public string Url { get; private set; } + public string Url { get; protected set; } - public string HtmlUrl { get; private set; } + public string HtmlUrl { get; protected set; } internal string DebuggerDisplay { From 85313478ea9d8fe3c620c723603aeee00535a275 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Tue, 5 Jul 2016 15:57:36 +0200 Subject: [PATCH 30/47] change constructor --- Octokit/Models/Response/RepositoryInvitation.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs index feb69b51f9..8ebb93c5ed 100644 --- a/Octokit/Models/Response/RepositoryInvitation.cs +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -14,9 +14,7 @@ public enum InvitationPermissionType [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RepositoryInvitation { - public RepositoryInvitation() - { - } + public RepositoryInvitation() { } public RepositoryInvitation(int id, Repository repository, User invitee, User inviter, InvitationPermissionType permissions, DateTimeOffset createdAt, string url, string htmlUrl) { From f3d0c03c93bdbcc7656accea8bb83f0b6fe006fd Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Wed, 6 Jul 2016 14:58:58 +0200 Subject: [PATCH 31/47] fix merge conflicts --- .../IObservableRepoCollaboratorsClient.cs | 31 +++------ .../ObservableRepoCollaboratorsClient.cs | 45 ++++++------- .../ObservableRepoCollaboratorsClientTests.cs | 10 +-- Octokit/Clients/IRepoCollaboratorsClient.cs | 40 +++++------- Octokit/Clients/RepoCollaboratorsClient.cs | 63 +++++++------------ 5 files changed, 67 insertions(+), 122 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs index ca5371b73a..1f5c04b462 100644 --- a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs @@ -79,31 +79,12 @@ public interface IObservableRepoCollaboratorsClient IObservable IsCollaborator(int repositoryId, string user); /// -<<<<<<< HEAD - /// Invites a user as a collaborator to a repository. - /// - /// The owner of the repository - /// The name of the repository - /// The username of the prospective collaborator - /// The permission to set - /// - IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission); - - /// - /// Removes a user as a collaborator for a repository. -======= /// Adds a new collaborator to the repository. ->>>>>>> refs/remotes/octokit/master /// /// /// See the API documentation for more information. /// /// The owner of the repository -<<<<<<< HEAD - /// The name of the repository - /// Username of the prospective collaborator - IObservable Delete(string owner, string repo, string user); -======= /// The name of the repository /// Username of the new collaborator /// Thrown when a general API error occurs. @@ -120,6 +101,15 @@ public interface IObservableRepoCollaboratorsClient /// Thrown when a general API error occurs. IObservable Add(int repositoryId, string user); + /// + /// Invites a user as a collaborator to a repository. + /// + /// The owner of the repository + /// The name of the repository + /// The username of the prospective collaborator + /// The permission to set + IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission); + /// /// Deletes a collaborator from the repository. /// @@ -142,6 +132,5 @@ public interface IObservableRepoCollaboratorsClient /// Username of the removed collaborator /// Thrown when a general API error occurs. IObservable Delete(int repositoryId, string user); ->>>>>>> refs/remotes/octokit/master } -} +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs index 2e986ce7dd..e1d1585d1e 100644 --- a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs @@ -73,13 +73,8 @@ public IObservable GetAll(string owner, string name, ApiOptions options) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); -<<<<<<< HEAD - return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, repo), options); -======= - return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, name), options); ->>>>>>> refs/remotes/octokit/master } /// @@ -134,28 +129,7 @@ public IObservable IsCollaborator(int repositoryId, string user) } /// -<<<<<<< HEAD - /// Invites a user as a collaborator to a repository. - /// - /// The owner of the repository - /// The name of the repository - /// The username of the prospective collaborator - /// The permission to set - public IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission) - { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); - Ensure.ArgumentNotNullOrEmptyString(user, "user"); - Ensure.ArgumentNotNull(permission, "psermission"); - - return _client.Invite(owner, repo, user, permission).ToObservable(); - } - - /// - /// Removes a user as a collaborator for a repository. -======= /// Adds a new collaborator to the repository. ->>>>>>> refs/remotes/octokit/master /// /// /// See the API documentation for more information. @@ -189,6 +163,23 @@ public IObservable Add(int repositoryId, string user) return _client.Add(repositoryId, user).ToObservable(); } + /// + /// Invites a user as a collaborator to a repository. + /// + /// The owner of the repository + /// The name of the repository + /// The username of the prospective collaborator + /// The permission to set + public IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "psermission"); + + return _client.Invite(owner, repo, user, permission).ToObservable(); + } + /// /// Deletes a collaborator from the repository. /// @@ -224,4 +215,4 @@ public IObservable Delete(int repositoryId, string user) return _client.Delete(repositoryId, user).ToObservable(); } } -} +} \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs index 11d82da6e2..26969fc963 100644 --- a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs @@ -67,7 +67,7 @@ public void RequestsCorrectUrl() _client.GetAll(owner, name); _githubClient.Connection.Received(1) .Get>(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Is>(dictionary => dictionary.Count == 0), + Arg.Is>(dictionary => dictionary.Count == 0), Arg.Any()); } @@ -79,7 +79,7 @@ public void RequestsCorrectUrlWithRepositoryId() _client.GetAll(repositoryId); _githubClient.Connection.Received(1) .Get>(Arg.Is(u => u.ToString() == expectedUrl), - Arg.Is>(dictionary => dictionary.Count == 0), + Arg.Is>(dictionary => dictionary.Count == 0), Arg.Any()); } @@ -331,7 +331,6 @@ public void CallsCreateOnRegularDeploymentsClientWithRepositoryId() } } -<<<<<<< HEAD public class TheInviteMethod { private readonly IGitHubClient _githubClient; @@ -406,10 +405,7 @@ public void CallsInviteOnRegularDeploymentsClient() } } - public class TheCtor -======= public class TheDeleteMethod ->>>>>>> refs/remotes/octokit/master { private readonly IGitHubClient _githubClient; private IObservableRepoCollaboratorsClient _client; @@ -489,4 +485,4 @@ public void CallsCreateOnRegularDeploymentsClientWithRepositoryId() } } } -} +} \ No newline at end of file diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 3196ad14c9..a83e2a21fe 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -86,26 +86,6 @@ public interface IRepoCollaboratorsClient /// /// See the API documentation for more information. /// -<<<<<<< HEAD - /// Thrown when a general API error occurs. - Task Add(string owner, string repo, string user); - - /// - /// Invites a new collaborator to the repo - /// - /// - /// See the API documentation for more information. - /// - /// The owner of the repository. - /// The name of the repository. - /// The name of the user to invite. - /// The permission to set. - /// Thrown when a general API error occurs. - Task Invite(string owner, string repo, string user, CollaboratorRequest permission); - - /// - /// Deletes a collaborator from the repo -======= /// The owner of the repository /// The name of the repository /// Username of the new collaborator @@ -123,6 +103,19 @@ public interface IRepoCollaboratorsClient /// Thrown when a general API error occurs. Task Add(int repositoryId, string user); + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository. + /// The name of the repository. + /// The name of the user to invite. + /// The permission to set. + /// Thrown when a general API error occurs. + Task Invite(string owner, string repo, string user, CollaboratorRequest permission); + /// /// Deletes a collaborator from the repository. /// @@ -137,7 +130,6 @@ public interface IRepoCollaboratorsClient /// /// Deletes a collaborator from the repository. ->>>>>>> refs/remotes/octokit/master /// /// /// See the API documentation for more information. @@ -145,10 +137,6 @@ public interface IRepoCollaboratorsClient /// The id of the repository /// Username of the removed collaborator /// Thrown when a general API error occurs. -<<<<<<< HEAD - Task Delete(string owner, string repo, string user); -======= Task Delete(int repositoryId, string user); ->>>>>>> refs/remotes/octokit/master } -} +} \ No newline at end of file diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 4332ef72af..e98fa07a3c 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -148,20 +148,12 @@ public async Task IsCollaborator(int repositoryId, string user) /// The name of the repository /// Username of the new collaborator /// Thrown when a general API error occurs. -<<<<<<< HEAD - public Task Add(string owner, string repo, string user) -======= public Task Add(string owner, string name, string user) ->>>>>>> refs/remotes/octokit/master { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); -<<<<<<< HEAD - return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user)); -======= - return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, name, user)); } @@ -179,7 +171,27 @@ public Task Add(int repositoryId, string user) Ensure.ArgumentNotNullOrEmptyString(user, "user"); return ApiConnection.Put(ApiUrls.RepoCollaborator(repositoryId, user)); ->>>>>>> refs/remotes/octokit/master + } + + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository. + /// The name of the repository. + /// The name of the user to invite. + /// The permission to set. + /// Thrown when a general API error occurs. + public Task Invite(string owner, string repo, string user, CollaboratorRequest permission) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "permission"); + + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), permission, null, AcceptHeaders.InvitationsApiPreview); } /// @@ -192,20 +204,12 @@ public Task Add(int repositoryId, string user) /// The name of the repository /// Username of the deleted collaborator /// Thrown when a general API error occurs. -<<<<<<< HEAD - public Task Delete(string owner, string repo, string user) -======= public Task Delete(string owner, string name, string user) ->>>>>>> refs/remotes/octokit/master { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); -<<<<<<< HEAD - return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, repo, user)); -======= - return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, name, user)); } @@ -223,29 +227,6 @@ public Task Delete(int repositoryId, string user) Ensure.ArgumentNotNullOrEmptyString(user, "user"); return ApiConnection.Delete(ApiUrls.RepoCollaborator(repositoryId, user)); ->>>>>>> refs/remotes/octokit/master - } - - /// - /// Invites a new collaborator to the repo - /// - /// - /// See the API documentation for more information. - /// - /// The owner of the repository. - /// The name of the repository. - /// The name of the user to invite. - /// The permission to set. - /// Thrown when a general API error occurs. - /// - public Task Invite(string owner, string repo, string user, CollaboratorRequest permission) - { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); - Ensure.ArgumentNotNullOrEmptyString(user, "user"); - Ensure.ArgumentNotNull(permission, "permission"); - - return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), permission, null, AcceptHeaders.InvitationsApiPreview); } } -} +} \ No newline at end of file From 69f4e07aafd612c178a7cdbbef1a7f16c9d28c52 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Thu, 7 Jul 2016 08:20:52 +0200 Subject: [PATCH 32/47] [WIP] RepositoryInvitationsClientTests --- .../RepositoryInvitationsClientTests.cs | 46 +++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 1 + 2 files changed, 47 insertions(+) create mode 100644 Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs new file mode 100644 index 0000000000..8e804a8f7c --- /dev/null +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -0,0 +1,46 @@ +using Octokit; +using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; +using System.Threading.Tasks; +using Xunit; + +public class RepositoryInvitationsClientTests +{ + const string owner = "octocat"; + const string name = "Hello-World"; + + public class TheGetAllForRepositoryMethod + { + + [IntegrationTest] + public async Task CanGetAllInvitations() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, owner, permission); + + Assert.Equal(owner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + var invitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id); + + Assert.Equal(1, invitations.Count); + Assert.Equal(invitations[0].CreatedAt, response.CreatedAt); + Assert.Equal(invitations[0].Id, response.Id); + Assert.Equal(invitations[0].Invitee.Login, response.Invitee.Login); + Assert.Equal(invitations[0].Inviter.Login, response.Inviter.Login); + Assert.Equal(invitations[0].Permissions, response.Permissions); + Assert.Equal(invitations[0].Repository.Id, response.Repository.Id); + } + } + + } +} + diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index aa34483de1..d1d320ba1e 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -109,6 +109,7 @@ + From 16df43e7440a0f32e6e8285623d16dbdc2c444d5 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 8 Jul 2016 12:53:09 +0200 Subject: [PATCH 33/47] fix api url xml --- .../Clients/RepositoryCollaboratorClientTests.cs | 4 ++-- Octokit/Helpers/ApiUrls.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index f6a5eacecc..7e9826773b 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -321,9 +321,9 @@ public async Task CanInviteNewCollaborator() var permission = new CollaboratorRequest(); // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "maddin2016", permission); + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "ocotkat", permission); - Assert.Equal("maddin2016", response.Invitee.Login); + Assert.Equal("octokat", response.Invitee.Login); Assert.Equal(InvitationPermissionType.Write, response.Permissions); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 15115ad789..b07d732970 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1285,7 +1285,7 @@ public static Uri Blob(string owner, string name) { return Blob(owner, name, ""); } - + /// /// Returns the for a specific blob. /// @@ -3016,7 +3016,7 @@ public static Uri Reactions(int number) } /// - /// Returns the for a single repository invitation. + /// Returns the for repository invitations. /// /// The id of the repository /// The for repository invitations. @@ -3026,7 +3026,7 @@ public static Uri RepositoryInvitations(int repositoryId) } /// - /// Returns the for repository invitations. + /// Returns the for a single repository invitation. /// /// The id of the repository /// The id of the invitation From d841119d838d548ba5bea3cab5710ce082e39706 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 8 Jul 2016 13:38:48 +0200 Subject: [PATCH 34/47] change collaborator request constructor --- .../Clients/RepositoryCollaboratorClientTests.cs | 2 +- .../Clients/RepositoryInvitationsClientTests.cs | 1 - Octokit/Models/Request/CollaboratorRequest.cs | 11 ++++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index 7e9826773b..b86538da09 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -321,7 +321,7 @@ public async Task CanInviteNewCollaborator() var permission = new CollaboratorRequest(); // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "ocotkat", permission); + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "octokat", permission); Assert.Equal("octokat", response.Invitee.Login); Assert.Equal(InvitationPermissionType.Write, response.Permissions); diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 8e804a8f7c..c87515a71b 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -40,7 +40,6 @@ public async Task CanGetAllInvitations() Assert.Equal(invitations[0].Repository.Id, response.Repository.Id); } } - } } diff --git a/Octokit/Models/Request/CollaboratorRequest.cs b/Octokit/Models/Request/CollaboratorRequest.cs index b4b2a424fc..a6776d617c 100644 --- a/Octokit/Models/Request/CollaboratorRequest.cs +++ b/Octokit/Models/Request/CollaboratorRequest.cs @@ -6,16 +6,17 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class CollaboratorRequest { - public CollaboratorRequest() - { - Permission = Permission.Push; - } - + /// + /// Used to set the permission for a collaborator. + /// public CollaboratorRequest(Permission permissions) { Permission = permissions; } + /// + /// The permission to grant the collaborator on this repository. + /// public Permission Permission { get; private set; } internal string DebuggerDisplay From 48d8153617835893e72ea8762e378df95af60af8 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 8 Jul 2016 13:54:48 +0200 Subject: [PATCH 35/47] change unit tests for collaborator request --- .../Clients/RepositoryCollaboratorClientTests.cs | 2 +- .../Clients/RepositoryInvitationsClientTests.cs | 2 +- Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs | 4 ++-- .../Reactive/ObservableRepoCollaboratorsClientTests.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index b86538da09..37a6710ab6 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -318,7 +318,7 @@ public async Task CanInviteNewCollaborator() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "octokat", permission); diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index c87515a71b..648e6d9233 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -21,7 +21,7 @@ public async Task CanGetAllInvitations() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, owner, permission); diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 14d1321ec1..abca35696f 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -237,7 +237,7 @@ public void RequestsCorrectUrl() var connection = Substitute.For(); var client = new RepoCollaboratorsClient(connection); - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); client.Invite("owner", "test", "user1", permission); connection.Received().Put(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Is(permission), Arg.Any(), Arg.Is("application/vnd.github.swamp-thing-preview+json")); @@ -247,7 +247,7 @@ public void RequestsCorrectUrl() public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For()); - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); await Assert.ThrowsAsync(() => client.Invite(null, "test", "user1", permission)); await Assert.ThrowsAsync(() => client.Invite("", "test", "user1", permission)); diff --git a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs index 26969fc963..f036648c86 100644 --- a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs @@ -357,7 +357,7 @@ private void SetupWithNonReactiveClient() public void EnsuresNonNullArguments() { SetupWithNonReactiveClient(); - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); Assert.Throws(() => _client.Invite(null, "repo", "user", permission)); Assert.Throws(() => _client.Invite("owner", null, "user", permission)); @@ -369,7 +369,7 @@ public void EnsuresNonNullArguments() public void EnsuresNonEmptyArguments() { SetupWithNonReactiveClient(); - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); Assert.Throws(() => _client.Invite("", "repo", "user", permission)); Assert.Throws(() => _client.Invite("owner", "", "user", permission)); @@ -380,7 +380,7 @@ public void EnsuresNonEmptyArguments() public async Task EnsuresNonWhitespaceArguments() { SetupWithNonReactiveClient(); - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.Invite(whitespace, "repo", "user", permission)); @@ -394,7 +394,7 @@ await AssertEx.ThrowsWhenGivenWhitespaceArgument( public void CallsInviteOnRegularDeploymentsClient() { SetupWithoutNonReactiveClient(); - var permission = new CollaboratorRequest(); + var permission = new CollaboratorRequest(Permission.Push); _client.Invite("owner", "repo", "user", permission); From 89e76e3a76cb7334f734cc6aab2d9ae35ce52f11 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 8 Jul 2016 14:08:13 +0200 Subject: [PATCH 36/47] change repocollaboratorsclient change overloads for add in invite methods to set permissions --- Octokit/Clients/RepoCollaboratorsClient.cs | 74 +++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index e98fa07a3c..a61f3e493b 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -157,6 +157,34 @@ public Task Add(string owner, string name, string user) return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, name, user)); } + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + public async Task Add(string owner, string name, string user, CollaboratorRequest permission) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + try + { + var response = await Connection.Put(ApiUrls.RepoCollaborator(owner, name, user), permission); + return response.HttpResponse.IsTrue(); + } + catch + { + return false; + } + } + /// /// Adds a new collaborator to the repository. /// @@ -173,6 +201,50 @@ public Task Add(int repositoryId, string user) return ApiConnection.Put(ApiUrls.RepoCollaborator(repositoryId, user)); } + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + public async Task Add(int repositoryId, string user, CollaboratorRequest permission) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + try + { + var response = await Connection.Put(ApiUrls.RepoCollaborator(repositoryId, user), permission); + return response.HttpResponse.IsTrue(); + } + catch + { + return false; + } + } + + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository. + /// The name of the repository. + /// The name of the user to invite. + /// Thrown when a general API error occurs. + public Task Invite(string owner, string repo, string user) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), new object(), null, AcceptHeaders.InvitationsApiPreview); + } + /// /// Invites a new collaborator to the repo /// @@ -182,7 +254,7 @@ public Task Add(int repositoryId, string user) /// The owner of the repository. /// The name of the repository. /// The name of the user to invite. - /// The permission to set. + /// The permission to set. Only valid on organization-owned repositories. /// Thrown when a general API error occurs. public Task Invite(string owner, string repo, string user, CollaboratorRequest permission) { From 864498dd78295e1cb81e198a6a52a58d74a8b137 Mon Sep 17 00:00:00 2001 From: Martin Scholz Date: Fri, 8 Jul 2016 14:56:31 +0200 Subject: [PATCH 37/47] [WIP] integration tests --- .../RepositoryInvitationsClientTests.cs | 72 ++++++++++++++++++- .../Clients/RepositoryInvitationsClient.cs | 8 +-- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 648e6d9233..ace7de2bbb 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -1,6 +1,7 @@ using Octokit; using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; +using System.Linq; using System.Threading.Tasks; using Xunit; @@ -11,7 +12,6 @@ public class RepositoryInvitationsClientTests public class TheGetAllForRepositoryMethod { - [IntegrationTest] public async Task CanGetAllInvitations() { @@ -32,12 +32,78 @@ public async Task CanGetAllInvitations() var invitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id); Assert.Equal(1, invitations.Count); - Assert.Equal(invitations[0].CreatedAt, response.CreatedAt); + Assert.Equal(invitations[0].CreatedAt, response.CreatedAt); Assert.Equal(invitations[0].Id, response.Id); Assert.Equal(invitations[0].Invitee.Login, response.Invitee.Login); Assert.Equal(invitations[0].Inviter.Login, response.Inviter.Login); Assert.Equal(invitations[0].Permissions, response.Permissions); - Assert.Equal(invitations[0].Repository.Id, response.Repository.Id); + Assert.Equal(invitations[0].Repository.Id, response.Repository.Id); + } + } + } + + public class TheGetAllForCurrentMethod + { + [IntegrationTest] + public async Task CanGetAllInvitations() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + var invitations = await github.Repository.Invitation.GetAllForCurrent(); + + Assert.True(invitations.Count >= 1); + Assert.NotNull(invitations.FirstOrDefault(i => i.CreatedAt == response.CreatedAt)); + Assert.NotNull(invitations.FirstOrDefault(i => i.Id == response.Id)); + Assert.NotNull(invitations.FirstOrDefault(i => i.Inviter.Login == response.Inviter.Login)); + Assert.NotNull(invitations.FirstOrDefault(i => i.Invitee.Login == response.Invitee.Login)); + Assert.NotNull(invitations.FirstOrDefault(i => i.Permissions == response.Permissions)); + Assert.NotNull(invitations.FirstOrDefault(i => i.Repository.Id == response.Repository.Id)); + } + } + } + + public class TheDeclineMethod + { + [IntegrationTest] + public async Task CanDeclineInvitation() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + var declineResponse = await github.Repository.Invitation.Decline(response.Id); + + Assert.False(declineResponse); + + //Assert.True(invitations.Count >= 1); + //Assert.NotNull(invitations.FirstOrDefault(i => i.CreatedAt == response.CreatedAt)); + //Assert.NotNull(invitations.FirstOrDefault(i => i.Id == response.Id)); + //Assert.NotNull(invitations.FirstOrDefault(i => i.Inviter.Login == response.Inviter.Login)); + //Assert.NotNull(invitations.FirstOrDefault(i => i.Invitee.Login == response.Invitee.Login)); + //Assert.NotNull(invitations.FirstOrDefault(i => i.Permissions == response.Permissions)); + //Assert.NotNull(invitations.FirstOrDefault(i => i.Repository.Id == response.Repository.Id)); } } } diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 799059c7da..56f9336bac 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -26,7 +26,7 @@ public async Task Accept(int invitationId) try { - var httpStatusCode = await ApiConnection.Connection.Patch(endpoint, AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); + var httpStatusCode = await Connection.Patch(endpoint, AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } catch @@ -49,10 +49,10 @@ public async Task Decline(int invitationId) try { - var httpStatusCode = await ApiConnection.Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); + var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } - catch + catch(Exception ex) { return false; } @@ -73,7 +73,7 @@ public async Task Delete(int repositoryId, int invitationId) try { - var httpStatusCode = await ApiConnection.Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); + var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } catch From ee15ec4cab243e71f0bb6b804e54a7b9c20fbd8b Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Sat, 9 Jul 2016 22:27:05 +0200 Subject: [PATCH 38/47] add methods for interface --- .../RepositoryInvitationsClientTests.cs | 4 +- Octokit/Clients/IRepoCollaboratorsClient.cs | 37 +++++++++++++++++++ .../Clients/RepositoryInvitationsClient.cs | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index ace7de2bbb..2e19c205bd 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -88,14 +88,14 @@ public async Task CanDeclineInvitation() var permission = new CollaboratorRequest(Permission.Push); // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner); Assert.Equal(context.RepositoryOwner, response.Invitee.Login); Assert.Equal(InvitationPermissionType.Write, response.Permissions); var declineResponse = await github.Repository.Invitation.Decline(response.Id); - Assert.False(declineResponse); + Assert.True(declineResponse); //Assert.True(invitations.Count >= 1); //Assert.NotNull(invitations.FirstOrDefault(i => i.CreatedAt == response.CreatedAt)); diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index a83e2a21fe..4c753dd731 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -92,6 +92,19 @@ public interface IRepoCollaboratorsClient /// Thrown when a general API error occurs. Task Add(string owner, string name, string user); + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + Task Add(string owner, string name, string user, CollaboratorRequest permission); + /// /// Adds a new collaborator to the repository. /// @@ -103,6 +116,30 @@ public interface IRepoCollaboratorsClient /// Thrown when a general API error occurs. Task Add(int repositoryId, string user); + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + Task Add(int repositoryId, string user, CollaboratorRequest permission); + + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository. + /// The name of the repository. + /// The name of the user to invite. + /// Thrown when a general API error occurs. + Task Invite(string owner, string repo, string user); + /// /// Invites a new collaborator to the repo /// diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 56f9336bac..a97442924d 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -52,7 +52,7 @@ public async Task Decline(int invitationId) var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } - catch(Exception ex) + catch { return false; } From e661ad171bc56d7033327e3b600704f89d954474 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Sun, 10 Jul 2016 22:27:17 +0200 Subject: [PATCH 39/47] NotFoundExceptions --- Octokit/Clients/RepositoryInvitationsClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index a97442924d..92a859ad9d 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -29,7 +29,7 @@ public async Task Accept(int invitationId) var httpStatusCode = await Connection.Patch(endpoint, AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } - catch + catch(NotFoundException) { return false; } @@ -52,7 +52,7 @@ public async Task Decline(int invitationId) var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } - catch + catch(NotFoundException) { return false; } @@ -76,7 +76,7 @@ public async Task Delete(int repositoryId, int invitationId) var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.InvitationsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } - catch + catch(NotFoundException) { return false; } From fad44953882b18b362841d9e86aac4c79af547b4 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Sun, 10 Jul 2016 22:40:36 +0200 Subject: [PATCH 40/47] add overload for invite method --- Octokit/Clients/IRepoCollaboratorsClient.cs | 23 +++++++++++++ Octokit/Clients/RepoCollaboratorsClient.cs | 36 ++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 4c753dd731..3ff5dea89b 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -153,6 +153,29 @@ public interface IRepoCollaboratorsClient /// Thrown when a general API error occurs. Task Invite(string owner, string repo, string user, CollaboratorRequest permission); + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository. + /// The name of the user to invite. + /// Thrown when a general API error occurs. + Task Invite(int respositoryId, string user); + + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository. + /// The name of the user to invite. + /// The permission to set. + /// Thrown when a general API error occurs. + Task Invite(int repositoryId, string user, CollaboratorRequest permission); + /// /// Deletes a collaborator from the repository. /// diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index a61f3e493b..21950cb2d5 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -240,7 +240,7 @@ public Task Invite(string owner, string repo, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); - Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), new object(), null, AcceptHeaders.InvitationsApiPreview); } @@ -266,6 +266,40 @@ public Task Invite(string owner, string repo, string user, return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), permission, null, AcceptHeaders.InvitationsApiPreview); } + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository. + /// The name of the user to invite. + /// Thrown when a general API error occurs. + public Task Invite(int repositoryId, string user) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return ApiConnection.Put(ApiUrls.RepoCollaborator(repositoryId, user), new object(), null, AcceptHeaders.InvitationsApiPreview); + } + + /// + /// Invites a new collaborator to the repo + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository. + /// The name of the user to invite. + /// The permission to set. + /// Thrown when a general API error occurs. + public Task Invite(int repositoryId, string user, CollaboratorRequest permission) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "permission"); + + return ApiConnection.Put(ApiUrls.RepoCollaborator(repositoryId, user), permission, null, AcceptHeaders.InvitationsApiPreview); + } + /// /// Deletes a collaborator from the repository. /// From 479e3509926090e2ed9ab4b7f71d8e2dd3572a48 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Sun, 10 Jul 2016 22:44:18 +0200 Subject: [PATCH 41/47] rename repo property --- Octokit/Clients/IRepoCollaboratorsClient.cs | 8 ++++---- Octokit/Clients/RepoCollaboratorsClient.cs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 3ff5dea89b..0394340dea 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -135,10 +135,10 @@ public interface IRepoCollaboratorsClient /// See the API documentation for more information. /// /// The owner of the repository. - /// The name of the repository. + /// The name of the repository. /// The name of the user to invite. /// Thrown when a general API error occurs. - Task Invite(string owner, string repo, string user); + Task Invite(string owner, string name, string user); /// /// Invites a new collaborator to the repo @@ -147,11 +147,11 @@ public interface IRepoCollaboratorsClient /// See the API documentation for more information. /// /// The owner of the repository. - /// The name of the repository. + /// The name of the repository. /// The name of the user to invite. /// The permission to set. /// Thrown when a general API error occurs. - Task Invite(string owner, string repo, string user, CollaboratorRequest permission); + Task Invite(string owner, string name, string user, CollaboratorRequest permission); /// /// Invites a new collaborator to the repo diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 21950cb2d5..219fa8c05b 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -233,16 +233,16 @@ public async Task Add(int repositoryId, string user, CollaboratorRequest p /// See the API documentation for more information. /// /// The owner of the repository. - /// The name of the repository. + /// The name of the repository. /// The name of the user to invite. /// Thrown when a general API error occurs. - public Task Invite(string owner, string repo, string user) + public Task Invite(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), new object(), null, AcceptHeaders.InvitationsApiPreview); + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, name, user), new object(), null, AcceptHeaders.InvitationsApiPreview); } /// @@ -252,18 +252,18 @@ public Task Invite(string owner, string repo, string user) /// See the API documentation for more information. /// /// The owner of the repository. - /// The name of the repository. + /// The name of the repository. /// The name of the user to invite. /// The permission to set. Only valid on organization-owned repositories. /// Thrown when a general API error occurs. - public Task Invite(string owner, string repo, string user, CollaboratorRequest permission) + public Task Invite(string owner, string name, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(permission, "permission"); - return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user), permission, null, AcceptHeaders.InvitationsApiPreview); + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, name, user), permission, null, AcceptHeaders.InvitationsApiPreview); } /// From a299fc3a043b784258821fd16e10c47c4e0e738d Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Mon, 11 Jul 2016 23:25:23 +0200 Subject: [PATCH 42/47] gramar --- Octokit/Clients/IRepoCollaboratorsClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 0394340dea..c5ff8211c2 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -162,7 +162,7 @@ public interface IRepoCollaboratorsClient /// The id of the repository. /// The name of the user to invite. /// Thrown when a general API error occurs. - Task Invite(int respositoryId, string user); + Task Invite(int repositoryId, string user); /// /// Invites a new collaborator to the repo From 7727f06f35a3ff38eaa581b4db60bae521d17308 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Tue, 12 Jul 2016 00:05:42 +0200 Subject: [PATCH 43/47] overloads for observable repo collaborators client --- .../IObservableRepoCollaboratorsClient.cs | 68 +++++++++++- .../ObservableRepoCollaboratorsClient.cs | 105 +++++++++++++++++- .../Clients/RepoCollaboratorsClientTests.cs | 4 +- Octokit/Clients/IRepoCollaboratorsClient.cs | 4 +- Octokit/Clients/RepoCollaboratorsClient.cs | 2 +- 5 files changed, 169 insertions(+), 14 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs index 1f5c04b462..79e84beb26 100644 --- a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs @@ -90,6 +90,19 @@ public interface IObservableRepoCollaboratorsClient /// Thrown when a general API error occurs. IObservable Add(string owner, string name, string user); + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + IObservable Add(string owner, string name, string user, CollaboratorRequest permission); + /// /// Adds a new collaborator to the repository. /// @@ -101,14 +114,63 @@ public interface IObservableRepoCollaboratorsClient /// Thrown when a general API error occurs. IObservable Add(int repositoryId, string user); + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + IObservable Add(int repositoryId, string user, CollaboratorRequest permission); + /// /// Invites a user as a collaborator to a repository. /// + /// + /// See the API documentation for more information. + /// /// The owner of the repository - /// The name of the repository + /// The name of the repository + /// The username of the prospective collaborator + IObservable Invite(string owner, string name, string user); + + /// + /// Invites a user as a collaborator to a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository /// The username of the prospective collaborator - /// The permission to set - IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission); + /// The permission to set. Only valid on organization-owned repositories. + IObservable Invite(string owner, string name, string user, CollaboratorRequest permission); + + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Username of the new collaborator + /// Thrown when a general API error occurs. + IObservable Invite(int repositoryId, string user); + + /// + /// Invites a user as a collaborator to a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + IObservable Invite(int repositoryId, string user, CollaboratorRequest permission); /// /// Deletes a collaborator from the repository. diff --git a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs index e1d1585d1e..3eea4a4236 100644 --- a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs @@ -132,7 +132,7 @@ public IObservable IsCollaborator(int repositoryId, string user) /// Adds a new collaborator to the repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -147,6 +147,27 @@ public IObservable Add(string owner, string name, string user) return _client.Add(owner, name, user).ToObservable(); } + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + public IObservable Add(string owner, string name, string user, CollaboratorRequest permission) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "permission"); + + return _client.Add(owner, name, user, permission).ToObservable(); + } + /// /// Adds a new collaborator to the repository. /// @@ -163,21 +184,93 @@ public IObservable Add(int repositoryId, string user) return _client.Add(repositoryId, user).ToObservable(); } + /// + /// Adds a new collaborator to the repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Username of the new collaborator + /// The permission to set. Only valid on organization-owned repositories. + /// Thrown when a general API error occurs. + public IObservable Add(int repositoryId, string user, CollaboratorRequest permission) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "permission"); + + return _client.Add(repositoryId, user, permission).ToObservable(); + } + + /// + /// Invites a user as a collaborator to a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The owner of the repository + /// The name of the repository + /// The username of the prospective collaborator + public IObservable Invite(string owner, string name, string user) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return _client.Invite(owner, name, user).ToObservable(); + } + /// /// Invites a user as a collaborator to a repository. /// + /// + /// See the API documentation for more information. + /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// The username of the prospective collaborator - /// The permission to set - public IObservable Invite(string owner, string repo, string user, CollaboratorRequest permission) + /// The permission to set. Only valid on organization-owned repositories. + public IObservable Invite(string owner, string name, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(permission, "psermission"); + + return _client.Invite(owner, name, user, permission).ToObservable(); + } + + /// + /// Invites a user as a collaborator to a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// The username of the prospective collaborator + + public IObservable Invite(int repositoryId, string user) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return _client.Invite(repositoryId, user).ToObservable(); + } + + /// + /// Invites a user as a collaborator to a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// The username of the prospective collaborator + /// The permission to set. Only valid on organization-owned repositories. + public IObservable Invite(int repositoryId, string user, CollaboratorRequest permission) + { Ensure.ArgumentNotNullOrEmptyString(user, "user"); Ensure.ArgumentNotNull(permission, "psermission"); - return _client.Invite(owner, repo, user, permission).ToObservable(); + return _client.Invite(repositoryId, user, permission).ToObservable(); } /// diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index abca35696f..3fb20b53ee 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -290,8 +290,8 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.Delete("owner", null, "user1")); await Assert.ThrowsAsync(() => client.Delete("owner", "test", null)); await Assert.ThrowsAsync(() => client.Delete(1, null)); - - await Assert.ThrowsAsync(() => client.Delete("", "test", "user1"));; + + await Assert.ThrowsAsync(() => client.Delete("", "test", "user1")); ; await Assert.ThrowsAsync(() => client.Delete("owner", "", "user1")); await Assert.ThrowsAsync(() => client.Delete("owner", "test", "")); await Assert.ThrowsAsync(() => client.Delete(1, "")); diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index c5ff8211c2..abc46874dc 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -149,7 +149,7 @@ public interface IRepoCollaboratorsClient /// The owner of the repository. /// The name of the repository. /// The name of the user to invite. - /// The permission to set. + /// The permission to set. Only valid on organization-owned repositories. /// Thrown when a general API error occurs. Task Invite(string owner, string name, string user, CollaboratorRequest permission); @@ -172,7 +172,7 @@ public interface IRepoCollaboratorsClient /// /// The id of the repository. /// The name of the user to invite. - /// The permission to set. + /// The permission to set. Only valid on organization-owned repositories. /// Thrown when a general API error occurs. Task Invite(int repositoryId, string user, CollaboratorRequest permission); diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 219fa8c05b..32ef1686fa 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -290,7 +290,7 @@ public Task Invite(int repositoryId, string user) /// /// The id of the repository. /// The name of the user to invite. - /// The permission to set. + /// The permission to set. Only valid on organization-owned repositories. /// Thrown when a general API error occurs. public Task Invite(int repositoryId, string user, CollaboratorRequest permission) { From 40e36fc991062beb20885fa76d11eeff5f68aa24 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Fri, 15 Jul 2016 22:03:29 +0200 Subject: [PATCH 44/47] change integration tests --- .../RepositoryInvitationsClientTests.cs | 36 +------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 2e19c205bd..d4b0c3421c 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -69,41 +69,7 @@ public async Task CanGetAllInvitations() Assert.NotNull(invitations.FirstOrDefault(i => i.Inviter.Login == response.Inviter.Login)); Assert.NotNull(invitations.FirstOrDefault(i => i.Invitee.Login == response.Invitee.Login)); Assert.NotNull(invitations.FirstOrDefault(i => i.Permissions == response.Permissions)); - Assert.NotNull(invitations.FirstOrDefault(i => i.Repository.Id == response.Repository.Id)); - } - } - } - - public class TheDeclineMethod - { - [IntegrationTest] - public async Task CanDeclineInvitation() - { - var github = Helper.GetAuthenticatedClient(); - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - - using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) - { - var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); - - // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner); - - Assert.Equal(context.RepositoryOwner, response.Invitee.Login); - Assert.Equal(InvitationPermissionType.Write, response.Permissions); - - var declineResponse = await github.Repository.Invitation.Decline(response.Id); - - Assert.True(declineResponse); - - //Assert.True(invitations.Count >= 1); - //Assert.NotNull(invitations.FirstOrDefault(i => i.CreatedAt == response.CreatedAt)); - //Assert.NotNull(invitations.FirstOrDefault(i => i.Id == response.Id)); - //Assert.NotNull(invitations.FirstOrDefault(i => i.Inviter.Login == response.Inviter.Login)); - //Assert.NotNull(invitations.FirstOrDefault(i => i.Invitee.Login == response.Invitee.Login)); - //Assert.NotNull(invitations.FirstOrDefault(i => i.Permissions == response.Permissions)); - //Assert.NotNull(invitations.FirstOrDefault(i => i.Repository.Id == response.Repository.Id)); + Assert.NotNull(invitations.FirstOrDefault(i => i.Repository.Id == response.Repository.Id)); } } } From 5a36c721862f84455332aa914b732d7e0420bc8c Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Sat, 16 Jul 2016 10:59:18 +0200 Subject: [PATCH 45/47] new integration tests --- .../RepositoryInvitationsClientTests.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index d4b0c3421c..eade77b36e 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -73,5 +73,65 @@ public async Task CanGetAllInvitations() } } } + + public class TheDeleteMethod + { + [IntegrationTest] + public async Task CanDeleteInvitation() + { + var github = Helper.GetAuthenticatedClient(); + + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + var delete = await github.Repository.Invitation.Delete(response.Repository.Id, response.Id); + + Assert.True(delete); + } + } + } + + public class TheUpdateMethod + { + [IntegrationTest] + public async Task CanUpdateInvitation() + { + var github = Helper.GetAuthenticatedClient(); + + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + var updatedInvitation = new InvitationUpdate(InvitationPermissionType.Admin); + + var update = await github.Repository.Invitation.Edit(response.Repository.Id, response.Id, updatedInvitation); + + Assert.Equal(updatedInvitation.Permissions, update.Permissions); + Assert.Equal(response.Id, update.Id); + Assert.Equal(response.Repository.Id, update.Repository.Id); + Assert.Equal(response.Invitee.Login, update.Invitee.Login); + Assert.Equal(response.Inviter.Login, update.Inviter.Login); + } + } + } } From 0ec91bdaf3dd6bd82acb02a7df8b5a5a13e20735 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Wed, 20 Jul 2016 11:10:35 +0200 Subject: [PATCH 46/47] add decline test --- .../RepositoryInvitationsClientTests.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index eade77b36e..63c6f02a55 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -74,6 +74,33 @@ public async Task CanGetAllInvitations() } } + public class TheDeclineMethod + { + [IntegrationTest] + public async Task CanDeclineInvitation() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + // Decline the invitation + var declined = await github.Repository.Invitation.Decline(response.Id); + + Assert.True(declined); + } + } + } + public class TheDeleteMethod { [IntegrationTest] From acd0f33b0ee3c2ca0e91f984f29c2ca56fdab728 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Thu, 21 Jul 2016 10:53:52 +0200 Subject: [PATCH 47/47] add test for accept invitation --- .../RepositoryInvitationsClientTests.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 63c6f02a55..7b2ee01591 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -74,6 +74,33 @@ public async Task CanGetAllInvitations() } } + public class TheAcceptMethod + { + [IntegrationTest] + public async Task CanAcceptInvitation() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + // Accept the invitation + var accepted = await github.Repository.Invitation.Accept(response.Id); + + Assert.True(accepted); + } + } + } + public class TheDeclineMethod { [IntegrationTest]