Example #1
0
        public TheEditMethod()
        {
            _github = Helper.GetAuthenticatedClient();
            _releaseClient = _github.Release;

            _context = _github.CreateRepositoryContext("public-repo").Result;
        }
    public AssigneesClientTests()
    {
        _github = Helper.GetAuthenticatedClient();
        var repoName = Helper.MakeNameWithTimestamp("public-repo");

        _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result;
    }
 public TheCreateReactionMethod()
 {
     _github = Helper.GetAuthenticatedClient();
     var repoName = Helper.MakeNameWithTimestamp("public-repo");
     _issuesClient = _github.Issue;
     _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result;
 }
    public ReferencesClientTests()
    {
        _github = Helper.GetAuthenticatedClient();

        _fixture = _github.Git.Reference;

        _context = _github.CreateRepositoryContext("public-repo").Result;
    }
Example #5
0
    public TreeClientTests()
    {
        _github = Helper.GetAuthenticatedClient();

        _fixture = _github.GitDatabase.Tree;

        _context = _github.CreateRepositoryContext("public-repo").Result;
    }
            public async Task GetsAllCheckSuites()
            {
                using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
                {
                    AutoInit = true
                }))
                {
                    var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");

                    var checkSuites = await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha);

                    Assert.NotEmpty(checkSuites.CheckSuites);
                    foreach (var checkSuite in checkSuites.CheckSuites)
                    {
                        Assert.Equal(headCommit.Sha, checkSuite.HeadSha);
                    }
                }
            }
            public async Task UpdatesPreferences()
            {
                using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
                {
                    AutoInit = true
                }))
                {
                    var preference = new CheckSuitePreferences(new[]
                    {
                        new CheckSuitePreferenceAutoTrigger(Helper.GitHubAppId, false)
                    });
                    var result = await _githubAppInstallation.Check.Suite.UpdatePreferences(repoContext.RepositoryOwner, repoContext.RepositoryName, preference);

                    Assert.Equal(repoContext.RepositoryId, result.Repository.Id);
                    Assert.Equal(Helper.GitHubAppId, result.Preferences.AutoTriggerChecks[0].AppId);
                    Assert.Equal(false, result.Preferences.AutoTriggerChecks[0].Setting);
                }
            }
Example #8
0
    public MilestonesClientTests()
    {
        _github = Helper.GetAuthenticatedClient();

        _milestonesClient = _github.Issue.Milestone;
        var repoName = Helper.MakeNameWithTimestamp("public-repo");

        _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result;
    }
Example #9
0
    public PullRequestReviewCommentReactionsClientTests()
    {
        _github = Helper.GetAuthenticatedClient();

        _client = _github.PullRequest.Comment;

        // We'll create a pull request that can be used by most tests
        _context = _github.CreateRepositoryContext("test-repo").Result;
    }
    public PullRequestsClientTests()
    {
        _github = Helper.GetAuthenticatedClient();

        _fixture = _github.Repository.PullRequest;
        _repositoryCommentsClient = _github.Repository.Comment;

        _context = _github.CreateRepositoryContext("source-repo").Result;
    }
    public PullRequestReviewCommentsClientTests()
    {
        _github = Helper.GetAuthenticatedClient();

        _client = _github.PullRequest.Comment;

        // We'll create a pull request that can be used by most tests
        _context = _github.CreateRepositoryContext("test-repo").Result;
    }
Example #12
0
    public PullRequestsClientTests()
    {
        _github = Helper.GetAuthenticatedClient();

        _fixture = _github.Repository.PullRequest;
        _repositoryCommentsClient = _github.Repository.RepositoryComments;

        _context = _github.CreateRepositoryContext("source-repo").Result;
    }
Example #13
0
    public MergingClientTests()
    {
        _github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
        {
            Credentials = Helper.Credentials
        };

        _fixture = _github.Repository.Merging;
        _context = _github.CreateRepositoryContext("public-repo").Result;
    }
        public PullRequestReviewRequestClientTestsBase()
        {
            _github = Helper.GetAuthenticatedClient();

            _client = _github.PullRequest.ReviewRequest;

            _context = _github.CreateRepositoryContext("test-repo").Result;

            Task.WaitAll(_collaboratorLogins.Select(AddCollaborator).ToArray());
        }
        public TheCreateReactionMethod()
        {
            _github = Helper.GetAuthenticatedClient();

            _issuesClient = _github.Issue;

            var repoName = Helper.MakeNameWithTimestamp("public-repo");

            _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result;
        }
    public MergingClientTests()
    {
        _github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
        {
            Credentials = Helper.Credentials
        };

        _fixture = _github.Repository.Merging;
        _context = _github.CreateRepositoryContext("public-repo").Result;
    }
