Ejemplo n.º 1
0
    /// <summary>
    /// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request)
    /// </summary>
    /// <returns></returns>
    async Task <PullRequestData> CreatePullRequest(RepositoryContext context, string branch = branchName)
    {
        string branchHead = "heads/" + branch;
        string branchRef  = "refs/" + branchHead;


        var repoName = context.RepositoryName;

        // Creating a commit in master

        var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/master", "A master commit message");

        // Creating a branch

        var newBranch = new NewReference(branchRef, createdCommitInMaster.Sha);
        await _github.Git.Reference.Create(Helper.UserName, repoName, newBranch);

        // Creating a commit in the branch

        var createdCommitInBranch = await CreateCommit(repoName, "Hello from the fork!", path, branchHead, "A branch commit message");

        // Creating a pull request

        var pullRequest        = new NewPullRequest("Nice title for the pull request", branch, "master");
        var createdPullRequest = await _github.PullRequest.Create(Helper.UserName, repoName, pullRequest);

        var data = new PullRequestData
        {
            Sha    = createdCommitInBranch.Sha,
            Number = createdPullRequest.Number
        };

        return(data);
    }
    /// <summary>
    /// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request)
    /// </summary>
    /// <returns></returns>
    async Task <PullRequestData> CreatePullRequest(Repository repository)
    {
        var repoName = repository.Name;

        // Creating a commit in master

        var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/master", "A master commit message");

        // Creating a branch

        var newBranch = new NewReference(branchRef, createdCommitInMaster.Sha);
        await _gitHubClient.GitDatabase.Reference.Create(Helper.UserName, repoName, newBranch);

        // Creating a commit in the branch

        var createdCommitInBranch = await CreateCommit(repoName, "Hello from the fork!", path, branchHead, "A branch commit message");

        // Creating a pull request

        var pullRequest        = new NewPullRequest("Nice title for the pull request", branchName, "master");
        var createdPullRequest = await _gitHubClient.PullRequest.Create(Helper.UserName, repoName, pullRequest);

        var data = new PullRequestData
        {
            Sha    = createdCommitInBranch.Sha,
            Number = createdPullRequest.Number,
        };

        return(data);
    }
Ejemplo n.º 3
0
        private async Task <long?> CreateHomeworkViaPullRequest(long taskId, string repName, int pullRequestNumber)
        {
            var task     = _repository.TaskManager.Get(t => t.Id == taskId);
            var student  = _repository.UserManager.Get(u => u.Id == User.Identity.GetUserId());
            var homework = new Homework(new HomeworkCreateViewModel {
                TaskId = taskId
            }, task, student);

            if (_repository.HomeworkManager.Add(homework))
            {
                var prd = new PullRequestData(homework, repName, pullRequestNumber);

                if (_repository.PullRequestsDataManager.Add(prd))
                {
                    await(new NewPullRequestHomeworkNotification(task, student, prd.Id, Request.RequestContext)).Send();
                    return(prd.Id);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
    async Task <int> HelperCreatePullRequestReviewCommentWithReactions(string owner, string repo, PullRequestData pullRequest)
    {
        var github = Helper.GetAuthenticatedClient();

        const string body     = "A review comment message";
        const int    position = 1;

        var reviewComment = await CreateComment(body, position, repo, pullRequest.Sha, pullRequest.Number);

        foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
        {
            var newReaction = new NewReaction(reactionType);

            var reaction = await github.Reaction.PullRequestReviewComment.Create(owner, repo, reviewComment.Id, newReaction);

            Assert.IsType <Reaction>(reaction);
            Assert.Equal(reactionType, reaction.Content);
            Assert.Equal(reviewComment.User.Id, reaction.User.Id);
        }

        return(reviewComment.Id);
    }
    /// <summary>
    /// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request)
    /// </summary>
    /// <returns></returns>
    async Task<PullRequestData> CreatePullRequest(RepositoryContext context)
    {
        var repoName = context.RepositoryName;

        // Creating a commit in master

        var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/master", "A master commit message");

        // Creating a branch

        var newBranch = new NewReference(branchRef, createdCommitInMaster.Sha);
        await _github.Git.Reference.Create(Helper.UserName, repoName, newBranch);

        // Creating a commit in the branch

        var createdCommitInBranch = await CreateCommit(repoName, "Hello from the fork!", path, branchHead, "A branch commit message");

        // Creating a pull request

        var pullRequest = new NewPullRequest("Nice title for the pull request", branchName, "master");
        var createdPullRequest = await _github.PullRequest.Create(Helper.UserName, repoName, pullRequest);

        var data = new PullRequestData
        {
            Sha = createdCommitInBranch.Sha,
            Number = createdPullRequest.Number,
        };

        return data;
    }
    async Task<int> HelperCreatePullRequestReviewCommentWithReactions(string owner, string repo, PullRequestData pullRequest)
    {
        var github = Helper.GetAuthenticatedClient();

        const string body = "A review comment message";
        const int position = 1;

        var reviewComment = await CreateComment(body, position, repo, pullRequest.Sha, pullRequest.Number);

        foreach (ReactionType reactionType in Enum.GetValues(typeof(ReactionType)))
        {
            var newReaction = new NewReaction(reactionType);

            var reaction = await github.Reaction.PullRequestReviewComment.Create(owner, repo, reviewComment.Id, newReaction);

            Assert.IsType<Reaction>(reaction);
            Assert.Equal(reactionType, reaction.Content);
            Assert.Equal(reviewComment.User.Id, reaction.User.Id);
        }

        return reviewComment.Id;
    }