This commit is contained in:
KOUNOIKE
2018-12-29 18:33:39 +09:00
parent 38c8977dab
commit 2745a3bfaa
10 changed files with 88 additions and 57 deletions

View File

@@ -9,6 +9,7 @@ import gitbucket.core.service.IssuesService._
class DashboardController class DashboardController
extends DashboardControllerBase extends DashboardControllerBase
with IssuesService with IssuesService
with MergeService
with PullRequestService with PullRequestService
with RepositoryService with RepositoryService
with AccountService with AccountService

View File

@@ -24,6 +24,7 @@ class IssuesController
with ReadableUsersAuthenticator with ReadableUsersAuthenticator
with ReferrerAuthenticator with ReferrerAuthenticator
with WritableUsersAuthenticator with WritableUsersAuthenticator
with MergeService
with PullRequestService with PullRequestService
with WebHookIssueCommentService with WebHookIssueCommentService
with WebHookPullRequestReviewCommentService with WebHookPullRequestReviewCommentService

View File

@@ -534,15 +534,15 @@ trait PullRequestsControllerBase extends ControllerBase {
) )
createPullRequest( createPullRequest(
originUserName = repository.owner, originRepository = repository,
originRepositoryName = repository.name,
issueId = issueId, issueId = issueId,
originBranch = form.targetBranch, originBranch = form.targetBranch,
requestUserName = form.requestUserName, requestUserName = form.requestUserName,
requestRepositoryName = form.requestRepositoryName, requestRepositoryName = form.requestRepositoryName,
requestBranch = form.requestBranch, requestBranch = form.requestBranch,
commitIdFrom = form.commitIdFrom, commitIdFrom = form.commitIdFrom,
commitIdTo = form.commitIdTo commitIdTo = form.commitIdTo,
loginAccount = context.loginAccount.get
) )
// insert labels // insert labels
@@ -557,29 +557,6 @@ trait PullRequestsControllerBase extends ControllerBase {
} }
} }
// fetch requested branch
fetchAsPullRequest(owner, name, form.requestUserName, form.requestRepositoryName, form.requestBranch, issueId)
// record activity
recordPullRequestActivity(owner, name, loginUserName, issueId, form.title)
// call web hook
callPullRequestWebHook("opened", repository, issueId, context.loginAccount.get)
getIssue(owner, name, issueId.toString) foreach { issue =>
// extract references and create refer comment
createReferComment(
owner,
name,
issue,
form.title + " " + form.content.getOrElse(""),
context.loginAccount.get
)
// call hooks
PluginRegistry().getPullRequestHooks.foreach(_.created(issue, repository))
}
redirect(s"/${owner}/${name}/pull/${issueId}") redirect(s"/${owner}/${name}/pull/${issueId}")
} }
}) })

View File

@@ -50,6 +50,7 @@ class RepositoryViewerController
with ReadableUsersAuthenticator with ReadableUsersAuthenticator
with ReferrerAuthenticator with ReferrerAuthenticator
with WritableUsersAuthenticator with WritableUsersAuthenticator
with MergeService
with PullRequestService with PullRequestService
with CommitStatusService with CommitStatusService
with WebHookPullRequestService with WebHookPullRequestService

View File

