Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits.
This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT.
If this is not provided, then COMMIT is assumed to maintain backwards compatability.
If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Enumeration of the feed content object types.
|
| | | */
|
| | | public static enum FeedContentObjectType {
|
| | | COMMIT, TAG;
|
| | |
|
| | | public static FeedContentObjectType forName(String name) {
|
| | | for (FeedContentObjectType type : values()) {
|
| | | if (type.name().equalsIgnoreCase(name)) {
|
| | | return type;
|
| | | }
|
| | | }
|
| | | return COMMIT;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return name().toLowerCase();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * The types of objects that can be indexed and queried.
|
| | | */
|
| | | public static enum SearchObjectType {
|
| | |
| | | searchType = type;
|
| | | }
|
| | | }
|
| | |
|
| | | Constants.FeedContentObjectType objectType = Constants.FeedContentObjectType.COMMIT;
|
| | | if (!StringUtils.isEmpty(request.getParameter("ot"))) {
|
| | | Constants.FeedContentObjectType type = Constants.FeedContentObjectType.forName(request.getParameter("ot"));
|
| | | if (type != null) {
|
| | | objectType = type;
|
| | | }
|
| | | }
|
| | |
|
| | | int length = settings.getInteger(Keys.web.syndicationEntries, 25);
|
| | | if (StringUtils.isEmpty(objectId)) {
|
| | | objectId = org.eclipse.jgit.lib.Constants.HEAD;
|
| | |
| | |
|
| | |
|
| | | boolean mountParameters = settings.getBoolean(Keys.web.mountParameters, true);
|
| | | String urlPattern;
|
| | | if (mountParameters) {
|
| | | // mounted parameters
|
| | | urlPattern = "{0}/commit/{1}/{2}";
|
| | | } else {
|
| | | // parameterized parameters
|
| | | urlPattern = "{0}/commit/?r={1}&h={2}";
|
| | | }
|
| | |
|
| | | String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
|
| | | if (StringUtils.isEmpty(gitblitUrl)) {
|
| | | gitblitUrl = HttpUtils.getGitblitURL(request);
|
| | |
| | | feedName = model.name;
|
| | | feedTitle = model.name;
|
| | | feedDescription = model.description;
|
| | | }
|
| | |
|
| | | if (objectType == Constants.FeedContentObjectType.TAG) {
|
| | |
|
| | | String urlPattern;
|
| | | if (mountParameters) {
|
| | | // mounted parameters
|
| | | urlPattern = "{0}/tag/{1}/{2}";
|
| | | } else {
|
| | | // parameterized parameters
|
| | | urlPattern = "{0}/tag/?r={1}&h={2}";
|
| | | }
|
| | |
|
| | | List<RefModel> tags = JGitUtils.getTags(repository, false, length, offset);
|
| | |
|
| | | for (RefModel tag : tags) {
|
| | | FeedEntryModel entry = new FeedEntryModel();
|
| | | entry.title = tag.getName();
|
| | | entry.author = tag.getAuthorIdent().getName();
|
| | | entry.link = MessageFormat.format(urlPattern, gitblitUrl,
|
| | | StringUtils.encodeURL(model.name.replace('/', fsc)), tag.getObjectId().getName());
|
| | | entry.published = tag.getDate();
|
| | | entry.contentType = "text/html";
|
| | | entry.content = tag.getFullMessage();
|
| | | entry.repository = model.name;
|
| | | entry.branch = objectId;
|
| | |
|
| | | entry.tags = new ArrayList<String>();
|
| | |
|
| | | // add tag id and referenced commit id
|
| | | entry.tags.add("tag:" + tag.getObjectId().getName());
|
| | | entry.tags.add("commit:" + tag.getReferencedObjectId().getName());
|
| | |
|
| | | entries.add(entry);
|
| | | }
|
| | | } else {
|
| | |
|
| | | String urlPattern;
|
| | | if (mountParameters) {
|
| | | // mounted parameters
|
| | | urlPattern = "{0}/commit/{1}/{2}";
|
| | | } else {
|
| | | // parameterized parameters
|
| | | urlPattern = "{0}/commit/?r={1}&h={2}";
|
| | | }
|
| | |
|
| | | List<RevCommit> commits;
|
| | |
| | | entries.add(entry);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // sort & truncate the feed
|
| | | Collections.sort(entries);
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of tags in the repository. If repository does not exist
|
| | | * or is empty, an empty list is returned.
|
| | | *
|
| | | * @param repository
|
| | | * @param fullName
|
| | | * if true, /refs/tags/yadayadayada is returned. If false,
|
| | | * yadayadayada is returned.
|
| | | * @param maxCount
|
| | | * if < 0, all tags are returned
|
| | | * @param offset
|
| | | * if maxCount provided sets the starting point of the records to return
|
| | | * @return list of tags
|
| | | */
|
| | | public static List<RefModel> getTags(Repository repository, boolean fullName, int maxCount, int offset) {
|
| | | return getRefs(repository, Constants.R_TAGS, fullName, maxCount, offset);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of local branches in the repository. If repository does
|
| | | * not exist or is empty, an empty list is returned.
|
| | | *
|
| | |
| | | */
|
| | | private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,
|
| | | int maxCount) {
|
| | | return getRefs(repository, refs, fullName, maxCount, 0);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns a list of references in the repository matching "refs". If the
|
| | | * repository is null or empty, an empty list is returned.
|
| | | *
|
| | | * @param repository
|
| | | * @param refs
|
| | | * if unspecified, all refs are returned
|
| | | * @param fullName
|
| | | * if true, /refs/something/yadayadayada is returned. If false,
|
| | | * yadayadayada is returned.
|
| | | * @param maxCount
|
| | | * if < 0, all references are returned
|
| | | * @param offset
|
| | | * if maxCount provided sets the starting point of the records to return
|
| | | * @return list of references
|
| | | */
|
| | | private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,
|
| | | int maxCount, int offset) {
|
| | | List<RefModel> list = new ArrayList<RefModel>();
|
| | | if (maxCount == 0) {
|
| | | return list;
|
| | |
| | | Collections.sort(list);
|
| | | Collections.reverse(list);
|
| | | if (maxCount > 0 && list.size() > maxCount) {
|
| | | list = new ArrayList<RefModel>(list.subList(0, maxCount));
|
| | | if (offset < 0) {
|
| | | offset = 0;
|
| | | }
|
| | | int endIndex = offset + maxCount;
|
| | | if (endIndex > list.size()) {
|
| | | endIndex = list.size();
|
| | | }
|
| | | list = new ArrayList<RefModel>(list.subList(offset, endIndex));
|
| | | }
|
| | | } catch (IOException e) {
|
| | | error(e, repository, "{0} failed to retrieve {1}", refs);
|