diff --git a/src/main/scala/gitbucket/core/controller/AccountController.scala b/src/main/scala/gitbucket/core/controller/AccountController.scala index 0c72af7..19c553a 100644 --- a/src/main/scala/gitbucket/core/controller/AccountController.scala +++ b/src/main/scala/gitbucket/core/controller/AccountController.scala @@ -6,7 +6,7 @@ import gitbucket.core.plugin.PluginRegistry import gitbucket.core.service._ import gitbucket.core.ssh.SshUtil -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.StringUtil._ diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala index 872886e..ab2a0f1 100644 --- a/src/main/scala/gitbucket/core/controller/ApiController.scala +++ b/src/main/scala/gitbucket/core/controller/ApiController.scala @@ -5,7 +5,7 @@ import gitbucket.core.service.IssuesService.IssueSearchCondition import gitbucket.core.service.PullRequestService._ import gitbucket.core.service._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.JGitUtil._ import gitbucket.core.util._ diff --git a/src/main/scala/gitbucket/core/controller/ControllerBase.scala b/src/main/scala/gitbucket/core/controller/ControllerBase.scala index 21784c3..ceff777 100644 --- a/src/main/scala/gitbucket/core/controller/ControllerBase.scala +++ b/src/main/scala/gitbucket/core/controller/ControllerBase.scala @@ -5,7 +5,7 @@ import gitbucket.core.api.ApiError import gitbucket.core.model.Account import gitbucket.core.service.{AccountService, SystemSettingsService,RepositoryService} -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ import gitbucket.core.util._ diff --git a/src/main/scala/gitbucket/core/controller/FileUploadController.scala b/src/main/scala/gitbucket/core/controller/FileUploadController.scala index 9ca7e6b..cff4ceb 100644 --- a/src/main/scala/gitbucket/core/controller/FileUploadController.scala +++ b/src/main/scala/gitbucket/core/controller/FileUploadController.scala @@ -5,7 +5,7 @@ import gitbucket.core.service.{AccountService, RepositoryService} import gitbucket.core.servlet.Database import gitbucket.core.util._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ import org.eclipse.jgit.api.Git diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index 1cd4282..9d0316f 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -4,13 +4,13 @@ import gitbucket.core.model.Account import gitbucket.core.service._ import gitbucket.core.util.Implicits._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.{Keys, LDAPUtil, ReferrerAuthenticator, UsersAuthenticator} import io.github.gitbucket.scalatra.forms._ import org.scalatra.Ok -class IndexController extends IndexControllerBase +class IndexController extends IndexControllerBase with RepositoryService with ActivityService with AccountService with RepositorySearchService with IssuesService with UsersAuthenticator with ReferrerAuthenticator diff --git a/src/main/scala/gitbucket/core/controller/IssuesController.scala b/src/main/scala/gitbucket/core/controller/IssuesController.scala index f55db68..eeb19ac 100644 --- a/src/main/scala/gitbucket/core/controller/IssuesController.scala +++ b/src/main/scala/gitbucket/core/controller/IssuesController.scala @@ -3,7 +3,7 @@ import gitbucket.core.issues.html import gitbucket.core.service.IssuesService._ import gitbucket.core.service._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Implicits._ import gitbucket.core.util._ import gitbucket.core.view diff --git a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala index dd0c0f7..cf8c49b 100644 --- a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala +++ b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala @@ -8,7 +8,7 @@ import gitbucket.core.service.PullRequestService._ import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.service._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ import gitbucket.core.util._ diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala index 8a14ab0..0ca0305 100644 --- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala @@ -6,7 +6,7 @@ import gitbucket.core.service.WebHookService._ import gitbucket.core.util._ import gitbucket.core.util.JGitUtil._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Directory._ import io.github.gitbucket.scalatra.forms._ @@ -92,14 +92,14 @@ get("/:owner/:repository/settings")(ownerOnly { repository => redirect(s"/${repository.owner}/${repository.name}/settings/options") }) - + /** * Display the Options page. */ get("/:owner/:repository/settings/options")(ownerOnly { html.options(_, flash.get("info")) }) - + /** * Save the repository options. */ diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 71f4cf2..1b4ecc9 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -10,7 +10,7 @@ import gitbucket.core.util._ import gitbucket.core.util.JGitUtil._ import gitbucket.core.util.StringUtil._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Directory._ import gitbucket.core.model.{Account, WebHook} diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index 801b873..ac2fbff 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -9,7 +9,7 @@ import gitbucket.core.plugin.PluginRegistry import SystemSettingsService._ import gitbucket.core.util.Implicits._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.StringUtil._ import io.github.gitbucket.scalatra.forms._ diff --git a/src/main/scala/gitbucket/core/controller/WikiController.scala b/src/main/scala/gitbucket/core/controller/WikiController.scala index f46b4be..49cc97d 100644 --- a/src/main/scala/gitbucket/core/controller/WikiController.scala +++ b/src/main/scala/gitbucket/core/controller/WikiController.scala @@ -5,14 +5,14 @@ import gitbucket.core.service.{AccountService, ActivityService, RepositoryService, WikiService} import gitbucket.core.util._ import gitbucket.core.util.StringUtil._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Directory._ import io.github.gitbucket.scalatra.forms._ import org.eclipse.jgit.api.Git import org.scalatra.i18n.Messages -class WikiController extends WikiControllerBase +class WikiController extends WikiControllerBase with WikiService with RepositoryService with AccountService with ActivityService with ReadableUsersAuthenticator with ReferrerAuthenticator @@ -20,7 +20,7 @@ self: WikiService with RepositoryService with ActivityService with ReadableUsersAuthenticator with ReferrerAuthenticator => case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String, id: String) - + val newForm = mapping( "pageName" -> trim(label("Page name" , text(required, maxlength(40), pagename, unique))), "content" -> trim(label("Content" , text(required, conflictForNew))), @@ -28,7 +28,7 @@ "currentPageName" -> trim(label("Current page name" , text())), "id" -> trim(label("Latest commit id" , text())) )(WikiPageEditForm.apply) - + val editForm = mapping( "pageName" -> trim(label("Page name" , text(required, maxlength(40), pagename))), "content" -> trim(label("Content" , text(required, conflictForEdit))), @@ -36,7 +36,7 @@ "currentPageName" -> trim(label("Current page name" , text(required))), "id" -> trim(label("Latest commit id" , text(required))) )(WikiPageEditForm.apply) - + get("/:owner/:repository/wiki")(referrersOnly { repository => getWikiPage(repository.owner, repository.name, "Home").map { page => html.page("Home", page, getWikiPageList(repository.owner, repository.name), @@ -45,7 +45,7 @@ getWikiPage(repository.owner, repository.name, "_Footer")) } getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/Home/_edit") }) - + get("/:owner/:repository/wiki/:page")(referrersOnly { repository => val pageName = StringUtil.urlDecode(params("page")) @@ -56,7 +56,7 @@ getWikiPage(repository.owner, repository.name, "_Footer")) } getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_edit") }) - + get("/:owner/:repository/wiki/:page/_history")(referrersOnly { repository => val pageName = StringUtil.urlDecode(params("page")) @@ -67,7 +67,7 @@ } } }) - + get("/:owner/:repository/wiki/:page/_compare/:commitId")(referrersOnly { repository => val pageName = StringUtil.urlDecode(params("page")) val Array(from, to) = params("commitId").split("\\.\\.\\.") @@ -77,7 +77,7 @@ isEditable(repository), flash.get("info")) } }) - + get("/:owner/:repository/wiki/_compare/:commitId")(referrersOnly { repository => val Array(from, to) = params("commitId").split("\\.\\.\\.") @@ -120,7 +120,7 @@ html.edit(pageName, getWikiPage(repository.owner, repository.name, pageName), repository) } else Unauthorized() }) - + post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) => if(isEditable(repository)){ defining(context.loginAccount.get){ loginAccount => @@ -145,13 +145,13 @@ } } else Unauthorized() }) - + get("/:owner/:repository/wiki/_new")(readableUsersOnly { repository => if(isEditable(repository)){ html.edit("", None, repository) } else Unauthorized() }) - + post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) => if(isEditable(repository)){ defining(context.loginAccount.get){ loginAccount => @@ -169,7 +169,7 @@ } } else Unauthorized() }) - + get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository => if(isEditable(repository)){ val pageName = StringUtil.urlDecode(params("page")) @@ -186,7 +186,7 @@ get("/:owner/:repository/wiki/_pages")(referrersOnly { repository => html.pages(getWikiPageList(repository.owner, repository.name), repository, isEditable(repository)) }) - + get("/:owner/:repository/wiki/_history")(referrersOnly { repository => using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git => JGitUtil.getCommitLog(git, "master") match { diff --git a/src/main/scala/gitbucket/core/plugin/Plugin.scala b/src/main/scala/gitbucket/core/plugin/Plugin.scala index 5303469..4367c68 100644 --- a/src/main/scala/gitbucket/core/plugin/Plugin.scala +++ b/src/main/scala/gitbucket/core/plugin/Plugin.scala @@ -5,7 +5,7 @@ import gitbucket.core.model.Account import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.service.SystemSettingsService.SystemSettings -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import io.github.gitbucket.solidbase.model.Version /** diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala index e3c0c3b..7ba1026 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala @@ -9,7 +9,7 @@ import gitbucket.core.service.ProtectedBranchService.ProtectedBranchReceiveHook import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.service.SystemSettingsService.SystemSettings -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.DatabaseConfig import gitbucket.core.util.Directory._ import io.github.gitbucket.solidbase.Solidbase diff --git a/src/main/scala/gitbucket/core/service/AccessTokenService.scala b/src/main/scala/gitbucket/core/service/AccessTokenService.scala index d9a9411..2e25cc0 100644 --- a/src/main/scala/gitbucket/core/service/AccessTokenService.scala +++ b/src/main/scala/gitbucket/core/service/AccessTokenService.scala @@ -42,7 +42,7 @@ Accounts .join(AccessTokens) .filter { case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) } - .map { case (ac, t) => ac } + .map { case (ac, t) => ac } .firstOption def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] = diff --git a/src/main/scala/gitbucket/core/service/HandleCommentService.scala b/src/main/scala/gitbucket/core/service/HandleCommentService.scala index fe94605..aaa4cf7 100644 --- a/src/main/scala/gitbucket/core/service/HandleCommentService.scala +++ b/src/main/scala/gitbucket/core/service/HandleCommentService.scala @@ -4,7 +4,7 @@ import gitbucket.core.model.Issue import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile.blockingApi._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.Notifier diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala index d9c5898..c6c4085 100644 --- a/src/main/scala/gitbucket/core/service/IssuesService.scala +++ b/src/main/scala/gitbucket/core/service/IssuesService.scala @@ -3,14 +3,13 @@ import gitbucket.core.util.JGitUtil.CommitInfo import gitbucket.core.util.StringUtil._ import gitbucket.core.util.Implicits._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.model.{Issue, PullRequest, IssueComment, IssueLabel, Label, Account, Repository, CommitState, Role} import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import gitbucket.core.model.Profile.dateColumnType - - trait IssuesService { self: AccountService with RepositoryService => import IssuesService._ @@ -27,33 +26,37 @@ def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account, Issue)] = IssueComments.filter(_.byIssue(owner, repository, issueId)) .filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment")) - .join(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName ) - .join(Issues).on{ case ((t1, t2), t3) => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) } - .map{ case ((t1, t2), t3) => (t1, t2, t3) } + .join(Accounts).on { case t1 ~ t2 => t1.commentedUserName === t2.userName } + .join(Issues).on { case t1 ~ t2 ~ t3 => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) } + .map { case t1 ~ t2 ~ t3 => (t1, t2, t3) } .list def getMergedComment(owner: String, repository: String, issueId: Int)(implicit s: Session): Option[(IssueComment, Account)] = { - getCommentsForApi(owner, repository, issueId).collectFirst { case (comment, account, _) if comment.action == "merged" => (comment, account) } + getCommentsForApi(owner, repository, issueId) + .collectFirst { case (comment, account, _) if comment.action == "merged" => (comment, account) } } - def getComment(owner: String, repository: String, commentId: String)(implicit s: Session) = + def getComment(owner: String, repository: String, commentId: String)(implicit s: Session): Option[IssueComment] = { if (commentId forall (_.isDigit)) IssueComments filter { t => t.byPrimaryKey(commentId.toInt) && t.byRepository(owner, repository) } firstOption else None + } - def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session) = + def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session): List[Label] = { IssueLabels - .join(Labels).on { (t1, t2) => + .join(Labels).on { case t1 ~ t2 => t1.byLabel(t2.userName, t2.repositoryName, t2.labelId) } - .filter ( _._1.byIssue(owner, repository, issueId) ) - .map ( _._2 ) + .filter { case t1 ~ t2 => t1.byIssue(owner, repository, issueId) } + .map { case t1 ~ t2 => t2 } .list + } - def getIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = + def getIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session): Option[IssueLabel] = { IssueLabels filter (_.byPrimaryKey(owner, repository, issueId, labelId)) firstOption + } /** * Returns the count of the search result against issues. @@ -63,9 +66,9 @@ * @param repos Tuple of the repository owner and the repository name * @return the count of the search result */ - def countIssue(condition: IssueSearchCondition, onlyPullRequest: Boolean, - repos: (String, String)*)(implicit s: Session): Int = + def countIssue(condition: IssueSearchCondition, onlyPullRequest: Boolean, repos: (String, String)*)(implicit s: Session): Int = { Query(searchIssueQuery(repos, condition, onlyPullRequest).length).first + } /** * Returns the Map which contains issue count for each labels. @@ -79,16 +82,16 @@ filterUser: Map[String, String])(implicit s: Session): Map[String, Int] = { searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), false) - .join(IssueLabels).on { (t1, t2) => + .join(IssueLabels).on { case t1 ~ t2 => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) } - .join(Labels).on { case ((t1, t2), t3) => + .join(Labels).on { case t1 ~ t2 ~ t3 => t2.byLabel(t3.userName, t3.repositoryName, t3.labelId) } - .groupBy { case ((t1, t2), t3) => + .groupBy { case t1 ~ t2 ~ t3 => t3.labelName } - .map { case (labelName, t) => + .map { case labelName ~ t => labelName -> t.length } .list.toMap @@ -96,8 +99,12 @@ def getCommitStatues(userName: String, repositoryName: String, issueId: Int)(implicit s: Session): Option[CommitStatusInfo] = { val status = PullRequests - .filter { pr => (pr.userName === userName.bind) && (pr.repositoryName === repositoryName.bind) && (pr.issueId === issueId.bind) } - .join(CommitStatuses).on((pr, cs) => pr.userName === cs.userName && pr.repositoryName === cs.repositoryName && pr.commitIdTo === cs.commitId) + .filter { pr => + pr.userName === userName.bind && pr.repositoryName === repositoryName.bind && pr.issueId === issueId.bind + } + .join(CommitStatuses).on { case pr ~ cs => + pr.userName === cs.userName && pr.repositoryName === cs.repositoryName && pr.commitIdTo === cs.commitId + } .list if(status.nonEmpty){ @@ -129,11 +136,11 @@ (implicit s: Session): List[IssueInfo] = { // get issues and comment count and labels val result = searchIssueQueryBase(condition, pullRequest, offset, limit, repos) - .joinLeft (IssueLabels) .on { case (((t1, t2), i), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) } - .joinLeft (Labels) .on { case ((((t1, t2), i), t3), t4) => t3.map(_.byLabel(t4.userName, t4.repositoryName, t4.labelId)) } - .joinLeft (Milestones) .on { case (((((t1, t2), i), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) } - .sortBy { case (((((t1, t2), i), t3), t4), t5) => i asc } - .map { case (((((t1, t2), i), t3), t4), t5) => + .joinLeft (IssueLabels) .on { case t1 ~ t2 ~ i ~ t3 => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) } + .joinLeft (Labels) .on { case t1 ~ t2 ~ i ~ t3 ~ t4 => t3.map(_.byLabel(t4.userName, t4.repositoryName, t4.labelId)) } + .joinLeft (Milestones) .on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) } + .sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => i asc } + .map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => (t1, t2.commentCount, t4.map(_.labelId), t4.map(_.labelName), t4.map(_.color), t5.map(_.title)) } .list @@ -156,9 +163,9 @@ (implicit s: Session): List[(Issue, Account)] = { // get issues and comment count and labels searchIssueQueryBase(condition, false, offset, limit, repos) - .join(Accounts).on { case (((t1, t2), i), t3) => t3.userName === t1.openedUserName } - .sortBy { case (((t1, t2), i), t3) => i asc } - .map { case (((t1, t2), i), t3) => (t1, t3) } + .join(Accounts).on { case t1 ~ t2 ~ i ~ t3 => t3.userName === t1.openedUserName } + .sortBy { case t1 ~ t2 ~ i ~ t3 => i asc } + .map { case t1 ~ t2 ~ i ~ t3 => (t1, t3) } .list } @@ -169,12 +176,12 @@ (implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account)] = { // get issues and comment count and labels searchIssueQueryBase(condition, true, offset, limit, repos) - .join(PullRequests).on { case (((t1, t2), i), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) } - .join(Repositories).on { case ((((t1, t2), i), t3), t4) => t4.byRepository(t1.userName, t1.repositoryName) } - .join(Accounts).on { case (((((t1, t2), i), t3), t4), t5) => t5.userName === t1.openedUserName } - .join(Accounts).on { case ((((((t1, t2), i), t3), t4), t5), t6) => t6.userName === t4.userName } - .sortBy { case ((((((t1, t2), i), t3), t4), t5), t6) => i asc } - .map { case ((((((t1, t2), i), t3), t4), t5), t6) => (t1, t5, t2.commentCount, t3, t4, t6) } + .join(PullRequests).on { case t1 ~ t2 ~ i ~ t3 => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) } + .join(Repositories).on { case t1 ~ t2 ~ i ~ t3 ~ t4 => t4.byRepository(t1.userName, t1.repositoryName) } + .join(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => t5.userName === t1.openedUserName } + .join(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => t6.userName === t4.userName } + .sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => i asc } + .map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => (t1, t5, t2.commentCount, t3, t4, t6) } .list } @@ -247,36 +254,39 @@ def insertIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String], assignedUserName: Option[String], milestoneId: Option[Int], - isPullRequest: Boolean = false)(implicit s: Session) = + isPullRequest: Boolean = false)(implicit s: Session): Int = { // next id number sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int] - .firstOption.filter { id => + .firstOption.filter { id => Issues insert Issue( - owner, - repository, - id, - loginUser, - milestoneId, - assignedUserName, - title, - content, - false, - currentDate, - currentDate, - isPullRequest) + owner, + repository, + id, + loginUser, + milestoneId, + assignedUserName, + title, + content, + false, + currentDate, + currentDate, + isPullRequest) // increment issue id IssueId - .filter (_.byPrimaryKey(owner, repository)) - .map (_.issueId) - .update (id) > 0 + .filter(_.byPrimaryKey(owner, repository)) + .map(_.issueId) + .update(id) > 0 } get + } - def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = + def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session): Int = { IssueLabels insert IssueLabel(owner, repository, issueId, labelId) + } - def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) = + def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session): Int = { IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) delete + } def createComment(owner: String, repository: String, loginUser: String, issueId: Int, content: String, action: String)(implicit s: Session): Int = { @@ -291,29 +301,30 @@ updatedDate = currentDate) } - def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit s: Session) = { + def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit s: Session): Int = { Issues .filter (_.byPrimaryKey(owner, repository, issueId)) .map { t => (t.title, t.content.?, t.updatedDate) } .update (title, content, currentDate) } - def updateAssignedUserName(owner: String, repository: String, issueId: Int, - assignedUserName: Option[String])(implicit s: Session) = + def updateAssignedUserName(owner: String, repository: String, issueId: Int, assignedUserName: Option[String])(implicit s: Session): Int = { Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.assignedUserName?).update (assignedUserName) + } - def updateMilestoneId(owner: String, repository: String, issueId: Int, - milestoneId: Option[Int])(implicit s: Session) = + def updateMilestoneId(owner: String, repository: String, issueId: Int, milestoneId: Option[Int])(implicit s: Session): Int = { Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).update (milestoneId) + } - def updateComment(commentId: Int, content: String)(implicit s: Session) = { + def updateComment(commentId: Int, content: String)(implicit s: Session): Int = { IssueComments.filter (_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).update(content, currentDate) } - def deleteComment(commentId: Int)(implicit s: Session) = + def deleteComment(commentId: Int)(implicit s: Session): Int = { IssueComments filter (_.byPrimaryKey(commentId)) delete + } - def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) = { + def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session): Int = { (Issues filter (_.byPrimaryKey(owner, repository, issueId)) map(t => (t.closed, t.updatedDate))).update((closed, currentDate)) } @@ -325,8 +336,7 @@ * @param query the keywords separated by whitespace. * @return issues with comment count and matched content of issue or comment */ - def searchIssuesByKeyword(owner: String, repository: String, query: String) - (implicit s: Session): List[(Issue, Int, String)] = { + def searchIssuesByKeyword(owner: String, repository: String, query: String)(implicit s: Session): List[(Issue, Int, String)] = { //import slick.driver.JdbcDriver.likeEncode val keywords = splitWords(query.toLowerCase) @@ -374,7 +384,7 @@ }.toList } - def closeIssuesFromMessage(message: String, userName: String, owner: String, repository: String)(implicit s: Session) = { + 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){ createComment(owner, repository, userName, issue.issueId, "Close", "close") @@ -383,7 +393,7 @@ } } - def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(implicit s: Session) = { + def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(implicit s: Session): Unit = { extractIssueId(message).foreach { issueId => val content = fromIssue.issueId + ":" + fromIssue.title if(getIssue(owner, repository, issueId).isDefined){ @@ -395,7 +405,7 @@ } } - def createIssueComment(owner: String, repository: String, commit: CommitInfo)(implicit s: Session) = { + def createIssueComment(owner: String, repository: String, commit: CommitInfo)(implicit s: Session): Unit = { extractIssueId(commit.fullMessage).foreach { issueId => if(getIssue(owner, repository, issueId).isDefined){ getAccountByMailAddress(commit.committerEmailAddress).foreach { account => diff --git a/src/main/scala/gitbucket/core/service/MergeService.scala b/src/main/scala/gitbucket/core/service/MergeService.scala index d58a4ec..a581300 100644 --- a/src/main/scala/gitbucket/core/service/MergeService.scala +++ b/src/main/scala/gitbucket/core/service/MergeService.scala @@ -2,7 +2,7 @@ import gitbucket.core.model.Account import gitbucket.core.util.Directory._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import org.eclipse.jgit.merge.MergeStrategy import org.eclipse.jgit.api.Git diff --git a/src/main/scala/gitbucket/core/service/PullRequestService.scala b/src/main/scala/gitbucket/core/service/PullRequestService.scala index a512d2c..3807e55 100644 --- a/src/main/scala/gitbucket/core/service/PullRequestService.scala +++ b/src/main/scala/gitbucket/core/service/PullRequestService.scala @@ -4,7 +4,7 @@ import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile.blockingApi._ import difflib.{Delta, DiffUtils} -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.JGitUtil diff --git a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala index c040851..7381bbc 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryCreationService.scala @@ -1,7 +1,7 @@ package gitbucket.core.service import gitbucket.core.model.Profile.profile.blockingApi._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Directory._ import gitbucket.core.util.JGitUtil import gitbucket.core.model.Account diff --git a/src/main/scala/gitbucket/core/service/RepositorySearchService.scala b/src/main/scala/gitbucket/core/service/RepositorySearchService.scala index a104414..d08c7bc 100644 --- a/src/main/scala/gitbucket/core/service/RepositorySearchService.scala +++ b/src/main/scala/gitbucket/core/service/RepositorySearchService.scala @@ -4,7 +4,7 @@ import gitbucket.core.util._ import gitbucket.core.util.StringUtil import Directory._ -import ControlUtil._ +import SyntaxSugars._ import org.eclipse.jgit.revwalk.RevWalk import org.eclipse.jgit.treewalk.TreeWalk import org.eclipse.jgit.lib.FileMode diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala index 85d6832..9b5a1bf 100644 --- a/src/main/scala/gitbucket/core/service/RepositoryService.scala +++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala @@ -2,7 +2,7 @@ import gitbucket.core.controller.Context import gitbucket.core.util._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.model.{Account, Collaborator, Repository, RepositoryOptions, Role} import gitbucket.core.model.Profile._ import gitbucket.core.model.Profile.profile.blockingApi._ @@ -206,7 +206,7 @@ /** * Returns the specified repository information. - * + * * @param userName the user name of the repository owner * @param repositoryName the repository name * @return the repository information diff --git a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala index a04f690..1647cba 100644 --- a/src/main/scala/gitbucket/core/service/SystemSettingsService.scala +++ b/src/main/scala/gitbucket/core/service/SystemSettingsService.scala @@ -1,9 +1,9 @@ package gitbucket.core.service -import gitbucket.core.util.{Directory, ControlUtil} +import gitbucket.core.util.{Directory, SyntaxSugars} import gitbucket.core.util.Implicits._ import Directory._ -import ControlUtil._ +import SyntaxSugars._ import SystemSettingsService._ import javax.servlet.http.HttpServletRequest diff --git a/src/main/scala/gitbucket/core/service/WikiService.scala b/src/main/scala/gitbucket/core/service/WikiService.scala index 1bff5dc..c5dad27 100644 --- a/src/main/scala/gitbucket/core/service/WikiService.scala +++ b/src/main/scala/gitbucket/core/service/WikiService.scala @@ -5,7 +5,7 @@ import gitbucket.core.model.Account import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.util._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import org.eclipse.jgit.api.Git import org.eclipse.jgit.treewalk.CanonicalTreeParser import org.eclipse.jgit.lib._ @@ -17,10 +17,10 @@ import scala.collection.JavaConverters._ object WikiService { - + /** * The model for wiki page. - * + * * @param name the page name * @param content the page content * @param committer the last committer @@ -28,10 +28,10 @@ * @param id the latest commit id */ case class WikiPageInfo(name: String, content: String, committer: String, time: Date, id: String) - + /** * The model for wiki page history. - * + * * @param name the page name * @param committer the committer the committer * @param message the commit message diff --git a/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala b/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala index ed14f30..903a1d9 100644 --- a/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala @@ -8,7 +8,7 @@ import org.apache.commons.io.{FileUtils, IOUtils} import org.json4s.jackson.Serialization._ import org.apache.http.HttpStatus -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ /** * Provides GitLFS Transfer API diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala index e84bf9e..c4ffe41 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -10,7 +10,7 @@ import gitbucket.core.service.IssuesService.IssueSearchCondition import gitbucket.core.service.WebHookService._ import gitbucket.core.service._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.Implicits._ import gitbucket.core.util._ import org.eclipse.jgit.api.Git @@ -27,7 +27,7 @@ /** * Provides Git repository via HTTP. - * + * * This servlet provides only Git repository functionality. * Authentication is provided by [[GitAuthenticationFilter]]. */ @@ -174,7 +174,7 @@ extends PostReceiveHook with PreReceiveHook with RepositoryService with AccountService with IssuesService with ActivityService with PullRequestService with WebHookService with WebHookPullRequestService with CommitsService { - + private val logger = LoggerFactory.getLogger(classOf[CommitLogHook]) private var existIds: Seq[String] = Nil diff --git a/src/main/scala/gitbucket/core/ssh/GitCommand.scala b/src/main/scala/gitbucket/core/ssh/GitCommand.scala index ca1e021..9461803 100644 --- a/src/main/scala/gitbucket/core/ssh/GitCommand.scala +++ b/src/main/scala/gitbucket/core/ssh/GitCommand.scala @@ -4,13 +4,13 @@ import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry} import gitbucket.core.service.{AccountService, DeployKeyService, RepositoryService, SystemSettingsService} import gitbucket.core.servlet.{CommitLogHook, Database} -import gitbucket.core.util.{ControlUtil, Directory} +import gitbucket.core.util.{SyntaxSugars, Directory} import org.apache.sshd.server.{Command, CommandFactory, Environment, ExitCallback, SessionAware} import org.apache.sshd.server.session.ServerSession import org.slf4j.LoggerFactory import java.io.{File, InputStream, OutputStream} -import ControlUtil._ +import SyntaxSugars._ import org.eclipse.jgit.api.Git import Directory._ import gitbucket.core.ssh.PublicKeyAuthenticator.AuthType diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala index bbcb339..30e6ae0 100644 --- a/src/main/scala/gitbucket/core/util/Authenticator.scala +++ b/src/main/scala/gitbucket/core/util/Authenticator.scala @@ -5,7 +5,7 @@ import gitbucket.core.model.Role import RepositoryService.RepositoryInfo import Implicits._ -import ControlUtil._ +import SyntaxSugars._ /** * Allows only oneself and administrators. diff --git a/src/main/scala/gitbucket/core/util/ControlUtil.scala b/src/main/scala/gitbucket/core/util/ControlUtil.scala deleted file mode 100644 index 74569ac..0000000 --- a/src/main/scala/gitbucket/core/util/ControlUtil.scala +++ /dev/null @@ -1,52 +0,0 @@ -package gitbucket.core.util - -import org.eclipse.jgit.api.Git -import scala.util.control.Exception._ -import scala.language.reflectiveCalls - -/** - * Provides control facilities. - */ -object ControlUtil { - - def defining[A, B](value: A)(f: A => B): B = f(value) - - def using[A <% { def close(): Unit }, B](resource: A)(f: A => B): B = - try f(resource) finally { - if(resource != null){ - ignoring(classOf[Throwable]) { - resource.close() - } - } - } - - def using[A <% { def close(): Unit }, B <% { def close(): Unit }, C](resource1: A, resource2: B)(f: (A, B) => C): C = - try f(resource1, resource2) finally { - if(resource1 != null){ - ignoring(classOf[Throwable]) { - resource1.close() - } - } - if(resource2 != null){ - ignoring(classOf[Throwable]) { - resource2.close() - } - } - } - - def using[T](git: Git)(f: Git => T): T = - try f(git) finally git.getRepository.close() - - def using[T](git1: Git, git2: Git)(f: (Git, Git) => T): T = - try f(git1, git2) finally { - git1.getRepository.close() - git2.getRepository.close() - } - - def ignore[T](f: => Unit): Unit = try { - f - } catch { - case e: Exception => () - } - -} diff --git a/src/main/scala/gitbucket/core/util/FileUtil.scala b/src/main/scala/gitbucket/core/util/FileUtil.scala index d6947c0..4f2a21d 100644 --- a/src/main/scala/gitbucket/core/util/FileUtil.scala +++ b/src/main/scala/gitbucket/core/util/FileUtil.scala @@ -3,7 +3,7 @@ import org.apache.commons.io.FileUtils import org.apache.tika.Tika import java.io.File -import ControlUtil._ +import SyntaxSugars._ import scala.util.Random object FileUtil { diff --git a/src/main/scala/gitbucket/core/util/JDBCUtil.scala b/src/main/scala/gitbucket/core/util/JDBCUtil.scala index f94b341..ffb39ef 100644 --- a/src/main/scala/gitbucket/core/util/JDBCUtil.scala +++ b/src/main/scala/gitbucket/core/util/JDBCUtil.scala @@ -3,7 +3,7 @@ import java.io._ import java.sql._ import java.text.SimpleDateFormat -import ControlUtil._ +import SyntaxSugars._ import scala.annotation.tailrec import scala.collection.mutable.ListBuffer diff --git a/src/main/scala/gitbucket/core/util/JGitUtil.scala b/src/main/scala/gitbucket/core/util/JGitUtil.scala index 009b043..e15af9b 100644 --- a/src/main/scala/gitbucket/core/util/JGitUtil.scala +++ b/src/main/scala/gitbucket/core/util/JGitUtil.scala @@ -4,7 +4,7 @@ import org.eclipse.jgit.api.Git import Directory._ import StringUtil._ -import ControlUtil._ +import SyntaxSugars._ import scala.annotation.tailrec import scala.collection.JavaConverters._ @@ -78,7 +78,7 @@ case class CommitInfo(id: String, shortMessage: String, fullMessage: String, parents: List[String], authorTime: Date, authorName: String, authorEmailAddress: String, commitTime: Date, committerName: String, committerEmailAddress: String){ - + def this(rev: org.eclipse.jgit.revwalk.RevCommit) = this( rev.getName, rev.getShortMessage, @@ -159,7 +159,7 @@ /** * Returns RevCommit from the commit or tag id. - * + * * @param git the Git object * @param objectId the ObjectId of the commit or tag * @return the RevCommit for the specified commit or tag @@ -240,7 +240,7 @@ /** * Returns the file list of the specified path. - * + * * @param git the Git object * @param revision the branch name or commit id * @param path the directory path (optional) @@ -411,7 +411,7 @@ /** * Returns the commit list of the specified branch. - * + * * @param git the Git object * @param revision the branch name or commit id * @param page the page number (1-) @@ -421,7 +421,7 @@ */ def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0, path: String = ""): Either[String, (List[CommitInfo], Boolean)] = { val fixedPage = if(page <= 0) 1 else page - + @scala.annotation.tailrec def getCommitLog(i: java.util.Iterator[RevCommit], count: Int, logs: List[CommitInfo]): (List[CommitInfo], Boolean) = i.hasNext match { @@ -431,7 +431,7 @@ } case _ => (logs, i.hasNext) } - + using(new RevWalk(git.getRepository)){ revWalk => defining(git.getRepository.resolve(revision)){ objectId => if(objectId == null){ @@ -469,10 +469,10 @@ } } - + /** * Returns the commit list between two revisions. - * + * * @param git the Git object * @param from the from revision * @param to the to revision @@ -481,10 +481,10 @@ // TODO swap parameters 'from' and 'to'!? def getCommitLog(git: Git, from: String, to: String): List[CommitInfo] = getCommitLogs(git, to)(_.getName == from) - + /** * Returns the latest RevCommit of the specified path. - * + * * @param git the Git object * @param path the path * @param revision the branch name or commit id diff --git a/src/main/scala/gitbucket/core/util/LDAPUtil.scala b/src/main/scala/gitbucket/core/util/LDAPUtil.scala index 98daddc..65d2279 100644 --- a/src/main/scala/gitbucket/core/util/LDAPUtil.scala +++ b/src/main/scala/gitbucket/core/util/LDAPUtil.scala @@ -1,7 +1,7 @@ package gitbucket.core.util import gitbucket.core.model.Account -import ControlUtil._ +import SyntaxSugars._ import gitbucket.core.service.SystemSettingsService import gitbucket.core.service.SystemSettingsService.Ldap import com.novell.ldap._ @@ -111,9 +111,9 @@ } } - val conn: LDAPConnection = + val conn: LDAPConnection = if(ssl) { - new LDAPConnection(new LDAPJSSESecureSocketFactory()) + new LDAPConnection(new LDAPJSSESecureSocketFactory()) }else { new LDAPConnection(new LDAPJSSEStartTLSFactory()) } diff --git a/src/main/scala/gitbucket/core/util/LockUtil.scala b/src/main/scala/gitbucket/core/util/LockUtil.scala index 4b13d17..0924719 100644 --- a/src/main/scala/gitbucket/core/util/LockUtil.scala +++ b/src/main/scala/gitbucket/core/util/LockUtil.scala @@ -2,7 +2,7 @@ import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.locks.{ReentrantLock, Lock} -import ControlUtil._ +import SyntaxSugars._ object LockUtil { diff --git a/src/main/scala/gitbucket/core/util/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala index 042ca9f..3c8dba5 100644 --- a/src/main/scala/gitbucket/core/util/Notifier.scala +++ b/src/main/scala/gitbucket/core/util/Notifier.scala @@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory import gitbucket.core.controller.Context import SystemSettingsService.Smtp -import ControlUtil.defining +import SyntaxSugars.defining trait Notifier extends RepositoryService with AccountService with IssuesService { diff --git a/src/main/scala/gitbucket/core/util/StringUtil.scala b/src/main/scala/gitbucket/core/util/StringUtil.scala index da7dc50..587df35 100644 --- a/src/main/scala/gitbucket/core/util/StringUtil.scala +++ b/src/main/scala/gitbucket/core/util/StringUtil.scala @@ -3,7 +3,7 @@ import java.net.{URLDecoder, URLEncoder} import org.mozilla.universalchardet.UniversalDetector -import ControlUtil._ +import SyntaxSugars._ import org.apache.commons.io.input.BOMInputStream import org.apache.commons.io.IOUtils import org.apache.commons.codec.binary.Base64 diff --git a/src/main/scala/gitbucket/core/util/SyntaxSugars.scala b/src/main/scala/gitbucket/core/util/SyntaxSugars.scala new file mode 100644 index 0000000..1c0384a --- /dev/null +++ b/src/main/scala/gitbucket/core/util/SyntaxSugars.scala @@ -0,0 +1,56 @@ +package gitbucket.core.util + +import org.eclipse.jgit.api.Git +import scala.util.control.Exception._ +import scala.language.reflectiveCalls + +/** + * Provides control facilities. + */ +object SyntaxSugars { + + def defining[A, B](value: A)(f: A => B): B = f(value) + + def using[A <% { def close(): Unit }, B](resource: A)(f: A => B): B = + try f(resource) finally { + if(resource != null){ + ignoring(classOf[Throwable]) { + resource.close() + } + } + } + + def using[A <% { def close(): Unit }, B <% { def close(): Unit }, C](resource1: A, resource2: B)(f: (A, B) => C): C = + try f(resource1, resource2) finally { + if(resource1 != null){ + ignoring(classOf[Throwable]) { + resource1.close() + } + } + if(resource2 != null){ + ignoring(classOf[Throwable]) { + resource2.close() + } + } + } + + def using[T](git: Git)(f: Git => T): T = + try f(git) finally git.getRepository.close() + + def using[T](git1: Git, git2: Git)(f: (Git, Git) => T): T = + try f(git1, git2) finally { + git1.getRepository.close() + git2.getRepository.close() + } + + def ignore[T](f: => Unit): Unit = try { + f + } catch { + case _: Exception => () + } + + object ~ { + def unapply[A, B](t: (A, B)): Option[(A, B)] = Some(t) + } + +} diff --git a/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala b/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala index 68d4b7f..f9eecd4 100644 --- a/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala +++ b/src/test/scala/gitbucket/core/service/MergeServiceSpec.scala @@ -1,7 +1,7 @@ package gitbucket.core.service import gitbucket.core.util.Directory._ -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.GitSpecUtil._ import org.eclipse.jgit.api.Git @@ -119,4 +119,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala index 7eb7ba5..f5b4769 100644 --- a/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala +++ b/src/test/scala/gitbucket/core/service/ServiceSpecBase.scala @@ -2,7 +2,7 @@ import gitbucket.core.GitBucketCoreModule import gitbucket.core.util.{DatabaseConfig, FileUtil} -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import io.github.gitbucket.solidbase.Solidbase import liquibase.database.core.H2Database import liquibase.database.jvm.JdbcConnection diff --git a/src/test/scala/gitbucket/core/util/GitSpecUtil.scala b/src/test/scala/gitbucket/core/util/GitSpecUtil.scala index 11506c3..7e4d461 100644 --- a/src/test/scala/gitbucket/core/util/GitSpecUtil.scala +++ b/src/test/scala/gitbucket/core/util/GitSpecUtil.scala @@ -1,6 +1,6 @@ package gitbucket.core.util -import gitbucket.core.util.ControlUtil._ +import gitbucket.core.util.SyntaxSugars._ import org.apache.commons.io.FileUtils import org.eclipse.jgit.api.Git diff --git a/src/test/scala/gitbucket/core/view/PaginationSpec.scala b/src/test/scala/gitbucket/core/view/PaginationSpec.scala index 79da56a..eb23efe 100644 --- a/src/test/scala/gitbucket/core/view/PaginationSpec.scala +++ b/src/test/scala/gitbucket/core/view/PaginationSpec.scala @@ -1,7 +1,7 @@ package gitbucket.core.view -import gitbucket.core.util.ControlUtil -import ControlUtil._ +import gitbucket.core.util.SyntaxSugars +import SyntaxSugars._ import org.scalatest.FunSpec class PaginationSpec extends FunSpec {