@@ -106,15 +106,15 @@ trait ApiPullRequestControllerBase extends ControllerBase {
) )
createPullRequest( createPullRequest(
originUserName = repository.owner, originRepository = repository,
originRepositoryName = repository.name,
issueId = issueId, issueId = issueId,
originBranch = createPullReq.base, originBranch = createPullReq.base,
requestUserName = reqOwner, requestUserName = reqOwner,
requestRepositoryName = repository.name, requestRepositoryName = repository.name,
requestBranch = reqBranch, requestBranch = reqBranch,
commitIdFrom = commitIdFrom.getName, commitIdFrom = commitIdFrom.getName,
commitIdTo = commitIdTo.getName commitIdTo = commitIdTo.getName,
loginAccount = context.loginAccount.get
) )
getApiPullRequest(repository, issueId).map(JsonFormat(_)) getApiPullRequest(repository, issueId).map(JsonFormat(_))
case _ => case _ =>
@@ -133,15 +133,15 @@ trait ApiPullRequestControllerBase extends ControllerBase {
case (Some(commitIdFrom), Some(commitIdTo)) => case (Some(commitIdFrom), Some(commitIdTo)) =>
changeIssueToPullRequest(repository.owner, repository.name, createPullReqAlt.issue) changeIssueToPullRequest(repository.owner, repository.name, createPullReqAlt.issue)
createPullRequest( createPullRequest(
originUserName = repository.owner, originRepository = repository,
originRepositoryName = repository.name,
issueId = createPullReqAlt.issue, issueId = createPullReqAlt.issue,
originBranch = createPullReqAlt.base, originBranch = createPullReqAlt.base,
requestUserName = reqOwner, requestUserName = reqOwner,
requestRepositoryName = repository.name, requestRepositoryName = repository.name,
requestBranch = reqBranch, requestBranch = reqBranch,
commitIdFrom = commitIdFrom.getName, commitIdFrom = commitIdFrom.getName,
commitIdTo = commitIdTo.getName commitIdTo = commitIdTo.getName,
loginAccount = context.loginAccount.get
) )
getApiPullRequest(repository, createPullReqAlt.issue).map(JsonFormat(_)) getApiPullRequest(repository, createPullReqAlt.issue).map(JsonFormat(_))
case _ => case _ =>

View File

@@ -6,6 +6,8 @@ import gitbucket.core.model.Profile.profile.blockingApi._
import difflib.{Delta, DiffUtils} import difflib.{Delta, DiffUtils}
import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.service.RepositoryService.RepositoryInfo
import gitbucket.core.api.JsonFormat import gitbucket.core.api.JsonFormat
import gitbucket.core.controller.Context
import gitbucket.core.plugin.PluginRegistry
import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.SyntaxSugars._
import gitbucket.core.util.Directory._ import gitbucket.core.util.Directory._
import gitbucket.core.util.Implicits._ import gitbucket.core.util.Implicits._
@@ -20,7 +22,13 @@ import org.eclipse.jgit.lib.ObjectId
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
trait PullRequestService { trait PullRequestService {
self: IssuesService with CommitsService with WebHookService with WebHookPullRequestService with RepositoryService => self: IssuesService
with CommitsService
with WebHookService
with WebHookPullRequestService
with RepositoryService
with MergeService
with ActivityService =>
import PullRequestService._ import PullRequestService._
def getPullRequest(owner: String, repository: String, issueId: Int)( def getPullRequest(owner: String, repository: String, issueId: Int)(
@@ -81,19 +89,20 @@ trait PullRequestService {
// .map { x => PullRequestCount(x._1, x._2) } // .map { x => PullRequestCount(x._1, x._2) }
def createPullRequest( def createPullRequest(
originUserName: String, originRepository: RepositoryInfo,
originRepositoryName: String,
issueId: Int, issueId: Int,
originBranch: String, originBranch: String,
requestUserName: String, requestUserName: String,
requestRepositoryName: String, requestRepositoryName: String,
requestBranch: String, requestBranch: String,
commitIdFrom: String, commitIdFrom: String,
commitIdTo: String commitIdTo: String,
)(implicit s: Session): Unit = loginAccount: Account
)(implicit s: Session, context: Context): Unit = {
getIssue(originRepository.owner, originRepository.name, issueId.toString).foreach { baseIssue =>
PullRequests insert PullRequest( PullRequests insert PullRequest(
originUserName, originRepository.owner,
originRepositoryName, originRepository.name,
issueId, issueId,
originBranch, originBranch,
requestUserName, requestUserName,
@@ -103,6 +112,44 @@ trait PullRequestService {
commitIdTo commitIdTo
) )
// fetch requested branch
fetchAsPullRequest(
originRepository.owner,
originRepository.name,
requestUserName,
requestRepositoryName,
requestBranch,
issueId
)
// record activity
recordPullRequestActivity(
originRepository.owner,
originRepository.name,
loginAccount.userName,
issueId,
baseIssue.title
)
// call web hook
callPullRequestWebHook("opened", originRepository, issueId, loginAccount)
getIssue(originRepository.owner, originRepository.name, issueId.toString) foreach { issue =>
// extract references and create refer comment
createReferComment(
originRepository.owner,
originRepository.name,
issue,
baseIssue.title + " " + baseIssue.content,
loginAccount
)
// call hooks
PluginRegistry().getPullRequestHooks.foreach(_.created(issue, originRepository))
}
}
}
def getPullRequestsByRequest(userName: String, repositoryName: String, branch: String, closed: Option[Boolean])( def getPullRequestsByRequest(userName: String, repositoryName: String, branch: String, closed: Option[Boolean])(
implicit s: Session implicit s: Session
): List[PullRequest] = ): List[PullRequest] =

View File

@@ -215,6 +215,7 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
with AccountService with AccountService
with IssuesService with IssuesService
with ActivityService with ActivityService
with MergeService
with PullRequestService with PullRequestService
with WebHookService with WebHookService
with LabelsService with LabelsService

View File

@@ -6,6 +6,7 @@ import org.scalatest.FunSpec
class PullRequestServiceSpec class PullRequestServiceSpec
extends FunSpec extends FunSpec
with ServiceSpecBase with ServiceSpecBase
with MergeService
with PullRequestService with PullRequestService
with IssuesService with IssuesService
with AccountService with AccountService

View File

@@ -10,12 +10,12 @@ import gitbucket.core.model._
import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile._
import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile._
import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.profile.blockingApi._
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import java.sql.DriverManager import java.sql.DriverManager
import java.io.File import java.io.File
import gitbucket.core.controller.Context
import scala.util.Random import scala.util.Random
trait ServiceSpecBase { trait ServiceSpecBase {
@@ -44,8 +44,8 @@ trait ServiceSpecBase {
def user(name: String)(implicit s: Session): Account = AccountService.getAccountByUserName(name).get def user(name: String)(implicit s: Session): Account = AccountService.getAccountByUserName(name).get
lazy val dummyService = new RepositoryService with AccountService with ActivityService with IssuesService lazy val dummyService = new RepositoryService with AccountService with ActivityService with IssuesService
with PullRequestService with CommitsService with CommitStatusService with LabelsService with MilestonesService with MergeService with PullRequestService with CommitsService with CommitStatusService with LabelsService
with PrioritiesService with WebHookService with WebHookPullRequestService with MilestonesService with PrioritiesService with WebHookService with WebHookPullRequestService
with WebHookPullRequestReviewCommentService {} with WebHookPullRequestReviewCommentService {}
def generateNewUserWithDBRepository(userName: String, repositoryName: String)(implicit s: Session): Account = { def generateNewUserWithDBRepository(userName: String, repositoryName: String)(implicit s: Session): Account = {
@@ -76,16 +76,18 @@ trait ServiceSpecBase {
val Array(baseUserName, baseRepositoryName, baesBranch) = base.split("/") val Array(baseUserName, baseRepositoryName, baesBranch) = base.split("/")
val Array(requestUserName, requestRepositoryName, requestBranch) = request.split("/") val Array(requestUserName, requestRepositoryName, requestBranch) = request.split("/")
val issueId = generateNewIssue(baseUserName, baseRepositoryName, Option(loginUser).getOrElse(requestUserName)) val issueId = generateNewIssue(baseUserName, baseRepositoryName, Option(loginUser).getOrElse(requestUserName))
val baseRepository = dummyService.getRepository(baseUserName, baseRepositoryName)
val loginAccount = dummyService.getAccountByUserName(loginUser)
dummyService.createPullRequest( dummyService.createPullRequest(
originUserName = baseUserName, originRepository = baseRepository.get,
originRepositoryName = baseRepositoryName,
issueId = issueId, issueId = issueId,
originBranch = baesBranch, originBranch = baesBranch,
requestUserName = requestUserName, requestUserName = requestUserName,
requestRepositoryName = requestRepositoryName, requestRepositoryName = requestRepositoryName,
requestBranch = requestBranch, requestBranch = requestBranch,
commitIdFrom = baesBranch, commitIdFrom = baesBranch,
commitIdTo = requestBranch commitIdTo = requestBranch,
loginAccount = loginAccount.get
) )
dummyService.getPullRequest(baseUserName, baseRepositoryName, issueId).get dummyService.getPullRequest(baseUserName, baseRepositoryName, issueId).get
} }

View File

@@ -6,8 +6,8 @@ import gitbucket.core.model.WebHookContentType
class WebHookServiceSpec extends FunSuite with ServiceSpecBase { class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
lazy val service = new WebHookPullRequestService with AccountService with ActivityService with RepositoryService lazy val service = new WebHookPullRequestService with AccountService with ActivityService with RepositoryService
with PullRequestService with IssuesService with CommitsService with LabelsService with MilestonesService with MergeService with PullRequestService with IssuesService with CommitsService with LabelsService
with PrioritiesService with WebHookPullRequestReviewCommentService with MilestonesService with PrioritiesService with WebHookPullRequestReviewCommentService
test("WebHookPullRequestService.getPullRequestsByRequestForWebhook") { test("WebHookPullRequestService.getPullRequestsByRequestForWebhook") {
withTestDB { implicit session => withTestDB { implicit session =>