From 1300427bdd9ebc9c7c7db67dfe2ee1a49a91a4af Mon Sep 17 00:00:00 2001 From: notauserx <82922717+notauserx@users.noreply.github.com> Date: Wed, 8 Mar 2023 22:27:29 +0600 Subject: [PATCH] [FEAT] Updates permissions for App Installations and Collaborators endpoints --- .../Extensions.cs | 16 +- .../IObservableRepoCollaboratorsClient.cs | 48 ++--- .../ObservableRepoCollaboratorsClient.cs | 58 ++--- .../Clients/GitHubAppsClientTests.cs | 4 +- .../Clients/RepositoryBranchesClientTests.cs | 8 +- .../RepositoryCollaboratorClientTests.cs | 112 +++++----- .../RepositoryInvitationsClientTests.cs | 24 +-- .../Clients/TeamsClientTests.cs | 2 +- .../OrganizationRepositoryWithTeamContext.cs | 4 +- .../ObservableGitHubAppsClientTests.cs | 4 +- ...rvableRepositoryCollaboratorClientTests.cs | 59 ++--- .../Clients/RepoCollaboratorsClientTests.cs | 202 ++++++++++++++++-- Octokit.Tests/Clients/TeamsClientTests.cs | 2 +- .../ObservableRepoCollaboratorsClientTests.cs | 36 ++-- Octokit/Clients/IRepoCollaboratorsClient.cs | 40 ++-- Octokit/Clients/RepoCollaboratorsClient.cs | 48 ++--- .../Models/{Request => Common}/Permission.cs | 138 ++++++++---- Octokit/Models/Request/CollaboratorRequest.cs | 17 +- .../RepositoryCollaboratorListRequest.cs | 10 +- .../Request/RepositoryPermissionRequest.cs | 4 +- Octokit/Models/Response/Collaborator.cs | 87 ++++++++ .../Models/Response/CollaboratorPermission.cs | 21 -- .../CollaboratorPermissionResponse.cs | 28 +++ Octokit/Models/Response/Installation.cs | 15 +- .../Response/InstallationPermissions.cs | 151 ++++++------- Octokit/Models/Response/PermissionLevel.cs | 16 -- .../Models/Response/RepositoryInvitation.cs | 41 ++-- 27 files changed, 735 insertions(+), 460 deletions(-) rename Octokit/Models/{Request => Common}/Permission.cs (51%) create mode 100644 Octokit/Models/Response/Collaborator.cs delete mode 100644 Octokit/Models/Response/CollaboratorPermission.cs create mode 100644 Octokit/Models/Response/CollaboratorPermissionResponse.cs delete mode 100644 Octokit/Models/Response/PermissionLevel.cs diff --git a/Octokit.AsyncPaginationExtension/Extensions.cs b/Octokit.AsyncPaginationExtension/Extensions.cs index c541ac0bd8..cd131c8da3 100644 --- a/Octokit.AsyncPaginationExtension/Extensions.cs +++ b/Octokit.AsyncPaginationExtension/Extensions.cs @@ -547,20 +547,20 @@ public static IPaginatedList GetAllAssetsAsync(this IReleasesClien => pageSize > 0 ? new PaginatedList(options => t.GetAllAssets(repositoryId, id, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); /// - public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, string owner, string name, int pageSize = DEFAULT_PAGE_SIZE) - => pageSize > 0 ? new PaginatedList(options => t.GetAll(owner, name, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); + public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, string owner, string name, int pageSize = DEFAULT_PAGE_SIZE) + => pageSize > 0 ? new PaginatedList(options => t.GetAll(owner, name, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); /// - public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, long repositoryId, int pageSize = DEFAULT_PAGE_SIZE) - => pageSize > 0 ? new PaginatedList(options => t.GetAll(repositoryId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); + public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, long repositoryId, int pageSize = DEFAULT_PAGE_SIZE) + => pageSize > 0 ? new PaginatedList(options => t.GetAll(repositoryId, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); /// - public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, string owner, string name, RepositoryCollaboratorListRequest request, int pageSize = DEFAULT_PAGE_SIZE) - => pageSize > 0 ? new PaginatedList(options => t.GetAll(owner, name, request, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); + public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, string owner, string name, RepositoryCollaboratorListRequest request, int pageSize = DEFAULT_PAGE_SIZE) + => pageSize > 0 ? new PaginatedList(options => t.GetAll(owner, name, request, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); /// - public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, long repositoryId, RepositoryCollaboratorListRequest request, int pageSize = DEFAULT_PAGE_SIZE) - => pageSize > 0 ? new PaginatedList(options => t.GetAll(repositoryId, request, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); + public static IPaginatedList GetAllAsync(this IRepoCollaboratorsClient t, long repositoryId, RepositoryCollaboratorListRequest request, int pageSize = DEFAULT_PAGE_SIZE) + => pageSize > 0 ? new PaginatedList(options => t.GetAll(repositoryId, request, options), pageSize) : throw new ArgumentOutOfRangeException(nameof(pageSize), pageSize, "The page size must be positive."); /// public static IPaginatedList GetAllForCurrentAsync(this IRepositoriesClient t, int pageSize = DEFAULT_PAGE_SIZE) diff --git a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs index 6dc5561174..4c442b97dc 100644 --- a/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepoCollaboratorsClient.cs @@ -4,10 +4,10 @@ namespace Octokit.Reactive { /// - /// A client for GitHub's Collaborators on a Repository. + /// A client for GitHub's Collaborators API. /// /// - /// See the Collaborators API documentation for more details. + /// See the Collaborators API documentation for more details. /// public interface IObservableRepoCollaboratorsClient { @@ -15,99 +15,99 @@ public interface IObservableRepoCollaboratorsClient /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Thrown when a general API error occurs. - IObservable GetAll(string owner, string name); + IObservable GetAll(string owner, string name); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Thrown when a general API error occurs. - IObservable GetAll(long repositoryId); + IObservable GetAll(long repositoryId); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Options for changing the API response /// Thrown when a general API error occurs. - IObservable GetAll(string owner, string name, ApiOptions options); + IObservable GetAll(string owner, string name, ApiOptions options); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Options for changing the API response /// Thrown when a general API error occurs. - IObservable GetAll(long repositoryId, ApiOptions options); + IObservable GetAll(long repositoryId, ApiOptions options); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. - IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request); + IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. - IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request); + IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. - IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options); + IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. - IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options); + IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options); /// /// Checks if a user is a collaborator on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -136,7 +136,7 @@ public interface IObservableRepoCollaboratorsClient /// The name of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. - IObservable ReviewPermission(string owner, string name, string user); + IObservable ReviewPermission(string owner, string name, string user); /// /// Review a user's permission level in a repository @@ -147,13 +147,13 @@ public interface IObservableRepoCollaboratorsClient /// The id of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. - IObservable ReviewPermission(long repositoryId, string user); + IObservable ReviewPermission(long repositoryId, string user); /// /// Adds a new collaborator to the repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -165,7 +165,7 @@ public interface IObservableRepoCollaboratorsClient /// Adds a new collaborator to the repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -247,7 +247,7 @@ public interface IObservableRepoCollaboratorsClient /// Deletes a collaborator from the repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository diff --git a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs index 38f8f710e3..bae3ee476e 100644 --- a/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepoCollaboratorsClient.cs @@ -6,10 +6,10 @@ namespace Octokit.Reactive { /// - /// A client for GitHub's Collaborators on a Repository. + /// A client for GitHub's Collaborators API. /// /// - /// See the Collaborators API documentation for more details. + /// See the Collaborators API documentation for more details. /// public class ObservableRepoCollaboratorsClient : IObservableRepoCollaboratorsClient { @@ -32,12 +32,12 @@ public ObservableRepoCollaboratorsClient(IGitHubClient client) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Thrown when a general API error occurs. - public IObservable GetAll(string owner, string name) + public IObservable GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -49,11 +49,11 @@ public IObservable GetAll(string owner, string name) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Thrown when a general API error occurs. - public IObservable GetAll(long repositoryId) + public IObservable GetAll(long repositoryId) { return GetAll(repositoryId, ApiOptions.None); } @@ -62,13 +62,13 @@ public IObservable GetAll(long repositoryId) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Options for changing the API response /// Thrown when a general API error occurs. - public IObservable GetAll(string owner, string name, ApiOptions options) + public IObservable GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -81,12 +81,12 @@ public IObservable GetAll(string owner, string name, ApiOptions options) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Options for changing the API response /// Thrown when a general API error occurs. - public IObservable GetAll(long repositoryId, ApiOptions options) + public IObservable GetAll(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); @@ -97,13 +97,13 @@ public IObservable GetAll(long repositoryId, ApiOptions options) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. - public IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request) + public IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -116,12 +116,12 @@ public IObservable GetAll(string owner, string name, RepositoryCollaborato /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. - public IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request) + public IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); @@ -132,46 +132,46 @@ public IObservable GetAll(long repositoryId, RepositoryCollaboratorListReq /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. - public IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options) + public IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, name), request.ToParametersDictionary(), options); + return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, name), request.ToParametersDictionary(), options); } /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. - public IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options) + public IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(repositoryId), request.ToParametersDictionary(), options); + return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(repositoryId), request.ToParametersDictionary(), options); } /// /// Checks if a user is a collaborator on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -212,7 +212,7 @@ public IObservable IsCollaborator(long repositoryId, string user) /// The name of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. - public IObservable ReviewPermission(string owner, string name, string user) + public IObservable ReviewPermission(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -230,7 +230,7 @@ public IObservable ReviewPermission(string owner, string /// The id of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. - public IObservable ReviewPermission(long repositoryId, string user) + public IObservable ReviewPermission(long repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); @@ -297,7 +297,7 @@ public IObservable Add(long repositoryId, string user) /// Adds a new collaborator to the repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Username of the new collaborator @@ -315,7 +315,7 @@ public IObservable Add(long repositoryId, string user, Col /// Invites a user as a collaborator to a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -333,7 +333,7 @@ public IObservable Invite(string owner, string name, strin /// Invites a user as a collaborator to a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -353,7 +353,7 @@ public IObservable Invite(string owner, string name, strin /// Invites a user as a collaborator to a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// The username of the prospective collaborator @@ -369,7 +369,7 @@ public IObservable Invite(long repositoryId, string user) /// Invites a user as a collaborator to a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// The username of the prospective collaborator @@ -386,7 +386,7 @@ public IObservable Invite(long repositoryId, string user, /// Deletes a collaborator from the repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository diff --git a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs index d935d23abc..7a26b714b1 100644 --- a/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GitHubAppsClientTests.cs @@ -71,7 +71,7 @@ public async Task GetsAllInstallations() Assert.Equal(Helper.GitHubAppId, installation.AppId); Assert.NotNull(installation.Account); Assert.NotNull(installation.Permissions); - Assert.Equal(InstallationPermissionLevel.Read, installation.Permissions.Metadata); + Assert.Equal(InstallationReadWritePermissionLevel.Read, installation.Permissions.Metadata); Assert.False(string.IsNullOrEmpty(installation.HtmlUrl)); Assert.NotEqual(0, installation.TargetId); } @@ -101,7 +101,7 @@ public async Task GetsInstallation() Assert.Equal(Helper.GitHubAppId, result.AppId); Assert.NotNull(result.Account); Assert.NotNull(result.Permissions); - Assert.Equal(InstallationPermissionLevel.Read, result.Permissions.Metadata); + Assert.Equal(InstallationReadWritePermissionLevel.Read, result.Permissions.Metadata); Assert.False(string.IsNullOrEmpty(result.HtmlUrl)); Assert.NotEqual(0, result.TargetId); } diff --git a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs index f2798554fa..682fe7f3c5 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs @@ -1241,7 +1241,7 @@ await _github.Organization.Team.AddRepository( team2.TeamId, repoContext.RepositoryOwner, repoContext.RepositoryName, - new RepositoryPermissionRequest(Permission.Push)); + new RepositoryPermissionRequest(TeamPermissionLegacy.Push)); var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; var restrictions = await _github.Repository.Branch.UpdateProtectedBranchTeamRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, newTeam); @@ -1265,7 +1265,7 @@ await _github.Organization.Team.AddRepository( team2.TeamId, repoContext.RepositoryOwner, repoContext.RepositoryName, - new RepositoryPermissionRequest(Permission.Push)); + new RepositoryPermissionRequest(TeamPermissionLegacy.Push)); var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; var restrictions = await _github.Repository.Branch.UpdateProtectedBranchTeamRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, newTeam); @@ -1292,7 +1292,7 @@ await _github.Organization.Team.AddRepository( team2.TeamId, repoContext.RepositoryOwner, repoContext.RepositoryName, - new RepositoryPermissionRequest(Permission.Push)); + new RepositoryPermissionRequest(TeamPermissionLegacy.Push)); var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; var restrictions = await _github.Repository.Branch.AddProtectedBranchTeamRestrictions(repoContext.RepositoryOwner, repoContext.RepositoryName, repoContext.RepositoryDefaultBranch, newTeam); @@ -1316,7 +1316,7 @@ await _github.Organization.Team.AddRepository( team2.TeamId, repoContext.RepositoryOwner, repoContext.RepositoryName, - new RepositoryPermissionRequest(Permission.Push)); + new RepositoryPermissionRequest(TeamPermissionLegacy.Push)); var newTeam = new BranchProtectionTeamCollection() { team2.TeamName }; var restrictions = await _github.Repository.Branch.AddProtectedBranchTeamRestrictions(repoContext.RepositoryId, repoContext.RepositoryDefaultBranch, newTeam); diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index 0859a81431..6ac5ce5959 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -2,8 +2,8 @@ using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; -using Xunit; using Octokit.Tests.Integration.Helpers; +using Xunit; public class RepositoryCollaboratorClientTests { @@ -19,19 +19,15 @@ public async Task ReturnsAllCollaborators() { var fixture = github.Repository.Collaborator; - // add a collaborator - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - 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); + Assert.Equal(1, collaborators.Count); } } [IntegrationTest] - public async Task ReturnsAllCollaboratorsWithRepositoryId() + public async Task ReturnsCollaboratorsWithPermissionFilter() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -40,12 +36,29 @@ public async Task ReturnsAllCollaboratorsWithRepositoryId() { var fixture = github.Repository.Collaborator; - // add a collaborator - await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); + var collaborators = await fixture.GetAll(context.RepositoryOwner, + context.RepositoryName, + new RepositoryCollaboratorListRequest() { Permission = CollaboratorPermission.Admin }); + + Assert.NotNull(collaborators); + Assert.Equal(1, collaborators.Count); + } + } + + [IntegrationTest] + public async Task ReturnsAllCollaboratorsWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; var collaborators = await fixture.GetAll(context.Repository.Id); + Assert.NotNull(collaborators); - Assert.Equal(2, collaborators.Count); + Assert.Equal(1, collaborators.Count); } } @@ -59,9 +72,6 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithoutStart() { var fixture = github.Repository.Collaborator; - // add some collaborators - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - var options = new ApiOptions { PageSize = 1, @@ -69,6 +79,7 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithoutStart() }; var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options); + Assert.NotNull(collaborators); Assert.Equal(1, collaborators.Count); } @@ -84,9 +95,6 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithoutStartAndRepositoryId( { var fixture = github.Repository.Collaborator; - // add some collaborators - await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); - var options = new ApiOptions { PageSize = 1, @@ -94,6 +102,7 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithoutStartAndRepositoryId( }; var collaborators = await fixture.GetAll(context.Repository.Id, options); + Assert.NotNull(collaborators); Assert.Equal(1, collaborators.Count); } @@ -109,9 +118,6 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithStart() { var fixture = github.Repository.Collaborator; - // add some collaborators - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - var options = new ApiOptions { PageSize = 1, @@ -120,8 +126,9 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithStart() }; var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options); + Assert.NotNull(collaborators); - Assert.Equal(1, collaborators.Count); + Assert.Equal(0, collaborators.Count); } } @@ -135,9 +142,6 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithStartAndRepositoryId() { var fixture = github.Repository.Collaborator; - // add some collaborators - await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); - var options = new ApiOptions { PageSize = 1, @@ -146,8 +150,9 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithStartAndRepositoryId() }; var collaborators = await fixture.GetAll(context.Repository.Id, options); + Assert.NotNull(collaborators); - Assert.Equal(1, collaborators.Count); + Assert.Equal(0, collaborators.Count); } } @@ -161,9 +166,6 @@ public async Task ReturnsDistinctResultsBasedOnStartPage() { var fixture = github.Repository.Collaborator; - // add some collaborators - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - var startOptions = new ApiOptions { PageSize = 1, @@ -181,7 +183,8 @@ public async Task ReturnsDistinctResultsBasedOnStartPage() var secondPage = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, skipStartOptions); - Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.Equal(1, firstPage.Count); + Assert.Equal(0, secondPage.Count); } } @@ -195,9 +198,6 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId() { var fixture = github.Repository.Collaborator; - // add some collaborators - await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); - var startOptions = new ApiOptions { PageSize = 1, @@ -215,7 +215,8 @@ public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId() var secondPage = await fixture.GetAll(context.Repository.Id, skipStartOptions); - Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.Equal(1, firstPage.Count); + Assert.Equal(0, secondPage.Count); } } } @@ -232,10 +233,7 @@ public async Task ReturnsTrueIfUserIsCollaborator() { var fixture = github.Repository.Collaborator; - // add a collaborator - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - - var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner); Assert.True(isCollab); } @@ -251,10 +249,7 @@ public async Task ReturnsTrueIfUserIsCollaboratorWithRepositoryId() { var fixture = github.Repository.Collaborator; - // add a collaborator - await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); - - var isCollab = await fixture.IsCollaborator(context.Repository.Id, "m-zuber-octokit-integration-tests"); + var isCollab = await fixture.IsCollaborator(context.Repository.Id, context.RepositoryOwner); Assert.True(isCollab); } @@ -275,7 +270,7 @@ public async Task ReturnsReadPermissionForNonCollaborator() var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); - Assert.Equal(PermissionLevel.Read, permission.Permission); + Assert.Equal("read", permission.Permission); } } @@ -291,12 +286,12 @@ public async Task ReturnsReadPermissionForNonCollaboratorWithRepositoryId() var permission = await fixture.ReviewPermission(context.RepositoryId, "octokitnet-test1"); - Assert.Equal(PermissionLevel.Read, permission.Permission); + Assert.Equal("read", permission.Permission); } } [IntegrationTest] - public async Task ReturnsWritePermissionForCollaborator() + public async Task ReturnsWritePermissionForCollaboratorInvitation() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -306,16 +301,15 @@ public async Task ReturnsWritePermissionForCollaborator() var fixture = github.Repository.Collaborator; // add a collaborator - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); + var invitation = await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1", new CollaboratorRequest("write")); - var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); - - Assert.Equal(PermissionLevel.Write, permission.Permission); + Assert.Equal(InvitationPermissionType.Write, invitation.Permissions); } } + [IntegrationTest] - public async Task ReturnsWritePermissionForCollaboratorWithRepositoryId() + public async Task ReturnsWritePermissionForCollaboratorInvitationWithRepositoryId() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -325,11 +319,9 @@ public async Task ReturnsWritePermissionForCollaboratorWithRepositoryId() var fixture = github.Repository.Collaborator; // add a collaborator - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); + var invitation = await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1", new CollaboratorRequest("write")); - var permission = await fixture.ReviewPermission(context.RepositoryId, "octokitnet-test1"); - - Assert.Equal(PermissionLevel.Write, permission.Permission); + Assert.Equal(InvitationPermissionType.Write, invitation.Permissions); } } @@ -345,7 +337,7 @@ public async Task ReturnsAdminPermissionForOwner() var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner); - Assert.Equal(PermissionLevel.Admin, permission.Permission); + Assert.Equal("admin", permission.Permission); } } @@ -361,7 +353,7 @@ public async Task ReturnsAdminPermissionForOwnerWithRepositoryId() var permission = await fixture.ReviewPermission(context.RepositoryId, context.RepositoryOwner); - Assert.Equal(PermissionLevel.Admin, permission.Permission); + Assert.Equal("admin", permission.Permission); } } @@ -382,7 +374,7 @@ public async Task ReturnsNonePermissionForPrivateRepository() var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); - Assert.Equal(PermissionLevel.None, permission.Permission); + Assert.Equal("none", permission.Permission); } } @@ -403,14 +395,14 @@ public async Task ReturnsNonePermissionForPrivateRepositoryWithRepositoryId() var permission = await fixture.ReviewPermission(context.RepositoryId, "octokitnet-test1"); - Assert.Equal(PermissionLevel.None, permission.Permission); + Assert.Equal("none", permission.Permission); } } } public class TheDeleteMethod { - [IntegrationTest] + [Fact(Skip = "Adding a collaborator sends an invitation, need to figure out a way to test the remove method.")] public async Task CheckDeleteMethod() { var github = Helper.GetAuthenticatedClient(); @@ -432,7 +424,7 @@ public async Task CheckDeleteMethod() } } - [IntegrationTest] + [Fact(Skip = "Adding a collaborator sends an invitation, need to figure out a way to test the remove method.")] public async Task CheckDeleteMethodWithRepositoryId() { var github = Helper.GetAuthenticatedClient(); @@ -466,7 +458,7 @@ public async Task CanInviteNewCollaborator() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, "octokat", permission); diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index e05b52b5b0..a3590942eb 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -20,7 +20,7 @@ public async Task CanGetAllInvitations() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator, permission); @@ -50,7 +50,7 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response1 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator1, permission); @@ -86,7 +86,7 @@ public async Task ReturnsCorrectCountOfInvitationsWithoutStart() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator, permission); @@ -116,7 +116,7 @@ public async Task ReturnsDistinctInvitationsBasedOnStart() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response1 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator1, permission); @@ -161,7 +161,7 @@ public async Task CanGetAllInvitations() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); @@ -195,7 +195,7 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName))); } var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator to all repos foreach (var context in contexts) @@ -243,7 +243,7 @@ public async Task ReturnsCorrectCountOfInvitationsWithoutStart() contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName))); } var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator to all repos foreach (var context in contexts) @@ -290,7 +290,7 @@ public async Task ReturnsDistinctInvitationsBasedOnStart() contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName))); } var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator to all repos foreach (var context in contexts) @@ -351,7 +351,7 @@ public async Task CanAcceptInvitation() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); @@ -378,7 +378,7 @@ public async Task CanDeclineInvitation() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); @@ -406,7 +406,7 @@ public async Task CanDeleteInvitation() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); @@ -433,7 +433,7 @@ public async Task CanUpdateInvitation() using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) { var fixture = github.Repository.Collaborator; - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); // invite a collaborator var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index 0735cc2f60..5cbd7ba8a0 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -326,7 +326,7 @@ public async Task CanAddRepository() var team = teamContext.Team; var repo = repoContext.Repository; - var addRepo = await _github.Organization.Team.AddRepository(team.Id, team.Organization.Login, repo.Name, new RepositoryPermissionRequest(Permission.Admin)); + var addRepo = await _github.Organization.Team.AddRepository(team.Id, team.Organization.Login, repo.Name, new RepositoryPermissionRequest(TeamPermissionLegacy.Admin)); Assert.True(addRepo); diff --git a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs index df568cfef6..ab010f9386 100644 --- a/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs +++ b/Octokit.Tests.Integration/Helpers/OrganizationRepositoryWithTeamContext.cs @@ -73,7 +73,7 @@ await client.Organization.Team.AddRepository( team.TeamId, repoContext.RepositoryOwner, repoContext.RepositoryName, - new RepositoryPermissionRequest(Permission.Push)); + new RepositoryPermissionRequest(TeamPermissionLegacy.Push)); // Protect default branch var protection = new BranchProtectionSettingsUpdate( @@ -100,7 +100,7 @@ await client.Organization.Team.AddRepository( contextOrgTeam.TeamId, contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, - new RepositoryPermissionRequest(Permission.Push)); + new RepositoryPermissionRequest(TeamPermissionLegacy.Push)); // Protect default branch var protection = new BranchProtectionSettingsUpdate( diff --git a/Octokit.Tests.Integration/Reactive/ObservableGitHubAppsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableGitHubAppsClientTests.cs index 59e6e402cd..f5da91a3de 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableGitHubAppsClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableGitHubAppsClientTests.cs @@ -73,7 +73,7 @@ public async Task GetsAllInstallations() Assert.Equal(Helper.GitHubAppId, installation.AppId); Assert.NotNull(installation.Account); Assert.NotNull(installation.Permissions); - Assert.Equal(InstallationPermissionLevel.Read, installation.Permissions.Metadata); + Assert.Equal(InstallationReadWritePermissionLevel.Read, installation.Permissions.Metadata); Assert.False(string.IsNullOrEmpty(installation.HtmlUrl)); Assert.NotEqual(0, installation.TargetId); } @@ -103,7 +103,7 @@ public async Task GetsInstallation() Assert.Equal(Helper.GitHubAppId, result.AppId); Assert.NotNull(result.Account); Assert.NotNull(result.Permissions); - Assert.Equal(InstallationPermissionLevel.Read, result.Permissions.Metadata); + Assert.Equal(InstallationReadWritePermissionLevel.Read, result.Permissions.Metadata); Assert.False(string.IsNullOrEmpty(result.HtmlUrl)); Assert.NotEqual(0, result.TargetId); } diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs index 363e7465a8..2fad13688c 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryCollaboratorClientTests.cs @@ -4,8 +4,8 @@ using Octokit; using Octokit.Reactive; using Octokit.Tests.Integration; -using Xunit; using Octokit.Tests.Integration.Helpers; +using Xunit; public class ObservableRepositoryCollaboratorClientTests { @@ -21,14 +21,10 @@ public async Task ReturnsAllCollaborators() { var fixture = new ObservableRepoCollaboratorsClient(github); - // add a collaborator - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - 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); + Assert.Equal(1, collaborators.Count); } } @@ -42,9 +38,6 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithoutStart() { var fixture = new ObservableRepoCollaboratorsClient(github); - // add some collaborators - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - var options = new ApiOptions { PageSize = 1, @@ -52,6 +45,7 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithoutStart() }; var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options).ToList(); + Assert.NotNull(collaborators); Assert.Equal(1, collaborators.Count); } @@ -67,9 +61,6 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithStart() { var fixture = new ObservableRepoCollaboratorsClient(github); - // add some collaborators - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - var options = new ApiOptions { PageSize = 1, @@ -78,8 +69,9 @@ public async Task ReturnsCorrectCountOfCollaboratorsWithStart() }; var collaborators = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, options).ToList(); + Assert.NotNull(collaborators); - Assert.Equal(1, collaborators.Count); + Assert.Equal(0, collaborators.Count); } } @@ -93,9 +85,6 @@ public async Task ReturnsDistinctResultsBasedOnStartPage() { var fixture = new ObservableRepoCollaboratorsClient(github); - // add some collaborators - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - var startOptions = new ApiOptions { PageSize = 1, @@ -113,7 +102,8 @@ public async Task ReturnsDistinctResultsBasedOnStartPage() var secondPage = await fixture.GetAll(context.RepositoryOwner, context.RepositoryName, skipStartOptions).ToList(); - Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.Equal(1, firstPage.Count); + Assert.Equal(0, secondPage.Count); } } } @@ -130,10 +120,7 @@ public async Task ReturnsTrueIfUserIsCollaborator() { var fixture = new ObservableRepoCollaboratorsClient(github); - // add a collaborator - fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); - - var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner); Assert.True(isCollab); } @@ -153,7 +140,7 @@ public async Task ReturnsReadPermissionForNonCollaborator() var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); - Assert.Equal(PermissionLevel.Read, permission.Permission); + Assert.Equal("read", permission.Permission); } } @@ -169,12 +156,12 @@ public async Task ReturnsReadPermissionForNonCollaboratorWithRepositoryId() var permission = await fixture.ReviewPermission(context.RepositoryId, "octokitnet-test1"); - Assert.Equal(PermissionLevel.Read, permission.Permission); + Assert.Equal("read", permission.Permission); } } [IntegrationTest] - public async Task ReturnsWritePermissionForCollaborator() + public async Task ReturnsWritePermissionForCollaboratorInvitation() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -184,16 +171,14 @@ public async Task ReturnsWritePermissionForCollaborator() var fixture = new ObservableRepoCollaboratorsClient(github); // add a collaborator - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); + var invitation = await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1", new CollaboratorRequest("write")); - var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); - - Assert.Equal(PermissionLevel.Write, permission.Permission); + Assert.Equal(InvitationPermissionType.Write, invitation.Permissions); } } [IntegrationTest] - public async Task ReturnsWritePermissionForCollaboratorWithRepositoryId() + public async Task ReturnsWritePermissionForCollaboratorInvitationWithRepositoryId() { var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -203,11 +188,9 @@ public async Task ReturnsWritePermissionForCollaboratorWithRepositoryId() var fixture = new ObservableRepoCollaboratorsClient(github); // add a collaborator - await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); - - var permission = await fixture.ReviewPermission(context.RepositoryId, "octokitnet-test1"); + var invitation = await fixture.Add(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1", new CollaboratorRequest("write")); - Assert.Equal(PermissionLevel.Write, permission.Permission); + Assert.Equal(InvitationPermissionType.Write, invitation.Permissions); } } @@ -223,7 +206,7 @@ public async Task ReturnsAdminPermissionForOwner() var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner); - Assert.Equal(PermissionLevel.Admin, permission.Permission); + Assert.Equal("admin", permission.Permission); } } @@ -239,7 +222,7 @@ public async Task ReturnsAdminPermissionForOwnerWithRepositoryId() var permission = await fixture.ReviewPermission(context.RepositoryId, context.RepositoryOwner); - Assert.Equal(PermissionLevel.Admin, permission.Permission); + Assert.Equal("admin", permission.Permission); } } @@ -260,7 +243,7 @@ public async Task ReturnsNonePermissionForPrivateRepository() var permission = await fixture.ReviewPermission(context.RepositoryOwner, context.RepositoryName, "octokitnet-test1"); - Assert.Equal(PermissionLevel.None, permission.Permission); + Assert.Equal("none", permission.Permission); } } @@ -281,7 +264,7 @@ public async Task ReturnsNonePermissionForPrivateRepositoryWithRepositoryId() var permission = await fixture.ReviewPermission(context.RepositoryId, "octokitnet-test1"); - Assert.Equal(PermissionLevel.None, permission.Permission); + Assert.Equal("none", permission.Permission); } } } diff --git a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs index 7e5f0d9084..a97a491a8f 100644 --- a/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Clients/RepoCollaboratorsClientTests.cs @@ -35,7 +35,7 @@ public void RequestsCorrectUrl() client.GetAll("owner", "test"); - connection.Received().GetAll( + connection.Received().GetAll( Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Any>(), Args.ApiOptions); @@ -49,7 +49,7 @@ public void RequestsCorrectUrlWithRepositoryId() client.GetAll(1); - connection.Received().GetAll( + connection.Received().GetAll( Arg.Is(u => u.ToString() == "repositories/1/collaborators"), Arg.Any>(), Args.ApiOptions); @@ -71,7 +71,7 @@ public void RequestsCorrectUrlWithApiOptions() client.GetAll("owner", "test", options); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Any>(), options); } @@ -87,7 +87,7 @@ public void RequestsCorrectUrlWithCollaboratorFilter() client.GetAll("owner", "test", request); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Is>(d => d["affiliation"] == "all"), Args.ApiOptions); @@ -99,7 +99,7 @@ public void RequestsCorrectUrlWithCollaboratorFilter() client.GetAll("owner", "test", request); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Is>(d => d["affiliation"] == "direct"), Args.ApiOptions); @@ -111,11 +111,93 @@ public void RequestsCorrectUrlWithCollaboratorFilter() client.GetAll("owner", "test", request); connection.Received() - .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), Arg.Is>(d => d["affiliation"] == "outside"), Args.ApiOptions); } + [Fact] + public void RequestsCorrectUrlWithPermissionFilter() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + var request = new RepositoryCollaboratorListRequest(); + + client.GetAll("owner", "test", request); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + Arg.Is>(d => !d.ContainsKey("permission")), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Permission = CollaboratorPermission.Admin + }; + + client.GetAll("owner", "test", request); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + Arg.Is>(d => d["permission"] == "admin"), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Permission = CollaboratorPermission.Maintain + }; + + client.GetAll("owner", "test", request); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + Arg.Is>(d => d["permission"] == "maintain"), + Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithCollaboratorFilterAndPermissionFilter() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + var request = new RepositoryCollaboratorListRequest(); + + client.GetAll("owner", "test", request); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + Arg.Is>(d => d["affiliation"] == "all" && !d.ContainsKey("permission")), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Affiliation = CollaboratorAffiliation.Direct, + Permission = CollaboratorPermission.Admin + }; + + client.GetAll("owner", "test", request); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + Arg.Is>(d => d["affiliation"] == "direct" && d["permission"] == "admin"), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Affiliation = CollaboratorAffiliation.Outside, + Permission = CollaboratorPermission.Pull + }; + + client.GetAll("owner", "test", request); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators"), + Arg.Is>(d => d["affiliation"] == "outside" && d["permission"] == "pull"), + Args.ApiOptions); + } + [Fact] public void RequestsCorrectUrlWithApiOptionsAndRepositoryId() { @@ -132,7 +214,7 @@ public void RequestsCorrectUrlWithApiOptionsAndRepositoryId() client.GetAll(1, options); connection.Received() - .GetAll( + .GetAll( Arg.Is(u => u.ToString() == "repositories/1/collaborators"), Arg.Any>(), options); @@ -149,7 +231,7 @@ public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId() client.GetAll(1, request); connection.Received() - .GetAll( + .GetAll( Arg.Is(u => u.ToString() == "repositories/1/collaborators"), Arg.Is>(d => d["affiliation"] == "all"), Args.ApiOptions); @@ -162,7 +244,7 @@ public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId() client.GetAll(1, request); connection.Received() - .GetAll( + .GetAll( Arg.Is(u => u.ToString() == "repositories/1/collaborators"), Arg.Is>(d => d["affiliation"] == "direct"), Args.ApiOptions); @@ -175,12 +257,100 @@ public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId() client.GetAll(1, request); connection.Received() - .GetAll( + .GetAll( Arg.Is(u => u.ToString() == "repositories/1/collaborators"), Arg.Is>(d => d["affiliation"] == "outside"), Args.ApiOptions); } + [Fact] + public void RequestsCorrectUrlWithPermissionFilterAndRepositoryId() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + var request = new RepositoryCollaboratorListRequest(); + + client.GetAll(1, request); + + connection.Received() + .GetAll( + Arg.Is(u => u.ToString() == "repositories/1/collaborators"), + Arg.Is>(d => !d.ContainsKey("permission")), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Permission = CollaboratorPermission.Triage + }; + + client.GetAll(1, request); + + connection.Received() + .GetAll( + Arg.Is(u => u.ToString() == "repositories/1/collaborators"), + Arg.Is>(d => d["permission"] == "triage"), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Permission = CollaboratorPermission.Push + }; + + client.GetAll(1, request); + + connection.Received() + .GetAll( + Arg.Is(u => u.ToString() == "repositories/1/collaborators"), + Arg.Is>(d => d["permission"] == "push"), + Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithCollaboratorFilterPermissionFilterAndRepositoryId() + { + var connection = Substitute.For(); + var client = new RepoCollaboratorsClient(connection); + + var request = new RepositoryCollaboratorListRequest(); + + client.GetAll(1, request); + + connection.Received() + .GetAll( + Arg.Is(u => u.ToString() == "repositories/1/collaborators"), + Arg.Is>(d => d["affiliation"] == "all" && !d.ContainsKey("permission")), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Affiliation = CollaboratorAffiliation.Direct, + Permission = CollaboratorPermission.Triage + }; + + client.GetAll(1, request); + + connection.Received() + .GetAll( + Arg.Is(u => u.ToString() == "repositories/1/collaborators"), + Arg.Is>(d => d["affiliation"] == "direct" && d["permission"] == "triage"), + Args.ApiOptions); + + request = new RepositoryCollaboratorListRequest + { + Affiliation = CollaboratorAffiliation.Outside, + Permission = CollaboratorPermission.Push + }; + + client.GetAll(1, request); + + connection.Received() + .GetAll( + Arg.Is(u => u.ToString() == "repositories/1/collaborators"), + Arg.Is>(d => d["affiliation"] == "outside" && d["permission"] == "push"), + Args.ApiOptions); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -301,7 +471,7 @@ public void RequestsCorrectUrl() var client = new RepoCollaboratorsClient(connection); client.ReviewPermission("owner", "test", "user1"); - connection.Received().Get( + connection.Received().Get( Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1/permission"), Arg.Any>()); } @@ -313,7 +483,7 @@ public void RequestsCorrectUrlWithRepositoryId() var client = new RepoCollaboratorsClient(connection); client.ReviewPermission(1L, "user1"); - connection.Received().Get( + connection.Received().Get( Arg.Is(u => u.ToString() == "repositories/1/collaborators/user1/permission"), Arg.Any>()); } @@ -393,8 +563,8 @@ public async Task SurfacesAuthorizationExceptionWhenSpecifyingCollaboratorReques connection.Put(Arg.Any(), Arg.Any()).ThrowsAsync(new AuthorizationException()); - await Assert.ThrowsAsync(() => client.Add("owner", "test", "user1", new CollaboratorRequest(Permission.Pull))); - await Assert.ThrowsAsync(() => client.Add(1, "user1", new CollaboratorRequest(Permission.Pull))); + await Assert.ThrowsAsync(() => client.Add("owner", "test", "user1", new CollaboratorRequest("pull"))); + await Assert.ThrowsAsync(() => client.Add(1, "user1", new CollaboratorRequest("pull"))); } } @@ -406,7 +576,7 @@ public void RequestsCorrectUrl() var connection = Substitute.For(); var client = new RepoCollaboratorsClient(connection); - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); client.Invite("owner", "test", "user1", permission); connection.Received().Put(Arg.Is(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Is(permission)); @@ -416,7 +586,7 @@ public void RequestsCorrectUrl() public async Task EnsuresNonNullArguments() { var client = new RepoCollaboratorsClient(Substitute.For()); - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); await Assert.ThrowsAsync(() => client.Invite(null, "test", "user1", permission)); await Assert.ThrowsAsync(() => client.Invite("", "test", "user1", permission)); diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index b29e921c07..7f11425840 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -416,7 +416,7 @@ public async Task AddOrUpdatePermission() { var connection = Substitute.For(); var client = new TeamsClient(connection); - var newPermission = new RepositoryPermissionRequest(Permission.Admin); + var newPermission = new RepositoryPermissionRequest(TeamPermissionLegacy.Admin); await client.AddRepository(1, "org", "repo", newPermission); diff --git a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs index d48a007a96..7876db4bcc 100644 --- a/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepoCollaboratorsClientTests.cs @@ -68,7 +68,7 @@ public void RequestsCorrectUrl() _client.GetAll(owner, name); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 1)); } @@ -79,7 +79,7 @@ public void RequestsCorrectUrlWithRepositoryId() _client.GetAll(repositoryId); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 1)); } @@ -98,7 +98,7 @@ public void RequestsCorrectUrlWithApiOptions() _client.GetAll(owner, name, options); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 3)); // StartPage is setted => only 1 option (StartPage) in dictionary @@ -109,7 +109,7 @@ public void RequestsCorrectUrlWithApiOptions() _client.GetAll(owner, name, options); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 2)); // PageCount is setted => none of options in dictionary @@ -120,7 +120,7 @@ public void RequestsCorrectUrlWithApiOptions() _client.GetAll(owner, name, options); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 1)); } @@ -133,7 +133,7 @@ public void RequestsCorrectUrlWithCollaboratorFilter() _client.GetAll(owner, name, request); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(d => d["affiliation"] == "all")); request = new RepositoryCollaboratorListRequest @@ -143,7 +143,7 @@ public void RequestsCorrectUrlWithCollaboratorFilter() _client.GetAll(owner, name, request); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(d => d["affiliation"] == "direct")); // PageCount is setted => none of options in dictionary @@ -154,7 +154,7 @@ public void RequestsCorrectUrlWithCollaboratorFilter() _client.GetAll(owner, name, request); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(d => d["affiliation"] == "outside")); } @@ -173,7 +173,7 @@ public void RequestsCorrectUrlWithApiOptionsAndRepositoryId() _client.GetAll(repositoryId, options); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 3)); // StartPage is setted => only 1 option (StartPage) in dictionary @@ -184,7 +184,7 @@ public void RequestsCorrectUrlWithApiOptionsAndRepositoryId() _client.GetAll(repositoryId, options); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 2)); // PageCount is setted => none of options in dictionary @@ -195,7 +195,7 @@ public void RequestsCorrectUrlWithApiOptionsAndRepositoryId() _client.GetAll(repositoryId, options); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(dictionary => dictionary.Count == 1)); } @@ -208,7 +208,7 @@ public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId() _client.GetAll(repositoryId, request); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(d => d["affiliation"] == "all")); request = new RepositoryCollaboratorListRequest @@ -218,7 +218,7 @@ public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId() _client.GetAll(repositoryId, request); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(d => d["affiliation"] == "direct")); request = new RepositoryCollaboratorListRequest @@ -228,7 +228,7 @@ public void RequestsCorrectUrlWithCollaboratorFilterAndRepositoryId() _client.GetAll(repositoryId, request); _githubClient.Connection.Received(1) - .Get>(Arg.Is(u => u.ToString() == expectedUrl), + .Get>(Arg.Is(u => u.ToString() == expectedUrl), Arg.Is>(d => d["affiliation"] == "outside")); } } @@ -507,7 +507,7 @@ private void SetupWithNonReactiveClient() public void EnsuresNonNullArguments() { SetupWithNonReactiveClient(); - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); Assert.Throws(() => _client.Invite(null, "repo", "user", permission)); Assert.Throws(() => _client.Invite("owner", null, "user", permission)); @@ -519,7 +519,7 @@ public void EnsuresNonNullArguments() public void EnsuresNonEmptyArguments() { SetupWithNonReactiveClient(); - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); Assert.Throws(() => _client.Invite("", "repo", "user", permission)); Assert.Throws(() => _client.Invite("owner", "", "user", permission)); @@ -530,7 +530,7 @@ public void EnsuresNonEmptyArguments() public async Task EnsuresNonWhitespaceArguments() { SetupWithNonReactiveClient(); - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.Invite(whitespace, "repo", "user", permission)); @@ -544,7 +544,7 @@ await AssertEx.ThrowsWhenGivenWhitespaceArgument( public void CallsInviteOnRegularDeploymentsClient() { SetupWithoutNonReactiveClient(); - var permission = new CollaboratorRequest(Permission.Push); + var permission = new CollaboratorRequest("push"); _client.Invite("owner", "repo", "user", permission); diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index 1cc0593598..7f65ccf7a2 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -4,10 +4,10 @@ namespace Octokit { /// - /// A client for GitHub's Collaborators on a Repository. + /// A client for GitHub's Collaborators API. /// /// - /// See the Collaborators API documentation for more details. + /// See the Collaborators API documentation for more details. /// public interface IRepoCollaboratorsClient { @@ -15,93 +15,93 @@ public interface IRepoCollaboratorsClient /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Thrown when a general API error occurs. - Task> GetAll(string owner, string name); + Task> GetAll(string owner, string name); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Thrown when a general API error occurs. - Task> GetAll(long repositoryId); + Task> GetAll(long repositoryId); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Options for changing the API response /// Thrown when a general API error occurs. - Task> GetAll(string owner, string name, ApiOptions options); + Task> GetAll(string owner, string name, ApiOptions options); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Options for changing the API response /// Thrown when a general API error occurs. - Task> GetAll(long repositoryId, ApiOptions options); + Task> GetAll(long repositoryId, ApiOptions options); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. - Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request); + Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. - Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request); + Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. - Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options); + Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options); /// /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. - Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options); + Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options); /// /// Checks if a user is a collaborator on a repository. @@ -136,7 +136,7 @@ public interface IRepoCollaboratorsClient /// The name of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. - Task ReviewPermission(string owner, string name, string user); + Task ReviewPermission(string owner, string name, string user); /// /// Review a user's permission level in a repository @@ -147,7 +147,7 @@ public interface IRepoCollaboratorsClient /// The id of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. - Task ReviewPermission(long repositoryId, string user); + Task ReviewPermission(long repositoryId, string user); /// /// Adds a new collaborator to the repository. diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 499ba4a23d..7cfc1e0800 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -4,10 +4,10 @@ namespace Octokit { /// - /// A client for GitHub's Collaborators on a Repository. + /// A client for GitHub's Collaborators API. /// /// - /// See the Collaborators API documentation for more details. + /// See the Collaborators API documentation for more details. /// public class RepoCollaboratorsClient : ApiClient, IRepoCollaboratorsClient { @@ -24,13 +24,13 @@ public RepoCollaboratorsClient(IApiConnection apiConnection) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Thrown when a general API error occurs. [ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")] - public Task> GetAll(string owner, string name) + public Task> GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -42,12 +42,12 @@ public Task> GetAll(string owner, string name) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Thrown when a general API error occurs. [ManualRoute("GET", "/repository/{id}/collaborators")] - public Task> GetAll(long repositoryId) + public Task> GetAll(long repositoryId) { return GetAll(repositoryId, ApiOptions.None); } @@ -56,14 +56,14 @@ public Task> GetAll(long repositoryId) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Options for changing the API response /// Thrown when a general API error occurs. [ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")] - public Task> GetAll(string owner, string name, ApiOptions options) + public Task> GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -76,13 +76,13 @@ public Task> GetAll(string owner, string name, ApiOptions op /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Options for changing the API response /// Thrown when a general API error occurs. [ManualRoute("GET", "/repository/{id}/collaborators")] - public Task> GetAll(long repositoryId, ApiOptions options) + public Task> GetAll(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); @@ -93,14 +93,14 @@ public Task> GetAll(long repositoryId, ApiOptions options) /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. [ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")] - public Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request) + public Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); @@ -113,13 +113,13 @@ public Task> GetAll(string owner, string name, RepositoryCol /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. [ManualRoute("GET", "/repository/{id}/collaborators")] - public Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request) + public Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); @@ -130,7 +130,7 @@ public Task> GetAll(long repositoryId, RepositoryCollaborato /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository @@ -138,14 +138,14 @@ public Task> GetAll(long repositoryId, RepositoryCollaborato /// Options for changing the API response /// Thrown when a general API error occurs. [ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")] - public Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options) + public Task> GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.RepoCollaborators(owner, name), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.RepoCollaborators(owner, name), request.ToParametersDictionary(), options); } @@ -153,19 +153,19 @@ public Task> GetAll(string owner, string name, RepositoryCol /// Gets all the collaborators on a repository. /// /// - /// See the API documentation for more information. + /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. [ManualRoute("GET", "/repository/{id}/collaborators")] - public Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options) + public Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.RepoCollaborators(repositoryId), request.ToParametersDictionary(), options); + return ApiConnection.GetAll(ApiUrls.RepoCollaborators(repositoryId), request.ToParametersDictionary(), options); } /// @@ -232,14 +232,14 @@ public async Task IsCollaborator(long repositoryId, string user) /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. [ManualRoute("GET", "/repos/{owner}/{repo}/collaborators/{username}/permission")] - public Task ReviewPermission(string owner, string name, string user) + public Task ReviewPermission(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return ApiConnection - .Get(ApiUrls.RepoCollaboratorPermission(owner, name, user), null); + .Get(ApiUrls.RepoCollaboratorPermission(owner, name, user), null); } /// @@ -252,12 +252,12 @@ public Task ReviewPermission(string owner, string name, /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. [ManualRoute("GET", "/repository/{id}/collaborators/{username}/permission")] - public Task ReviewPermission(long repositoryId, string user) + public Task ReviewPermission(long repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return ApiConnection - .Get(ApiUrls.RepoCollaboratorPermission(repositoryId, user), null); + .Get(ApiUrls.RepoCollaboratorPermission(repositoryId, user), null); } /// diff --git a/Octokit/Models/Request/Permission.cs b/Octokit/Models/Common/Permission.cs similarity index 51% rename from Octokit/Models/Request/Permission.cs rename to Octokit/Models/Common/Permission.cs index f3f94e003b..91a133ffeb 100644 --- a/Octokit/Models/Request/Permission.cs +++ b/Octokit/Models/Common/Permission.cs @@ -1,45 +1,53 @@ using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; using System.Globalization; using Octokit.Internal; +// Permission.cs file houses all permission-related enums / classes +// This file was created based on this suggestion https://github.com/octokit/octokit.net/issues/2323#issuecomment-1322766701 + namespace Octokit { + public enum InstallationReadWritePermissionLevel + { + [Parameter(Value = "read")] + Read, + [Parameter(Value = "write")] + Write + } + + public enum InstallationReadWriteAdminPermissionLevel + { + [Parameter(Value = "read")] + Read, + [Parameter(Value = "write")] + Write, + [Parameter(Value = "admin")] + Admin + } + + public enum InstallationWritePermissionLevel + { + [Parameter(Value = "write")] + Write + } + + public enum InstallationReadPermissionLevel + { + [Parameter(Value = "read")] + Read + } + /// - /// Used to describe a permission level. + /// The permission to grant the team on this repository(Legacy). /// - [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] - public enum Permission + public enum TeamPermissionLegacy { - /// - /// team members can pull, push and administer these repositories. - /// - [Parameter(Value = "admin")] - Admin, - - /// - /// team members can manage the repository without access to sensitive or destructive actions. Recommended for project managers. Only applies to repositories owned by organizations. - /// - [Parameter(Value = "maintain")] - Maintain, - - /// - /// team members can proactively manage issues and pull requests without write access. Recommended for contributors who triage a repository. Only applies to repositories owned by organizations. - /// - [Parameter(Value = "triage")] - Triage, - - /// - /// team members can pull and push, but not administer these repositories - /// + [Parameter(Value = "pull")] + Pull, [Parameter(Value = "push")] Push, - - /// - /// team members can pull, but not push to or administer these repositories - /// - [Parameter(Value = "pull")] - Pull + [Parameter(Value = "admin")] + Admin } /// @@ -47,7 +55,6 @@ public enum Permission /// Default: pull /// Can be one of: pull, push /// - [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] public enum TeamPermission { /// @@ -63,6 +70,37 @@ public enum TeamPermission Push } + /// + /// The permission associated with the invitation for a collaborator in a repository + /// + public enum InvitationPermissionType + { + [Parameter(Value = "read")] + Read, + [Parameter(Value = "write")] + Write, + [Parameter(Value = "admin")] + Admin, + [Parameter(Value = "triage")] + Triage, + [Parameter(Value = "maintain")] + Maintain + } + + public enum CollaboratorPermission + { + [Parameter(Value = "pull")] + Pull, + [Parameter(Value = "triage")] + Triage, + [Parameter(Value = "push")] + Push, + [Parameter(Value = "maintain")] + Maintain, + [Parameter(Value = "admin")] + Admin + } + /// /// Object for team repository permissions /// @@ -114,13 +152,37 @@ public TeamRepositoryPermissions(bool pull, bool triage, bool push, bool maintai /// public bool Admin { get; private set; } - internal string DebuggerDisplay - { - get - { - return string.Format(CultureInfo.InvariantCulture, + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, $"Permissions: Pull: {Pull}, Triage: {Triage}, Push: {Push}, Maintain: {Maintain}, Admin: {Admin}"); - } + } + + /// + /// Object for collaborator permissions + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CollaboratorPermissions + { + public CollaboratorPermissions() { } + public CollaboratorPermissions(bool pull, bool? triage, bool push, bool? maintain, bool admin) + { + Pull = pull; + Triage = triage; + Push = push; + Maintain = maintain; + Admin = admin; } + + public bool Pull { get; private set; } + + public bool? Triage { get; private set; } + + public bool Push { get; private set; } + + public bool? Maintain { get; private set; } + + public bool Admin { get; private set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, + $"Permissions: Pull: {Pull}, Triage: {Triage}, Push: {Push}, Maintain: {Maintain}, Admin: {Admin}"); } } diff --git a/Octokit/Models/Request/CollaboratorRequest.cs b/Octokit/Models/Request/CollaboratorRequest.cs index a6776d617c..ffb6e6d875 100644 --- a/Octokit/Models/Request/CollaboratorRequest.cs +++ b/Octokit/Models/Request/CollaboratorRequest.cs @@ -9,22 +9,19 @@ public class CollaboratorRequest /// /// Used to set the permission for a collaborator. /// - public CollaboratorRequest(Permission permissions) + public CollaboratorRequest(string permission) { - Permission = permissions; + Permission = permission; } /// /// The permission to grant the collaborator on this repository. + /// Only valid on organization-owned repositories. We accept the following permissions to be set: + /// pull, triage, push, maintain, admin and you can also specify a custom repository role name, + /// if the owning organization has defined any. /// - public Permission Permission { get; private set; } + public string Permission { get; private set; } - internal string DebuggerDisplay - { - get - { - return string.Format(CultureInfo.InvariantCulture, "Permission: {0}", Permission); - } - } + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, $"Permission: {Permission}"); } } diff --git a/Octokit/Models/Request/RepositoryCollaboratorListRequest.cs b/Octokit/Models/Request/RepositoryCollaboratorListRequest.cs index 6f5a8a4f4c..6cc11e6f48 100644 --- a/Octokit/Models/Request/RepositoryCollaboratorListRequest.cs +++ b/Octokit/Models/Request/RepositoryCollaboratorListRequest.cs @@ -26,10 +26,12 @@ public RepositoryCollaboratorListRequest() /// public CollaboratorAffiliation Affiliation { get; set; } - internal string DebuggerDisplay - { - get { return string.Format(CultureInfo.InvariantCulture, "Affiliation: {0}", Affiliation); } - } + /// + /// Filter collaborators by the permissions they have on the repository. If not specified, all collaborators will be returned. + /// + public CollaboratorPermission? Permission { get; set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, $"Affiliation: {Affiliation} Permission: {Permission}"); } /// diff --git a/Octokit/Models/Request/RepositoryPermissionRequest.cs b/Octokit/Models/Request/RepositoryPermissionRequest.cs index 9475b01195..184892dfa0 100644 --- a/Octokit/Models/Request/RepositoryPermissionRequest.cs +++ b/Octokit/Models/Request/RepositoryPermissionRequest.cs @@ -10,7 +10,7 @@ public class RepositoryPermissionRequest /// /// Used to add or update a team repository. /// - public RepositoryPermissionRequest(Permission permission) + public RepositoryPermissionRequest(TeamPermissionLegacy permission) { Permission = permission; } @@ -18,7 +18,7 @@ public RepositoryPermissionRequest(Permission permission) /// /// The permission to grant the team on this repository. /// - public Permission Permission { get; private set; } + public TeamPermissionLegacy Permission { get; private set; } internal string DebuggerDisplay { diff --git a/Octokit/Models/Response/Collaborator.cs b/Octokit/Models/Response/Collaborator.cs new file mode 100644 index 0000000000..269fcc2d53 --- /dev/null +++ b/Octokit/Models/Response/Collaborator.cs @@ -0,0 +1,87 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class Collaborator + { + public Collaborator() { } + + public Collaborator(string login, int id, string email, string name, string nodeId, string avatarUrl, string gravatarUrl, string url, string htmlUrl, string followersUrl, string followingUrl, string gistsUrl, string type, string starredUrl, string subscriptionsUrl, string organizationsUrl, string reposUrl, string eventsUrl, string receivedEventsUrl, bool siteAdmin, CollaboratorPermissions permissions, string roleName) + { + Login = login; + Id = id; + Email = email; + Name = name; + NodeId = nodeId; + AvatarUrl = avatarUrl; + GravatarUrl = gravatarUrl; + Url = url; + HtmlUrl = htmlUrl; + FollowersUrl = followersUrl; + FollowingUrl = followingUrl; + GistsUrl = gistsUrl; + StarredUrl = starredUrl; + SubscriptionsUrl = subscriptionsUrl; + OrganizationsUrl = organizationsUrl; + ReposUrl = reposUrl; + EventsUrl = eventsUrl; + ReceivedEventsUrl = receivedEventsUrl; + Type = type; + SiteAdmin = siteAdmin; + Permissions = permissions; + RoleName = roleName; + } + + public string Login { get; protected set; } + + public int Id { get; protected set; } + + public string Email { get; protected set; } + + public string Name { get; protected set; } + + /// + /// GraphQL Node Id + /// + public string NodeId { get; protected set; } + + public string AvatarUrl { get; protected set; } + + public string GravatarUrl { get; protected set; } + + public string Url { get; protected set; } + + public string HtmlUrl { get; protected set; } + + public string FollowersUrl { get; protected set; } + + public string FollowingUrl { get; protected set; } + + public string GistsUrl { get; protected set; } + + public string StarredUrl { get; protected set; } + + public string SubscriptionsUrl { get; protected set; } + + public string OrganizationsUrl { get; protected set; } + + public string ReposUrl { get; protected set; } + + public string EventsUrl { get; protected set; } + + public string ReceivedEventsUrl { get; protected set; } + + public string Type { get; protected set; } + + public bool SiteAdmin { get; protected set; } + + public CollaboratorPermissions Permissions { get; protected set; } + + public string RoleName { get; protected set; } + + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, + $"Collaborator: Id: {Id} Login: {Login}"); + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/CollaboratorPermission.cs b/Octokit/Models/Response/CollaboratorPermission.cs deleted file mode 100644 index 7e2ed0a577..0000000000 --- a/Octokit/Models/Response/CollaboratorPermission.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Diagnostics; - -namespace Octokit -{ - [DebuggerDisplay("{DebuggerDisplay,nq}")] - public class CollaboratorPermission - { - public CollaboratorPermission() { } - - public CollaboratorPermission(PermissionLevel permission, User user) - { - Permission = permission; - User = user; - } - - public StringEnum Permission { get; private set; } - public User User { get; private set; } - - internal string DebuggerDisplay => $"User: {User.Id} Permission: {Permission}"; - } -} diff --git a/Octokit/Models/Response/CollaboratorPermissionResponse.cs b/Octokit/Models/Response/CollaboratorPermissionResponse.cs new file mode 100644 index 0000000000..7dd8aa8b9e --- /dev/null +++ b/Octokit/Models/Response/CollaboratorPermissionResponse.cs @@ -0,0 +1,28 @@ +using System.Diagnostics; + +namespace Octokit +{ + /// + /// Based on "#/components/schemas/repository-collaborator-permission: + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class CollaboratorPermissionResponse + { + public CollaboratorPermissionResponse() { } + + public CollaboratorPermissionResponse(string permission, string roleName, Collaborator collaborator) + { + Permission = permission; + RoleName = roleName; + Collaborator = collaborator; + } + + public string Permission { get; private set; } + + public string RoleName { get; private set; } + + public Collaborator Collaborator { get; private set; } + + internal string DebuggerDisplay => $"Collaborator: {Collaborator.Id} Permission: {Permission} RoleName: {RoleName}"; + } +} diff --git a/Octokit/Models/Response/Installation.cs b/Octokit/Models/Response/Installation.cs index 98e002630d..99d4e372f9 100644 --- a/Octokit/Models/Response/Installation.cs +++ b/Octokit/Models/Response/Installation.cs @@ -9,16 +9,18 @@ namespace Octokit /// Represents an application installation. /// /// - /// For more information see https://developer.github.com/v3/apps/#find-installations + /// For more information see https://docs.github.com/en/rest/apps/installations?apiVersion=2022-11-28#list-app-installations-accessible-to-the-user-access-token /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class Installation : InstallationId { public Installation() { } - public Installation(long id, User account, string accessTokenUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection) : base(id) + public Installation(long id, User account, string accessTokensUrl, string repositoriesUrl, string htmlUrl, long appId, long targetId, AccountType targetType, InstallationPermissions permissions, IReadOnlyList events, string singleFileName, string repositorySelection) : base(id) { Account = account; + AccessTokensUrl = accessTokensUrl; + RepositoriesUrl = repositoriesUrl; HtmlUrl = htmlUrl; AppId = appId; TargetId = targetId; @@ -34,6 +36,10 @@ public Installation(long id, User account, string accessTokenUrl, string reposit /// public User Account { get; private set; } + public string AccessTokensUrl { get; private set; } + + public string RepositoriesUrl { get; private set; } + /// /// The URL to view the Installation on GitHub. /// @@ -74,10 +80,7 @@ public Installation(long id, User account, string accessTokenUrl, string reposit /// public StringEnum RepositorySelection { get; private set; } - internal new string DebuggerDisplay - { - get { return string.Format(CultureInfo.InvariantCulture, "Id: {0} AppId: {1}", Id, AppId); } - } + internal new string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Id: {0} AppId: {1}", Id, AppId); } public enum InstallationRepositorySelection diff --git a/Octokit/Models/Response/InstallationPermissions.cs b/Octokit/Models/Response/InstallationPermissions.cs index b45fe0bab2..5e4baf3803 100644 --- a/Octokit/Models/Response/InstallationPermissions.cs +++ b/Octokit/Models/Response/InstallationPermissions.cs @@ -1,9 +1,10 @@ using System.Diagnostics; -using System.Globalization; -using Octokit.Internal; namespace Octokit { + /// + /// The permissions granted to the user-to-server access token. + /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class InstallationPermissions { @@ -11,39 +12,39 @@ public InstallationPermissions() { } public InstallationPermissions ( - InstallationPermissionLevel? actions, - InstallationPermissionLevel? administration, - InstallationPermissionLevel? checks, - InstallationPermissionLevel? contents, - InstallationPermissionLevel? deployments, - InstallationPermissionLevel? environments, - InstallationPermissionLevel? issues, - InstallationPermissionLevel? metadata, - InstallationPermissionLevel? packages, - InstallationPermissionLevel? pages, - InstallationPermissionLevel? pullRequests, - InstallationPermissionLevel? repositoryAnnouncementBanners, - InstallationPermissionLevel? repositoryHooks, - InstallationPermissionLevel? repositoryProjects, - InstallationPermissionLevel? secretScanningAlerts, - InstallationPermissionLevel? secrets, - InstallationPermissionLevel? securityEvents, - InstallationPermissionLevel? singleFile, - InstallationPermissionLevel? statuses, - InstallationPermissionLevel? vulnerabilityAlerts, - InstallationPermissionLevel? workflows, - InstallationPermissionLevel? members, - InstallationPermissionLevel? organizationAdministration, - InstallationPermissionLevel? organizationCustomRoles, - InstallationPermissionLevel? organizationAnnouncementBanners, - InstallationPermissionLevel? organizationHooks, - InstallationPermissionLevel? organizationPlan, - InstallationPermissionLevel? organizationProjects, - InstallationPermissionLevel? organizationPackages, - InstallationPermissionLevel? organizationSecrets, - InstallationPermissionLevel? organizationSelfHostedRunners, - InstallationPermissionLevel? organizationUserBlocking, - InstallationPermissionLevel? teamDiscussions + InstallationReadWritePermissionLevel? actions, + InstallationReadWritePermissionLevel? administration, + InstallationReadWritePermissionLevel? checks, + InstallationReadWritePermissionLevel? contents, + InstallationReadWritePermissionLevel? deployments, + InstallationReadWritePermissionLevel? environments, + InstallationReadWritePermissionLevel? issues, + InstallationReadWritePermissionLevel? metadata, + InstallationReadWritePermissionLevel? packages, + InstallationReadWritePermissionLevel? pages, + InstallationReadWritePermissionLevel? pullRequests, + InstallationReadWritePermissionLevel? repositoryAnnouncementBanners, + InstallationReadWritePermissionLevel? repositoryHooks, + InstallationReadWriteAdminPermissionLevel? repositoryProjects, + InstallationReadWritePermissionLevel? secretScanningAlerts, + InstallationReadWritePermissionLevel? secrets, + InstallationReadWritePermissionLevel? securityEvents, + InstallationReadWritePermissionLevel? singleFile, + InstallationReadWritePermissionLevel? statuses, + InstallationReadWritePermissionLevel? vulnerabilityAlerts, + InstallationWritePermissionLevel? workflows, + InstallationReadWritePermissionLevel? members, + InstallationReadWritePermissionLevel? organizationAdministration, + InstallationReadWritePermissionLevel? organizationCustomRoles, + InstallationReadWritePermissionLevel? organizationAnnouncementBanners, + InstallationReadWritePermissionLevel? organizationHooks, + InstallationReadPermissionLevel? organizationPlan, + InstallationReadWriteAdminPermissionLevel? organizationProjects, + InstallationReadWritePermissionLevel? organizationPackages, + InstallationReadWritePermissionLevel? organizationSecrets, + InstallationReadWritePermissionLevel? organizationSelfHostedRunners, + InstallationReadWritePermissionLevel? organizationUserBlocking, + InstallationReadWritePermissionLevel? teamDiscussions ) { Actions = actions; @@ -84,180 +85,168 @@ public InstallationPermissions /// /// The level of permission to grant the access token for GitHub Actions workflows, workflow runs, and artifacts. /// - public StringEnum? Actions { get; private set; } + public StringEnum? Actions { get; private set; } /// /// The level of permission to grant the access token for repository creation, deletion, settings, teams, and collaborators creation. /// - public StringEnum? Administration { get; private set; } + public StringEnum? Administration { get; private set; } /// /// The level of permission to grant the access token for checks on code. /// - public StringEnum? Checks { get; private set; } + public StringEnum? Checks { get; private set; } /// /// The level of permission to grant the access token for repository contents, commits, branches, downloads, releases, and merges. /// - public StringEnum? Contents { get; private set; } + public StringEnum? Contents { get; private set; } /// /// The level of permission to grant the access token for deployments and deployment statuses. /// - public StringEnum? Deployments { get; private set; } + public StringEnum? Deployments { get; private set; } /// /// The level of permission to grant the access token for managing repository environments. /// - public StringEnum? Environments { get; private set; } + public StringEnum? Environments { get; private set; } /// /// The level of permission to grant the access token for issues and related comments, assignees, labels, and milestones. /// - public StringEnum? Issues { get; private set; } + public StringEnum? Issues { get; private set; } /// /// The level of permission to grant the access token to search repositories, list collaborators, and access repository metadata. /// - public StringEnum? Metadata { get; private set; } + public StringEnum? Metadata { get; private set; } /// /// The level of permission to grant the access token for packages published to GitHub Packages. /// - public StringEnum? Packages { get; private set; } + public StringEnum? Packages { get; private set; } /// /// The level of permission to grant the access token to retrieve Pages statuses, configuration, and builds, as well as create new builds. /// - public StringEnum? Pages { get; private set; } + public StringEnum? Pages { get; private set; } /// /// The level of permission to grant the access token for pull requests and related comments, assignees, labels, milestones, and merges. /// - public StringEnum? PullRequests { get; private set; } + public StringEnum? PullRequests { get; private set; } /// /// The level of permission to grant the access token to view and manage announcement banners for a repository. /// - public StringEnum? RepositoryAnnouncementBanners { get; private set; } + public StringEnum? RepositoryAnnouncementBanners { get; private set; } /// /// The level of permission to grant the access token to manage the post-receive hooks for a repository. /// - public StringEnum? RepositoryHooks { get; private set; } + public StringEnum? RepositoryHooks { get; private set; } /// /// The level of permission to grant the access token to manage repository projects, columns, and cards. /// - public StringEnum? RepositoryProjects { get; private set; } + public StringEnum? RepositoryProjects { get; private set; } /// /// The level of permission to grant the access token to view and manage secret scanning alerts. /// - public StringEnum? SecretScanningAlerts { get; private set; } + public StringEnum? SecretScanningAlerts { get; private set; } /// /// The level of permission to grant the access token to manage repository secrets. /// - public StringEnum? Secrets { get; private set; } + public StringEnum? Secrets { get; private set; } /// /// The level of permission to grant the access token to view and manage security events like code scanning alerts. /// - public StringEnum? SecurityEvents { get; private set; } + public StringEnum? SecurityEvents { get; private set; } /// /// The level of permission to grant the access token to manage just a single file. /// - public StringEnum? SingleFile { get; private set; } + public StringEnum? SingleFile { get; private set; } /// /// The level of permission to grant the access token for commit statuses. /// - public StringEnum? Statuses { get; private set; } + public StringEnum? Statuses { get; private set; } /// /// The level of permission to grant the access token to manage Dependabot alerts. /// - public StringEnum? VulnerabilityAlerts { get; private set; } + public StringEnum? VulnerabilityAlerts { get; private set; } /// /// The level of permission to grant the access token to update GitHub Actions workflow files. /// - public StringEnum? Workflows { get; private set; } + public StringEnum? Workflows { get; private set; } /// /// The level of permission to grant the access token for organization teams and members. /// - public StringEnum? Members { get; private set; } + public StringEnum? Members { get; private set; } /// /// The level of permission to grant the access token to manage access to an organization. /// - public StringEnum? OrganizationAdministration { get; private set; } + public StringEnum? OrganizationAdministration { get; private set; } /// /// The level of permission to grant the access token for custom roles management. This property is in beta and is subject to change. /// - public StringEnum? OrganizationCustomRoles { get; private set; } + public StringEnum? OrganizationCustomRoles { get; private set; } /// /// The level of permission to grant the access token to view and manage announcement banners for an organization. /// - public StringEnum? OrganizationAnnouncementBanners { get; private set; } + public StringEnum? OrganizationAnnouncementBanners { get; private set; } /// /// The level of permission to grant the access token to manage the post-receive hooks for an organization. /// - public StringEnum? OrganizationHooks { get; private set; } + public StringEnum? OrganizationHooks { get; private set; } /// /// The level of permission to grant the access token for viewing an organization's plan. /// - public StringEnum? OrganizationPlan { get; private set; } + public StringEnum? OrganizationPlan { get; private set; } /// /// The level of permission to grant the access token to manage organization projects and projects beta (where available). /// - public StringEnum? OrganizationProjects { get; private set; } + public StringEnum? OrganizationProjects { get; private set; } /// /// The level of permission to grant the access token for organization packages published to GitHub Packages. /// - public StringEnum? OrganizationPackages { get; private set; } + public StringEnum? OrganizationPackages { get; private set; } /// /// The level of permission to grant the access token to manage organization secrets. /// - public StringEnum? OrganizationSecrets { get; private set; } + public StringEnum? OrganizationSecrets { get; private set; } /// /// The level of permission to grant the access token to view and manage GitHub Actions self-hosted runners available to an organization. /// - public StringEnum? OrganizationSelfHostedRunners { get; private set; } + public StringEnum? OrganizationSelfHostedRunners { get; private set; } /// /// The level of permission to grant the access token to view and manage users blocked by the organization. /// - public StringEnum? OrganizationUserBlocking { get; private set; } + public StringEnum? OrganizationUserBlocking { get; private set; } /// /// The level of permission to grant the access token to manage team discussions and related comments. /// - public StringEnum? TeamDiscussions { get; private set; } + public StringEnum? TeamDiscussions { get; private set; } - internal string DebuggerDisplay - { - get => $"Actions: {Actions}, Administration: {Administration}, Checks: {Checks}, Contents: {Contents}, Deployments: {Deployments}, Environments: {Environments}, Issues: {Issues}, Metadata: {Metadata}, Packages: {Packages}, Pages: {Pages}, PullRequests: {PullRequests}, RepositoryAnnouncementBanners: {RepositoryAnnouncementBanners}, RepositoryHooks: {RepositoryHooks}, RepositoryProjects: {RepositoryProjects}, SecretScanningAlerts: {SecretScanningAlerts}, Secrets: {Secrets}, SecurityEvents: {SecurityEvents}, SingleFile: {SingleFile}, Statuses: {Statuses}, VulnerabilityAlerts: {VulnerabilityAlerts}, Workflows: {Workflows}, Members: {Members}, OrganizationAdministration: {OrganizationAdministration}, OrganizationCustomRoles: {OrganizationCustomRoles}, OrganizationAnnouncementBanners: {OrganizationAnnouncementBanners}, OrganizationHooks: {OrganizationHooks}, OrganizationPlan: {OrganizationPlan}, OrganizationProjects: {OrganizationProjects}, OrganizationPackages: {OrganizationPackages}, OrganizationSecrets: {OrganizationSecrets}, OrganizationSelfHostedRunners: {OrganizationSelfHostedRunners}, OrganizationUserBlocking: {OrganizationUserBlocking}, TeamDiscussions: {TeamDiscussions}"; - } - } - - public enum InstallationPermissionLevel - { - [Parameter(Value = "read")] - Read, - - [Parameter(Value = "write")] - Write + internal string DebuggerDisplay => $"Actions: {Actions}, Administration: {Administration}, Checks: {Checks}, Contents: {Contents}, Deployments: {Deployments}, Environments: {Environments}, Issues: {Issues}, Metadata: {Metadata}, Packages: {Packages}, Pages: {Pages}, PullRequests: {PullRequests}, RepositoryAnnouncementBanners: {RepositoryAnnouncementBanners}, RepositoryHooks: {RepositoryHooks}, RepositoryProjects: {RepositoryProjects}, SecretScanningAlerts: {SecretScanningAlerts}, Secrets: {Secrets}, SecurityEvents: {SecurityEvents}, SingleFile: {SingleFile}, Statuses: {Statuses}, VulnerabilityAlerts: {VulnerabilityAlerts}, Workflows: {Workflows}, Members: {Members}, OrganizationAdministration: {OrganizationAdministration}, OrganizationCustomRoles: {OrganizationCustomRoles}, OrganizationAnnouncementBanners: {OrganizationAnnouncementBanners}, OrganizationHooks: {OrganizationHooks}, OrganizationPlan: {OrganizationPlan}, OrganizationProjects: {OrganizationProjects}, OrganizationPackages: {OrganizationPackages}, OrganizationSecrets: {OrganizationSecrets}, OrganizationSelfHostedRunners: {OrganizationSelfHostedRunners}, OrganizationUserBlocking: {OrganizationUserBlocking}, TeamDiscussions: {TeamDiscussions}"; } } diff --git a/Octokit/Models/Response/PermissionLevel.cs b/Octokit/Models/Response/PermissionLevel.cs deleted file mode 100644 index b857a2b7bd..0000000000 --- a/Octokit/Models/Response/PermissionLevel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Octokit.Internal; - -namespace Octokit -{ - public enum PermissionLevel - { - [Parameter(Value = "admin")] - Admin, - [Parameter(Value = "write")] - Write, - [Parameter(Value = "read")] - Read, - [Parameter(Value = "none")] - None - } -} diff --git a/Octokit/Models/Response/RepositoryInvitation.cs b/Octokit/Models/Response/RepositoryInvitation.cs index 98b027e553..bc76e303f4 100644 --- a/Octokit/Models/Response/RepositoryInvitation.cs +++ b/Octokit/Models/Response/RepositoryInvitation.cs @@ -1,28 +1,18 @@ using System; using System.Diagnostics; using System.Globalization; -using Octokit.Internal; namespace Octokit { - public enum InvitationPermissionType - { - [Parameter(Value = "read")] - Read, - - [Parameter(Value = "write")] - Write, - - [Parameter(Value = "admin")] - Admin - } - + /// + /// Repository invitations let you manage who you collaborate with. + /// [DebuggerDisplay("{DebuggerDisplay,nq}")] public class RepositoryInvitation { public RepositoryInvitation() { } - public RepositoryInvitation(int id, string nodeId, Repository repository, User invitee, User inviter, InvitationPermissionType permissions, DateTimeOffset createdAt, string url, string htmlUrl) + public RepositoryInvitation(int id, string nodeId, Repository repository, User invitee, User inviter, InvitationPermissionType permissions, DateTimeOffset createdAt, bool expired, string url, string htmlUrl) { Id = id; NodeId = nodeId; @@ -31,10 +21,14 @@ public RepositoryInvitation(int id, string nodeId, Repository repository, User i Inviter = inviter; Permissions = permissions; CreatedAt = createdAt; + Expired = expired; Url = url; HtmlUrl = htmlUrl; } + /// + /// Unique identifier of the repository invitation. + /// public int Id { get; private set; } /// @@ -48,21 +42,26 @@ public RepositoryInvitation(int id, string nodeId, Repository repository, User i public User Inviter { get; private set; } + /// + /// The permission associated with the invitation. + /// public StringEnum Permissions { get; private set; } public DateTimeOffset CreatedAt { get; private set; } + /// + /// Whether or not the invitation has expired + /// + public bool Expired { get; private set; } + + /// + /// URL for the repository invitation + /// public string Url { get; private set; } public string HtmlUrl { get; private set; } - internal string DebuggerDisplay - { - get - { - return string.Format(CultureInfo.InvariantCulture, + internal string DebuggerDisplay => string.Format(CultureInfo.InvariantCulture, "Repository Invitation: Id: {0} Permissions: {1}", Id, Permissions); - } - } } }