diff --git a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs index 3ce1483f..f266b453 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryBranchesClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; namespace Octokit.Reactive @@ -94,7 +95,7 @@ namespace Octokit.Reactive IObservable Edit(long repositoryId, string branch, BranchUpdate update); /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -105,7 +106,7 @@ namespace Octokit.Reactive IObservable GetBranchProtection(string owner, string name, string branch); /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -115,7 +116,7 @@ namespace Octokit.Reactive IObservable GetBranchProtection(long repositoryId, string branch); /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -127,7 +128,7 @@ namespace Octokit.Reactive IObservable UpdateBranchProtection(string owner, string name, string branch, BranchProtectionSettingsUpdate update); /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -138,7 +139,7 @@ namespace Octokit.Reactive IObservable UpdateBranchProtection(long repositoryId, string branch, BranchProtectionSettingsUpdate update); /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -149,7 +150,7 @@ namespace Octokit.Reactive IObservable DeleteBranchProtection(string owner, string name, string branch); /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -157,5 +158,382 @@ namespace Octokit.Reactive /// The Id of the repository /// The name of the branch IObservable DeleteBranchProtection(long repositoryId, string branch); + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + IObservable GetRequiredStatusChecks(string owner, string name, string branch); + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + IObservable GetRequiredStatusChecks(long repositoryId, string branch); + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// Required status checks + IObservable UpdateRequiredStatusChecks(string owner, string name, string branch, BranchProtectionRequiredStatusChecksUpdate update); + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// Required status checks + IObservable UpdateRequiredStatusChecks(long repositoryId, string branch, BranchProtectionRequiredStatusChecksUpdate update); + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + IObservable DeleteRequiredStatusChecks(string owner, string name, string branch); + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + IObservable DeleteRequiredStatusChecks(long repositoryId, string branch); + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + IObservable GetRequiredStatusChecksContexts(string owner, string name, string branch); + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + IObservable GetRequiredStatusChecksContexts(long repositoryId, string branch); + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to replace + IObservable UpdateRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts); + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to replace + IObservable UpdateRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts); + + /// + /// Add the required status checks context for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to add + IObservable AddRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts); + + /// + /// Add the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to add + IObservable AddRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts); + + /// + /// Remove the required status checks context for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to remove + IObservable DeleteRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts); + + /// + /// Remove the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to remove + IObservable DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts); + + /// + /// Get the restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + IObservable GetProtectedBranchRestrictions(string owner, string name, string branch); + + /// + /// Get the restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + IObservable GetProtectedBranchRestrictions(long repositoryId, string branch); + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + IObservable DeleteProtectedBranchRestrictions(string owner, string name, string branch); + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + IObservable DeleteProtectedBranchRestrictions(long repositoryId, string branch); + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + IObservable GetProtectedBranchTeamRestrictions(string owner, string name, string branch); + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + IObservable GetProtectedBranchTeamRestrictions(long repositoryId, string branch); + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access + IObservable UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams); + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access + IObservable UpdateProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams); + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access + IObservable AddProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams); + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access + IObservable AddProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams); + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams to remove + IObservable DeleteProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams); + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams to remove + IObservable DeleteProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams); + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + IObservable GetProtectedBranchUserRestrictions(string owner, string name, string branch); + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + IObservable GetProtectedBranchUserRestrictions(long repositoryId, string branch); + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access + IObservable UpdateProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users); + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access + IObservable UpdateProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to add + IObservable AddProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users); + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to add + IObservable AddProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to remove + IObservable DeleteProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users); + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to remove + IObservable DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs index ddeda860..e6cc4978 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryBranchesClient.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; @@ -149,7 +150,7 @@ namespace Octokit.Reactive } /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -167,7 +168,7 @@ namespace Octokit.Reactive } /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -182,7 +183,7 @@ namespace Octokit.Reactive } /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -202,7 +203,7 @@ namespace Octokit.Reactive } /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -219,7 +220,7 @@ namespace Octokit.Reactive } /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -237,7 +238,7 @@ namespace Octokit.Reactive } /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -250,5 +251,606 @@ namespace Octokit.Reactive return _client.DeleteBranchProtection(repositoryId, branch).ToObservable(); } + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public IObservable GetRequiredStatusChecks(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetRequiredStatusChecks(owner, name, branch).ToObservable(); + } + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public IObservable GetRequiredStatusChecks(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetRequiredStatusChecks(repositoryId, branch).ToObservable(); + } + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// Required status checks + public IObservable UpdateRequiredStatusChecks(string owner, string name, string branch, BranchProtectionRequiredStatusChecksUpdate update) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(update, "update"); + + return _client.UpdateRequiredStatusChecks(owner, name, branch, update).ToObservable(); + } + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// Required status checks + public IObservable UpdateRequiredStatusChecks(long repositoryId, string branch, BranchProtectionRequiredStatusChecksUpdate update) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(update, "update"); + + return _client.UpdateRequiredStatusChecks(repositoryId, branch, update).ToObservable(); + } + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public IObservable DeleteRequiredStatusChecks(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.DeleteRequiredStatusChecks(owner, name, branch).ToObservable(); + } + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public IObservable DeleteRequiredStatusChecks(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.DeleteRequiredStatusChecks(repositoryId, branch).ToObservable(); + } + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public IObservable GetRequiredStatusChecksContexts(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetRequiredStatusChecksContexts(owner, name, branch).ToObservable().SelectMany(x => x); + } + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public IObservable GetRequiredStatusChecksContexts(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetRequiredStatusChecksContexts(repositoryId, branch).ToObservable().SelectMany(x => x); + } + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to replace + public IObservable UpdateRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return _client.UpdateRequiredStatusChecksContexts(owner, name, branch, contexts).ToObservable().SelectMany(x => x); + } + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to replace + public IObservable UpdateRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return _client.UpdateRequiredStatusChecksContexts(repositoryId, branch, contexts).ToObservable().SelectMany(x => x); + } + + /// + /// Add the required status checks context for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to add + public IObservable AddRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return _client.AddRequiredStatusChecksContexts(owner, name, branch, contexts).ToObservable().SelectMany(x => x); + } + + /// + /// Add the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to add + public IObservable AddRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return _client.AddRequiredStatusChecksContexts(repositoryId, branch, contexts).ToObservable().SelectMany(x => x); + } + + /// + /// Remove the required status checks context for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to remove + public IObservable DeleteRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return _client.DeleteRequiredStatusChecksContexts(owner, name, branch, contexts).ToObservable().SelectMany(x => x); + } + + /// + /// Remove the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to remove + public IObservable DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return _client.DeleteRequiredStatusChecksContexts(repositoryId, branch, contexts).ToObservable().SelectMany(x => x); + } + + /// + /// Get the restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public IObservable GetProtectedBranchRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetProtectedBranchRestrictions(owner, name, branch).ToObservable(); + } + + /// + /// Get the restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public IObservable GetProtectedBranchRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetProtectedBranchRestrictions(repositoryId, branch).ToObservable(); + } + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public IObservable DeleteProtectedBranchRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.DeleteProtectedBranchRestrictions(owner, name, branch).ToObservable(); + } + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public IObservable DeleteProtectedBranchRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.DeleteProtectedBranchRestrictions(repositoryId, branch).ToObservable(); + } + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public IObservable GetProtectedBranchTeamRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetProtectedBranchTeamRestrictions(owner, name, branch).ToObservable().SelectMany(x => x); + } + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public IObservable GetProtectedBranchTeamRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetProtectedBranchTeamRestrictions(repositoryId, branch).ToObservable().SelectMany(x => x); + } + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access + public IObservable UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return _client.UpdateProtectedBranchTeamRestrictions(owner, name, branch, teams).ToObservable().SelectMany(x => x); + } + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access + public IObservable UpdateProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return _client.UpdateProtectedBranchTeamRestrictions(repositoryId, branch, teams).ToObservable().SelectMany(x => x); + } + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access + public IObservable AddProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return _client.AddProtectedBranchTeamRestrictions(owner, name, branch, teams).ToObservable().SelectMany(x => x); + } + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access + public IObservable AddProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return _client.AddProtectedBranchTeamRestrictions(repositoryId, branch, teams).ToObservable().SelectMany(x => x); + } + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams to remove + public IObservable DeleteProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return _client.DeleteProtectedBranchTeamRestrictions(owner, name, branch, teams).ToObservable().SelectMany(x => x); + } + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams to remove + public IObservable DeleteProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return _client.DeleteProtectedBranchTeamRestrictions(repositoryId, branch, teams).ToObservable().SelectMany(x => x); + } + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public IObservable GetProtectedBranchUserRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetProtectedBranchUserRestrictions(owner, name, branch).ToObservable().SelectMany(x => x); + } + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public IObservable GetProtectedBranchUserRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return _client.GetProtectedBranchUserRestrictions(repositoryId, branch).ToObservable().SelectMany(x => x); + } + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access + public IObservable UpdateProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return _client.UpdateProtectedBranchUserRestrictions(owner, name, branch, users).ToObservable().SelectMany(x => x); + } + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access + public IObservable UpdateProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return _client.UpdateProtectedBranchUserRestrictions(repositoryId, branch, users).ToObservable().SelectMany(x => x); + } + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to add + public IObservable AddProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return _client.AddProtectedBranchUserRestrictions(owner, name, branch, users).ToObservable().SelectMany(x => x); + } + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to add + public IObservable AddProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return _client.AddProtectedBranchUserRestrictions(repositoryId, branch, users).ToObservable().SelectMany(x => x); + } + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to remove + public IObservable DeleteProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return _client.DeleteProtectedBranchUserRestrictions(owner, name, branch, users).ToObservable().SelectMany(x => x); + } + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to remove + public IObservable DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return _client.DeleteProtectedBranchUserRestrictions(repositoryId, branch, users).ToObservable().SelectMany(x => x); + } } } diff --git a/Octokit.Tests.Conventions/PaginationTests.cs b/Octokit.Tests.Conventions/PaginationTests.cs index 2f1c3c88..2c4cb774 100644 --- a/Octokit.Tests.Conventions/PaginationTests.cs +++ b/Octokit.Tests.Conventions/PaginationTests.cs @@ -15,7 +15,7 @@ namespace Octokit.Tests.Conventions var methodsOrdered = clientInterface.GetMethodsOrdered(); var methodsWhichCanPaginate = methodsOrdered - .Where(x => x.Name.StartsWith("GetAll")); + .Where(x => x.Name.StartsWith("GetAll") && !x.HasAttribute()); var invalidMethods = methodsWhichCanPaginate .Where(method => MethodHasAppropriateOverload(method, methodsOrdered) == null) @@ -35,7 +35,7 @@ namespace Octokit.Tests.Conventions var methodsThatCanPaginate = methodsOrdered .Where(x => x.ReturnType.GetTypeInfo().TypeCategory == TypeCategory.ReadOnlyList) - .Where(x => x.Name.StartsWith("Get")); + .Where(x => x.Name.StartsWith("Get") && !x.HasAttribute()); var invalidMethods = methodsThatCanPaginate .Where(x => !x.Name.StartsWith("GetAll")) diff --git a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs index 39542e61..b59b6e41 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryBranchesClientTests.cs @@ -190,6 +190,7 @@ public class RepositoryBranchesClientTests Assert.NotNull(branch); Assert.Equal("master", branch.Name); Assert.NotNull(branch.Protection); + Assert.True(branch.Protected); } @@ -486,7 +487,7 @@ public class RepositoryBranchesClientTests { IGitHubClient _github; IRepositoryBranchesClient _client; - + public TheDeleteBranchProtectionMethod() { _github = Helper.GetAuthenticatedClient(); @@ -543,4 +544,785 @@ public class RepositoryBranchesClientTests } } } + + public class TheGetRequiredStatusChecksMethod : IDisposable + { + IRepositoryBranchesClient _client; + RepositoryContext _userRepoContext; + + public TheGetRequiredStatusChecksMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task GetsRequiredStatusChecks() + { + var repoOwner = _userRepoContext.RepositoryOwner; + var repoName = _userRepoContext.RepositoryName; + var requiredStatusChecks = await _client.GetRequiredStatusChecks(repoOwner, repoName, "master"); + + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.IncludeAdmins); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(2, requiredStatusChecks.Contexts.Count); + } + + [IntegrationTest] + public async Task GetsRequiredStatusChecksWithRepositoryId() + { + var repoId = _userRepoContext.RepositoryId; + var requiredStatusChecks = await _client.GetRequiredStatusChecks(repoId, "master"); + + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.IncludeAdmins); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(2, requiredStatusChecks.Contexts.Count); + } + + public void Dispose() + { + if (_userRepoContext != null) + _userRepoContext.Dispose(); + } + } + + public class TheUpdateRequiredStatusChecksMethod : IDisposable + { + IRepositoryBranchesClient _client; + RepositoryContext _userRepoContext; + + public TheUpdateRequiredStatusChecksMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task UpdateRequiredStatusChecks() + { + var repoOwner = _userRepoContext.RepositoryOwner; + var repoName = _userRepoContext.RepositoryName; + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "new" }); + var requiredStatusChecks = await _client.UpdateRequiredStatusChecks(repoOwner, repoName, "master", update); + + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.Contexts.Contains("new")); + Assert.True(requiredStatusChecks.IncludeAdmins); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(1, requiredStatusChecks.Contexts.Count); + } + + [IntegrationTest] + public async Task UpdatesRequiredStatusChecksWithRepositoryId() + { + var repoId = _userRepoContext.RepositoryId; + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "new" }); + var requiredStatusChecks = await _client.UpdateRequiredStatusChecks(repoId, "master", update); + + Assert.NotNull(requiredStatusChecks); + Assert.NotNull(requiredStatusChecks.Contexts); + Assert.True(requiredStatusChecks.Contexts.Contains("new")); + Assert.True(requiredStatusChecks.IncludeAdmins); + Assert.True(requiredStatusChecks.Strict); + Assert.Equal(1, requiredStatusChecks.Contexts.Count); + } + + public void Dispose() + { + if (_userRepoContext != null) + _userRepoContext.Dispose(); + } + } + + public class TheDeleteRequiredStatusChecksMethod + { + IGitHubClient _github; + IRepositoryBranchesClient _client; + + public TheDeleteRequiredStatusChecksMethod() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + } + + [IntegrationTest] + public async Task DeletesRequiredStatusChecks() + { + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryOwner; + var repoName = context.RepositoryName; + var deleted = await _client.DeleteRequiredStatusChecks(repoOwner, repoName, "master"); + + Assert.True(deleted); + } + } + + [IntegrationTest] + public async Task DeletesRequiredStatusChecksWithRepositoryId() + { + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryId; + var deleted = await _client.DeleteRequiredStatusChecks(repoId, "master"); + + Assert.True(deleted); + } + } + } + + public class TheGetRequiredStatusChecksContextsMethod : IDisposable + { + IRepositoryBranchesClient _client; + RepositoryContext _userRepoContext; + + public TheGetRequiredStatusChecksContextsMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task GetsRequiredStatusChecksContexts() + { + var repoOwner = _userRepoContext.RepositoryOwner; + var repoName = _userRepoContext.RepositoryName; + var requiredStatusChecksContexts = await _client.GetRequiredStatusChecksContexts(repoOwner, repoName, "master"); + + Assert.NotNull(requiredStatusChecksContexts); + Assert.Equal(2, requiredStatusChecksContexts.Count); + } + + [IntegrationTest] + public async Task GetsRequiredStatusChecksContextsWithRepositoryId() + { + var repoId = _userRepoContext.RepositoryId; + var requiredStatusChecksContexts = await _client.GetRequiredStatusChecksContexts(repoId, "master"); + + Assert.NotNull(requiredStatusChecksContexts); + Assert.Equal(2, requiredStatusChecksContexts.Count); + } + + public void Dispose() + { + if (_userRepoContext != null) + _userRepoContext.Dispose(); + } + } + + public class TheUpdateRequiredStatusChecksContextsMethod : IDisposable + { + IRepositoryBranchesClient _client; + RepositoryContext _userRepoContext; + + public TheUpdateRequiredStatusChecksContextsMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task UpdateRequiredStatusChecksContexts() + { + var repoOwner = _userRepoContext.RepositoryOwner; + var repoName = _userRepoContext.RepositoryName; + var update = new List() { "build2" }; + var requiredStatusChecksContexts = await _client.UpdateRequiredStatusChecksContexts(repoOwner, repoName, "master", update); + + Assert.Equal(1, requiredStatusChecksContexts.Count); + } + + [IntegrationTest] + public async Task UpdatesRequiredStatusChecksContextsWithRepositoryId() + { + var repoId = _userRepoContext.RepositoryId; + var update = new List() { "build2" }; + var requiredStatusChecksContexts = await _client.UpdateRequiredStatusChecksContexts(repoId, "master", update); + + Assert.Equal(1, requiredStatusChecksContexts.Count); + } + + public void Dispose() + { + if (_userRepoContext != null) + _userRepoContext.Dispose(); + } + } + + public class TheAddRequiredStatusChecksContextsMethod : IDisposable + { + IRepositoryBranchesClient _client; + RepositoryContext _userRepoContext; + + public TheAddRequiredStatusChecksContextsMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _userRepoContext = github.CreateRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task AddsRequiredStatusChecksContexts() + { + var repoOwner = _userRepoContext.RepositoryOwner; + var repoName = _userRepoContext.RepositoryName; + var update = new List() { "build2", "deploy" }; + var requiredStatusChecksContexts = await _client.AddRequiredStatusChecksContexts(repoOwner, repoName, "master", update); + + Assert.NotNull(requiredStatusChecksContexts); + Assert.NotNull(requiredStatusChecksContexts.Count); + Assert.Equal(4, requiredStatusChecksContexts.Count); + } + + [IntegrationTest] + public async Task AddsRequiredStatusChecksContextsWithRepositoryId() + { + var repoId = _userRepoContext.RepositoryId; + var update = new List() { "build2", "deploy" }; + var requiredStatusChecksContexts = await _client.AddRequiredStatusChecksContexts(repoId, "master", update); + + Assert.NotNull(requiredStatusChecksContexts); + Assert.NotNull(requiredStatusChecksContexts.Count); + Assert.Equal(4, requiredStatusChecksContexts.Count); + } + + public void Dispose() + { + if (_userRepoContext != null) + _userRepoContext.Dispose(); + } + } + + public class TheDeleteRequiredStatusChecksContextsMethod + { + IGitHubClient _github; + IRepositoryBranchesClient _client; + + public TheDeleteRequiredStatusChecksContextsMethod() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + } + + [IntegrationTest] + public async Task DeletesRequiredStatusChecksContexts() + { + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryOwner; + var repoName = context.RepositoryName; + var contextsToRemove = new List() { "build" }; + var deleted = await _client.DeleteRequiredStatusChecksContexts(repoOwner, repoName, "master", contextsToRemove); + + Assert.NotNull(deleted); + Assert.True(deleted.Contains("test")); + } + } + + [IntegrationTest] + public async Task DeletesRequiredStatusChecksContextsWithRepositoryId() + { + using (var context = await _github.CreateRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryId; + var contextsToRemove = new List() { "build" }; + var deleted = await _client.DeleteRequiredStatusChecksContexts(repoId, "master", contextsToRemove); + + Assert.NotNull(deleted); + Assert.True(deleted.Contains("test")); + } + } + } + + public class TheGetProtectedBranchRestrictionsMethod : IDisposable + { + IRepositoryBranchesClient _client; + OrganizationRepositoryWithTeamContext _orgRepoContext; + + public TheGetProtectedBranchRestrictionsMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task GetsRequirProtectedBranchRestrictionsForOrgRepo() + { + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + var restrictions = await _client.GetProtectedBranchRestrictions(repoOwner, repoName, "master"); + + Assert.Equal(1, restrictions.Teams.Count); + Assert.Equal(0, restrictions.Users.Count); + } + + [IntegrationTest] + public async Task GetsProtectedBranchRestrictionsForOrgRepoWithRepositoryId() + { + var repoId = _orgRepoContext.RepositoryContext.RepositoryId; + var restrictions = await _client.GetProtectedBranchRestrictions(repoId, "master"); + + Assert.Equal(1, restrictions.Teams.Count); + Assert.Equal(0, restrictions.Users.Count); + } + + public void Dispose() + { + if (_orgRepoContext != null) + _orgRepoContext.Dispose(); + } + } + + public class TheDeleteProtectedBranchRestrictionsMethod + { + IGitHubClient _github; + IRepositoryBranchesClient _client; + + public TheDeleteProtectedBranchRestrictionsMethod() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + } + + [IntegrationTest] + public async Task DeletesRProtectedBranchRestrictionsForOrgRepo() + { + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var deleted = await _client.DeleteProtectedBranchRestrictions(repoOwner, repoName, "master"); + + Assert.True(deleted); + } + } + + [IntegrationTest] + public async Task DeletesProtectedBranchRestrictionsForOrgRepoWithRepositoryId() + { + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var deleted = await _client.DeleteProtectedBranchRestrictions(repoId, "master"); + + Assert.True(deleted); + } + } + } + + public class TheGetProtectedBranchTeamRestrictionsMethod : IDisposable + { + IRepositoryBranchesClient _client; + OrganizationRepositoryWithTeamContext _orgRepoContext; + + public TheGetProtectedBranchTeamRestrictionsMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task GetsProtectedBranchTeamRestrictionsForOrgRepo() + { + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + var restrictions = await _client.GetProtectedBranchTeamRestrictions(repoOwner, repoName, "master"); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + + [IntegrationTest] + public async Task GetsProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + var repoId = _orgRepoContext.RepositoryContext.RepositoryId; + var restrictions = await _client.GetProtectedBranchTeamRestrictions(repoId, "master"); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + + public void Dispose() + { + if (_orgRepoContext != null) + _orgRepoContext.Dispose(); + } + } + + public class TheUpdateProtectedBranchTeamRestrictionsMethod : IDisposable + { + IRepositoryBranchesClient _client; + OrganizationRepositoryWithTeamContext _orgRepoContext; + TeamContext _contextOrgTeam2; + IGitHubClient _github; + + public TheUpdateProtectedBranchTeamRestrictionsMethod() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + + _contextOrgTeam2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; + _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task UpdatesProtectedBranchTeamRestrictionsForOrgRepo() + { + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + _contextOrgTeam2.TeamId, + repoOwner, + repoName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; + var restrictions = await _client.UpdateProtectedBranchTeamRestrictions(repoOwner, repoName, "master", newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(_contextOrgTeam2.TeamName, restrictions[0].Name); + } + + [IntegrationTest] + public async Task UpdatesProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + var repoId = _orgRepoContext.RepositoryContext.RepositoryId; + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + _contextOrgTeam2.TeamId, + repoOwner, + repoName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; + var restrictions = await _client.UpdateProtectedBranchTeamRestrictions(repoId, "master", newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + + public void Dispose() + { + if (_orgRepoContext != null) + _orgRepoContext.Dispose(); + + if (_contextOrgTeam2 != null) + _contextOrgTeam2.Dispose(); + } + } + + public class TheAddProtectedBranchTeamRestrictionsMethod : IDisposable + { + IRepositoryBranchesClient _client; + OrganizationRepositoryWithTeamContext _orgRepoContext; + TeamContext _contextOrgTeam2; + IGitHubClient _github; + + public TheAddProtectedBranchTeamRestrictionsMethod() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + + _contextOrgTeam2 = _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team2"))).Result; + _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task AddsProtectedBranchTeamRestrictionsForOrgRepo() + { + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + _contextOrgTeam2.TeamId, + repoOwner, + repoName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; + var restrictions = await _client.AddProtectedBranchTeamRestrictions(repoOwner, repoName, "master", newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(2, restrictions.Count); + } + + [IntegrationTest] + public async Task AddsProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + var repoId = _orgRepoContext.RepositoryContext.RepositoryId; + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + + // Grant team push access to repo + await _github.Organization.Team.AddRepository( + _contextOrgTeam2.TeamId, + repoOwner, + repoName, + new RepositoryPermissionRequest(Permission.Push)); + + var newTeam = new BranchProtectionTeamCollection() { _contextOrgTeam2.TeamName }; + var restrictions = await _client.AddProtectedBranchTeamRestrictions(repoId, "master", newTeam); + + Assert.NotNull(restrictions); + Assert.Equal(2, restrictions.Count); + } + + public void Dispose() + { + if (_orgRepoContext != null) + _orgRepoContext.Dispose(); + + if (_contextOrgTeam2 != null) + _contextOrgTeam2.Dispose(); + } + } + + public class TheDeleteProtectedBranchTeamRestrictions + { + IGitHubClient _github; + IRepositoryBranchesClient _client; + + public TheDeleteProtectedBranchTeamRestrictions() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + } + + [IntegrationTest] + public async Task DeletesRProtectedBranchTeamRestrictionsForOrgRepo() + { + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var teamToRemove = new BranchProtectionTeamCollection() { context.TeamContext.TeamName }; + var deleted = await _client.DeleteProtectedBranchTeamRestrictions(repoOwner, repoName, "master", teamToRemove); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } + } + + [IntegrationTest] + public async Task DeletesProtectedBranchTeamRestrictionsForOrgRepoWithRepositoryId() + { + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var teamToRemove = new BranchProtectionTeamCollection() { context.TeamContext.TeamName }; + var deleted = await _client.DeleteProtectedBranchTeamRestrictions(repoId, "master", teamToRemove); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } + } + } + + public class TheGetProtectedBranchUserRestrictionsMethod : IDisposable + { + IRepositoryBranchesClient _client; + OrganizationRepositoryWithTeamContext _orgRepoContext; + + public TheGetProtectedBranchUserRestrictionsMethod() + { + var github = Helper.GetAuthenticatedClient(); + _client = github.Repository.Branch; + + _orgRepoContext = github.CreateOrganizationRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task GetsProtectedBranchUserRestrictionsForOrgRepo() + { + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + var restrictions = await _client.GetProtectedBranchUserRestrictions(repoOwner, repoName, "master"); + + Assert.NotNull(restrictions); + Assert.Equal(0, restrictions.Count); + } + + [IntegrationTest] + public async Task GetsProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + var repoId = _orgRepoContext.RepositoryContext.RepositoryId; + var restrictions = await _client.GetProtectedBranchUserRestrictions(repoId, "master"); + + Assert.NotNull(restrictions); + Assert.Equal(0, restrictions.Count); + } + + public void Dispose() + { + if (_orgRepoContext != null) + _orgRepoContext.Dispose(); + } + } + + public class TheUpdateProtectedBranchUserRestrictionsMethod : IDisposable + { + IRepositoryBranchesClient _client; + IGitHubClient _github; + OrganizationRepositoryWithTeamContext _orgRepoContext; + + public TheUpdateProtectedBranchUserRestrictionsMethod() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + + _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task UpdatesProtectedBranchUserRestrictionsForOrgRepo() + { + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _client.UpdateProtectedBranchUserRestrictions(repoOwner, repoName, "master", newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + + [IntegrationTest] + public async Task UpdatesProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + var repoId = _orgRepoContext.RepositoryContext.RepositoryId; + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _client.UpdateProtectedBranchUserRestrictions(repoId, "master", newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + + public void Dispose() + { + if (_orgRepoContext != null) + _orgRepoContext.Dispose(); + } + } + + public class TheAddProtectedBranchUserRestrictionsMethod : IDisposable + { + IRepositoryBranchesClient _client; + IGitHubClient _github; + OrganizationRepositoryWithTeamContext _orgRepoContext; + + public TheAddProtectedBranchUserRestrictionsMethod() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + + _orgRepoContext = _github.CreateOrganizationRepositoryWithProtectedBranch().Result; + } + + [IntegrationTest] + public async Task AddsProtectedBranchUserRestrictionsForOrgRepo() + { + var repoOwner = _orgRepoContext.RepositoryContext.RepositoryOwner; + var repoName = _orgRepoContext.RepositoryContext.RepositoryName; + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _client.AddProtectedBranchUserRestrictions(repoOwner, repoName, "master", newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + + [IntegrationTest] + public async Task AddsProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + var repoId = _orgRepoContext.RepositoryContext.RepositoryId; + var newUser = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + + var restrictions = await _client.AddProtectedBranchUserRestrictions(repoId, "master", newUser); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + } + + public void Dispose() + { + if (_orgRepoContext != null) + _orgRepoContext.Dispose(); + } + } + + public class TheDeleteProtectedBranchUserRestrictions + { + IGitHubClient _github; + IRepositoryBranchesClient _client; + + public TheDeleteProtectedBranchUserRestrictions() + { + _github = Helper.GetAuthenticatedClient(); + _client = _github.Repository.Branch; + } + + [IntegrationTest] + public async Task DeletesProtectedBranchUserRestrictionsForOrgRepo() + { + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoOwner = context.RepositoryContext.RepositoryOwner; + var repoName = context.RepositoryContext.RepositoryName; + var user = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + var restrictions = await _client.AddProtectedBranchUserRestrictions(repoOwner, repoName, "master", user); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + + var deleted = await _client.DeleteProtectedBranchUserRestrictions(repoOwner, repoName, "master", user); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } + } + + [IntegrationTest] + public async Task DeletesProtectedBranchUserRestrictionsForOrgRepoWithRepositoryId() + { + using (var context = await _github.CreateOrganizationRepositoryWithProtectedBranch()) + { + var repoId = context.RepositoryContext.RepositoryId; + var user = new BranchProtectionUserCollection() { _github.User.Current().Result.Login }; + var restrictions = await _client.AddProtectedBranchUserRestrictions(repoId, "master", user); + + Assert.NotNull(restrictions); + Assert.Equal(1, restrictions.Count); + + var deleted = await _client.DeleteProtectedBranchUserRestrictions(repoId, "master", user); + + Assert.NotNull(deleted); + Assert.Equal(0, deleted.Count); + } + } + } } diff --git a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs index 6a1fea96..846a77bc 100644 --- a/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryBranchesClientTests.cs @@ -234,7 +234,7 @@ namespace Octokit.Tests.Clients public async Task EnsuresNonNullArguments() { var client = new RepositoryBranchesClient(Substitute.For()); - + await Assert.ThrowsAsync(() => client.GetBranchProtection(null, "repo", "branch")); await Assert.ThrowsAsync(() => client.GetBranchProtection("owner", null, "branch")); await Assert.ThrowsAsync(() => client.GetBranchProtection("owner", "repo", null)); @@ -350,5 +350,854 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.DeleteBranchProtection(1, "")); } } + + public class TheGetRequiredStatusChecksMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetRequiredStatusChecks("owner", "repo", "branch"); + + connection.Received() + .Get(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_status_checks"), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetRequiredStatusChecks(1, "branch"); + + connection.Received() + .Get(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_status_checks"), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks(null, "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks("owner", null, "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks(1, null)); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks("", "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks("owner", "", "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks("owner", "repo", "")); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecks(1, "")); + } + } + + public class TheUpdateRequiredStatusChecksMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateRequiredStatusChecks("owner", "repo", "branch", update); + + connection.Received() + .Patch(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_status_checks"), Arg.Any(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateRequiredStatusChecks(1, "branch", update); + + connection.Received() + .Patch(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_status_checks"), Arg.Any(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }); + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks(null, "repo", "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks("owner", null, "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks("owner", "repo", null, update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks(1, null, update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks("", "repo", "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks("owner", "", "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks("owner", "repo", "", update)); + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecks(1, "", update)); + } + } + + public class TheDeleteRequiredStatusChecksMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteRequiredStatusChecks("owner", "repo", "branch"); + + connection.Connection.Received() + .Delete(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_status_checks"), Arg.Any(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteRequiredStatusChecks(1, "branch"); + + connection.Connection.Received() + .Delete(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_status_checks"), Arg.Any(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks(null, "repo", "branch")); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks("owner", null, "branch")); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks(1, null)); + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks("", "repo", "branch")); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks("owner", "", "branch")); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks("owner", "repo", "")); + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecks(1, "")); + } + } + + public class TheGetRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetRequiredStatusChecksContexts("owner", "repo", "branch"); + + connection.Received() + .Get>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_status_checks/contexts"), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetRequiredStatusChecksContexts(1, "branch"); + + connection.Received() + .Get>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_status_checks/contexts"), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts(null, "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts("owner", null, "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts(1, null)); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts("", "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts("owner", "", "branch")); + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts("owner", "repo", "")); + + await Assert.ThrowsAsync(() => client.GetRequiredStatusChecksContexts(1, "")); + } + } + + public class TheUpdateRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var update = new List() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateRequiredStatusChecksContexts("owner", "repo", "branch", update); + + connection.Received() + .Put>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_status_checks/contexts"), Arg.Any>(), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var update = new List() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateRequiredStatusChecksContexts(1, "branch", update); + + connection.Received() + .Put>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_status_checks/contexts"), Arg.Any>(), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var update = new List() { "test" }; + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts(null, "repo", "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts("owner", null, "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts("owner", "repo", null, update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts(1, null, update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts("", "repo", "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts("owner", "", "branch", update)); + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts("owner", "repo", "", update)); + + await Assert.ThrowsAsync(() => client.UpdateRequiredStatusChecksContexts(1, "", update)); + } + } + + public class TheAddRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newContexts = new List() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.AddRequiredStatusChecksContexts("owner", "repo", "branch", newContexts); + + connection.Received() + .Post>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_status_checks/contexts"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newContexts = new List() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.AddRequiredStatusChecksContexts(1, "branch", newContexts); + + connection.Received() + .Post>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_status_checks/contexts"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var newContexts = new List() { "test" }; + + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts(null, "repo", "branch", newContexts)); + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts("owner", null, "branch", newContexts)); + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts("owner", "repo", null, newContexts)); + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts(1, null, newContexts)); + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts("", "repo", "branch", newContexts)); + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts("owner", "", "branch", newContexts)); + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts("owner", "repo", "", newContexts)); + + await Assert.ThrowsAsync(() => client.AddRequiredStatusChecksContexts(1, "", newContexts)); + } + } + + public class TheDeleteRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var contextsToRemove = new List() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteRequiredStatusChecksContexts("owner", "repo", "branch", contextsToRemove); + + connection.Received() + .Delete>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/required_status_checks/contexts"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var contextsToRemove = new List() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteRequiredStatusChecksContexts(1, "branch", contextsToRemove); + + connection.Received() + .Delete>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/required_status_checks/contexts"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var contextsToRemove = new List() { "test" }; + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts(null, "repo", "branch", contextsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts("owner", null, "branch", contextsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts("owner", "repo", null, contextsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts(1, null, contextsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts("", "repo", "branch", contextsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts("owner", "", "branch", contextsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts("owner", "repo", "", contextsToRemove)); + + await Assert.ThrowsAsync(() => client.DeleteRequiredStatusChecksContexts(1, "", contextsToRemove)); + } + } + + public class TheGetProtectedBranchRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetProtectedBranchRestrictions("owner", "repo", "branch"); + + connection.Received() + .Get(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions"), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetProtectedBranchRestrictions(1, "branch"); + + connection.Received() + .Get(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions"), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions(null, "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions("owner", null, "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions(1, null)); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions("", "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions("owner", "", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions("owner", "repo", "")); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchRestrictions(1, "")); + } + } + + public class TheDeleteProtectedBranchRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteProtectedBranchRestrictions("owner", "repo", "branch"); + + connection.Connection.Received() + .Delete(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions"), Arg.Any(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteProtectedBranchRestrictions(1, "branch"); + + connection.Connection.Received() + .Delete(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions"), Arg.Any(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions(null, "repo", "branch")); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions("owner", null, "branch")); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions(1, null)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions("", "repo", "branch")); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions("owner", "", "branch")); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions("owner", "repo", "")); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchRestrictions(1, "")); + } + } + + public class TheGetProtectedBranchTeamRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetProtectedBranchTeamRestrictions("owner", "repo", "branch"); + + connection.Received() + .Get>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetProtectedBranchTeamRestrictions(1, "branch"); + + connection.Received() + .Get>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions(null, "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions("owner", null, "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions(1, null)); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions("", "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions("owner", "", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions("owner", "repo", "")); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchTeamRestrictions(1, "")); + } + } + + public class TheSetProtectedBranchTeamRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams); + + connection.Received() + .Put>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), Arg.Any>(), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateProtectedBranchTeamRestrictions(1, "branch", newTeams); + + connection.Received() + .Put>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), Arg.Any>(), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions(null, "repo", "branch", newTeams)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions("owner", null, "branch", newTeams)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions("owner", "repo", null, newTeams)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions(1, null, newTeams)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions("", "repo", "branch", newTeams)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions("owner", "", "branch", newTeams)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions("owner", "repo", "", newTeams)); + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchTeamRestrictions(1, "", newTeams)); + } + } + + public class TheAddProtectedBranchTeamRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.AddProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams); + + connection.Received() + .Post>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.AddProtectedBranchTeamRestrictions(1, "branch", newTeams); + + connection.Received() + .Post>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions(null, "repo", "branch", newTeams)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions("owner", null, "branch", newTeams)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", null, newTeams)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions(1, null, newTeams)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions("", "repo", "branch", newTeams)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions("owner", "", "branch", newTeams)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", "", newTeams)); + + await Assert.ThrowsAsync(() => client.AddProtectedBranchTeamRestrictions(1, "", newTeams)); + } + } + + public class TheDeleteProtectedBranchTeamRestrictions + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var teamsToRemove = new BranchProtectionTeamCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "branch", teamsToRemove); + + connection.Received() + .Delete>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var teamsToRemove = new BranchProtectionTeamCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteProtectedBranchTeamRestrictions(1, "branch", teamsToRemove); + + connection.Received() + .Delete>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var teamsToRemove = new BranchProtectionTeamCollection() { "test" }; + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions(null, "repo", "branch", teamsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions("owner", null, "branch", teamsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", null, teamsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions(1, null, teamsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions("", "repo", "branch", teamsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions("owner", "", "branch", teamsToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "", teamsToRemove)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchTeamRestrictions(1, "", teamsToRemove)); + } + } + + public class TheGetProtectedBranchUserRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetProtectedBranchUserRestrictions("owner", "repo", "branch"); + + connection.Received() + .Get>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/users"), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.GetProtectedBranchUserRestrictions(1, "branch"); + + connection.Received() + .Get>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/users"), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions(null, "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions("owner", null, "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions("owner", "repo", null)); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions(1, null)); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions("", "repo", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions("owner", "", "branch")); + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions("owner", "repo", "")); + + await Assert.ThrowsAsync(() => client.GetProtectedBranchUserRestrictions(1, "")); + } + } + + public class TheSetProtectedBranchUserRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newUsers = new BranchProtectionUserCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateProtectedBranchUserRestrictions("owner", "repo", "branch", newUsers); + + connection.Received() + .Put>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/users"), Arg.Any>(), null, previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newUsers = new BranchProtectionUserCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.UpdateProtectedBranchUserRestrictions(1, "branch", newUsers); + + connection.Received() + .Put>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/users"), Arg.Any>(), null, previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions(null, "repo", "branch", newUsers)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions("owner", null, "branch", newUsers)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions("owner", "repo", null, newUsers)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions(1, null, newUsers)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions("", "repo", "branch", newUsers)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions("owner", "", "branch", newUsers)); + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions("owner", "repo", "", newUsers)); + + await Assert.ThrowsAsync(() => client.UpdateProtectedBranchUserRestrictions(1, "", newUsers)); + } + } + + public class TheAddProtectedBranchUserRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newUsers = new BranchProtectionUserCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.AddProtectedBranchUserRestrictions("owner", "repo", "branch", newUsers); + + connection.Received() + .Post>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/users"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var newUsers = new BranchProtectionUserCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.AddProtectedBranchUserRestrictions(1, "branch", newUsers); + + connection.Received() + .Post>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/users"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions(null, "repo", "branch", newUsers)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions("owner", null, "branch", newUsers)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions("owner", "repo", null, newUsers)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions(1, null, newUsers)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions("", "repo", "branch", newUsers)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions("owner", "", "branch", newUsers)); + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions("owner", "repo", "", newUsers)); + + await Assert.ThrowsAsync(() => client.AddProtectedBranchUserRestrictions(1, "", newUsers)); + } + } + + public class TheDeleteProtectedBranchUserRestrictions + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var usersToRemove = new BranchProtectionUserCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteProtectedBranchUserRestrictions("owner", "repo", "branch", usersToRemove); + + connection.Received() + .Delete>(Arg.Is(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/users"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryBranchesClient(connection); + var usersToRemove = new BranchProtectionUserCollection() { "test" }; + const string previewAcceptsHeader = "application/vnd.github.loki-preview+json"; + + client.DeleteProtectedBranchUserRestrictions(1, "branch", usersToRemove); + + connection.Received() + .Delete>(Arg.Is(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/users"), Arg.Any>(), previewAcceptsHeader); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new RepositoryBranchesClient(Substitute.For()); + var usersToRemove = new BranchProtectionUserCollection() { "test" }; + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions(null, "repo", "branch", usersToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions("owner", null, "branch", usersToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", null, usersToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", "branch", null)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions(1, null, usersToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions(1, "branch", null)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions("", "repo", "branch", usersToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions("owner", "", "branch", usersToRemove)); + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", "", usersToRemove)); + + await Assert.ThrowsAsync(() => client.DeleteProtectedBranchUserRestrictions(1, "", usersToRemove)); + } + } } } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs index 5a8e6338..a4dd6a66 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryBranchesClientTests.cs @@ -204,7 +204,7 @@ namespace Octokit.Tests.Reactive { var gitHubClient = Substitute.For(); var client = new ObservableRepositoryBranchesClient(gitHubClient); - + client.GetBranchProtection("owner", "repo", "branch"); gitHubClient.Repository.Branch.Received() @@ -339,5 +339,820 @@ namespace Octokit.Tests.Reactive Assert.Throws(() => client.DeleteBranchProtection(1, "")); } } + + public class TheGetRequiredStatusChecksMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetRequiredStatusChecks("owner", "repo", "branch"); + + gitHubClient.Repository.Branch.Received() + .GetRequiredStatusChecks("owner", "repo", "branch"); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetRequiredStatusChecks(1, "branch"); + + gitHubClient.Repository.Branch.Received() + .GetRequiredStatusChecks(1, "branch"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + + Assert.Throws(() => client.GetRequiredStatusChecks(null, "repo", "branch")); + Assert.Throws(() => client.GetRequiredStatusChecks("owner", null, "branch")); + Assert.Throws(() => client.GetRequiredStatusChecks("owner", "repo", null)); + + Assert.Throws(() => client.GetRequiredStatusChecks(1, null)); + + Assert.Throws(() => client.GetRequiredStatusChecks("", "repo", "branch")); + Assert.Throws(() => client.GetRequiredStatusChecks("owner", "", "branch")); + Assert.Throws(() => client.GetRequiredStatusChecks("owner", "repo", "")); + + Assert.Throws(() => client.GetRequiredStatusChecks(1, "")); + } + } + + public class TheUpdateRequiredStatusChecksMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }); + + client.UpdateRequiredStatusChecks("owner", "repo", "branch", update); + + gitHubClient.Repository.Branch.Received() + .UpdateRequiredStatusChecks("owner", "repo", "branch", update); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }); + + client.UpdateRequiredStatusChecks(1, "branch", update); + + gitHubClient.Repository.Branch.Received() + .UpdateRequiredStatusChecks(1, "branch", update); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var update = new BranchProtectionRequiredStatusChecksUpdate(true, true, new[] { "test" }); + + Assert.Throws(() => client.UpdateRequiredStatusChecks(null, "repo", "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecks("owner", null, "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecks("owner", "repo", null, update)); + Assert.Throws(() => client.UpdateRequiredStatusChecks("owner", "repo", "branch", null)); + + Assert.Throws(() => client.UpdateRequiredStatusChecks(1, null, update)); + Assert.Throws(() => client.UpdateRequiredStatusChecks(1, "branch", null)); + + Assert.Throws(() => client.UpdateRequiredStatusChecks("", "repo", "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecks("owner", "", "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecks("owner", "repo", "", update)); + + Assert.Throws(() => client.UpdateRequiredStatusChecks(1, "", update)); + } + } + + public class TheDeleteRequiredStatusChecksMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.DeleteRequiredStatusChecks("owner", "repo", "branch"); + + gitHubClient.Repository.Branch.Received() + .DeleteRequiredStatusChecks("owner", "repo", "branch"); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.DeleteRequiredStatusChecks(1, "branch"); + + gitHubClient.Repository.Branch.Received() + .DeleteRequiredStatusChecks(1, "branch"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + + Assert.Throws(() => client.DeleteRequiredStatusChecks(null, "repo", "branch")); + Assert.Throws(() => client.DeleteRequiredStatusChecks("owner", null, "branch")); + Assert.Throws(() => client.DeleteRequiredStatusChecks("owner", "repo", null)); + + Assert.Throws(() => client.DeleteRequiredStatusChecks(1, null)); + + Assert.Throws(() => client.DeleteRequiredStatusChecks("", "repo", "branch")); + Assert.Throws(() => client.DeleteRequiredStatusChecks("owner", "", "branch")); + Assert.Throws(() => client.DeleteRequiredStatusChecks("owner", "repo", "")); + + Assert.Throws(() => client.DeleteRequiredStatusChecks(1, "")); + } + } + + public class TheGetRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetRequiredStatusChecksContexts("owner", "repo", "branch"); + + gitHubClient.Repository.Branch.Received() + .GetRequiredStatusChecksContexts("owner", "repo", "branch"); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetRequiredStatusChecksContexts(1, "branch"); + + gitHubClient.Repository.Branch.Received() + .GetRequiredStatusChecksContexts(1, "branch"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + + Assert.Throws(() => client.GetRequiredStatusChecksContexts(null, "repo", "branch")); + Assert.Throws(() => client.GetRequiredStatusChecksContexts("owner", null, "branch")); + Assert.Throws(() => client.GetRequiredStatusChecksContexts("owner", "repo", null)); + + Assert.Throws(() => client.GetRequiredStatusChecksContexts(1, null)); + + Assert.Throws(() => client.GetRequiredStatusChecksContexts("", "repo", "branch")); + Assert.Throws(() => client.GetRequiredStatusChecksContexts("owner", "", "branch")); + Assert.Throws(() => client.GetRequiredStatusChecksContexts("owner", "repo", "")); + + Assert.Throws(() => client.GetRequiredStatusChecksContexts(1, "")); + } + } + + public class TheUpdateRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var update = new List() { "test" }; + + client.UpdateRequiredStatusChecksContexts("owner", "repo", "branch", update); + + gitHubClient.Repository.Branch.Received() + .UpdateRequiredStatusChecksContexts("owner", "repo", "branch", update); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var update = new List() { "test" }; + + client.UpdateRequiredStatusChecksContexts(1, "branch", update); + + gitHubClient.Repository.Branch.Received() + .UpdateRequiredStatusChecksContexts(1, "branch", update); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var update = new List() { "test" }; + + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts(null, "repo", "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts("owner", null, "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts("owner", "repo", null, update)); + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts("owner", "repo", "branch", null)); + + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts(1, null, update)); + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts(1, "branch", null)); + + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts("", "repo", "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts("owner", "", "branch", update)); + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts("owner", "repo", "", update)); + + Assert.Throws(() => client.UpdateRequiredStatusChecksContexts(1, "", update)); + } + } + + public class TheAddRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newContexts = new List() { "test" }; + + client.AddRequiredStatusChecksContexts("owner", "repo", "branch", newContexts); + + gitHubClient.Repository.Branch.Received() + .AddRequiredStatusChecksContexts("owner", "repo", "branch", newContexts); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newContexts = new List() { "test" }; + + client.AddRequiredStatusChecksContexts(1, "branch", newContexts); + + gitHubClient.Repository.Branch.Received() + .AddRequiredStatusChecksContexts(1, "branch", newContexts); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var newContexts = new List() { "test" }; + + Assert.Throws(() => client.AddRequiredStatusChecksContexts(null, "repo", "branch", newContexts)); + Assert.Throws(() => client.AddRequiredStatusChecksContexts("owner", null, "branch", newContexts)); + Assert.Throws(() => client.AddRequiredStatusChecksContexts("owner", "repo", null, newContexts)); + Assert.Throws(() => client.AddRequiredStatusChecksContexts("owner", "repo", "branch", null)); + + Assert.Throws(() => client.AddRequiredStatusChecksContexts(1, null, newContexts)); + Assert.Throws(() => client.AddRequiredStatusChecksContexts(1, "branch", null)); + + Assert.Throws(() => client.AddRequiredStatusChecksContexts("", "repo", "branch", newContexts)); + Assert.Throws(() => client.AddRequiredStatusChecksContexts("owner", "", "branch", newContexts)); + Assert.Throws(() => client.AddRequiredStatusChecksContexts("owner", "repo", "", newContexts)); + + Assert.Throws(() => client.AddRequiredStatusChecksContexts(1, "", newContexts)); + } + } + + public class TheDeleteRequiredStatusChecksContextsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var contextsToRemove = new List() { "test" }; + + client.DeleteRequiredStatusChecksContexts("owner", "repo", "branch", contextsToRemove); + + gitHubClient.Repository.Branch.Received() + .DeleteRequiredStatusChecksContexts("owner", "repo", "branch", contextsToRemove); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var contextsToRemove = new List() { "test" }; + + client.DeleteRequiredStatusChecksContexts(1, "branch", contextsToRemove); + + gitHubClient.Repository.Branch.Received() + .DeleteRequiredStatusChecksContexts(1, "branch", contextsToRemove); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var contextsToRemove = new List() { "test" }; + + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts(null, "repo", "branch", contextsToRemove)); + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts("owner", null, "branch", contextsToRemove)); + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts("owner", "repo", null, contextsToRemove)); + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts("owner", "repo", "branch", null)); + + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts(1, null, contextsToRemove)); + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts(1, "branch", null)); + + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts("", "repo", "branch", contextsToRemove)); + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts("owner", "", "branch", contextsToRemove)); + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts("owner", "repo", "", contextsToRemove)); + + Assert.Throws(() => client.DeleteRequiredStatusChecksContexts(1, "", contextsToRemove)); + } + } + + public class TheGetProtectedBranchRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetProtectedBranchRestrictions("owner", "repo", "branch"); + + gitHubClient.Repository.Branch.Received() + .GetProtectedBranchRestrictions("owner", "repo", "branch"); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetProtectedBranchRestrictions(1, "branch"); + + gitHubClient.Repository.Branch.Received() + .GetProtectedBranchRestrictions(1, "branch"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + + Assert.Throws(() => client.GetProtectedBranchRestrictions(null, "repo", "branch")); + Assert.Throws(() => client.GetProtectedBranchRestrictions("owner", null, "branch")); + Assert.Throws(() => client.GetProtectedBranchRestrictions("owner", "repo", null)); + + Assert.Throws(() => client.GetProtectedBranchRestrictions(1, null)); + + Assert.Throws(() => client.GetProtectedBranchRestrictions("", "repo", "branch")); + Assert.Throws(() => client.GetProtectedBranchRestrictions("owner", "", "branch")); + Assert.Throws(() => client.GetProtectedBranchRestrictions("owner", "repo", "")); + + Assert.Throws(() => client.GetProtectedBranchRestrictions(1, "")); + } + } + + public class TheDeleteProtectedBranchRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.DeleteProtectedBranchRestrictions("owner", "repo", "branch"); + + gitHubClient.Repository.Branch.Received() + .DeleteProtectedBranchRestrictions("owner", "repo", "branch"); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.DeleteProtectedBranchRestrictions(1, "branch"); + + gitHubClient.Repository.Branch.Received() + .DeleteProtectedBranchRestrictions(1, "branch"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + + Assert.Throws(() => client.DeleteProtectedBranchRestrictions(null, "repo", "branch")); + Assert.Throws(() => client.DeleteProtectedBranchRestrictions("owner", null, "branch")); + Assert.Throws(() => client.DeleteProtectedBranchRestrictions("owner", "repo", null)); + + Assert.Throws(() => client.DeleteProtectedBranchRestrictions(1, null)); + + Assert.Throws(() => client.DeleteProtectedBranchRestrictions("", "repo", "branch")); + Assert.Throws(() => client.DeleteProtectedBranchRestrictions("owner", "", "branch")); + Assert.Throws(() => client.DeleteProtectedBranchRestrictions("owner", "repo", "")); + + Assert.Throws(() => client.DeleteProtectedBranchRestrictions(1, "")); + } + } + + public class TheGetProtectedBranchTeamRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetProtectedBranchTeamRestrictions("owner", "repo", "branch"); + + gitHubClient.Repository.Branch.Received() + .GetProtectedBranchTeamRestrictions("owner", "repo", "branch"); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetProtectedBranchTeamRestrictions(1, "branch"); + + gitHubClient.Repository.Branch.Received() + .GetProtectedBranchTeamRestrictions(1, "branch"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions(null, "repo", "branch")); + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions("owner", null, "branch")); + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions("owner", "repo", null)); + + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions(1, null)); + + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions("", "repo", "branch")); + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions("owner", "", "branch")); + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions("owner", "repo", "")); + + Assert.Throws(() => client.GetProtectedBranchTeamRestrictions(1, "")); + } + } + + public class TheSetProtectedBranchTeamRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + client.UpdateProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams); + + gitHubClient.Repository.Branch.Received() + .UpdateProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + client.UpdateProtectedBranchTeamRestrictions(1, "branch", newTeams); + + gitHubClient.Repository.Branch.Received() + .UpdateProtectedBranchTeamRestrictions(1, "branch", newTeams); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions(null, "repo", "branch", newTeams)); + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions("owner", null, "branch", newTeams)); + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions("owner", "repo", null, newTeams)); + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions("owner", "repo", "branch", null)); + + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions(1, null, newTeams)); + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions(1, "branch", null)); + + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions("", "repo", "branch", newTeams)); + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions("owner", "", "branch", newTeams)); + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions("owner", "repo", "", newTeams)); + + Assert.Throws(() => client.UpdateProtectedBranchTeamRestrictions(1, "", newTeams)); + } + } + + public class TheAddProtectedBranchTeamRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + client.AddProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams); + + gitHubClient.Repository.Branch.Received() + .AddProtectedBranchTeamRestrictions("owner", "repo", "branch", newTeams); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + client.AddProtectedBranchTeamRestrictions(1, "branch", newTeams); + + gitHubClient.Repository.Branch.Received() + .AddProtectedBranchTeamRestrictions(1, "branch", newTeams); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var newTeams = new BranchProtectionTeamCollection() { "test" }; + + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions(null, "repo", "branch", newTeams)); + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions("owner", null, "branch", newTeams)); + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", null, newTeams)); + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", "branch", null)); + + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions(1, null, newTeams)); + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions(1, "branch", null)); + + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions("", "repo", "branch", newTeams)); + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions("owner", "", "branch", newTeams)); + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", "", newTeams)); + + Assert.Throws(() => client.AddProtectedBranchTeamRestrictions(1, "", newTeams)); + } + } + + public class TheDeleteProtectedBranchTeamRestrictions + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var teamsToRemove = new BranchProtectionTeamCollection() { "test" }; + + client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "branch", teamsToRemove); + + gitHubClient.Repository.Branch.Received() + .DeleteProtectedBranchTeamRestrictions("owner", "repo", "branch", teamsToRemove); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var teamsToRemove = new BranchProtectionTeamCollection() { "test" }; + + client.DeleteProtectedBranchTeamRestrictions(1, "branch", teamsToRemove); + + gitHubClient.Repository.Branch.Received() + .DeleteProtectedBranchTeamRestrictions(1, "branch", teamsToRemove); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var teamsToRemove = new BranchProtectionTeamCollection() { "test" }; + + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions(null, "repo", "branch", teamsToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions("owner", null, "branch", teamsToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", null, teamsToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "branch", null)); + + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions(1, null, teamsToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions(1, "branch", null)); + + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions("", "repo", "branch", teamsToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions("owner", "", "branch", teamsToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "", teamsToRemove)); + + Assert.Throws(() => client.DeleteProtectedBranchTeamRestrictions(1, "", teamsToRemove)); + } + } + + public class TheGetProtectedBranchUserRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetProtectedBranchUserRestrictions("owner", "repo", "branch"); + + gitHubClient.Repository.Branch.Received() + .GetProtectedBranchUserRestrictions("owner", "repo", "branch"); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + + client.GetProtectedBranchUserRestrictions(1, "branch"); + + gitHubClient.Repository.Branch.Received() + .GetProtectedBranchUserRestrictions(1, "branch"); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + + Assert.Throws(() => client.GetProtectedBranchUserRestrictions(null, "repo", "branch")); + Assert.Throws(() => client.GetProtectedBranchUserRestrictions("owner", null, "branch")); + Assert.Throws(() => client.GetProtectedBranchUserRestrictions("owner", "repo", null)); + + Assert.Throws(() => client.GetProtectedBranchUserRestrictions(1, null)); + + Assert.Throws(() => client.GetProtectedBranchUserRestrictions("", "repo", "branch")); + Assert.Throws(() => client.GetProtectedBranchUserRestrictions("owner", "", "branch")); + Assert.Throws(() => client.GetProtectedBranchUserRestrictions("owner", "repo", "")); + + Assert.Throws(() => client.GetProtectedBranchUserRestrictions(1, "")); + } + } + + public class TheSetProtectedBranchUserRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + client.UpdateProtectedBranchUserRestrictions("owner", "repo", "branch", newUsers); + + gitHubClient.Repository.Branch.Received() + .UpdateProtectedBranchUserRestrictions("owner", "repo", "branch", newUsers); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + client.UpdateProtectedBranchUserRestrictions(1, "branch", newUsers); + + gitHubClient.Repository.Branch.Received() + .UpdateProtectedBranchUserRestrictions(1, "branch", newUsers); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions(null, "repo", "branch", newUsers)); + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions("owner", null, "branch", newUsers)); + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions("owner", "repo", null, newUsers)); + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions("owner", "repo", "branch", null)); + + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions(1, null, newUsers)); + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions(1, "branch", null)); + + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions("", "repo", "branch", newUsers)); + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions("owner", "", "branch", newUsers)); + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions("owner", "repo", "", newUsers)); + + Assert.Throws(() => client.UpdateProtectedBranchUserRestrictions(1, "", newUsers)); + } + } + + public class TheAddProtectedBranchUserRestrictionsMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + client.AddProtectedBranchUserRestrictions("owner", "repo", "branch", newUsers); + + gitHubClient.Repository.Branch.Received() + .AddProtectedBranchUserRestrictions("owner", "repo", "branch", newUsers); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + client.AddProtectedBranchUserRestrictions(1, "branch", newUsers); + + gitHubClient.Repository.Branch.Received() + .AddProtectedBranchUserRestrictions(1, "branch", newUsers); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var newUsers = new BranchProtectionUserCollection() { "test" }; + + Assert.Throws(() => client.AddProtectedBranchUserRestrictions(null, "repo", "branch", newUsers)); + Assert.Throws(() => client.AddProtectedBranchUserRestrictions("owner", null, "branch", newUsers)); + Assert.Throws(() => client.AddProtectedBranchUserRestrictions("owner", "repo", null, newUsers)); + Assert.Throws(() => client.AddProtectedBranchUserRestrictions("owner", "repo", "branch", null)); + + Assert.Throws(() => client.AddProtectedBranchUserRestrictions(1, null, newUsers)); + Assert.Throws(() => client.AddProtectedBranchUserRestrictions(1, "branch", null)); + + Assert.Throws(() => client.AddProtectedBranchUserRestrictions("", "repo", "branch", newUsers)); + Assert.Throws(() => client.AddProtectedBranchUserRestrictions("owner", "", "branch", newUsers)); + Assert.Throws(() => client.AddProtectedBranchUserRestrictions("owner", "repo", "", newUsers)); + + Assert.Throws(() => client.AddProtectedBranchUserRestrictions(1, "", newUsers)); + } + } + + public class TheDeleteProtectedBranchUserRestrictions + { + [Fact] + public void RequestsTheCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var usersToRemove = new BranchProtectionUserCollection() { "test" }; + + client.DeleteProtectedBranchUserRestrictions("owner", "repo", "branch", usersToRemove); + + gitHubClient.Repository.Branch.Received() + .DeleteProtectedBranchUserRestrictions("owner", "repo", "branch", usersToRemove); + } + + [Fact] + public void RequestsTheCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryBranchesClient(gitHubClient); + var usersToRemove = new BranchProtectionUserCollection() { "test" }; + + client.DeleteProtectedBranchUserRestrictions(1, "branch", usersToRemove); + + gitHubClient.Repository.Branch.Received() + .DeleteProtectedBranchUserRestrictions(1, "branch", usersToRemove); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableRepositoryBranchesClient(Substitute.For()); + var usersToRemove = new BranchProtectionUserCollection() { "test" }; + + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions(null, "repo", "branch", usersToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions("owner", null, "branch", usersToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", null, usersToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", "branch", null)); + + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions(1, null, usersToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions(1, "branch", null)); + + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions("", "repo", "branch", usersToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions("owner", "", "branch", usersToRemove)); + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", "", usersToRemove)); + + Assert.Throws(() => client.DeleteProtectedBranchUserRestrictions(1, "", usersToRemove)); + } + } } } diff --git a/Octokit/Clients/IRepositoryBranchesClient.cs b/Octokit/Clients/IRepositoryBranchesClient.cs index df6f2c92..cd96d646 100644 --- a/Octokit/Clients/IRepositoryBranchesClient.cs +++ b/Octokit/Clients/IRepositoryBranchesClient.cs @@ -99,7 +99,7 @@ namespace Octokit Task Edit(long repositoryId, string branch, BranchUpdate update); /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -110,7 +110,7 @@ namespace Octokit Task GetBranchProtection(string owner, string name, string branch); /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -120,7 +120,7 @@ namespace Octokit Task GetBranchProtection(long repositoryId, string branch); /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -132,7 +132,7 @@ namespace Octokit Task UpdateBranchProtection(string owner, string name, string branch, BranchProtectionSettingsUpdate update); /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -143,7 +143,7 @@ namespace Octokit Task UpdateBranchProtection(long repositoryId, string branch, BranchProtectionSettingsUpdate update); /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -154,7 +154,7 @@ namespace Octokit Task DeleteBranchProtection(string owner, string name, string branch); /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -162,5 +162,390 @@ namespace Octokit /// The Id of the repository /// The name of the branch Task DeleteBranchProtection(long repositoryId, string branch); + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task GetRequiredStatusChecks(string owner, string name, string branch); + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task GetRequiredStatusChecks(long repositoryId, string branch); + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// Required status checks + Task UpdateRequiredStatusChecks(string owner, string name, string branch, BranchProtectionRequiredStatusChecksUpdate update); + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// Required status checks + Task UpdateRequiredStatusChecks(long repositoryId, string branch, BranchProtectionRequiredStatusChecksUpdate update); + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + Task DeleteRequiredStatusChecks(string owner, string name, string branch); + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + Task DeleteRequiredStatusChecks(long repositoryId, string branch); + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task> GetRequiredStatusChecksContexts(string owner, string name, string branch); + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task> GetRequiredStatusChecksContexts(long repositoryId, string branch); + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to replace + Task> UpdateRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts); + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to replace + Task> UpdateRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts); + + /// + /// Add the required status checks context for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to add + Task> AddRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts); + + /// + /// Add the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to add + Task> AddRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts); + + /// + /// Remove the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to remove + Task> DeleteRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts); + + /// + /// Remove the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to remove + Task> DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts); + + /// + /// Get restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + Task GetProtectedBranchRestrictions(string owner, string name, string branch); + + /// + /// Get restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + Task GetProtectedBranchRestrictions(long repositoryId, string branch); + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + Task DeleteProtectedBranchRestrictions(string owner, string name, string branch); + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + Task DeleteProtectedBranchRestrictions(long repositoryId, string branch); + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task> GetProtectedBranchTeamRestrictions(string owner, string name, string branch); + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task> GetProtectedBranchTeamRestrictions(long repositoryId, string branch); + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access + Task> UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams); + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access to add + Task> UpdateProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams); + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access to add + Task> AddProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams); + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access + Task> AddProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams); + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams to remove + Task> DeleteProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams); + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams to remove + Task> DeleteProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams); + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task> GetProtectedBranchUserRestrictions(string owner, string name, string branch); + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + [ExcludeFromPaginationConventionTest] + Task> GetProtectedBranchUserRestrictions(long repositoryId, string branch); + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access + Task> UpdateProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users); + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access + Task> UpdateProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to add + Task> AddProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users); + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to add + Task> AddProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to remove + Task> DeleteProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users); + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to remove + Task> DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users); } } diff --git a/Octokit/Clients/RepositoryBranchesClient.cs b/Octokit/Clients/RepositoryBranchesClient.cs index e1219df2..a2fa0049 100644 --- a/Octokit/Clients/RepositoryBranchesClient.cs +++ b/Octokit/Clients/RepositoryBranchesClient.cs @@ -151,7 +151,7 @@ namespace Octokit } /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -169,7 +169,7 @@ namespace Octokit } /// - /// Get the branch protection settings for the specified branch /> + /// Get the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -184,7 +184,7 @@ namespace Octokit } /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -199,12 +199,12 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); Ensure.ArgumentNotNull(update, "update"); - + return ApiConnection.Put(ApiUrls.RepoBranchProtection(owner, name, branch), update, null, AcceptHeaders.ProtectedBranchesApiPreview); } /// - /// Update the branch protection settings for the specified branch /> + /// Update the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -221,7 +221,7 @@ namespace Octokit } /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -248,7 +248,7 @@ namespace Octokit } /// - /// Remove the branch protection settings for the specified branch /> + /// Remove the branch protection settings for the specified branch /// /// /// See the API documentation for more details @@ -270,5 +270,646 @@ namespace Octokit return false; } } + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public Task GetRequiredStatusChecks(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get(ApiUrls.RepoRequiredStatusChecks(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Get the required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public Task GetRequiredStatusChecks(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get(ApiUrls.RepoRequiredStatusChecks(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// Required status checks + public Task UpdateRequiredStatusChecks(string owner, string name, string branch, BranchProtectionRequiredStatusChecksUpdate update) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(update, "update"); + + return ApiConnection.Patch(ApiUrls.RepoRequiredStatusChecks(owner, name, branch), update, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// Required status checks + public Task UpdateRequiredStatusChecks(long repositoryId, string branch, BranchProtectionRequiredStatusChecksUpdate update) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(update, "update"); + + return ApiConnection.Patch(ApiUrls.RepoRequiredStatusChecks(repositoryId, branch), update, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public async Task DeleteRequiredStatusChecks(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + var endpoint = ApiUrls.RepoRequiredStatusChecks(owner, name, branch); + + try + { + var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } + + /// + /// Remove required status checks for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public async Task DeleteRequiredStatusChecks(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + var endpoint = ApiUrls.RepoRequiredStatusChecks(repositoryId, branch); + + try + { + var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public Task> GetRequiredStatusChecksContexts(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Get the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public Task> GetRequiredStatusChecksContexts(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to replace + public Task> UpdateRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return ApiConnection.Put>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to replace + public Task> UpdateRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return ApiConnection.Put>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Add the required status checks context for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to add + public Task> AddRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return ApiConnection.Post>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Add the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to add + public Task> AddRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return ApiConnection.Post>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove the required status checks context for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// The contexts to remove + public Task> DeleteRequiredStatusChecksContexts(string owner, string name, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return ApiConnection.Delete>(ApiUrls.RepoRequiredStatusChecksContexts(owner, name, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove the required status checks contexts for the specified branch + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// The contexts to remove + public Task> DeleteRequiredStatusChecksContexts(long repositoryId, string branch, IReadOnlyList contexts) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(contexts, "contexts"); + + return ApiConnection.Delete>(ApiUrls.RepoRequiredStatusChecksContexts(repositoryId, branch), contexts, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Get restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public Task GetProtectedBranchRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get(ApiUrls.RepoRestrictions(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Get restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public Task GetProtectedBranchRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get(ApiUrls.RepoRestrictions(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public async Task DeleteProtectedBranchRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + var endpoint = ApiUrls.RepoRestrictions(owner, name, branch); + + try + { + var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } + + /// + /// Remove restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public async Task DeleteProtectedBranchRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + var endpoint = ApiUrls.RepoRestrictions(repositoryId, branch); + + try + { + var httpStatusCode = await Connection.Delete(endpoint, null, AcceptHeaders.ProtectedBranchesApiPreview).ConfigureAwait(false); + return httpStatusCode == HttpStatusCode.NoContent; + } + catch (NotFoundException) + { + return false; + } + } + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public Task> GetProtectedBranchTeamRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Get team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public Task> GetProtectedBranchTeamRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access + public Task> UpdateProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return ApiConnection.Put>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access + public Task> UpdateProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return ApiConnection.Put>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams with push access to add + public Task> AddProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return ApiConnection.Post>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Add team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams with push access to add + public Task> AddProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return ApiConnection.Post>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of teams to remove + public Task> DeleteProtectedBranchTeamRestrictions(string owner, string name, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return ApiConnection.Delete>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove team restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of teams to remove + public Task> DeleteProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(teams, "teams"); + + return ApiConnection.Delete>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + public Task> GetProtectedBranchUserRestrictions(string owner, string name, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Get user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + public Task> GetProtectedBranchUserRestrictions(long repositoryId, string branch) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + + return ApiConnection.Get>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access + public Task> UpdateProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return ApiConnection.Put>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Replace user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access + public Task> UpdateProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return ApiConnection.Put>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, null, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to add + public Task> AddProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return ApiConnection.Post>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Add user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to add + public Task> AddProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return ApiConnection.Post>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// List of users with push access to remove + public Task> DeleteProtectedBranchUserRestrictions(string owner, string name, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return ApiConnection.Delete>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, AcceptHeaders.ProtectedBranchesApiPreview); + } + + /// + /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) + /// + /// + /// See the API documentation for more details + /// + /// The Id of the repository + /// The name of the branch + /// List of users with push access to remove + public Task> DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users) + { + Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); + Ensure.ArgumentNotNull(users, "users"); + + return ApiConnection.Delete>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, AcceptHeaders.ProtectedBranchesApiPreview); + } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index a875a150..bd88186a 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -1635,6 +1635,121 @@ namespace Octokit return "repositories/{0}/branches/{1}/protection".FormatUri(repositoryId, branchName); } + /// + /// Returns the for required status checks for a protected branch. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// + public static Uri RepoRequiredStatusChecks(string owner, string name, string branchName) + { + return "repos/{0}/{1}/branches/{2}/protection/required_status_checks".FormatUri(owner, name, branchName); + } + + /// + /// Returns the for required status checks for a protected branch. + /// + /// The Id of the repository + /// The name of the branch + /// + public static Uri RepoRequiredStatusChecks(long repositoryId, string branchName) + { + return "repositories/{0}/branches/{1}/protection/required_status_checks".FormatUri(repositoryId, branchName); + } + + /// + /// Returns the for required status checks for a protected branch. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// + public static Uri RepoRequiredStatusChecksContexts(string owner, string name, string branchName) + { + return "repos/{0}/{1}/branches/{2}/protection/required_status_checks/contexts".FormatUri(owner, name, branchName); + } + + /// + /// Returns the for required status checks for a protected branch. + /// + /// The Id of the repository + /// The name of the branch + /// + public static Uri RepoRequiredStatusChecksContexts(long repositoryId, string branchName) + { + return "repositories/{0}/branches/{1}/protection/required_status_checks/contexts".FormatUri(repositoryId, branchName); + } + + /// + /// Returns the for restrictions for a protected branch. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// + public static Uri RepoRestrictions(string owner, string name, string branchName) + { + return "repos/{0}/{1}/branches/{2}/protection/restrictions".FormatUri(owner, name, branchName); + } + + /// + /// Returns the for restrictions for a protected branch. + /// + /// The Id of the repository + /// The name of the branch + /// + public static Uri RepoRestrictions(long repositoryId, string branchName) + { + return "repositories/{0}/branches/{1}/protection/restrictions".FormatUri(repositoryId, branchName); + } + + /// + /// Returns the for team restrictions for a protected branch. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// + public static Uri RepoRestrictionsTeams(string owner, string name, string branchName) + { + return "repos/{0}/{1}/branches/{2}/protection/restrictions/teams".FormatUri(owner, name, branchName); + } + + /// + /// Returns the for team restrictions for a protected branch. + /// + /// The Id of the repository + /// The name of the branch + /// + public static Uri RepoRestrictionsTeams(long repositoryId, string branchName) + { + return "repositories/{0}/branches/{1}/protection/restrictions/teams".FormatUri(repositoryId, branchName); + } + + /// + /// Returns the for user restrictions for a protected branch. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the branch + /// + public static Uri RepoRestrictionsUsers(string owner, string name, string branchName) + { + return "repos/{0}/{1}/branches/{2}/protection/restrictions/users".FormatUri(owner, name, branchName); + } + + /// + /// Returns the for user restrictions for a protected branch. + /// + /// The Id of the repository + /// The name of the branch + /// + public static Uri RepoRestrictionsUsers(long repositoryId, string branchName) + { + return "repositories/{0}/branches/{1}/protection/restrictions/users".FormatUri(repositoryId, branchName); + } + /// /// Returns the for a repository. /// diff --git a/Octokit/Helpers/ExcludeFromPaginationConventionTest.cs b/Octokit/Helpers/ExcludeFromPaginationConventionTest.cs new file mode 100644 index 00000000..d5c11db6 --- /dev/null +++ b/Octokit/Helpers/ExcludeFromPaginationConventionTest.cs @@ -0,0 +1,9 @@ +using System; + +namespace Octokit +{ + [AttributeUsage(AttributeTargets.Method)] + public sealed class ExcludeFromPaginationConventionTestAttribute : Attribute + { + } +} diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index 0d609033..9795ca5b 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -494,6 +494,25 @@ namespace Octokit return Connection.Delete(uri, data, accepts); } + /// + /// Performs an asynchronous HTTP DELETE request. + /// Attempts to map the response body to an object of type + /// + /// The type to map the response to + /// URI endpoint to send request to + /// The object to serialize as the body of the request + /// Specifies accept response media type + public async Task Delete(Uri uri, object data, string accepts) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(data, "data"); + Ensure.ArgumentNotNull(accepts, "accepts"); + + var response = await Connection.Delete(uri, data, accepts).ConfigureAwait(false); + + return response.Body; + } + /// /// Executes a GET to the API object at the specified URI. This operation is appropriate for API calls which /// queue long running calculations and return a collection of a resource. diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index c98b76e3..d9ede0a2 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -490,6 +490,22 @@ namespace Octokit return response.HttpResponse.StatusCode; } + /// + /// Performs an asynchronous HTTP DELETE request. + /// Attempts to map the response body to an object of type + /// + /// The type to map the response to + /// URI endpoint to send request to + /// The object to serialize as the body of the request + /// Specifies accept response media type + public Task> Delete(Uri uri, object data, string accepts) + { + Ensure.ArgumentNotNull(uri, "uri"); + Ensure.ArgumentNotNull(accepts, "accepts"); + + return SendData(uri, HttpMethod.Delete, data, accepts, null, CancellationToken.None); + } + /// /// Base address for the connection. /// diff --git a/Octokit/Http/IApiConnection.cs b/Octokit/Http/IApiConnection.cs index a7ff7505..ec7da6ff 100644 --- a/Octokit/Http/IApiConnection.cs +++ b/Octokit/Http/IApiConnection.cs @@ -320,6 +320,17 @@ namespace Octokit /// The returned Task Delete(Uri uri, object data, string accepts); + /// + /// Performs an asynchronous HTTP DELETE request. + /// Attempts to map the response body to an object of type + /// + /// The API resource's type. + /// URI endpoint to send request to + /// The object to serialize as the body of the request + /// Specifies accept response media type + /// The returned + Task Delete(Uri uri, object data, string accepts); + /// /// Executes a GET to the API object at the specified URI. This operation is appropriate for API calls which /// queue long running calculations and return a collection of a resource. diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index 1cfaa4e9..5ac737e9 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -237,6 +237,16 @@ namespace Octokit /// The returned Task Delete(Uri uri, object data, string accepts); + /// + /// Performs an asynchronous HTTP DELETE request. + /// Attempts to map the response body to an object of type + /// + /// The type to map the response to + /// URI endpoint to send request to + /// The object to serialize as the body of the request + /// Specifies accept response media type + Task> Delete(Uri uri, object data, string accepts); + /// /// Base address for the connection. /// diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 10f624f6..73fed27b 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -492,6 +492,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 7dc3e9b2..7f7bcb3b 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -503,6 +503,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index cfc5f43d..149382fa 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -499,6 +499,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 04a7fbc1..9add0540 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -489,6 +489,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 1d515df1..43e41813 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -496,6 +496,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 9f5f9761..70f229f9 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -125,6 +125,7 @@ +