close and mark as merged PR by pushed commits

This commit is contained in:
KOUNOIKE Yuusuke
2018-04-28 23:16:06 +09:00
parent cf038ebd38
commit 56eb2435e3
2 changed files with 39 additions and 0 deletions

View File

@@ -116,6 +116,24 @@ trait PullRequestService { self: IssuesService with CommitsService =>
.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 @@ trait PullRequestService { self: IssuesService with CommitsService =>
.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 {

View File

@@ -303,6 +303,19 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
} 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 {