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 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);
        }
Exemple #3
0
        /// <summary>
        /// Remove team 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-team-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="teams">List of teams to remove</param>
        public IObservable <Team> 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));
        }
Exemple #4
0
        /// <summary>
        /// Remove team 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-team-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="teams">List of teams to remove</param>
        public IObservable <Team> 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));
        }
            public async Task EnsuresNonNullArguments()
            {
                var client = new ObservableRepositoryBranchesClient(Substitute.For<IGitHubClient>());
                var teamsToRemove = new BranchProtectionTeamCollection() { "test" };

                Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchTeamRestrictions(null, "repo", "branch", teamsToRemove));
                Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchTeamRestrictions("owner", null, "branch", teamsToRemove));
                Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", null, teamsToRemove));
                Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "branch", null));

                Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchTeamRestrictions(1, null, teamsToRemove));
                Assert.Throws<ArgumentNullException>(() => client.DeleteProtectedBranchTeamRestrictions(1, "branch", null));

                Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchTeamRestrictions("", "repo", "branch", teamsToRemove));
                Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchTeamRestrictions("owner", "", "branch", teamsToRemove));
                Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchTeamRestrictions("owner", "repo", "", teamsToRemove));

                Assert.Throws<ArgumentException>(() => client.DeleteProtectedBranchTeamRestrictions(1, "", teamsToRemove));
            }
            public void RequestsTheCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableRepositoryBranchesClient(gitHubClient);
                var teamsToRemove = new BranchProtectionTeamCollection() { "test" };

                client.DeleteProtectedBranchTeamRestrictions(1, "branch", teamsToRemove);

                gitHubClient.Repository.Branch.Received()
                    .DeleteProtectedBranchTeamRestrictions(1, "branch", teamsToRemove);
            }
            public void RequestsTheCorrectUrl()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                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);
            }
        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);
        }
        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);
            }
        }
        /// <summary>
        /// Remove team 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-team-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="teams">List of teams to remove</param>
        public IObservable<Team> 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);
        }
        /// <summary>
        /// Remove team 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-team-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="teams">List of teams to remove</param>
        public IObservable<Team> 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);
        }
        /// <summary>
        /// Remove team 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-team-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="teams">List of teams to remove</param>
        public Task<IReadOnlyList<Team>> DeleteProtectedBranchTeamRestrictions(long repositoryId, string branch, BranchProtectionTeamCollection teams)
        {
            Ensure.ArgumentNotNullOrEmptyString(branch, "branch");
            Ensure.ArgumentNotNull(teams, "teams");

            return ApiConnection.Delete<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(repositoryId, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
        }
        /// <summary>
        /// Add team 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-team-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="teams">List of teams with push access to add</param>
        public Task<IReadOnlyList<Team>> 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<IReadOnlyList<Team>>(ApiUrls.RepoRestrictionsTeams(owner, name, branch), teams, AcceptHeaders.ProtectedBranchesApiPreview);
        }
            public void RequestsTheCorrectUrlWithRepositoryId()
            {
                var connection = Substitute.For<IApiConnection>();
                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<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader);
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new RepositoryBranchesClient(Substitute.For<IApiConnection>());
                var newTeams = new BranchProtectionTeamCollection() { "test" };

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchTeamRestrictions(null, "repo", "branch", newTeams));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchTeamRestrictions("owner", null, "branch", newTeams));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", null, newTeams));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", "branch", null));

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchTeamRestrictions(1, null, newTeams));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.AddProtectedBranchTeamRestrictions(1, "branch", null));

                await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchTeamRestrictions("", "repo", "branch", newTeams));
                await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchTeamRestrictions("owner", "", "branch", newTeams));
                await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchTeamRestrictions("owner", "repo", "", newTeams));

                await Assert.ThrowsAsync<ArgumentException>(() => client.AddProtectedBranchTeamRestrictions(1, "", newTeams));
            }
            public void RequestsTheCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                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<IReadOnlyList<Team>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/branches/branch/protection/restrictions/teams"), Arg.Any<IReadOnlyList<string>>(), previewAcceptsHeader);
            }