Ejemplo n.º 1
0
        public void NotifyUserAboutPullRequestWithUnresolvedConflicts(
            int pullRequestNumber,
            string gitHubUserName,
            IRepositoryConnectionContext repoContext,
            string pullRequestBranchName,
            string destinationBranch,
            string pullRequestUrl)
        {
            var comment = $"Cannot merge automatically. @{gitHubUserName} please resolve conflicts manually, approve review and merge pull request."
                          + "\r\n\r\n"
                          + "How to do it (using the GIT command line):\r\n"
                          + $"1. Fetch changes from server and checkout '{destinationBranch}' branch\r\n"
                          + "   ```\r\n"
                          + $"   git fetch && git checkout {destinationBranch} && " + "git reset --hard @{u}\r\n"
                          + "   ```\r\n"
                          + $"2. Merge 'origin/{pullRequestBranchName}' branch and resolve conflicts\r\n"
                          + "   ```\r\n"
                          + $"   git merge --no-ff origin/{pullRequestBranchName}\r\n"
                          + "   ```\r\n"
                          + $"4. Approve [pull request]({pullRequestUrl}/files#submit-review) review\r\n"
                          + $"5. Push changes to {destinationBranch}\r\n"
                          + "   ```\r\n"
                          + $"   git push origin {destinationBranch}\r\n"
                          + "   ```\r\n";

            repoContext.AddPullRequestComment(pullRequestNumber, comment);
            repoContext.AddReviewerToPullRequest(pullRequestNumber, new[] { gitHubUserName });
            repoContext.AssignUsersToPullRequest(pullRequestNumber, new[] { gitHubUserName });
        }
Ejemplo n.º 2
0
        public void TryMergeExistingPullRequest(
            PullRequest pullRequest,
            IRepositoryConnectionContext repoContext)
        {
            var coAuthorString     = CreateCoAuthoredByMessageForExistingPullRequest(pullRequest);
            var mergeCommitMessage = CreateMergeCommitMessage(pullRequest, coAuthorString);

            if (repoContext.MergePullRequest(pullRequest.Number, mergeCommitMessage))
            {
                _logger.LogInformation(
                    "Successfully merged pull request #{pullRequestNumber} into {branchName}",
                    pullRequest.Number,
                    pullRequest.Base.Ref);

                repoContext.AddPullRequestComment(pullRequest.Number, Consts.SuccessfulMergeComment);
            }
            else
            {
                _logger.LogInformation(
                    "Merging pull request #{pullRequestNumber} into {branchName} cannot be done automatically",
                    pullRequest.Number,
                    pullRequest.Base.Ref);
            }
        }