diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index 8f0ed76..ba3cfd8 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -1,9 +1,8 @@ package gitbucket.core.controller -import gitbucket.core.api._ import gitbucket.core.helper.xml import gitbucket.core.model.Account -import gitbucket.core.service.{RepositoryService, ActivityService, AccountService, RepositorySearchService, IssuesService} +import gitbucket.core.service._ import gitbucket.core.util.Implicits._ import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.{LDAPUtil, Keys, UsersAuthenticator, ReferrerAuthenticator, StringUtil} @@ -138,13 +137,21 @@ target.toLowerCase match { case "issue" => gitbucket.core.search.html.issues( - searchIssues(repository.owner, repository.name, query), countFiles(repository.owner, repository.name, query), + searchIssues(repository.owner, repository.name, query), + countWikiPages(repository.owner, repository.name, query), + query, page, repository) + + case "wiki" => gitbucket.core.search.html.wiki( + countFiles(repository.owner, repository.name, query), + countIssues(repository.owner, repository.name, query), + searchWikiPages(repository.owner, repository.name, query), query, page, repository) case _ => gitbucket.core.search.html.code( searchFiles(repository.owner, repository.name, query), countIssues(repository.owner, repository.name, query), + countWikiPages(repository.owner, repository.name, query), query, page, repository) } } diff --git a/src/main/scala/gitbucket/core/controller/WikiController.scala b/src/main/scala/gitbucket/core/controller/WikiController.scala index b81e75e..49fb2e2 100644 --- a/src/main/scala/gitbucket/core/controller/WikiController.scala +++ b/src/main/scala/gitbucket/core/controller/WikiController.scala @@ -12,7 +12,8 @@ import org.scalatra.i18n.Messages class WikiController extends WikiControllerBase - with WikiService with RepositoryService with AccountService with ActivityService with CollaboratorsAuthenticator with ReferrerAuthenticator + with WikiService with RepositoryService with AccountService with ActivityService + with CollaboratorsAuthenticator with ReferrerAuthenticator trait WikiControllerBase extends ControllerBase { self: WikiService with RepositoryService with ActivityService with CollaboratorsAuthenticator with ReferrerAuthenticator => diff --git a/src/main/scala/gitbucket/core/service/RepositorySearchService.scala b/src/main/scala/gitbucket/core/service/RepositorySearchService.scala index 3d9bd8a..bba7172 100644 --- a/src/main/scala/gitbucket/core/service/RepositorySearchService.scala +++ b/src/main/scala/gitbucket/core/service/RepositorySearchService.scala @@ -53,7 +53,30 @@ } } - private def searchRepositoryFiles(git: Git, query: String): List[(String, String)] = { + def countWikiPages(owner: String, repository: String, query: String): Int = + using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git => + if(JGitUtil.isEmpty(git)) 0 else searchRepositoryFiles(git, query).length + } + + def searchWikiPages(owner: String, repository: String, query: String): List[FileSearchResult] = + using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git => + if(JGitUtil.isEmpty(git)){ + Nil + } else { + val files = searchRepositoryFiles(git, query) + val commits = JGitUtil.getLatestCommitFromPaths(git, files.map(_._1), "HEAD") + files.map { case (path, text) => + val (highlightText, lineNumber) = getHighlightText(text, query) + FileSearchResult( + path.replaceFirst("\\.md$", ""), + commits(path).getCommitterIdent.getWhen, + highlightText, + lineNumber) + } + } + } + + def searchRepositoryFiles(git: Git, query: String): List[(String, String)] = { val revWalk = new RevWalk(git.getRepository) val objectId = git.getRepository.resolve("HEAD") val revCommit = revWalk.parseCommit(objectId) diff --git a/src/main/twirl/gitbucket/core/search/code.scala.html b/src/main/twirl/gitbucket/core/search/code.scala.html index 4ce3450..3dadb7a 100644 --- a/src/main/twirl/gitbucket/core/search/code.scala.html +++ b/src/main/twirl/gitbucket/core/search/code.scala.html @@ -1,5 +1,6 @@ @(files: List[gitbucket.core.service.RepositorySearchService.FileSearchResult], issueCount: Int, + wikiCount: Int, query: String, page: Int, repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context) @@ -7,7 +8,7 @@ @import gitbucket.core.view.helpers._ @import gitbucket.core.service.RepositorySearchService._ @html.main("Search Results", Some(repository)){ - @menu("code", files.size, issueCount, query, repository){ + @menu("code", files.size, issueCount, wikiCount, query, repository){ @if(files.isEmpty){