]> source.dussan.org Git - gitblit.git/commitdiff
Change enum name and unit test RSS tag queries 66/66/2
authorJames Moger <james.moger@gitblit.com>
Thu, 8 May 2014 17:09:08 +0000 (13:09 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 8 May 2014 17:11:41 +0000 (13:11 -0400)
releases.moxie
src/main/java/com/gitblit/Constants.java
src/main/java/com/gitblit/servlet/SyndicationServlet.java
src/main/java/com/gitblit/utils/SyndicationUtils.java
src/site/rpc.mkd
src/test/java/com/gitblit/tests/SyndicationUtilsTest.java

index 228fc7e651948bde806167b3c004e25d9828bbd0..96a0ae91461364329ea17686f21da32c9990d463 100644 (file)
@@ -13,9 +13,11 @@ r24: {
     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
 }
 
 #
index 2007c0a865ca4caa5157c6a45d74521c9055e965..95eb944a14ee41f65bcc8d7d17bc7417c4cda822 100644 (file)
@@ -405,11 +405,11 @@ public class Constants {
        /**\r
         * Enumeration of the feed content object types.\r
         */\r
-       public static enum FeedContentObjectType {\r
+       public static enum FeedObjectType {\r
                COMMIT, TAG;\r
 \r
-               public static FeedContentObjectType forName(String name) {\r
-                       for (FeedContentObjectType type : values()) {\r
+               public static FeedObjectType forName(String name) {\r
+                       for (FeedObjectType type : values()) {\r
                                if (type.name().equalsIgnoreCase(name)) {\r
                                        return type;\r
                                }\r
index 9650ee3a7da16a7a78af6a9870feea637257b7e4..631df781584109ef5322e20013eecd404c63fa8b 100644 (file)
@@ -164,9 +164,9 @@ public class SyndicationServlet extends DaggerServlet {
                        }\r
                }\r
 \r
-               Constants.FeedContentObjectType objectType = Constants.FeedContentObjectType.COMMIT;\r
+               Constants.FeedObjectType objectType = Constants.FeedObjectType.COMMIT;\r
                if (!StringUtils.isEmpty(request.getParameter("ot"))) {\r
-                       Constants.FeedContentObjectType type = Constants.FeedContentObjectType.forName(request.getParameter("ot"));\r
+                       Constants.FeedObjectType type = Constants.FeedObjectType.forName(request.getParameter("ot"));\r
                        if (type != null) {\r
                                objectType = type;\r
                        }\r
@@ -249,7 +249,7 @@ public class SyndicationServlet extends DaggerServlet {
                                feedDescription = model.description;\r
                        }\r
 \r
-                       if (objectType == Constants.FeedContentObjectType.TAG) {\r
+                       if (objectType == Constants.FeedObjectType.TAG) {\r
 \r
                                String urlPattern;\r
                                if (mountParameters) {\r
index 2ee1cf693be9ac3c180f46b6b5c91494a30932ab..93e9321aff12e7fefbe45945f9d3597e62bab2ec 100644 (file)
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.List;\r
 \r
 import com.gitblit.Constants;\r
+import com.gitblit.Constants.FeedObjectType;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.models.FeedEntryModel;\r
 import com.sun.syndication.feed.synd.SyndCategory;\r
@@ -137,6 +138,59 @@ public class SyndicationUtils {
         */\r
        public static List<FeedEntryModel> readFeed(String url, String repository, String branch,\r
                        int numberOfEntries, int page, String username, char[] password) throws IOException {\r
+               return readFeed(url, repository, branch, FeedObjectType.COMMIT, numberOfEntries,\r
+                               page, username, password);\r
+       }\r
+\r
+       /**\r
+        * Reads tags from the specified repository.\r
+        *\r
+        * @param url\r
+        *            the url of the Gitblit server\r
+        * @param repository\r
+        *            the repository name\r
+        * @param branch\r
+        *            the branch name (optional)\r
+        * @param numberOfEntries\r
+        *            the number of entries to retrieve. if <= 0 the server default\r
+        *            is used.\r
+        * @param page\r
+        *            0-indexed. used to paginate the results.\r
+        * @param username\r
+        * @param password\r
+        * @return a list of SyndicationModel entries\r
+        * @throws {@link IOException}\r
+        */\r
+       public static List<FeedEntryModel> readTags(String url, String repository,\r
+                       int numberOfEntries, int page, String username, char[] password) throws IOException {\r
+               return readFeed(url, repository, null, FeedObjectType.TAG, numberOfEntries,\r
+                               page, username, password);\r
+       }\r
+\r
+       /**\r
+        * Reads a Gitblit RSS feed.\r
+        *\r
+        * @param url\r
+        *            the url of the Gitblit server\r
+        * @param repository\r
+        *            the repository name\r
+        * @param branch\r
+        *            the branch name (optional)\r
+        * @param objectType\r
+        *            the object type to return (optional, COMMIT assummed)\r
+        * @param numberOfEntries\r
+        *            the number of entries to retrieve. if <= 0 the server default\r
+        *            is used.\r
+        * @param page\r
+        *            0-indexed. used to paginate the results.\r
+        * @param username\r
+        * @param password\r
+        * @return a list of SyndicationModel entries\r
+        * @throws {@link IOException}\r
+        */\r
+       private static List<FeedEntryModel> readFeed(String url, String repository, String branch,\r
+                       FeedObjectType objectType, int numberOfEntries, int page, String username,\r
+                       char[] password) throws IOException {\r
                // build feed url\r
                List<String> parameters = new ArrayList<String>();\r
                if (numberOfEntries > 0) {\r
@@ -148,6 +202,9 @@ public class SyndicationUtils {
                if (!StringUtils.isEmpty(branch)) {\r
                        parameters.add("h=" + branch);\r
                }\r
+               if (objectType != null) {\r
+                       parameters.add("ot=" + objectType.name());\r
+               }\r
                return readFeed(url, parameters, repository, branch, username, password);\r
        }\r
 \r
index 2e502e2ca0b678ef039edc2719da0707d511cc71..302084fb46194598669461e77e78027ec0114e78 100644 (file)
@@ -32,6 +32,7 @@ The Gitblit API includes methods for retrieving and interpreting RSS feeds.  The
 <tr><th>url parameter</th><th>default</th><th>description</th></tr>\r
 <tr><td colspan='3'><b>standard query</b></td></tr>\r
 <tr><td><em>repository</em></td><td><em>required</em></td><td>repository name is part of the url (see examples below)</td></tr>\r
+<tr><td>ot=</td><td><em>optional</em><br/>default: COMMIT</td><td>object type to return in results. COMMIT or TAG</td></tr>\r
 <tr><td>h=</td><td><em>optional</em><br/>default: HEAD</td><td>starting branch, ref, or commit id</td></tr>\r
 <tr><td>l=</td><td><em>optional</em><br/>default: web.syndicationEntries</td><td>maximum return count</td></tr>\r
 <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>\r
index d206bbdb3484bfd08b88d1f1c8637bd6be0bf513..b4bb044f2289b00f9bdba1551145337a1abf32b7 100644 (file)
@@ -21,7 +21,10 @@ import java.util.Date;
 import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Set;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
 \r
+import org.junit.AfterClass;\r
+import org.junit.BeforeClass;\r
 import org.junit.Test;\r
 \r
 import com.gitblit.Constants.SearchType;\r
@@ -30,6 +33,20 @@ import com.gitblit.utils.SyndicationUtils;
 \r
 public class SyndicationUtilsTest extends GitblitUnitTest {\r
 \r
+       private static final AtomicBoolean started = new AtomicBoolean(false);\r
+\r
+       @BeforeClass\r
+       public static void startGitblit() throws Exception {\r
+               started.set(GitBlitSuite.startGitblit());\r
+       }\r
+\r
+       @AfterClass\r
+       public static void stopGitblit() throws Exception {\r
+               if (started.get()) {\r
+                       GitBlitSuite.stopGitblit();\r
+               }\r
+       }\r
+\r
        @Test\r
        public void testSyndication() throws Exception {\r
                List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();\r
@@ -60,7 +77,7 @@ public class SyndicationUtilsTest extends GitblitUnitTest {
        }\r
 \r
        @Test\r
-       public void testFeedRead() throws Exception {\r
+       public void testFeedReadCommits() throws Exception {\r
                Set<String> links = new HashSet<String>();\r
                for (int i = 0; i < 2; i++) {\r
                        List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url, "ticgit.git",\r
@@ -76,6 +93,23 @@ public class SyndicationUtilsTest extends GitblitUnitTest {
                assertEquals("Feed pagination failed", 10, links.size());\r
        }\r
 \r
+       @Test\r
+       public void testFeedReadTags() throws Exception {\r
+               Set<String> links = new HashSet<String>();\r
+               for (int i = 0; i < 2; i++) {\r
+                       List<FeedEntryModel> feed = SyndicationUtils.readTags(GitBlitSuite.url, "test/gitective.git",\r
+                                       5, i, GitBlitSuite.account, GitBlitSuite.password.toCharArray());\r
+                       assertTrue(feed != null);\r
+                       assertTrue(feed.size() > 0);\r
+                       assertEquals(5, feed.size());\r
+                       for (FeedEntryModel entry : feed) {\r
+                               links.add(entry.link);\r
+                       }\r
+               }\r
+               // confirm we have 10 unique tags\r
+               assertEquals("Feed pagination failed", 10, links.size());\r
+       }\r
+\r
        @Test\r
        public void testSearchFeedRead() throws Exception {\r
                List<FeedEntryModel> feed = SyndicationUtils\r