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 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); }
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); } }
public async Task EnsuresNonNullArguments() { var client = new ObservableRepositoryBranchesClient(Substitute.For<IGitHubClient>()); var usersToRemove = new BranchProtectionUserCollection() { "test" }; Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchUserRestrictions(null, "repo", "branch", usersToRemove)); Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchUserRestrictions("owner", null, "branch", usersToRemove)); Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", null, usersToRemove)); Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", "branch", null)); Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchUserRestrictions(1, null, usersToRemove)); Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchUserRestrictions(1, "branch", null)); Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchUserRestrictions("", "repo", "branch", usersToRemove)); Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchUserRestrictions("owner", "", "branch", usersToRemove)); Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchUserRestrictions("owner", "repo", "", usersToRemove)); Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchUserRestrictions(1, "", usersToRemove)); }
public void RequestsTheCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryBranchesClient(gitHubClient); var usersToRemove = new BranchProtectionUserCollection() { "test" }; client.DeleteProtectedBranchUserRestrictions(1, "branch", usersToRemove); gitHubClient.Repository.Branch.Received() .DeleteProtectedBranchUserRestrictions(1, "branch", usersToRemove); }
public void RequestsTheCorrectUrl() { var gitHubClient = Substitute.For<IGitHubClient>(); 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); }
public async Task EnsuresNonNullArguments() { var client = new RepositoryBranchesClient(Substitute.For<IApiConnection>()); var newUsers = new BranchProtectionUserCollection() { "test" }; await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchUserRestrictions(null, "repo", "branch", newUsers)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchUserRestrictions("owner", null, "branch", newUsers)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchUserRestrictions("owner", "repo", null, newUsers)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchUserRestrictions("owner", "repo", "branch", null)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchUserRestrictions(1, null, newUsers)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchUserRestrictions(1, "branch", null)); await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchUserRestrictions("", "repo", "branch", newUsers)); await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchUserRestrictions("owner", "", "branch", newUsers)); await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchUserRestrictions("owner", "repo", "", newUsers)); await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchUserRestrictions(1, "", newUsers)); }
/// <summary> /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) /// </summary> /// <remarks> /// See the <a href="https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch">API documentation</a> for more details /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="branch">The name of the branch</param> /// <param name="users">List of users with push access to remove</param> public IObservable<User> 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); }
/// <summary> /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) /// </summary> /// <remarks> /// See the <a href="https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch">API documentation</a> for more details /// </remarks> /// <param name="repositoryId">The Id of the repository</param> /// <param name="branch">The name of the branch</param> /// <param name="users">List of users with push access to remove</param> public Task<IReadOnlyList<User>> DeleteProtectedBranchUserRestrictions(long repositoryId, string branch, BranchProtectionUserCollection users) { Ensure.ArgumentNotNullOrEmptyString(branch, "branch"); Ensure.ArgumentNotNull(users, "users"); return ApiConnection.Delete<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(repositoryId, branch), users, AcceptHeaders.ProtectedBranchesApiPreview); }
/// <summary> /// Add user restrictions for the specified branch (applies only to Organization owned repositories) /// </summary> /// <remarks> /// See the <a href="https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch">API documentation</a> for more details /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="branch">The name of the branch</param> /// <param name="users">List of users with push access to add</param> public Task<IReadOnlyList<User>> 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<IReadOnlyList<User>>(ApiUrls.RepoRestrictionsUsers(owner, name, branch), users, AcceptHeaders.ProtectedBranchesApiPreview); }
public void RequestsTheCorrectUrlWithRepositoryId() { var connection = Substitute.For<IApiConnection>(); 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<IReadOnlyList<User>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/users"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader); }
/// <summary> /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) /// </summary> /// <remarks> /// See the <a href="https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch">API documentation</a> for more details /// </remarks> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="branch">The name of the branch</param> /// <param name="users">List of users with push access to remove</param> public IObservable <User> 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)); }
/// <summary> /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) /// </summary> /// <remarks> /// See the <a href="https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch">API documentation</a> for more details /// </remarks> /// <param name="repositoryId">The Id of the repository</param> /// <param name="branch">The name of the branch</param> /// <param name="users">List of users with push access to remove</param> public IObservable<User> 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); }
/// <summary> /// Remove user restrictions for the specified branch (applies only to Organization owned repositories) /// </summary> /// <remarks> /// See the <a href="https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch">API documentation</a> for more details /// </remarks> /// <param name="repositoryId">The Id of the repository</param> /// <param name="branch">The name of the branch</param> /// <param name="users">List of users with push access to remove</param> public IObservable <User> 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)); }
public void RequestsTheCorrectUrl() { var connection = Substitute.For<IApiConnection>(); 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<IReadOnlyList<User>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/users"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader); }