diff --git a/src/main/scala/app/PullRequestsController.scala b/src/main/scala/app/PullRequestsController.scala index 67bf131..deb4c91 100644 --- a/src/main/scala/app/PullRequestsController.scala +++ b/src/main/scala/app/PullRequestsController.scala @@ -70,8 +70,11 @@ val name = repository.name getPullRequest(owner, name, issueId) map { case(issue, pullreq) => using(Git.open(getRepositoryDir(owner, name))){ git => - val (commits, diffs) = - getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo) + // prepare head branch + val commitIdTo = fetchPullRequest(git, issueId, pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch) + updateCommitIdTo(owner, name, issueId, commitIdTo) + + val (commits, diffs) = getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, commitIdTo) pulls.html.pullreq( issue, pullreq, @@ -101,7 +104,7 @@ }) post("/:owner/:repository/pull/:id/merge", mergeForm)(collaboratorsOnly { (form, repository) => - params("id").toIntOpt.flatMap{ issueId => + params("id").toIntOpt.flatMap { issueId => val owner = repository.owner val name = repository.name LockUtil.lock(s"${owner}/${name}/merge"){ @@ -116,9 +119,6 @@ // record activity recordMergeActivity(owner, name, loginAccount.userName, issueId, form.message) - // prepare head branch - fetchPullRequest(git, issueId, pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch) - // merge val mergeBaseRefName = s"refs/heads/${pullreq.branch}" val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true) @@ -356,9 +356,6 @@ issueId: Int): Boolean = { LockUtil.lock(s"${userName}/${repositoryName}/merge") { using(Git.open(getRepositoryDir(userName, repositoryName))) { git => - // fetch pull request contents - fetchPullRequest(git, issueId, requestUserName, requestRepositoryName, requestBranch) - // merge val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true) val mergeBaseTip = git.getRepository.resolve(s"refs/heads/${branch}") @@ -450,13 +447,15 @@ } /** - * Fetch pull request contents into refs/pull/${issueId}/head + * Fetch pull request contents into refs/pull/${issueId}/head and return the head commit id of the pull request. */ - private def fetchPullRequest(git: Git, issueId: Int, requestUserName: String, requestRepositoryName: String, requestBranch: String): Unit = { + private def fetchPullRequest(git: Git, issueId: Int, requestUserName: String, requestRepositoryName: String, requestBranch: String): String = { git.fetch .setRemote(getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString) .setRefSpecs(new RefSpec(s"refs/heads/${requestBranch}:refs/pull/${issueId}/head").setForceUpdate(true)) .call + + git.getRepository.resolve(s"refs/pull/${issueId}/head").getName } } diff --git a/src/main/scala/service/PullRequestService.scala b/src/main/scala/service/PullRequestService.scala index 5374b99..5b41a76 100644 --- a/src/main/scala/service/PullRequestService.scala +++ b/src/main/scala/service/PullRequestService.scala @@ -15,6 +15,9 @@ } } + def updateCommitIdTo(owner: String, repository: String, issueId: Int, commitIdTo: String): Unit = + Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId)).map(_.commitIdTo).update(commitIdTo) + def getPullRequestCountGroupByUser(closed: Boolean, owner: String, repository: Option[String]): List[PullRequestCount] = Query(PullRequests) .innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }