Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository invitations changes #1410

Merged
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
dcf1cf0
Merge remote-tracking branch 'refs/remotes/octokit/master'
martinscholz83 Jun 28, 2016
61dfff8
Merge remote-tracking branch 'refs/remotes/octokit/master'
martinscholz83 Jun 29, 2016
dc65dab
Merge remote-tracking branch 'refs/remotes/octokit/master'
martinscholz83 Jun 30, 2016
f6191d2
Merge branch 'master' of https://github.com/maddin2016/octokit.net
martinscholz83 Jun 30, 2016
7bd3b37
add invitations accept header
martinscholz83 Jun 30, 2016
9f9c5e0
create class RepositoryInvitation
martinscholz83 Jun 30, 2016
dcdfbc6
add repository invitations client
martinscholz83 Jun 30, 2016
f8e7899
add api urls for invitations
martinscholz83 Jun 30, 2016
6fbfa0e
[WIP]
martinscholz83 Jun 30, 2016
58d90c1
add methods to repository invitations client
martinscholz83 Jun 30, 2016
0a67ae0
add invite method to repo collaborators client
martinscholz83 Jun 30, 2016
9471562
some changes
martinscholz83 Jun 30, 2016
ae8e60f
Merge remote-tracking branch 'refs/remotes/octokit/master' into repos…
martinscholz83 Jul 1, 2016
e5d5f3c
Merge branch 'repository-invitations-changes' of https://github.com/m…
martinscholz83 Jul 1, 2016
a0eb6db
add observable client
martinscholz83 Jul 1, 2016
abc4b08
add dependings
martinscholz83 Jul 1, 2016
cd95700
add missing observable client
martinscholz83 Jul 1, 2016
aba8653
add missing xml params
martinscholz83 Jul 1, 2016
eb79e6a
check client
martinscholz83 Jul 1, 2016
a1b0fcb
change repository invitation model
martinscholz83 Jul 1, 2016
721ab95
[WIP] tests
martinscholz83 Jul 1, 2016
6727c4e
[WIP] tests; fix overloads for client
martinscholz83 Jul 1, 2016
ffa5999
change GetAllForCurrent; suppress message
martinscholz83 Jul 1, 2016
e81dde8
some more tests
martinscholz83 Jul 1, 2016
7b7d60e
[WIP]
martinscholz83 Jul 3, 2016
525dcfb
Merge remote-tracking branch 'refs/remotes/octokit/master' into repos…
martinscholz83 Jul 3, 2016
29b6f07
[WIP]
martinscholz83 Jul 3, 2016
24920c9
add collaborator request model
martinscholz83 Jul 4, 2016
3eb7bd4
change return types
martinscholz83 Jul 4, 2016
e65d596
add some more tests
martinscholz83 Jul 4, 2016
7536d96
fix xml doc
martinscholz83 Jul 4, 2016
7451528
check for null arguments
martinscholz83 Jul 4, 2016
7d8e520
fix tests
martinscholz83 Jul 4, 2016
1566f69
some fixes from @ryangribble
martinscholz83 Jul 4, 2016
a21b3a1
add parameterless constructor for RepositoryInvitation
martinscholz83 Jul 5, 2016
8d98235
change setter
martinscholz83 Jul 5, 2016
8531347
change constructor
martinscholz83 Jul 5, 2016
e7b9f8a
Merge remote-tracking branch 'refs/remotes/octokit/master' into repos…
martinscholz83 Jul 6, 2016
f3d0c03
fix merge conflicts
martinscholz83 Jul 6, 2016
69f4e07
[WIP] RepositoryInvitationsClientTests
martinscholz83 Jul 7, 2016
bc145aa
Merge remote-tracking branch 'refs/remotes/octokit/master' into repos…
martinscholz83 Jul 8, 2016
16df43e
fix api url xml
martinscholz83 Jul 8, 2016
d841119
change collaborator request constructor
martinscholz83 Jul 8, 2016
48d8153
change unit tests for collaborator request
martinscholz83 Jul 8, 2016
89e76e3
change repocollaboratorsclient
martinscholz83 Jul 8, 2016
864498d
[WIP] integration tests
martinscholz83 Jul 8, 2016
ee15ec4
add methods for interface
martinscholz83 Jul 9, 2016
e661ad1
NotFoundExceptions
martinscholz83 Jul 10, 2016
fad4495
add overload for invite method
martinscholz83 Jul 10, 2016
479e350
rename repo property
martinscholz83 Jul 10, 2016
a299fc3
gramar
martinscholz83 Jul 11, 2016
7727f06
overloads for observable repo collaborators client
martinscholz83 Jul 11, 2016
515a834
Merge remote-tracking branch 'refs/remotes/octokit/master' into repos…
martinscholz83 Jul 15, 2016
40e36fc
change integration tests
martinscholz83 Jul 15, 2016
5a36c72
new integration tests
martinscholz83 Jul 16, 2016
a3fd4fd
Merge remote-tracking branch 'refs/remotes/octokit/master' into repos…
martinscholz83 Jul 19, 2016
0ec91bd
add decline test
martinscholz83 Jul 20, 2016
acd0f33
add test for accept invitation
martinscholz83 Jul 21, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public interface IObservableRepoCollaboratorsClient
/// <returns></returns>
IObservable<Unit> Add(string owner, string repo, string user);

