Пример #1
0
 public PullRequestMergeResult getPullRequestMergeResult() {
   PullRequestMergeResult mergeResult = null;
   if (!StringUtils.isEmpty(this.fromBranch) && !StringUtils.isEmpty(this.toBranch)) {
     mergeResult = this.attemptMerge();
     Map<String, String> suggestText =
         suggestTitleAndBodyFromDiffCommit(mergeResult.getGitCommits());
     this.title = suggestText.get("title");
     this.body = suggestText.get("body");
   }
   return mergeResult;
 }
Пример #2
0
  /**
   * 보낸 코드를 병합해보고 결과 정보를 반환한다.
   *
   * @return
   */
  public PullRequestMergeResult attemptMerge() {
    final GitConflicts[] conflicts = {null};
    final List<GitCommit> commits = new ArrayList<>();
    final PullRequest pullRequest = this;

    GitRepository.cloneAndFetch(
        pullRequest,
        new AfterCloneAndFetchOperation() {
          @Override
          public void invoke(CloneAndFetch cloneAndFetch) throws IOException, GitAPIException {
            Repository clonedRepository = cloneAndFetch.getRepository();

            List<GitCommit> commitList =
                GitRepository.diffCommits(
                    clonedRepository,
                    cloneAndFetch.getDestFromBranchName(),
                    cloneAndFetch.getDestToBranchName());

            for (GitCommit gitCommit : commitList) {
              commits.add(gitCommit);
            }

            GitRepository.checkout(clonedRepository, cloneAndFetch.getDestToBranchName());

            String mergedCommitIdFrom;
            MergeResult mergeResult;

            synchronized (this) {
              mergedCommitIdFrom =
                  clonedRepository
                      .getRef(org.eclipse.jgit.lib.Constants.HEAD)
                      .getObjectId()
                      .getName();

              mergeResult =
                  GitRepository.merge(clonedRepository, cloneAndFetch.getDestFromBranchName());
            }

            if (mergeResult.getMergeStatus() == MergeResult.MergeStatus.CONFLICTING) {
              conflicts[0] = new GitConflicts(clonedRepository, mergeResult);
            } else if (mergeResult.getMergeStatus().isSuccessful()) {
              pullRequest.mergedCommitIdFrom = mergedCommitIdFrom;
              pullRequest.mergedCommitIdTo = mergeResult.getNewHead().getName();
            }
          }
        });

    PullRequestMergeResult pullRequestMergeResult = new PullRequestMergeResult();
    pullRequestMergeResult.setGitCommits(commits);
    pullRequestMergeResult.setGitConflicts(conflicts[0]);
    pullRequestMergeResult.setPullRequest(pullRequest);

    return pullRequestMergeResult;
  }