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

Organization membership preview API changes - Review user permission #1633

Merged
merged 12 commits into from
Jul 29, 2017
23 changes: 23 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ public interface IObservableRepoCollaboratorsClient
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<bool> IsCollaborator(long repositoryId, string user);

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">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 collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<CollaboratorPermission> ReviewPermission(string owner, string name, string user);

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="user">Username of the collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
IObservable<CollaboratorPermission> ReviewPermission(long repositoryId, string user);

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
Expand Down
35 changes: 35 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,41 @@ public IObservable<bool> IsCollaborator(long repositoryId, string user)
return _client.IsCollaborator(repositoryId, user).ToObservable();
}

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">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 collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<CollaboratorPermission> ReviewPermission(string owner, string name, string user)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(user, "user");

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

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="user">Username of the collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public IObservable<CollaboratorPermission> ReviewPermission(long repositoryId, string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");

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

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
Expand Down
23 changes: 23 additions & 0 deletions Octokit/Clients/IRepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ public interface IRepoCollaboratorsClient
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
Task<bool> IsCollaborator(long repositoryId, string user);

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">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 collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
Task<CollaboratorPermission> ReviewPermission(string owner, string name, string user);

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="user">Username of the collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
Task<CollaboratorPermission> ReviewPermission(long repositoryId, string user);

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
Expand Down
37 changes: 37 additions & 0 deletions Octokit/Clients/RepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,43 @@ public async Task<bool> IsCollaborator(long repositoryId, string user)
}
}

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">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 collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public Task<CollaboratorPermission> ReviewPermission(string owner, string name, string user)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(user, "user");

return ApiConnection
.Get<CollaboratorPermission>(ApiUrls.RepoCollaboratorPermission(owner, name, user), null, AcceptHeaders.OrganizationMembershipPreview);
}

/// <summary>
/// Review a user's permission level in a repository
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The id of the repository</param>
/// <param name="user">Username of the collaborator to check permission for</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
public Task<CollaboratorPermission> ReviewPermission(long repositoryId, string user)
{
Ensure.ArgumentNotNullOrEmptyString(user, "user");

return ApiConnection
.Get<CollaboratorPermission>(ApiUrls.RepoCollaboratorPermission(repositoryId, user), null, AcceptHeaders.OrganizationMembershipPreview);
}

/// <summary>
/// Adds a new collaborator to the repository.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions Octokit/Helpers/AcceptHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ public static class AcceptHeaders
public const string PullRequestReviewsApiPreview = "application/vnd.github.black-cat-preview+json";

public const string ProjectsApiPreview = "application/vnd.github.inertia-preview+json";

public const string OrganizationMembershipPreview = "application/vnd.github.korra-preview+json";

}
}
17 changes: 17 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,23 @@ public static Uri RepoCollaborator(string owner, string repo, string user)
return "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user);
}

/// <summary>
/// Returns the <see cref="Uri"/> to review the collaborators permission
/// </summary>
/// <param name="owner">The owner of the repo</param>
/// <param name="repo">The name of the repo</param>
/// <param name="user">The name of the user</param>
/// <returns>The <see cref="Uri"/> to review the collaborators permission</returns>
public static Uri RepoCollaboratorPermission(string owner, string repo, string user)
{
return "repos/{0}/{1}/collaborators/{2}/permission".FormatUri(owner, repo, user);
}

public static Uri RepoCollaboratorPermission(long repositoryId, string user)
{
return "repos/{0}/collaborators/{1}".FormatUri(repositoryId, user);
Copy link
Contributor

@ryangribble ryangribble Jul 25, 2017

Choose a reason for hiding this comment

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

Once you get into integration tests I think you'll find the URL for the repositoryId based endpoints is /repositories/<id> rather than /repos/<id>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whistling I was just testing you 😉

}

/// <summary>
/// Returns the <see cref="Uri"/> to check user is collaborator
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions Octokit/Models/Response/CollaboratorPermission.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Diagnostics;

namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class CollaboratorPermission
{
public StringEnum<CollaboratorPermissions> Permission { get; protected set; }
public User User { get; protected set; }

internal string DebuggerDisplay => $"User: {User.Id} Permission: {Permission}";
}
}
16 changes: 16 additions & 0 deletions Octokit/Models/Response/CollaboratorPermissions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Octokit.Internal;

namespace Octokit
{
public enum CollaboratorPermissions
{
[Parameter(Value = "admin")]
Admin,
[Parameter(Value = "write")]
Write,
[Parameter(Value = "read")]
Read,
[Parameter(Value = "none")]
None
}
}