Example #17
0
            public async Task GetsCheckSuite()
            {
                using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
                {
                    AutoInit = true
                }))
                {
                    // Need to get a CheckSuiteId so we can test the Get method
                    var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, "master");

                    var checkSuite = (await _githubAppInstallation.Check.Suite.GetAllForReference(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha)).CheckSuites.First();

                    // Get Check Suite by Id
                    var result = await _github.Check.Suite.Get(repoContext.RepositoryOwner, repoContext.RepositoryName, checkSuite.Id);

                    // Check result
                    Assert.Equal(checkSuite.Id, result.Id);
                    Assert.Equal(headCommit.Sha, result.HeadSha);
                }
            }
Example #18
0
    public async Task CanGetReactionPayloadForPullRequestReviews()
    {
        int numberToCreate = 2;

        using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("PullRequestReviewCommentsReactionTests")))
        {
            var commentIds = new List <int>();

            // Create a test pull request
            var pullRequest = await CreatePullRequest(context);

            // With multiple review comments with reactions
            for (int count = 1; count <= numberToCreate; count++)
            {
                var commentId = await HelperCreatePullRequestReviewCommentWithReactions(context.RepositoryOwner, context.RepositoryName, pullRequest);

                commentIds.Add(commentId);
            }
            Assert.Equal(numberToCreate, commentIds.Count);

            // Retrieve all review comments for the pull request
            var reviewComments = await _client.GetAll(context.RepositoryOwner, context.RepositoryName, pullRequest.Number);

            // Check the reactions
            foreach (var commentId in commentIds)
            {
                var retrieved = reviewComments.FirstOrDefault(x => x.Id == commentId);

                Assert.NotNull(retrieved);
                Assert.Equal(6, retrieved.Reactions.TotalCount);
                Assert.Equal(1, retrieved.Reactions.Plus1);
                Assert.Equal(1, retrieved.Reactions.Hooray);
                Assert.Equal(1, retrieved.Reactions.Heart);
                Assert.Equal(1, retrieved.Reactions.Laugh);
                Assert.Equal(1, retrieved.Reactions.Confused);
                Assert.Equal(1, retrieved.Reactions.Minus1);
            }
        }
    }
            public async Task ReturnsOutsideCollaborators()
            {
                var repoName = Helper.MakeNameWithTimestamp("public-repo");

                using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
                {
                    await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);

                    var outsideCollaborators = await _client
                                               .GetAll(Helper.Organization).ToList();

                    Assert.NotNull(outsideCollaborators);
                    Assert.Equal(1, outsideCollaborators.Count);
                }
            }
            public async Task GetsAllCheckRuns()
            {
                using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
                {
                    AutoInit = true
                }))
                {
                    // Create a new feature branch
                    var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");

                    var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");

                    // Create a check run for the feature branch
                    var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
                    {
                        Status = CheckStatus.InProgress
                    };
                    var created = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);

                    // Get the check
                    var request = new CheckRunRequest
                    {
                        CheckName = "name",
                        Status    = CheckStatusFilter.InProgress
                    };

                    var checkRuns = await _githubAppInstallation.Check.Run.GetAllForCheckSuite(repoContext.RepositoryOwner, repoContext.RepositoryName, created.CheckSuite.Id, request);

                    // Check result
                    Assert.NotEmpty(checkRuns.CheckRuns);
                    foreach (var checkRun in checkRuns.CheckRuns)
                    {
                        Assert.Equal(featureBranch.Object.Sha, checkRun.HeadSha);
                        Assert.Equal("name", checkRun.Name);
                        Assert.Equal(CheckStatus.InProgress, checkRun.Status);
                    }
                }
            }
            public async Task CreatesCheckRun()
            {
                using (var repoContext = await _github.CreateRepositoryContext(new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
                {
                    AutoInit = true
                }))
                {
                    // Create a new feature branch
                    var headCommit = await _github.Repository.Commit.Get(repoContext.RepositoryId, "master");

                    var featureBranch = await Helper.CreateFeatureBranch(repoContext.RepositoryOwner, repoContext.RepositoryName, headCommit.Sha, "my-feature");

                    // Create a check run for the feature branch
                    var newCheckRun = new NewCheckRun("name", featureBranch.Object.Sha)
                    {
                        Status = CheckStatus.Queued
                    };
                    var result = await _githubAppInstallation.Check.Run.Create(repoContext.RepositoryOwner, repoContext.RepositoryName, newCheckRun);

                    // Check result
                    Assert.NotNull(result);
                    Assert.Equal(featureBranch.Object.Sha, result.HeadSha);
                }
            }
        internal async static Task <RepositoryContext> CreateRepositoryWithProtectedBranch(this IGitHubClient client)
        {
            // Create user owned repo
            var userRepo = new NewRepository(Helper.MakeNameWithTimestamp("protected-repo"))
            {
                AutoInit = true
            };
            var contextUserRepo = await client.CreateRepositoryContext(userRepo);

            // Protect master branch
            var update = new BranchProtectionSettingsUpdate(new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }), null, true);

            await client.Repository.Branch.UpdateBranchProtection(contextUserRepo.RepositoryOwner, contextUserRepo.RepositoryName, "master", update);

            return(contextUserRepo);
        }
        public async Task CanCreateAndRetrieveStarsWithTimestamps()
        {
            using (var context = await _client.CreateRepositoryContext("public-repo"))
            {
                await _fixture.RemoveStarFromRepo(context.RepositoryOwner, context.RepositoryName);

                await _fixture.StarRepo(context.RepositoryOwner, context.RepositoryName);

                var currentUser = await _client.User.Current();

                var userStars = await _fixture.GetAllStargazersWithTimestamps(context.RepositoryOwner, context.RepositoryName);

                var userStar = userStars.SingleOrDefault(x => x.User.Id == currentUser.Id);
                Assert.NotNull(userStar);
                Assert.True(DateTimeOffset.UtcNow.Subtract(userStar.StarredAt) < TimeSpan.FromMinutes(5));
            }
        }
