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){

We couldn't find any code matching '@query'

} else { diff --git a/src/main/twirl/gitbucket/core/search/issues.scala.html b/src/main/twirl/gitbucket/core/search/issues.scala.html index 7feb997..8e5b3ca 100644 --- a/src/main/twirl/gitbucket/core/search/issues.scala.html +++ b/src/main/twirl/gitbucket/core/search/issues.scala.html @@ -1,5 +1,6 @@ -@(issues: List[gitbucket.core.service.RepositorySearchService.IssueSearchResult], - fileCount: Int, +@(fileCount: Int, + issues: List[gitbucket.core.service.RepositorySearchService.IssueSearchResult], + 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("issue", fileCount, issues.size, query, repository){ + @menu("issue", fileCount, issues.size, wikiCount, query, repository){ @if(issues.isEmpty){

We couldn't find any code matching '@query'

} else { diff --git a/src/main/twirl/gitbucket/core/search/menu.scala.html b/src/main/twirl/gitbucket/core/search/menu.scala.html index f011463..4e48280 100644 --- a/src/main/twirl/gitbucket/core/search/menu.scala.html +++ b/src/main/twirl/gitbucket/core/search/menu.scala.html @@ -1,4 +1,4 @@ -@(active: String, fileCount: Int, issueCount: Int, query: String, +@(active: String, fileCount: Int, issueCount: Int, wikiCount: Int, query: String, repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(body: Html)(implicit context: gitbucket.core.controller.Context) @import context._ @import gitbucket.core.view.helpers._ @@ -21,6 +21,14 @@ } + + + Wiki + @if(wikiCount != 0){ + @wikiCount + } + +
diff --git a/src/main/twirl/gitbucket/core/search/wiki.scala.html b/src/main/twirl/gitbucket/core/search/wiki.scala.html new file mode 100644 index 0000000..2f8652b --- /dev/null +++ b/src/main/twirl/gitbucket/core/search/wiki.scala.html @@ -0,0 +1,27 @@ +@(fileCount: Int, + issueCount: Int, + wikis: List[gitbucket.core.service.RepositorySearchService.FileSearchResult], + query: String, + page: Int, + repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context) +@import context._ +@import gitbucket.core.view.helpers._ +@import gitbucket.core.service.RepositorySearchService._ +@html.main("Search Results", Some(repository)){ + @menu("wiki", fileCount, issueCount, wikis.size, query, repository){ + @if(wikis.isEmpty){ +

We couldn't find any code matching '@query'

+ } else { +

We've found @wikis.size code @plural(wikis.size, "result")

+ } + @wikis.drop((page - 1) * CodeLimit).take(CodeLimit).map { file => +
+
@file.path
+
Last committed @helper.html.datetimeago(file.lastModified)
+
@Html(file.highlightText)
+
+ } + @helper.html.paginator(page, wikis.size, CodeLimit, 10, + s"${url(repository)}/search?q=${urlEncode(query)}&type=code") + } +} \ No newline at end of file