diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala index 685a8b4..c2bfba8 100644 --- a/src/main/scala/gitbucket/core/controller/ApiController.scala +++ b/src/main/scala/gitbucket/core/controller/ApiController.scala @@ -39,6 +39,7 @@ with WebHookService with WebHookPullRequestService with WebHookIssueCommentService + with WebHookPullRequestReviewCommentService with WikiService with ActivityService with PrioritiesService diff --git a/src/main/scala/gitbucket/core/controller/DashboardController.scala b/src/main/scala/gitbucket/core/controller/DashboardController.scala index d73f3c7..3dc8d1a 100644 --- a/src/main/scala/gitbucket/core/controller/DashboardController.scala +++ b/src/main/scala/gitbucket/core/controller/DashboardController.scala @@ -12,9 +12,13 @@ with PullRequestService with RepositoryService with AccountService + with ActivityService with CommitsService with LabelsService with PrioritiesService + with WebHookService + with WebHookPullRequestService + with WebHookPullRequestReviewCommentService with MilestonesService with UsersAuthenticator diff --git a/src/main/scala/gitbucket/core/controller/IssuesController.scala b/src/main/scala/gitbucket/core/controller/IssuesController.scala index 90676e6..514564a 100644 --- a/src/main/scala/gitbucket/core/controller/IssuesController.scala +++ b/src/main/scala/gitbucket/core/controller/IssuesController.scala @@ -26,6 +26,7 @@ with WritableUsersAuthenticator with PullRequestService with WebHookIssueCommentService + with WebHookPullRequestReviewCommentService with CommitsService with PrioritiesService diff --git a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala index 717e4ab..3b5ab5c 100644 --- a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala +++ b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala @@ -32,6 +32,7 @@ with CommitsService with ActivityService with WebHookPullRequestService + with WebHookPullRequestReviewCommentService with ReadableUsersAuthenticator with ReferrerAuthenticator with WritableUsersAuthenticator @@ -320,50 +321,14 @@ remoteRepository, pullreq.branch, loginAccount, - s"Merge branch '${alias}' into ${pullreq.requestBranch}" + s"Merge branch '${alias}' into ${pullreq.requestBranch}", + Some(pullreq) ) match { case None => // conflict flash += "error" -> s"Can't automatic merging branch '${alias}' into ${pullreq.requestBranch}." case Some(oldId) => // update pull request - updatePullRequests(owner, name, pullreq.requestBranch) - - using(Git.open(Directory.getRepositoryDir(owner, name))) { - git => - // after update branch - val newCommitId = git.getRepository.resolve(s"refs/heads/${pullreq.requestBranch}") - val commits = git.log - .addRange(oldId, newCommitId) - .call - .iterator - .asScala - .map(c => new JGitUtil.CommitInfo(c)) - .toList - - // call web hook - callPullRequestWebHookByRequestBranch( - "synchronize", - repository, - pullreq.requestBranch, - loginAccount - ) - callWebHookOf(owner, name, WebHook.Push) { - for { - ownerAccount <- getAccountByUserName(owner) - } yield { - WebHookService.WebHookPushPayload( - git, - loginAccount, - pullreq.requestBranch, - repository, - commits, - ownerAccount, - oldId = oldId, - newId = newCommitId - ) - } - } - } + updatePullRequests(owner, name, pullreq.requestBranch, loginAccount, "synchronize") flash += "info" -> s"Merge branch '${alias}' into ${pullreq.requestBranch}" } } @@ -374,119 +339,14 @@ }) post("/:owner/:repository/pull/:id/merge", mergeForm)(writableUsersOnly { (form, repository) => - params("id").toIntOpt.flatMap { - issueId => - val owner = repository.owner - val name = repository.name - if (repository.repository.options.mergeOptions.split(",").contains(form.strategy)) { - LockUtil.lock(s"${owner}/${name}") { - getPullRequest(owner, name, issueId).map { - case (issue, pullreq) => - using(Git.open(getRepositoryDir(owner, name))) { - git => - // mark issue as merged and close. - val loginAccount = context.loginAccount.get - val commentId = createComment(owner, name, loginAccount.userName, issueId, form.message, "merge") - createComment(owner, name, loginAccount.userName, issueId, "Close", "close") - updateClosed(owner, name, issueId, true) + params("id").toIntOpt.flatMap { issueId => + val owner = repository.owner + val name = repository.name - // record activity - recordMergeActivity(owner, name, loginAccount.userName, issueId, form.message) - - val (commits, _) = getRequestCompareInfo( - owner, - name, - pullreq.commitIdFrom, - pullreq.requestUserName, - pullreq.requestRepositoryName, - pullreq.commitIdTo - ) - - val revCommits = using(new RevWalk(git.getRepository)) { revWalk => - commits.flatten.map { commit => - revWalk.parseCommit(git.getRepository.resolve(commit.id)) - } - }.reverse - - // merge git repository - form.strategy match { - case "merge-commit" => - mergePullRequest( - git, - pullreq.branch, - issueId, - s"Merge pull request #${issueId} from ${pullreq.requestUserName}/${pullreq.requestBranch}\n\n" + form.message, - new PersonIdent(loginAccount.fullName, loginAccount.mailAddress) - ) - case "rebase" => - rebasePullRequest( - git, - pullreq.branch, - issueId, - revCommits, - new PersonIdent(loginAccount.fullName, loginAccount.mailAddress) - ) - case "squash" => - squashPullRequest( - git, - pullreq.branch, - issueId, - s"${issue.title} (#${issueId})\n\n" + form.message, - new PersonIdent(loginAccount.fullName, loginAccount.mailAddress) - ) - } - - // close issue by content of pull request - val defaultBranch = getRepository(owner, name).get.repository.defaultBranch - if (pullreq.branch == defaultBranch) { - commits.flatten.foreach { commit => - closeIssuesFromMessage(commit.fullMessage, loginAccount.userName, owner, name).foreach { - issueId => - getIssue(owner, name, issueId.toString).foreach { issue => - callIssuesWebHook("closed", repository, issue, loginAccount) - PluginRegistry().getIssueHooks - .foreach(_.closedByCommitComment(issue, repository, commit.fullMessage, loginAccount)) - } - } - } - val issueContent = issue.title + " " + issue.content.getOrElse("") - closeIssuesFromMessage( - issueContent, - loginAccount.userName, - owner, - name - ).foreach { issueId => - getIssue(owner, name, issueId.toString).foreach { issue => - callIssuesWebHook("closed", repository, issue, loginAccount) - PluginRegistry().getIssueHooks - .foreach(_.closedByCommitComment(issue, repository, issueContent, loginAccount)) - } - } - closeIssuesFromMessage(form.message, loginAccount.userName, owner, name).foreach { issueId => - getIssue(owner, name, issueId.toString).foreach { issue => - callIssuesWebHook("closed", repository, issue, loginAccount) - PluginRegistry().getIssueHooks - .foreach(_.closedByCommitComment(issue, repository, issueContent, loginAccount)) - } - } - } - - updatePullRequests(owner, name, pullreq.branch) - - // call web hook - callPullRequestWebHook("closed", repository, issueId, context.loginAccount.get) - - // call hooks - PluginRegistry().getPullRequestHooks.foreach { h => - h.addedComment(commentId, form.message, issue, repository) - h.merged(issue, repository) - } - - redirect(s"/${owner}/${name}/pull/${issueId}") - } - } - } - } else Some(BadRequest()) + mergePullRequest(repository, issueId, context.loginAccount.get, form.message, form.strategy) match { + case Right(objectId) => redirect(s"/${owner}/${name}/pull/${issueId}") + case Left(message) => Some(BadRequest()) + } } getOrElse NotFound() }) diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 02c4848..49cecce 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -13,7 +13,7 @@ import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Directory._ -import gitbucket.core.model.{Account, CommitState, CommitStatus, WebHook} +import gitbucket.core.model.{Account, CommitState, CommitStatus} import gitbucket.core.view import gitbucket.core.view.helpers import org.apache.commons.compress.archivers.{ArchiveEntry, ArchiveOutputStream} @@ -615,50 +615,17 @@ post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) => val id = params("id") createCommitComment( - repository.owner, - repository.name, + repository, id, - context.loginAccount.get.userName, + context.loginAccount.get, form.content, form.fileName, form.oldLineNumber, form.newLineNumber, + form.diff, form.issueId ) - for { - fileName <- form.fileName - diff <- form.diff - } { - saveCommitCommentDiff( - repository.owner, - repository.name, - id, - fileName, - form.oldLineNumber, - form.newLineNumber, - diff - ) - } - - form.issueId match { - case Some(issueId) => - recordCommentPullRequestActivity( - repository.owner, - repository.name, - context.loginAccount.get.userName, - issueId, - form.content - ) - case None => - recordCommentCommitActivity( - repository.owner, - repository.name, - context.loginAccount.get.userName, - id, - form.content - ) - } redirect(s"/${repository.owner}/${repository.name}/commit/${id}") }) @@ -683,63 +650,18 @@ ajaxPost("/:owner/:repository/commit/:id/comment/_data/new", commentForm)(readableUsersOnly { (form, repository) => val id = params("id") val commentId = createCommitComment( - repository.owner, - repository.name, + repository, id, - context.loginAccount.get.userName, + context.loginAccount.get, form.content, form.fileName, form.oldLineNumber, form.newLineNumber, + form.diff, form.issueId ) - for { - fileName <- form.fileName - diff <- form.diff - } { - saveCommitCommentDiff( - repository.owner, - repository.name, - id, - fileName, - form.oldLineNumber, - form.newLineNumber, - diff - ) - } - val comment = getCommitComment(repository.owner, repository.name, commentId.toString).get - form.issueId match { - case Some(issueId) => - getPullRequest(repository.owner, repository.name, issueId).foreach { - case (issue, pullRequest) => - recordCommentPullRequestActivity( - repository.owner, - repository.name, - context.loginAccount.get.userName, - issueId, - form.content - ) - PluginRegistry().getPullRequestHooks.foreach(_.addedComment(commentId, form.content, issue, repository)) - callPullRequestReviewCommentWebHook( - "create", - comment, - repository, - issue, - pullRequest, - context.loginAccount.get - ) - } - case None => - recordCommentCommitActivity( - repository.owner, - repository.name, - context.loginAccount.get.userName, - id, - form.content - ) - } helper.html .commitcomment(comment, hasDeveloperRole(repository.owner, repository.name, context.loginAccount), repository) }) diff --git a/src/main/scala/gitbucket/core/service/CommitsService.scala b/src/main/scala/gitbucket/core/service/CommitsService.scala index b59c929..f3b8e84 100644 --- a/src/main/scala/gitbucket/core/service/CommitsService.scala +++ b/src/main/scala/gitbucket/core/service/CommitsService.scala @@ -2,15 +2,20 @@ import java.io.File -import gitbucket.core.model.CommitComment +import gitbucket.core.api.JsonFormat +import gitbucket.core.controller.Context +import gitbucket.core.model.{Account, CommitComment} import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType +import gitbucket.core.plugin.PluginRegistry +import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.util.Directory._ import gitbucket.core.util.{FileUtil, StringUtil} import org.apache.commons.io.FileUtils trait CommitsService { + self: ActivityService with PullRequestService with WebHookPullRequestReviewCommentService => def getCommitComments(owner: String, repository: String, commitId: String, includePullRequest: Boolean)( implicit s: Session @@ -28,21 +33,21 @@ None def createCommitComment( - owner: String, - repository: String, + repository: RepositoryInfo, commitId: String, - loginUser: String, + loginAccount: Account, content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int], + diff: Option[String], issueId: Option[Int] - )(implicit s: Session): Int = - CommitComments returning CommitComments.map(_.commentId) insert CommitComment( - userName = owner, - repositoryName = repository, + )(implicit s: Session, c: JsonFormat.Context, context: Context): Int = { + val commentId = CommitComments returning CommitComments.map(_.commentId) insert CommitComment( + userName = repository.owner, + repositoryName = repository.name, commitId = commitId, - commentedUserName = loginUser, + commentedUserName = loginAccount.userName, content = content, fileName = fileName, oldLine = oldLine, @@ -55,6 +60,56 @@ originalNewLine = newLine ) + for { + fileName <- fileName + diff <- diff + } { + saveCommitCommentDiff( + repository.owner, + repository.name, + commitId, + fileName, + oldLine, + newLine, + diff + ) + } + + val comment = getCommitComment(repository.owner, repository.name, commentId.toString).get + issueId match { + case Some(issueId) => + getPullRequest(repository.owner, repository.name, issueId).foreach { + case (issue, pullRequest) => + recordCommentPullRequestActivity( + repository.owner, + repository.name, + loginAccount.userName, + issueId, + content + ) + PluginRegistry().getPullRequestHooks.foreach(_.addedComment(commentId, content, issue, repository)) + callPullRequestReviewCommentWebHook( + "create", + comment, + repository, + issue, + pullRequest, + loginAccount + ) + } + case None => + recordCommentCommitActivity( + repository.owner, + repository.name, + loginAccount.userName, + commitId, + content + ) + } + + commentId + } + def updateCommitCommentPosition(commentId: Int, commitId: String, oldLine: Option[Int], newLine: Option[Int])( implicit s: Session ): Unit = diff --git a/src/main/scala/gitbucket/core/service/MergeService.scala b/src/main/scala/gitbucket/core/service/MergeService.scala index fa4f0b5..b1a45c8 100644 --- a/src/main/scala/gitbucket/core/service/MergeService.scala +++ b/src/main/scala/gitbucket/core/service/MergeService.scala @@ -1,11 +1,12 @@ package gitbucket.core.service import gitbucket.core.api.JsonFormat -import gitbucket.core.model.{Account, WebHook} +import gitbucket.core.controller.Context +import gitbucket.core.model.{Account, PullRequest, WebHook} import gitbucket.core.plugin.PluginRegistry import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.util.Directory._ -import gitbucket.core.util.JGitUtil +import gitbucket.core.util.{JGitUtil, LockUtil} import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile._ @@ -20,7 +21,12 @@ import scala.collection.JavaConverters._ trait MergeService { - self: AccountService with ActivityService with IssuesService with RepositoryService with WebHookPullRequestService => + self: AccountService + with ActivityService + with IssuesService + with RepositoryService + with PullRequestService + with WebHookPullRequestService => import MergeService._ @@ -52,23 +58,35 @@ } /** merge the pull request with a merge commit */ - def mergePullRequest(git: Git, branch: String, issueId: Int, message: String, committer: PersonIdent): Unit = { + private def mergePullRequest( + git: Git, + branch: String, + issueId: Int, + message: String, + committer: PersonIdent + ): ObjectId = { new MergeCacheInfo(git, branch, issueId).merge(message, committer) } /** rebase to the head of the pull request branch */ - def rebasePullRequest( + private def rebasePullRequest( git: Git, branch: String, issueId: Int, commits: Seq[RevCommit], committer: PersonIdent - ): Unit = { + ): ObjectId = { new MergeCacheInfo(git, branch, issueId).rebase(committer, commits) } /** squash commits in the pull request and append it */ - def squashPullRequest(git: Git, branch: String, issueId: Int, message: String, committer: PersonIdent): Unit = { + private def squashPullRequest( + git: Git, + branch: String, + issueId: Int, + message: String, + committer: PersonIdent + ): ObjectId = { new MergeCacheInfo(git, branch, issueId).squash(message, committer) } @@ -150,7 +168,8 @@ remoteRepository: RepositoryInfo, remoteBranch: String, loginAccount: Account, - message: String + message: String, + pullreq: Option[PullRequest] )(implicit s: Session, c: JsonFormat.Context): Option[ObjectId] = { val localUserName = localRepository.owner val localRepositoryName = localRepository.name @@ -204,10 +223,163 @@ } } } + + pullreq.foreach { pullreq => + callWebHookOf(localRepository.owner, localRepository.name, WebHook.Push) { + for { + ownerAccount <- getAccountByUserName(localRepository.owner) + } yield { + WebHookService.WebHookPushPayload( + git, + loginAccount, + pullreq.requestBranch, + localRepository, + commits, + ownerAccount, + oldId = oldBaseId, + newId = newCommit + ) + } + } + } } oldBaseId }.toOption } + + def mergePullRequest( + repository: RepositoryInfo, + issueId: Int, + loginAccount: Account, + message: String, + strategy: String + )(implicit s: Session, c: JsonFormat.Context, context: Context): Either[String, ObjectId] = { + if (repository.repository.options.mergeOptions.split(",").contains(strategy)) { + LockUtil.lock(s"${repository.owner}/${repository.name}") { + getPullRequest(repository.owner, repository.name, issueId) + .map { + case (issue, pullreq) => + using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git => + // mark issue as merged and close. + val commentId = + createComment(repository.owner, repository.name, loginAccount.userName, issueId, message, "merge") + createComment(repository.owner, repository.name, loginAccount.userName, issueId, "Close", "close") + updateClosed(repository.owner, repository.name, issueId, true) + + // record activity + recordMergeActivity(repository.owner, repository.name, loginAccount.userName, issueId, message) + + val (commits, _) = getRequestCompareInfo( + repository.owner, + repository.name, + pullreq.commitIdFrom, + pullreq.requestUserName, + pullreq.requestRepositoryName, + pullreq.commitIdTo + ) + + val revCommits = using(new RevWalk(git.getRepository)) { revWalk => + commits.flatten.map { commit => + revWalk.parseCommit(git.getRepository.resolve(commit.id)) + } + }.reverse + + // merge git repository + (strategy match { + case "merge-commit" => + Some( + mergePullRequest( + git, + pullreq.branch, + issueId, + s"Merge pull request #${issueId} from ${pullreq.requestUserName}/${pullreq.requestBranch}\n\n" + message, + new PersonIdent(loginAccount.fullName, loginAccount.mailAddress) + ) + ) + case "rebase" => + Some( + rebasePullRequest( + git, + pullreq.branch, + issueId, + revCommits, + new PersonIdent(loginAccount.fullName, loginAccount.mailAddress) + ) + ) + case "squash" => + Some( + squashPullRequest( + git, + pullreq.branch, + issueId, + s"${issue.title} (#${issueId})\n\n" + message, + new PersonIdent(loginAccount.fullName, loginAccount.mailAddress) + ) + ) + case _ => + None + }) match { + case Some(newCommitId) => + // close issue by content of pull request + val defaultBranch = getRepository(repository.owner, repository.name).get.repository.defaultBranch + if (pullreq.branch == defaultBranch) { + commits.flatten.foreach { commit => + closeIssuesFromMessage( + commit.fullMessage, + loginAccount.userName, + repository.owner, + repository.name + ).foreach { issueId => + getIssue(repository.owner, repository.name, issueId.toString).foreach { issue => + callIssuesWebHook("closed", repository, issue, loginAccount) + PluginRegistry().getIssueHooks + .foreach(_.closedByCommitComment(issue, repository, commit.fullMessage, loginAccount)) + } + } + } + val issueContent = issue.title + " " + issue.content.getOrElse("") + closeIssuesFromMessage( + issueContent, + loginAccount.userName, + repository.owner, + repository.name + ).foreach { issueId => + getIssue(repository.owner, repository.name, issueId.toString).foreach { issue => + callIssuesWebHook("closed", repository, issue, loginAccount) + PluginRegistry().getIssueHooks + .foreach(_.closedByCommitComment(issue, repository, issueContent, loginAccount)) + } + } + closeIssuesFromMessage(message, loginAccount.userName, repository.owner, repository.name) + .foreach { issueId => + getIssue(repository.owner, repository.name, issueId.toString).foreach { issue => + callIssuesWebHook("closed", repository, issue, loginAccount) + PluginRegistry().getIssueHooks + .foreach(_.closedByCommitComment(issue, repository, issueContent, loginAccount)) + } + } + } + + updatePullRequests(repository.owner, repository.name, pullreq.branch, loginAccount, "closed") + + // call hooks + PluginRegistry().getPullRequestHooks.foreach { h => + h.addedComment(commentId, message, issue, repository) + h.merged(issue, repository) + } + + Right(newCommitId) + case None => + Left("Unknown strategy") + } + } + case _ => Left("Unknown error") + } + .getOrElse(Left("Pull request not found")) + } + } else Left("Strategy not allowed") + + } } object MergeService { @@ -242,13 +414,15 @@ force: Boolean, committer: PersonIdent, refLogMessage: Option[String] = None - ): Unit = { + ): ObjectId = { val refUpdate = repository.updateRef(ref) refUpdate.setNewObjectId(newObjectId) refUpdate.setForceUpdate(force) refUpdate.setRefLogIdent(committer) refLogMessage.foreach(refUpdate.setRefLogMessage(_, true)) refUpdate.update() + + newObjectId } } @@ -316,7 +490,7 @@ } // update branch from cache - def merge(message: String, committer: PersonIdent) = { + def merge(message: String, committer: PersonIdent): ObjectId = { if (checkConflict().isDefined) { throw new RuntimeException("This pull request can't merge automatically.") } @@ -329,7 +503,7 @@ Util.updateRefs(repository, s"refs/heads/${branch}", mergeCommitId, false, committer, Some("merged")) } - def rebase(committer: PersonIdent, commits: Seq[RevCommit]): Unit = { + def rebase(committer: PersonIdent, commits: Seq[RevCommit]): ObjectId = { if (checkConflict().isDefined) { throw new RuntimeException("This pull request can't merge automatically.") } @@ -361,7 +535,7 @@ Util.updateRefs(repository, s"refs/heads/${branch}", previousId, false, committer, Some("rebased")) } - def squash(message: String, committer: PersonIdent): Unit = { + def squash(message: String, committer: PersonIdent): ObjectId = { if (checkConflict().isDefined) { throw new RuntimeException("This pull request can't merge automatically.") } diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index d391f91..8b87334 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -4,6 +4,7 @@ import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import difflib.{Delta, DiffUtils} +import gitbucket.core.api.JsonFormat import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ @@ -15,7 +16,8 @@ import scala.collection.JavaConverters._ -trait PullRequestService { self: IssuesService with CommitsService => +trait PullRequestService { + self: IssuesService with CommitsService with WebHookService with WebHookPullRequestService with RepositoryService => import PullRequestService._ def getPullRequest(owner: String, repository: String, issueId: Int)( @@ -164,7 +166,10 @@ /** * Fetch pull request contents into refs/pull/${issueId}/head and update pull request table. */ - def updatePullRequests(owner: String, repository: String, branch: String)(implicit s: Session): Unit = { + def updatePullRequests(owner: String, repository: String, branch: String, loginAccount: Account, action: String)( + implicit s: Session, + c: JsonFormat.Context + ): Unit = { getPullRequestsByRequest(owner, repository, branch, Some(false)).foreach { pullreq => if (Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists.run) { // Update the git repository @@ -204,6 +209,14 @@ // Update commit id in the PULL_REQUEST table updateCommitId(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdTo, commitIdFrom) + + // call web hook + callPullRequestWebHookByRequestBranch( + action, + getRepository(owner, repository).get, + pullreq.requestBranch, + loginAccount + ) } } } diff --git a/src/main/scala/gitbucket/core/service/RepositoryCommitFileService.scala b/src/main/scala/gitbucket/core/service/RepositoryCommitFileService.scala index a0cfd70..55bf9fb 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryCommitFileService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryCommitFileService.scala @@ -135,7 +135,7 @@ refUpdate.update() // update pull request - updatePullRequests(repository.owner, repository.name, branch) + updatePullRequests(repository.owner, repository.name, branch, loginAccount, "synchronize") // record activity val commitInfo = new CommitInfo(JGitUtil.getRevCommitFromId(git, commitId)) @@ -161,8 +161,6 @@ hook.postReceive(repository.owner, repository.name, receivePack, receiveCommand, loginAccount.userName) } - //call web hook - callPullRequestWebHookByRequestBranch("synchronize", repository, branch, loginAccount) val commit = new JGitUtil.CommitInfo(JGitUtil.getRevCommitFromId(git, commitId)) callWebHookOf(repository.owner, repository.name, WebHook.Push) { getAccountByUserName(repository.owner).map { ownerAccount => diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala index c8945c4..46dbcc4 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -221,6 +221,7 @@ with PrioritiesService with MilestonesService with WebHookPullRequestService + with WebHookPullRequestReviewCommentService with CommitsService { private val logger = LoggerFactory.getLogger(classOf[CommitLogHook]) @@ -346,14 +347,8 @@ command.getType match { case ReceiveCommand.Type.CREATE | ReceiveCommand.Type.UPDATE | ReceiveCommand.Type.UPDATE_NONFASTFORWARD => - updatePullRequests(owner, repository, branchName) getAccountByUserName(pusher).foreach { pusherAccount => - callPullRequestWebHookByRequestBranch( - "synchronize", - repositoryInfo, - branchName, - pusherAccount - ) + updatePullRequests(owner, repository, branchName, pusherAccount, "synchronize") } case _ => }