diff --git a/src/main/scala/app/PullRequestsController.scala b/src/main/scala/app/PullRequestsController.scala index a7c85cd..0f08602 100644 --- a/src/main/scala/app/PullRequestsController.scala +++ b/src/main/scala/app/PullRequestsController.scala @@ -260,7 +260,7 @@ val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2 val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2 - val forkedId = getForkedCommitId(oldGit, newGit, + val forkedId = JGitUtil.getForkedCommitId(oldGit, newGit, originRepository.owner, originRepository.name, originBranch, forkedRepository.owner, forkedRepository.name, forkedBranch) @@ -432,17 +432,6 @@ (defaultOwner, value) } - /** - * Returns the identifier of the root commit (or latest merge commit) of the specified branch. - */ - private def getForkedCommitId(oldGit: Git, newGit: Git, userName: String, repositoryName: String, branch: String, - requestUserName: String, requestRepositoryName: String, requestBranch: String): String = - defining(JGitUtil.getAllCommitIds(oldGit)){ existIds => - JGitUtil.getCommitLogs(newGit, requestBranch, true) { commit => - existIds.contains(commit.name) && JGitUtil.getBranchesOfCommit(oldGit, commit.getName).contains(branch) - }.head.id - } - private def getRequestCompareInfo(userName: String, repositoryName: String, branch: String, requestUserName: String, requestRepositoryName: String, requestCommitId: String): (Seq[Seq[CommitInfo]], Seq[DiffInfo]) = using( diff --git a/src/main/scala/service/PullRequestService.scala b/src/main/scala/service/PullRequestService.scala index 7d11f08..1298493 100644 --- a/src/main/scala/service/PullRequestService.scala +++ b/src/main/scala/service/PullRequestService.scala @@ -18,6 +18,9 @@ def updateCommitIdTo(owner: String, repository: String, issueId: Int, commitIdTo: String): Unit = Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId)).map(_.commitIdTo).update(commitIdTo) + def updateCommitIdFrom(owner: String, repository: String, issueId: Int, commitIdFrom: String): Unit = + Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId)).map(_.commitIdFrom).update(commitIdFrom) + 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) } diff --git a/src/main/scala/servlet/GitRepositoryServlet.scala b/src/main/scala/servlet/GitRepositoryServlet.scala index 389c1af..94f0521 100644 --- a/src/main/scala/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/servlet/GitRepositoryServlet.scala @@ -218,14 +218,21 @@ private def updatePullRequests(branch: String) = getPullRequestsByRequest(owner, repository, branch, false).foreach { pullreq => if(getRepository(pullreq.userName, pullreq.repositoryName, baseUrl).isDefined){ - using(Git.open(Directory.getRepositoryDir(pullreq.userName, pullreq.repositoryName))){ git => - git.fetch + using(Git.open(Directory.getRepositoryDir(pullreq.userName, pullreq.repositoryName)), + Git.open(Directory.getRepositoryDir(pullreq.requestUserName, pullreq.requestRepositoryName))){ (oldGit, newGit) => + oldGit.fetch .setRemote(Directory.getRepositoryDir(owner, repository).toURI.toString) .setRefSpecs(new RefSpec(s"refs/heads/${branch}:refs/pull/${pullreq.issueId}/head").setForceUpdate(true)) .call - val commitIdTo = git.getRepository.resolve(s"refs/pull/${pullreq.issueId}/head").getName + val commitIdTo = oldGit.getRepository.resolve(s"refs/pull/${pullreq.issueId}/head").getName updateCommitIdTo(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdTo) + + val commitIdFrom = JGitUtil.getForkedCommitId(oldGit, newGit, + pullreq.userName, pullreq.repositoryName, pullreq.branch, + pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch) + // TODO(tanacasino): commitIdFrom and commitIdTo should be updated by one query... + updateCommitIdFrom(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdFrom) } } } diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index 97e8c41..9f48c39 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -617,5 +617,16 @@ } } + /** + * Returns the identifier of the root commit (or latest merge commit) of the specified branch. + */ + def getForkedCommitId(oldGit: Git, newGit: Git, + userName: String, repositoryName: String, branch: String, + requestUserName: String, requestRepositoryName: String, requestBranch: String): String = + defining(getAllCommitIds(oldGit)){ existIds => + getCommitLogs(newGit, requestBranch, true) { commit => + existIds.contains(commit.name) && getBranchesOfCommit(oldGit, commit.getName).contains(branch) + }.head.id + } }