diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index 8f665c6..c9854ea 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -700,11 +700,12 @@ def closeIssuesFromMessage(message: String, userName: String, owner: String, repository: String)( implicit s: Session - ): Unit = { - extractCloseId(message).foreach { issueId => - for (issue <- getIssue(owner, repository, issueId) if !issue.closed) { + ): Seq[Int] = { + extractCloseId(message).flatMap { issueId => + for (issue <- getIssue(owner, repository, issueId) if !issue.closed) yield { createComment(owner, repository, userName, issue.issueId, "Close", "close") updateClosed(owner, repository, issue.issueId, true) + issue.issueId } } } diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index 0f7f50c..c6cde8e 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -116,6 +116,24 @@ .map { case (t1, t2) => t1 } .list + def getPullRequestsByBranch(userName: String, repositoryName: String, branch: String, closed: Option[Boolean])( + implicit s: Session + ): List[PullRequest] = + PullRequests + .join(Issues) + .on { (t1, t2) => + t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) + } + .filter { + case (t1, t2) => + (t1.requestUserName === userName.bind) && + (t1.requestRepositoryName === repositoryName.bind) && + (t1.branch === branch.bind) && + (t2.closed === closed.get.bind, closed.isDefined) + } + .map { case (t1, t2) => t1 } + .list + /** * for repository viewer. * 1. find pull request from `branch` to other branch on same repository @@ -358,6 +376,14 @@ .sortWith(_.registeredDate before _.registeredDate) } + def markMergeAndClosePullRequest(userName: String, owner: String, repository: String, pull: PullRequest)( + implicit s: Session + ): Unit = { + createComment(owner, repository, userName, pull.issueId, "Merged by user", "merge") + createComment(owner, repository, userName, pull.issueId, "Close", "close") + updateClosed(owner, repository, pull.issueId, true) + } + } object PullRequestService { diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala index 0a8d956..cfc5f3b 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -296,13 +296,32 @@ createIssueComment(owner, repository, commit) // close issues if (refName(1) == "heads" && branchName == defaultBranch && command.getType == ReceiveCommand.Type.UPDATE) { - closeIssuesFromMessage(commit.fullMessage, pusher, owner, repository) + getAccountByUserName(pusher).map { pusherAccount => + closeIssuesFromMessage(commit.fullMessage, pusher, owner, repository).foreach { issueId => + getIssue(owner, repository, issueId.toString).map { issue => + callIssuesWebHook("closed", repositoryInfo, issue, baseUrl, pusherAccount) + } + } + } } } Some(commit) } else None } + // set PR as merged + val pulls = getPullRequestsByBranch(owner, repository, branchName, Some(false)) + pulls.foreach { pull => + if (commits.find { c => + c.id == pull.commitIdTo + }.isDefined) { + markMergeAndClosePullRequest(pusher, owner, repository, pull) + getAccountByUserName(pusher).map { pusherAccount => + callPullRequestWebHook("closed", repositoryInfo, pull.issueId, baseUrl, pusherAccount) + } + } + } + // record activity if (refName(1) == "heads") { command.getType match { diff --git a/src/main/twirl/gitbucket/core/pulls/menu.scala.html b/src/main/twirl/gitbucket/core/pulls/menu.scala.html index 5fc8c5e..d5bb98b 100644 --- a/src/main/twirl/gitbucket/core/pulls/menu.scala.html +++ b/src/main/twirl/gitbucket/core/pulls/menu.scala.html @@ -44,8 +44,8 @@ @helpers.user(comment.commentedUserName, styleClass = "username strong") merged @commits.size @helpers.plural(commits.size, "commit") - into @pullreq.userName:@pullreq.branch from @pullreq.requestUserName - :@pullreq.requestBranch + into @pullreq.userName:@pullreq.branch + from @pullreq.requestUserName:@pullreq.requestBranch @gitbucket.core.helper.html.datetimeago(comment.registeredDate) }.getOrElse { @@ -53,8 +53,8 @@ @helpers.user(issue.openedUserName, styleClass = "username strong") wants to merge @commits.size @helpers.plural(commits.size, "commit") - into @pullreq.userName:@pullreq.branch from @pullreq.requestUserName - :@pullreq.requestBranch + into @pullreq.userName:@pullreq.branch + from @pullreq.requestUserName:@pullreq.requestBranch } } else { @@ -62,8 +62,8 @@ @helpers.user(issue.openedUserName, styleClass = "username strong") wants to merge @commits.size @helpers.plural(commits.size, "commit") - into @pullreq.userName:@pullreq.branch from @pullreq.requestUserName - :@pullreq.requestBranch + into @pullreq.userName:@pullreq.branch + from @pullreq.requestUserName:@pullreq.requestBranch }