/// <summary>
/// Invites a user as a collaborator to a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repo">The name of the repository</param>
/// <param name="user">Username of the prospective collaborator</param>
/// <returns></returns>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove <returns> line as it's empty anyway

IObservable<RepositoryInvitation> Invite(string owner, string repo, string user);

/// <summary>
/// Removes a user as a collaborator for a repository.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,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; }
}
}
66 changes: 66 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;

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="id">The id of the invitation</param>
IObservable<Unit> Accept(int id);

/// <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="id">The id of the invitation</param>
IObservable<Unit> Decline(int id);

/// <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 ot the repository</param>
/// <param name="invitationId">The id of the invitation</param>
IObservable<Unit> 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="id">The id of the repository</param>
IObservable<RepositoryInvitation> GetAllForRepository(int id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for consistency, this variable should be named 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 ot the repository</param>
/// <param name="invitationId">The id of the invitation</param>
/// <param name="permissions">The permission for the collsborator</param>
IObservable<RepositoryInvitation> Edit(int repositoryId, int invitationId, InvitationUpdate permissions);
}
}
18 changes: 17 additions & 1 deletion Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public IObservable<User> GetAll(string owner, string repo, ApiOptions options)
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
Ensure.ArgumentNotNull(options, "options");

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

Expand Down Expand Up @@ -72,6 +72,22 @@ public IObservable<Unit> Add(string owner, string repo, string user)
return _client.Add(owner, repo, user).ToObservable();
}

/// <summary>
/// Invites a user as a collaborator to a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repo">The name of the repository</param>
/// <param name="user">Username of the prospective collaborator</param>
/// <returns></returns>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 <returns> line

public IObservable<RepositoryInvitation> 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();
}

/// <summary>
/// Removes a user as a collaborator for a repository.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 @@ -900,5 +901,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; }
}
}
95 changes: 95 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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)
{
Ensure.ArgumentNotNull(client, "client");

_client = client.Repository.Invitation;
_connection = client.Connection;
}

/// <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="id">The id of the invitation</param>
public IObservable<Unit> Accept(int id)
{
return _client.Accept(id).ToObservable();
}

/// <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="id">The id of the invitation</param>
public IObservable<Unit> Decline(int id)
{
return _client.Decline(id).ToObservable();
}

/// <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 ot the repository</param>
/// <param name="invitationId">The id of the invitation</param>
public IObservable<Unit> Delete(int repositoryId, int invitationId)
{
return _client.Delete(repositoryId, invitationId).ToObservable();
}

/// <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 ot the repository</param>
/// <param name="invitationId">The id of the invitation</param>
/// <param name="permissions">The permission for the collsborator</param>
public IObservable<RepositoryInvitation> Edit(int repositoryId, int invitationId, InvitationUpdate permissions)
{
return _client.Edit(repositoryId, invitationId, permissions).ToObservable();
}

/// <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>
public IObservable<RepositoryInvitation> GetAllForCurrent()
{
return _connection.GetAndFlattenAllPages<RepositoryInvitation>(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, null);
}

/// <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="id">The id of the repository</param>
public IObservable<RepositoryInvitation> GetAllForRepository(int id)
{
return _connection.GetAndFlattenAllPages<RepositoryInvitation>(ApiUrls.RepositoryInvitations(id), null, AcceptHeaders.InvitationsApiPreview, null);
}
}
}
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@
<Compile Include="Clients\ObservablePullRequestReviewCommentReactionsClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\ObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryInvitationsClient.cs" />
<Compile Include="Clients\ObservableRepositoryInvitationsClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@
<Compile Include="Clients\ObservablePullRequestReviewCommentReactionsClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\ObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryInvitationsClient.cs" />
<Compile Include="Clients\ObservableRepositoryInvitationsClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
<Compile Include="Clients\ObservablePullRequestReviewCommentReactionsClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\ObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryInvitationsClient.cs" />
<Compile Include="Clients\ObservableRepositoryInvitationsClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<Compile Include="Clients\IObservablePullRequestReviewCommentReactionsClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryInvitationsClient.cs" />
<Compile Include="Clients\IObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\IObservableUserAdministrationClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
Expand Down Expand Up @@ -134,6 +135,7 @@
<Compile Include="Clients\ObservableIssuesLabelsClient.cs" />
<Compile Include="Clients\ObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\ObservableRepositoryInvitationsClient.cs" />
<Compile Include="Clients\ObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\IObservableBlobsClient.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,24 @@ public async Task ReturnsTrueIfUserIsCollaborator()
}
}
}

public class TheInviteNewCollaboratorMethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be named as per the method being tested, eg TheInviteMethod

{
[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");

Assert.Equal("maddin2016", response.Invitee.Login);
}
}
}
}
26 changes: 26 additions & 0 deletions Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ public async Task EnsuresNonNullArguments()
}
}

public class TheInviteMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepoCollaboratorsClient(connection);

client.Invite("owner", "test", "user1");
connection.Received().Put<RepositoryInvitation>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Any<object>(), Arg.Any<string>(), Arg.Is<string>("application/vnd.github.swamp-thing-preview+json"));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepoCollaboratorsClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite(null, "test", "user1"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("", "test", "user1"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", null, "user1"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("owner", "", "user1"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("owner", "test", ""));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", "test", null));
}
}

public class TheDeleteMethod
{
[Fact]
Expand Down
Loading