Change enum name and unit test RSS tag queries
| | |
| | | changes: ~ |
| | | additions: |
| | | - Add FORK_REPOSITORY RPC request type (issue-371, pr-161, ticket-65) |
| | | - Add object type (ot) parameter for RSS queries to retrieve tag details (pr-165, ticket-66) |
| | | dependencyChanges: ~ |
| | | contributors: |
| | | - Manisha Gayathri |
| | | - Gerard Smyth |
| | | } |
| | | |
| | | # |
| | |
| | | /**
|
| | | * Enumeration of the feed content object types.
|
| | | */
|
| | | public static enum FeedContentObjectType {
|
| | | public static enum FeedObjectType {
|
| | | COMMIT, TAG;
|
| | |
|
| | | public static FeedContentObjectType forName(String name) {
|
| | | for (FeedContentObjectType type : values()) {
|
| | | public static FeedObjectType forName(String name) {
|
| | | for (FeedObjectType type : values()) {
|
| | | if (type.name().equalsIgnoreCase(name)) {
|
| | | return type;
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | Constants.FeedContentObjectType objectType = Constants.FeedContentObjectType.COMMIT;
|
| | | Constants.FeedObjectType objectType = Constants.FeedObjectType.COMMIT;
|
| | | if (!StringUtils.isEmpty(request.getParameter("ot"))) {
|
| | | Constants.FeedContentObjectType type = Constants.FeedContentObjectType.forName(request.getParameter("ot"));
|
| | | Constants.FeedObjectType type = Constants.FeedObjectType.forName(request.getParameter("ot"));
|
| | | if (type != null) {
|
| | | objectType = type;
|
| | | }
|
| | |
| | | feedDescription = model.description;
|
| | | }
|
| | |
|
| | | if (objectType == Constants.FeedContentObjectType.TAG) {
|
| | | if (objectType == Constants.FeedObjectType.TAG) {
|
| | |
|
| | | String urlPattern;
|
| | | if (mountParameters) {
|
| | |
| | | import java.util.List;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.FeedObjectType;
|
| | | import com.gitblit.GitBlitException;
|
| | | import com.gitblit.models.FeedEntryModel;
|
| | | import com.sun.syndication.feed.synd.SyndCategory;
|
| | |
| | | */
|
| | | public static List<FeedEntryModel> readFeed(String url, String repository, String branch,
|
| | | int numberOfEntries, int page, String username, char[] password) throws IOException {
|
| | | return readFeed(url, repository, branch, FeedObjectType.COMMIT, numberOfEntries,
|
| | | page, username, password);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Reads tags from the specified repository.
|
| | | *
|
| | | * @param url
|
| | | * the url of the Gitblit server
|
| | | * @param repository
|
| | | * the repository name
|
| | | * @param branch
|
| | | * the branch name (optional)
|
| | | * @param numberOfEntries
|
| | | * the number of entries to retrieve. if <= 0 the server default
|
| | | * is used.
|
| | | * @param page
|
| | | * 0-indexed. used to paginate the results.
|
| | | * @param username
|
| | | * @param password
|
| | | * @return a list of SyndicationModel entries
|
| | | * @throws {@link IOException}
|
| | | */
|
| | | public static List<FeedEntryModel> readTags(String url, String repository,
|
| | | int numberOfEntries, int page, String username, char[] password) throws IOException {
|
| | | return readFeed(url, repository, null, FeedObjectType.TAG, numberOfEntries,
|
| | | page, username, password);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Reads a Gitblit RSS feed.
|
| | | *
|
| | | * @param url
|
| | | * the url of the Gitblit server
|
| | | * @param repository
|
| | | * the repository name
|
| | | * @param branch
|
| | | * the branch name (optional)
|
| | | * @param objectType
|
| | | * the object type to return (optional, COMMIT assummed)
|
| | | * @param numberOfEntries
|
| | | * the number of entries to retrieve. if <= 0 the server default
|
| | | * is used.
|
| | | * @param page
|
| | | * 0-indexed. used to paginate the results.
|
| | | * @param username
|
| | | * @param password
|
| | | * @return a list of SyndicationModel entries
|
| | | * @throws {@link IOException}
|
| | | */
|
| | | private static List<FeedEntryModel> readFeed(String url, String repository, String branch,
|
| | | FeedObjectType objectType, int numberOfEntries, int page, String username,
|
| | | char[] password) throws IOException {
|
| | | // build feed url
|
| | | List<String> parameters = new ArrayList<String>();
|
| | | if (numberOfEntries > 0) {
|
| | |
| | | if (!StringUtils.isEmpty(branch)) {
|
| | | parameters.add("h=" + branch);
|
| | | }
|
| | | if (objectType != null) {
|
| | | parameters.add("ot=" + objectType.name());
|
| | | }
|
| | | return readFeed(url, parameters, repository, branch, username, password);
|
| | | }
|
| | |
|
| | |
| | | <tr><th>url parameter</th><th>default</th><th>description</th></tr>
|
| | | <tr><td colspan='3'><b>standard query</b></td></tr>
|
| | | <tr><td><em>repository</em></td><td><em>required</em></td><td>repository name is part of the url (see examples below)</td></tr>
|
| | | <tr><td>ot=</td><td><em>optional</em><br/>default: COMMIT</td><td>object type to return in results. COMMIT or TAG</td></tr>
|
| | | <tr><td>h=</td><td><em>optional</em><br/>default: HEAD</td><td>starting branch, ref, or commit id</td></tr>
|
| | | <tr><td>l=</td><td><em>optional</em><br/>default: web.syndicationEntries</td><td>maximum return count</td></tr>
|
| | | <tr><td>pg=</td><td><em>optional</em><br/>default: 0</td><td>page number for paging<br/>(offset into history = pagenumber*maximum return count)</td></tr>
|
| | |
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | |
|
| | | import org.junit.AfterClass;
|
| | | import org.junit.BeforeClass;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.Constants.SearchType;
|
| | |
| | | import com.gitblit.utils.SyndicationUtils;
|
| | |
|
| | | public class SyndicationUtilsTest extends GitblitUnitTest {
|
| | |
|
| | | private static final AtomicBoolean started = new AtomicBoolean(false);
|
| | |
|
| | | @BeforeClass
|
| | | public static void startGitblit() throws Exception {
|
| | | started.set(GitBlitSuite.startGitblit());
|
| | | }
|
| | |
|
| | | @AfterClass
|
| | | public static void stopGitblit() throws Exception {
|
| | | if (started.get()) {
|
| | | GitBlitSuite.stopGitblit();
|
| | | }
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testSyndication() throws Exception {
|
| | |
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFeedRead() throws Exception {
|
| | | public void testFeedReadCommits() throws Exception {
|
| | | Set<String> links = new HashSet<String>();
|
| | | for (int i = 0; i < 2; i++) {
|
| | | List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git",
|
| | |
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFeedReadTags() throws Exception {
|
| | | Set<String> links = new HashSet<String>();
|
| | | for (int i = 0; i < 2; i++) {
|
| | | List<FeedEntryModel> feed = SyndicationUtils.readTags(GitBlitSuite.url, "test/gitective.git",
|
| | | 5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
|
| | | assertTrue(feed != null);
|
| | | assertTrue(feed.size() > 0);
|
| | | assertEquals(5, feed.size());
|
| | | for (FeedEntryModel entry : feed) {
|
| | | links.add(entry.link);
|
| | | }
|
| | | }
|
| | | // confirm we have 10 unique tags
|
| | | assertEquals("Feed pagination failed", 10, links.size());
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testSearchFeedRead() throws Exception {
|
| | | List<FeedEntryModel> feed = SyndicationUtils
|
| | | .readSearchFeed(GitBlitSuite.url, "ticgit.git", null, "test", null, 5, 0,
|