Example #24
0
        public async Task CanAddRepository()
        {
            using (var teamContext = await _github.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team"))))
                using (var repoContext = await _github.CreateRepositoryContext(Helper.Organization, new NewRepository(Helper.MakeNameWithTimestamp("team-repository"))))
                {
                    var team = teamContext.Team;
                    var repo = repoContext.Repository;

                    var addRepo = await _github.Organization.Team.AddRepository(team.Id, team.Organization.Login, repo.Name, new RepositoryPermissionRequest(Permission.Admin));

                    Assert.True(addRepo);

                    var addedRepo = await _github.Organization.Team.GetAllRepositories(team.Id);

                    //Check if permission was correctly applied
                    Assert.True(addedRepo.First(x => x.Id == repo.Id).Permissions.Admin == true);
                }
        }
Example #25
0
            public async Task CanRemoveOutsideCollaborator()
            {
                var repoName = Helper.MakeNameWithTimestamp("public-repo");

                using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
                {
                    await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);

                    var result = await _client.Delete(Helper.Organization, _fixtureCollaborator);

                    Assert.True(result);

                    var outsideCollaborators = await _client
                                               .GetAll(Helper.Organization).ToList();

                    Assert.Empty(outsideCollaborators);
                }
            }
        public async Task CanGetReactionPayload()
        {
            var numberToCreate = 2;

            using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
            {
                var commentIds = new List <int>();

                // Create a single test issue
                var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName);

                // With multiple comments with reactions
                for (int count = 1; count <= numberToCreate; count++)
                {
                    var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber);

                    commentIds.Add(commentId);
                }
                Assert.Equal(numberToCreate, commentIds.Count);

                // Retrieve all comments for the issue
                var issueComments = await _issueCommentsClient.GetAllForIssue(context.RepositoryOwner, context.RepositoryName, issueNumber);

                // Check the reactions
                foreach (var commentId in commentIds)
                {
                    var retrieved = issueComments.FirstOrDefault(x => x.Id == commentId);

                    Assert.NotNull(retrieved);
                    Assert.Equal(6, retrieved.Reactions.TotalCount);
                    Assert.Equal(1, retrieved.Reactions.Plus1);
                    Assert.Equal(1, retrieved.Reactions.Hooray);
                    Assert.Equal(1, retrieved.Reactions.Heart);
                    Assert.Equal(1, retrieved.Reactions.Laugh);
                    Assert.Equal(1, retrieved.Reactions.Confused);
                    Assert.Equal(1, retrieved.Reactions.Minus1);
                }
            }
        }
Example #27
0
        internal async static Task <OrganizationRepositoryWithTeamContext> CreateOrganizationRepositoryWithProtectedBranch(this IGitHubClient client)
        {
            // Create organization owned repo
            var orgRepo = new NewRepository(Helper.MakeNameWithTimestamp("protected-org-repo"))
            {
                AutoInit = true
            };
            var contextOrgRepo = await client.CreateRepositoryContext(Helper.Organization, orgRepo);

            // Create team in org
            var contextOrgTeam = await client.CreateTeamContext(Helper.Organization, new NewTeam(Helper.MakeNameWithTimestamp("team")));

            // Grant team push access to repo
            await client.Organization.Team.AddRepository(
                contextOrgTeam.TeamId,
                contextOrgRepo.RepositoryOwner,
                contextOrgRepo.RepositoryName,
                new RepositoryPermissionRequest(Permission.Push));

            // Protect master branch
            var protection = new BranchProtectionSettingsUpdate(
                new BranchProtectionRequiredStatusChecksUpdate(true, new[] { "build", "test" }),
                new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(new BranchProtectionTeamCollection {
                contextOrgTeam.TeamName
            }), true, true, 3),
                new BranchProtectionPushRestrictionsUpdate(new BranchProtectionTeamCollection {
                contextOrgTeam.TeamName
            }),
                true);
            await client.Repository.Branch.UpdateBranchProtection(contextOrgRepo.RepositoryOwner, contextOrgRepo.RepositoryName, "master", protection);

            return(new OrganizationRepositoryWithTeamContext
            {
                RepositoryContext = contextOrgRepo,
                TeamContext = contextOrgTeam
            });
        }
        public async Task CanGetReactionPayload()
        {
            using (var context = await _github.CreateRepositoryContext(Helper.MakeNameWithTimestamp("IssueCommentsReactionTests")))
            {
                // Create a test issue
                var issueNumber = await HelperCreateIssue(context.RepositoryOwner, context.RepositoryName);

                // Create a test comment with reactions
                var commentId = await HelperCreateIssueCommentWithReactions(context.RepositoryOwner, context.RepositoryName, issueNumber);

                // Retrieve the comment
                var retrieved = await _issueCommentsClient.Get(context.RepositoryOwner, context.RepositoryName, commentId);

                // Check the reactions
                Assert.True(retrieved.Id > 0);
                Assert.Equal(6, retrieved.Reactions.TotalCount);
                Assert.Equal(1, retrieved.Reactions.Plus1);
                Assert.Equal(1, retrieved.Reactions.Hooray);
                Assert.Equal(1, retrieved.Reactions.Heart);
                Assert.Equal(1, retrieved.Reactions.Laugh);
                Assert.Equal(1, retrieved.Reactions.Confused);
                Assert.Equal(1, retrieved.Reactions.Minus1);
            }
        }
Example #29
0
        public async Task CanSubmitCommentedReview()
        {
            using (var context = await _github.CreateRepositoryContext("test-repo"))
            {
                await _github.CreateTheWorld(context.Repository);

                var pullRequest = await _github2.CreatePullRequest(context.Repository);

                var createdReview = await _github.CreatePullRequestReview(context.Repository, pullRequest.Number, "A pending review");

                var submitMessage = new PullRequestReviewSubmit
                {
                    Body  = "Roger roger!",
                    Event = PullRequestReviewEvent.Comment
                };
                var submittedReview = await _client.Submit(context.RepositoryOwner, context.RepositoryName, pullRequest.Number, createdReview.Id, submitMessage);

                Assert.Equal("Roger roger!", submittedReview.Body);
                Assert.Equal(PullRequestReviewState.Commented, submittedReview.State);
            }
        }
Example #30
0
        public TheCreateReactionMethod()
        {
            _github = Helper.GetAuthenticatedClient();

            _context = _github.CreateRepositoryContext("public-repo").Result;
        }
        public TestsWithNewRepository()
        {
            _github = Helper.GetAuthenticatedClient();

            _fixture = _github.Repository.Commits;

            _context = _github.CreateRepositoryContext("source-repo").Result;
        }
        public TheDeleteMethod()
        {
            _github = Helper.GetAuthenticatedClient();

            _context = _github.CreateRepositoryContext("public-repo").Result;
        }