Repository invitations changes (#1410)

* add invitations accept header

* create class RepositoryInvitation

* add repository invitations client

* add api urls for invitations

* [WIP]

* add methods to repository invitations client

* add invite method to repo collaborators client

need to add some new overload to post method in apiconnection

* some changes

* add observable client

* add dependings

* add missing observable client

* add missing xml params

* check client

* change repository invitation model

* [WIP] tests

* [WIP] tests; fix overloads for client

* change GetAllForCurrent; suppress message

* some more tests

* [WIP]

* [WIP]

* add collaborator request model

* change return types

change return types for invitation methods. add permission attribute for
repository collaborators invite method.

* add some more tests

* fix xml doc

* check for null arguments

* fix tests

* some fixes from @ryangribble

* add parameterless constructor for RepositoryInvitation

* change setter

* change constructor

* fix merge conflicts

* [WIP] RepositoryInvitationsClientTests

* fix api url xml

* change collaborator request constructor

* change unit tests for collaborator request

* change repocollaboratorsclient

change overloads for add in invite methods to set permissions

* [WIP] integration tests

* add methods for interface

* NotFoundExceptions

* add overload for invite method

* rename repo property

* gramar

* overloads for observable repo collaborators client

* change integration tests

* new integration tests

* add decline test

* add test for accept invitation
This commit is contained in:
Martin Scholz
2016-07-23 10:50:22 +02:00
committed by Ryan Gribble
parent e3fd99ea9d
commit 89500f4b8a
40 changed files with 1591 additions and 16 deletions
+131 -4
View File
@@ -102,7 +102,7 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(user, "user");
try
{
var response = await Connection.Get<object>(ApiUrls.RepoCollaborator(owner, name, user), null, null).ConfigureAwait(false);
@@ -153,10 +153,38 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(user, "user");
return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, name, user));
}
/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="user">Username of the new collaborator</param>
/// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public async Task<bool> 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<object>(ApiUrls.RepoCollaborator(owner, name, user), permission);
return response.HttpResponse.IsTrue();
}
catch
{
return false;
}
}
/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
@@ -173,6 +201,105 @@ namespace Octokit
return ApiConnection.Put(ApiUrls.RepoCollaborator(repositoryId, user));
}
/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="user">Username of the new collaborator</param>
/// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public async Task<bool> Add(int repositoryId, string user, CollaboratorRequest permission)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");
try
{
var response = await Connection.Put<object>(ApiUrls.RepoCollaborator(repositoryId, user), permission);
return response.HttpResponse.IsTrue();
}
catch
{
return false;
}
}
/// <summary>
/// Invites a new collaborator to the repo
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="user">The name of the user to invite.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public Task<RepositoryInvitation> Invite(string owner, string name, string user)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(user, "user");
return ApiConnection.Put<RepositoryInvitation>(ApiUrls.RepoCollaborator(owner, name, user), new object(), null, AcceptHeaders.InvitationsApiPreview);
}
/// <summary>
/// Invites a new collaborator to the repo
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="user">The name of the user to invite.</param>
/// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public Task<RepositoryInvitation> Invite(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 ApiConnection.Put<RepositoryInvitation>(ApiUrls.RepoCollaborator(owner, name, user), permission, null, AcceptHeaders.InvitationsApiPreview);
}
/// <summary>
/// Invites a new collaborator to the repo
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository.</param>
/// <param name="user">The name of the user to invite.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public Task<RepositoryInvitation> Invite(int repositoryId, string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");
return ApiConnection.Put<RepositoryInvitation>(ApiUrls.RepoCollaborator(repositoryId, user), new object(), null, AcceptHeaders.InvitationsApiPreview);
}
/// <summary>
/// Invites a new collaborator to the repo
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository.</param>
/// <param name="user">The name of the user to invite.</param>
/// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public Task<RepositoryInvitation> Invite(int repositoryId, string user, CollaboratorRequest permission)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");
Ensure.ArgumentNotNull(permission, "permission");
return ApiConnection.Put<RepositoryInvitation>(ApiUrls.RepoCollaborator(repositoryId, user), permission, null, AcceptHeaders.InvitationsApiPreview);
}
/// <summary>
/// Deletes a collaborator from the repository.
/// </summary>
@@ -188,7 +315,7 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(user, "user");
return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, name, user));
}
@@ -208,4 +335,4 @@ namespace Octokit
return ApiConnection.Delete(ApiUrls.RepoCollaborator(repositoryId, user));
}
}
}
}