Skip to content

Commit

Permalink
Repository invitations changes (#1410)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
martinscholz83 authored and ryangribble committed Jul 23, 2016
1 parent e3fd99e commit 89500f4
Show file tree
Hide file tree
Showing 40 changed files with 1,591 additions and 16 deletions.
73 changes: 72 additions & 1 deletion Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ public interface IObservableRepoCollaboratorsClient
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<Unit> Add(string owner, string name, string user);

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">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>
IObservable<bool> Add(string owner, string name, string user, CollaboratorRequest permission);

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
Expand All @@ -101,6 +114,64 @@ public interface IObservableRepoCollaboratorsClient
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<Unit> Add(int repositoryId, string 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>
IObservable<bool> Add(int repositoryId, string user, CollaboratorRequest permission);

/// <summary>
/// Invites a user as a collaborator to a 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">The username of the prospective collaborator</param>
IObservable<RepositoryInvitation> Invite(string owner, string name, string user);

/// <summary>
/// Invites a user as a collaborator to a 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">The username of the prospective collaborator</param>
/// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
IObservable<RepositoryInvitation> Invite(string owner, string name, string user, CollaboratorRequest permission);

/// <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>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<RepositoryInvitation> Invite(int repositoryId, string user);

/// <summary>
/// Invites a user as a collaborator to a 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>
IObservable<RepositoryInvitation> Invite(int repositoryId, string user, CollaboratorRequest permission);

/// <summary>
/// Deletes a collaborator from the repository.
/// </summary>
Expand All @@ -124,4 +195,4 @@ public interface IObservableRepoCollaboratorsClient
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<Unit> Delete(int repositoryId, string user);
}
}
}
9 changes: 9 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,21 @@ public interface IObservableRepositoriesClient
/// See the <a href="https://developer.github.com/v3/repos/keys/">Repository Deploy Keys API documentation</a> for more information.
/// </remarks>
IObservableRepositoryDeployKeysClient DeployKeys { get; }

/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
IObservableRepositoryPagesClient Page { get; }

/// <summary>
/// A client for GitHub's Repository Invitations API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/">Repository Invitations API documentation</a> for more information.
/// </remarks>
IObservableRepositoryInvitationsClient Invitation { get; }
}
}
67 changes: 67 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;

namespace Octokit.Reactive
{
public interface IObservableRepositoryInvitationsClient
{
/// <summary>
/// Accept a repository invitation.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/#accept-a-repository-invitation">API documentation</a> for more information.
/// </remarks>
/// <param name="invitationId">The id of the invitation.</param>
IObservable<bool> Accept(int invitationId);

/// <summary>
/// Decline a repository invitation.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/#decline-a-repository-invitation">API documentation</a> for more information.
/// </remarks>
/// <param name="invitationId">The id of the invitation.</param>
IObservable<bool> Decline(int invitationId);

/// <summary>
/// Deletes a repository invitation.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/#delete-a-repository-invitation">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository.</param>
/// <param name="invitationId">The id of the invitation.</param>
IObservable<bool> Delete(int repositoryId, int invitationId);

/// <summary>
/// Gets all invitations for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations">API documentation</a> for more information.
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<RepositoryInvitation> GetAllForCurrent();

/// <summary>
/// Gets all the invitations on a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/#list-invitations-for-a-repository">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
IObservable<RepositoryInvitation> GetAllForRepository(int repositoryId);

/// <summary>
/// Updates a repository invitation.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/#update-a-repository-invitation">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository.</param>
/// <param name="invitationId">The id of the invitation.</param>
/// <param name="permissions">The permission to set.</param>
/// <returns><see cref="RepositoryInvitation"/></returns>
IObservable<RepositoryInvitation> Edit(int repositoryId, int invitationId, InvitationUpdate permissions);
}
}
116 changes: 113 additions & 3 deletions Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public IObservable<User> GetAll(string owner, string name, ApiOptions options)
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(owner, name), options);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public IObservable<bool> IsCollaborator(int repositoryId, string user)
/// Adds a new collaborator to the repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// 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>
Expand All @@ -147,6 +147,27 @@ public IObservable<Unit> Add(string owner, string name, string user)
return _client.Add(owner, name, user).ToObservable();
}

/// <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 IObservable<bool> 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();
}

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
Expand All @@ -163,6 +184,95 @@ public IObservable<Unit> Add(int repositoryId, string user)
return _client.Add(repositoryId, user).ToObservable();
}

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">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 IObservable<bool> Add(int repositoryId, string user, CollaboratorRequest permission)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");
Ensure.ArgumentNotNull(permission, "permission");

return _client.Add(repositoryId, user, permission).ToObservable();
}

/// <summary>
/// Invites a user as a collaborator to a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">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 username of the prospective collaborator</param>
public IObservable<RepositoryInvitation> 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();
}

/// <summary>
/// Invites a user as a collaborator to a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">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 username of the prospective collaborator</param>
/// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
public IObservable<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, "psermission");

return _client.Invite(owner, name, user, permission).ToObservable();
}

/// <summary>
/// Invites a user as a collaborator to a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="user">The username of the prospective collaborator</param>

public IObservable<RepositoryInvitation> Invite(int repositoryId, string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");

return _client.Invite(repositoryId, user).ToObservable();
}

/// <summary>
/// Invites a user as a collaborator to a repository.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="user">The username of the prospective collaborator</param>
/// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
public IObservable<RepositoryInvitation> Invite(int repositoryId, string user, CollaboratorRequest permission)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");
Ensure.ArgumentNotNull(permission, "psermission");

return _client.Invite(repositoryId, user, permission).ToObservable();
}

/// <summary>
/// Deletes a collaborator from the repository.
/// </summary>
Expand Down Expand Up @@ -198,4 +308,4 @@ public IObservable<Unit> Delete(int repositoryId, string user)
return _client.Delete(repositoryId, user).ToObservable();
}
}
}
}
9 changes: 9 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public ObservableRepositoriesClient(IGitHubClient client)
Content = new ObservableRepositoryContentsClient(client);
Merging = new ObservableMergingClient(client);
Page = new ObservableRepositoryPagesClient(client);
Invitation = new ObservableRepositoryInvitationsClient(client);
}

/// <summary>
Expand Down Expand Up @@ -855,5 +856,13 @@ public IObservable<CompareResult> Compare(string owner, string name, string @bas
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
public IObservableRepositoryPagesClient Page { get; private set; }

/// <summary>
/// A client for GitHub's Repository Invitations API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/invitations/">Repository Invitations API documentation</a> for more information.
/// </remarks>
public IObservableRepositoryInvitationsClient Invitation { get; private set; }
}
}
Loading

0 comments on commit 89500f4

Please sign in to comment.