|
1 | 1 | package org.codelibs.gitbucket.fess.service |
2 | 2 |
|
| 3 | +import scala.util.control.Exception._ |
3 | 4 | import java.net.{URL, URLEncoder} |
4 | 5 | import java.util.Date |
5 | 6 |
|
6 | 7 | import gitbucket.core.controller.ControllerBase |
7 | 8 | import gitbucket.core.model.{Issue, Session} |
8 | 9 | import gitbucket.core.service.{AccountService, IssuesService, WikiService} |
9 | 10 | import gitbucket.core.util.Directory._ |
10 | | -import gitbucket.core.util.JGitUtil._ |
11 | 11 | import gitbucket.core.util.SyntaxSugars._ |
12 | 12 | import gitbucket.core.util._ |
13 | 13 | import org.codelibs.gitbucket.fess.service.FessSettingsService.FessSettings |
14 | 14 | import org.eclipse.jgit.api.Git |
15 | 15 | import org.json4s._ |
16 | | -import org.json4s.jackson.JsonMethods._ |
17 | 16 | import org.slf4j.LoggerFactory |
18 | 17 |
|
19 | 18 | import scala.io.Source._ |
@@ -141,18 +140,22 @@ trait FessSearchService { |
141 | 140 | def getCodeContents(query: String, |
142 | 141 | results: List[FessRawResult]): List[FessCodeInfo] = |
143 | 142 | results.flatMap(result => { |
144 | | - getRepositoryDataFromURL(result.url).map({ |
| 143 | + getRepositoryDataFromURL(result.url).flatMap({ |
145 | 144 | case (owner, repo, branch, path) => |
146 | | - val content = |
147 | | - getFileContent(owner, repo, branch, path).getOrElse("") |
148 | | - val (highlightText, highlightLineNumber) = |
149 | | - getHighlightText(content, query) |
150 | | - FessCodeInfo(owner, |
151 | | - repo, |
152 | | - result.url, |
153 | | - result.title, |
154 | | - highlightText, |
155 | | - highlightLineNumber) |
| 145 | + // getFileContent causes an exception if the repository is deleted. |
| 146 | + val contentOpt = allCatch opt { |
| 147 | + getFileContent(owner, repo, branch, path).get |
| 148 | + } |
| 149 | + contentOpt.map(content => { |
| 150 | + val (highlightText, highlightLineNumber) = |
| 151 | + getHighlightText(content, query) |
| 152 | + FessCodeInfo(owner, |
| 153 | + repo, |
| 154 | + result.url, |
| 155 | + result.title, |
| 156 | + highlightText, |
| 157 | + highlightLineNumber) |
| 158 | + }) |
156 | 159 | }) |
157 | 160 | }) |
158 | 161 |
|
@@ -195,7 +198,9 @@ trait FessSearchService { |
195 | 198 | results.flatMap(result => { |
196 | 199 | getWikiDataFromURL(result.url).flatMap({ |
197 | 200 | case (owner, repo, filename) => |
198 | | - getWikiPage(owner, repo, filename).map(wikiInfo => { |
| 201 | + // getWikiPage causes an exception if the repository is deleted. |
| 202 | + val wikiOpt = allCatch opt { getWikiPage(owner, repo, filename).get } |
| 203 | + wikiOpt.map(wikiInfo => { |
199 | 204 | val (content, lineNum) = getHighlightText(wikiInfo.content, query) |
200 | 205 | FessWikiInfo(owner, repo, result.url, filename, content, lineNum) |
201 | 206 | }) |
|
0 commit comments