mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
(refs #179)Fetch from the source repository before pull request is referred.
This commit is contained in:
@@ -70,8 +70,11 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val name = repository.name
|
val name = repository.name
|
||||||
getPullRequest(owner, name, issueId) map { case(issue, pullreq) =>
|
getPullRequest(owner, name, issueId) map { case(issue, pullreq) =>
|
||||||
using(Git.open(getRepositoryDir(owner, name))){ git =>
|
using(Git.open(getRepositoryDir(owner, name))){ git =>
|
||||||
val (commits, diffs) =
|
// prepare head branch
|
||||||
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
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(
|
pulls.html.pullreq(
|
||||||
issue, pullreq,
|
issue, pullreq,
|
||||||
@@ -116,9 +119,6 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
// record activity
|
// record activity
|
||||||
recordMergeActivity(owner, name, loginAccount.userName, issueId, form.message)
|
recordMergeActivity(owner, name, loginAccount.userName, issueId, form.message)
|
||||||
|
|
||||||
// prepare head branch
|
|
||||||
fetchPullRequest(git, issueId, pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch)
|
|
||||||
|
|
||||||
// merge
|
// merge
|
||||||
val mergeBaseRefName = s"refs/heads/${pullreq.branch}"
|
val mergeBaseRefName = s"refs/heads/${pullreq.branch}"
|
||||||
val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true)
|
val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true)
|
||||||
@@ -356,9 +356,6 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
issueId: Int): Boolean = {
|
issueId: Int): Boolean = {
|
||||||
LockUtil.lock(s"${userName}/${repositoryName}/merge") {
|
LockUtil.lock(s"${userName}/${repositoryName}/merge") {
|
||||||
using(Git.open(getRepositoryDir(userName, repositoryName))) { git =>
|
using(Git.open(getRepositoryDir(userName, repositoryName))) { git =>
|
||||||
// fetch pull request contents
|
|
||||||
fetchPullRequest(git, issueId, requestUserName, requestRepositoryName, requestBranch)
|
|
||||||
|
|
||||||
// merge
|
// merge
|
||||||
val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true)
|
val merger = MergeStrategy.RECURSIVE.newMerger(git.getRepository, true)
|
||||||
val mergeBaseTip = git.getRepository.resolve(s"refs/heads/${branch}")
|
val mergeBaseTip = git.getRepository.resolve(s"refs/heads/${branch}")
|
||||||
@@ -450,13 +447,15 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
git.fetch
|
||||||
.setRemote(getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString)
|
.setRemote(getRepositoryDir(requestUserName, requestRepositoryName).toURI.toString)
|
||||||
.setRefSpecs(new RefSpec(s"refs/heads/${requestBranch}:refs/pull/${issueId}/head").setForceUpdate(true))
|
.setRefSpecs(new RefSpec(s"refs/heads/${requestBranch}:refs/pull/${issueId}/head").setForceUpdate(true))
|
||||||
.call
|
.call
|
||||||
|
|
||||||
|
git.getRepository.resolve(s"refs/pull/${issueId}/head").getName
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ trait PullRequestService { self: IssuesService =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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] =
|
def getPullRequestCountGroupByUser(closed: Boolean, owner: String, repository: Option[String]): List[PullRequestCount] =
|
||||||
Query(PullRequests)
|
Query(PullRequests)
|
||||||
.innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }
|
.innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }
|
||||||
|
|||||||
Reference in New Issue
Block a user