From 4850b839067b39dc10a500812fded54b75d6bc98 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sat, 4 Jun 2016 23:35:23 +1000 Subject: [PATCH] Add Permissions attribute to User Update integration tests to ensure Permissions field is populated Add Accept header for this functionality, so it works on GHE 2.5 Fix impacted URL unit tests --- .../Clients/RepositoryCollaboratorClientTests.cs | 2 ++ .../Reactive/ObservableRepositoryCollaboratorClientTests.cs | 2 ++ Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs | 4 ++-- Octokit/Clients/RepoCollaboratorsClient.cs | 2 +- Octokit/Helpers/AcceptHeaders.cs | 4 +++- Octokit/Models/Response/User.cs | 5 ++++- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index abfff650..1035ab35 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -24,6 +24,8 @@ public class RepositoryCollaboratorClientTests var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName); Assert.NotNull(collaborators); Assert.Equal(2, collaborators.Count); + Assert.NotNull(collaborators[0].Permissions); + Assert.NotNull(collaborators[1].Permissions); } } diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs index c6fc5464..f26eff9a 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs @@ -26,6 +26,8 @@ public class ObservableRepositoryCollaboratorClientTests var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName).ToList(); Assert.NotNull(collaborators); Assert.Equal(2, collaborators.Count); + Assert.NotNull(collaborators[0].Permissions); + Assert.NotNull(collaborators[1].Permissions); } } diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 5c9921d4..d79c82a8 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -32,7 +32,7 @@ namespace Octokit.Tests.Clients var client = new RepoCollaboratorsClient(connection); client.GetAll("owner", "test"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), null, "application/vnd.github.ironman-preview+json", Args.ApiOptions); } [Fact] @@ -51,7 +51,7 @@ namespace Octokit.Tests.Clients client.GetAll("owner", "test", options); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), options); + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), null, "application/vnd.github.ironman-preview+json", options); } [Fact] diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index d72ea217..cf1f5a35 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -57,7 +57,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNull(options, "options"); - return ApiConnection.GetAll(ApiUrls.RepoCollaborators(owner, repo), options); + return ApiConnection.GetAll(ApiUrls.RepoCollaborators(owner, repo), null, AcceptHeaders.OrganizationPermissionsPreview, options); } /// diff --git a/Octokit/Helpers/AcceptHeaders.cs b/Octokit/Helpers/AcceptHeaders.cs index 3d448fb7..f08bc8e5 100644 --- a/Octokit/Helpers/AcceptHeaders.cs +++ b/Octokit/Helpers/AcceptHeaders.cs @@ -8,6 +8,8 @@ public const string RedirectsPreviewThenStableVersionJson = "application/vnd.github.quicksilver-preview+json; charset=utf-8, application/vnd.github.v3+json; charset=utf-8"; + public const string OrganizationPermissionsPreview = "application/vnd.github.ironman-preview+json"; + public const string LicensesApiPreview = "application/vnd.github.drax-preview+json"; public const string ProtectedBranchesApiPreview = "application/vnd.github.loki-preview+json"; @@ -20,6 +22,6 @@ public const string SquashCommitPreview = "application/vnd.github.polaris-preview+json"; - public const string MigrationsApiPreview = " application/vnd.github.wyandotte-preview+json"; + public const string MigrationsApiPreview = "application/vnd.github.wyandotte-preview+json"; } } diff --git a/Octokit/Models/Response/User.cs b/Octokit/Models/Response/User.cs index 5c7c515e..2cd22753 100644 --- a/Octokit/Models/Response/User.cs +++ b/Octokit/Models/Response/User.cs @@ -13,14 +13,17 @@ namespace Octokit { public User() { } - public User(string avatarUrl, string bio, string blog, int collaborators, string company, DateTimeOffset createdAt, int diskUsage, string email, int followers, int following, bool? hireable, string htmlUrl, int totalPrivateRepos, int id, string location, string login, string name, int ownedPrivateRepos, Plan plan, int privateGists, int publicGists, int publicRepos, string url, bool siteAdmin, string ldapDistinguishedName, DateTimeOffset? suspendedAt) + public User(string avatarUrl, string bio, string blog, int collaborators, string company, DateTimeOffset createdAt, int diskUsage, string email, int followers, int following, bool? hireable, string htmlUrl, int totalPrivateRepos, int id, string location, string login, string name, int ownedPrivateRepos, Plan plan, int privateGists, int publicGists, int publicRepos, string url, RepositoryPermissions permissions, bool siteAdmin, string ldapDistinguishedName, DateTimeOffset? suspendedAt) : base(avatarUrl, bio, blog, collaborators, company, createdAt, diskUsage, email, followers, following, hireable, htmlUrl, totalPrivateRepos, id, location, login, name, ownedPrivateRepos, plan, privateGists, publicGists, publicRepos, AccountType.User, url) { + Permissions = permissions; SiteAdmin = siteAdmin; LdapDistinguishedName = ldapDistinguishedName; SuspendedAt = suspendedAt; } + public RepositoryPermissions Permissions { get; protected set; } + /// /// Whether or not the user is an administrator of the site ///