import java.text.MessageFormat;\r
import java.util.ArrayList;\r
import java.util.List;\r
+import java.util.Map;\r
\r
import javax.servlet.http.HttpServlet;\r
\r
+import org.eclipse.jgit.lib.ObjectId;\r
import org.eclipse.jgit.lib.Repository;\r
import org.eclipse.jgit.revwalk.RevCommit;\r
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.SyndicatedEntryModel;\r
import com.gitblit.utils.HttpUtils;\r
import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.utils.JGitUtils.SearchType;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.utils.SyndicationUtils;\r
\r
String repositoryName = url;\r
String objectId = request.getParameter("h");\r
String l = request.getParameter("l");\r
+ String searchString = request.getParameter("s");\r
+ SearchType searchType = SearchType.COMMIT;\r
+ if (!StringUtils.isEmpty(request.getParameter("st"))) {\r
+ SearchType type = SearchType.forName(request.getParameter("st"));\r
+ if (type != null) {\r
+ searchType = type;\r
+ }\r
+ }\r
int length = GitBlit.getInteger(Keys.web.syndicationEntries, 25);\r
if (StringUtils.isEmpty(objectId)) {\r
objectId = org.eclipse.jgit.lib.Constants.HEAD;\r
response.setContentType("application/rss+xml; charset=UTF-8");\r
Repository repository = GitBlit.self().getRepository(repositoryName);\r
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
- List<RevCommit> commits = JGitUtils.getRevLog(repository, objectId, 0, length);\r
+ List<RevCommit> commits;\r
+ if (StringUtils.isEmpty(searchString)) {\r
+ // standard log/history lookup\r
+ commits = JGitUtils.getRevLog(repository, objectId, 0, length);\r
+ } else {\r
+ // repository search\r
+ commits = JGitUtils.searchRevlogs(repository, objectId, searchString, searchType, 0,\r
+ length);\r
+ }\r
+ Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository);\r
List<SyndicatedEntryModel> entries = new ArrayList<SyndicatedEntryModel>();\r
\r
boolean mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true);\r
entry.content = commit.getFullMessage();\r
entry.repository = model.name;\r
entry.branch = objectId;\r
+ List<RefModel> refs = allRefs.get(commit.getId());\r
+ if (refs != null && refs.size() > 0) {\r
+ List<String> tags = new ArrayList<String>();\r
+ for (RefModel ref : refs) {\r
+ tags.add(ref.getName());\r
+ }\r
+ entry.tags = tags;\r
+ }\r
entries.add(entry);\r
}\r
String feedLink;\r
import java.net.URLConnection;\r
import java.text.MessageFormat;\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.List;\r
\r
import com.gitblit.Constants;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.models.SyndicatedEntryModel;\r
+import com.gitblit.utils.JGitUtils.SearchType;\r
+import com.sun.syndication.feed.synd.SyndCategory;\r
+import com.sun.syndication.feed.synd.SyndCategoryImpl;\r
import com.sun.syndication.feed.synd.SyndContent;\r
import com.sun.syndication.feed.synd.SyndContentImpl;\r
import com.sun.syndication.feed.synd.SyndEntry;\r
entry.setLink(entryModel.link);\r
entry.setPublishedDate(entryModel.published);\r
\r
+ if (entryModel.tags != null && entryModel.tags.size() > 0) {\r
+ List<SyndCategory> tags = new ArrayList<SyndCategory>();\r
+ for (String tag : entryModel.tags) {\r
+ SyndCategoryImpl cat = new SyndCategoryImpl();\r
+ cat.setName(tag);\r
+ tags.add(cat);\r
+ }\r
+ entry.setCategories(tags);\r
+ }\r
+\r
SyndContent content = new SyndContentImpl();\r
content.setType(entryModel.contentType);\r
content.setValue(entryModel.content);\r
entry.setDescription(content);\r
+ \r
entries.add(entry);\r
}\r
feed.setEntries(entries);\r
if (!StringUtils.isEmpty(branch)) {\r
parameters.add("h=" + branch);\r
}\r
+ return readFeed(url, parameters, repository, branch, username, password);\r
+ }\r
+\r
+ /**\r
+ * Reads a Gitblit RSS search feed.\r
+ * \r
+ * @param url\r
+ * the url of the Gitblit server\r
+ * @param repository\r
+ * the repository name\r
+ * @param fragment\r
+ * the search fragment\r
+ * @param searchType\r
+ * the search type (optional, defaults to COMMIT)\r
+ * @param numberOfEntries\r
+ * the number of entries to retrieve. if <= 0 the server default\r
+ * is used.\r
+ * @param username\r
+ * @param password\r
+ * @return a list of SyndicationModel entries\r
+ * @throws {@link IOException}\r
+ */\r
+ public static List<SyndicatedEntryModel> readSearchFeed(String url, String repository,\r
+ String branch, String fragment, SearchType searchType, int numberOfEntries,\r
+ String username, char[] password) throws IOException {\r
+ // determine parameters\r
+ List<String> parameters = new ArrayList<String>();\r
+ parameters.add("s=" + StringUtils.encodeURL(fragment));\r
+ if (numberOfEntries > 0) {\r
+ parameters.add("l=" + numberOfEntries);\r
+ }\r
+ if (!StringUtils.isEmpty(branch)) {\r
+ parameters.add("h=" + branch);\r
+ }\r
+ if (searchType != null) {\r
+ parameters.add("st=" + searchType.name());\r
+ }\r
+ return readFeed(url, parameters, repository, branch, username, password);\r
+ }\r
+\r
+ /**\r
+ * Reads a Gitblit RSS feed.\r
+ * \r
+ * @param url\r
+ * the url of the Gitblit server\r
+ * @param parameters\r
+ * the list of RSS parameters\r
+ * @param repository\r
+ * the repository name\r
+ * @param username\r
+ * @param password\r
+ * @return a list of SyndicationModel entries\r
+ * @throws {@link IOException}\r
+ */\r
+ private static List<SyndicatedEntryModel> readFeed(String url, List<String> parameters,\r
+ String repository, String branch, String username, char[] password) throws IOException {\r
+ // build url\r
StringBuilder sb = new StringBuilder();\r
sb.append(MessageFormat.format("{0}" + Constants.SYNDICATION_PATH + "{1}", url, repository));\r
if (parameters.size() > 0) {\r
}\r
}\r
String feedUrl = sb.toString();\r
-\r
URLConnection conn = ConnectionUtils.openReadConnection(feedUrl, username, password);\r
InputStream is = conn.getInputStream();\r
SyndFeedInput input = new SyndFeedInput();\r
model.link = entry.getLink();\r
model.content = entry.getDescription().getValue();\r
model.contentType = entry.getDescription().getType();\r
+ if (entry.getCategories() != null && entry.getCategories().size() > 0) {\r
+ List<String> tags = new ArrayList<String>();\r
+ for (Object p : entry.getCategories()) {\r
+ SyndCategory cat = (SyndCategory) p;\r
+ tags.add(cat.getName());\r
+ }\r
+ model.tags = tags;\r
+ }\r
entries.add(model);\r
}\r
return entries;\r