-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 24 commits
dcf1cf0
61dfff8
dc65dab
f6191d2
7bd3b37
9f9c5e0
dcdfbc6
f8e7899
6fbfa0e
58d90c1
0a67ae0
9471562
ae8e60f
e5d5f3c
a0eb6db
abc4b08
cd95700
aba8653
eb79e6a
a1b0fcb
721ab95
6727c4e
ffa5999
e81dde8
7b7d60e
525dcfb
29b6f07
24920c9
3eb7bd4
e65d596
7536d96
7451528
7d8e520
1566f69
a21b3a1
8d98235
8531347
e7b9f8a
f3d0c03
69f4e07
bc145aa
16df43e
d841119
48d8153
89e76e3
864498d
ee15ec4
e661ad1
fad4495
479e350
a299fc3
7727f06
515a834
40e36fc
5a36c72
a3fd4fd
0ec91bd
acd0f33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for consistency, this variable should be named |
||
|
||
/// <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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
|
||
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 |
||
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> | ||
|
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); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,4 +136,24 @@ public async Task ReturnsTrueIfUserIsCollaborator() | |
} | ||
} | ||
} | ||
|
||
public class TheInviteNewCollaboratorMethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be named as per the method being tested, eg |
||
{ | ||
[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); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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