changeset 6653:98d26beb0965

api: add optional branches, tags and bookmarks information to get_repo API data Modified by Mads Kiilerich to make these revision names optional - there can be a lot of them.
author domruf <dominikruf@gmail.com>
date Wed, 29 Mar 2017 22:10:27 +0200
parents b60fb9461b18
children bf9900e6e177
files docs/api/api.rst kallithea/controllers/api/api.py kallithea/model/db.py kallithea/tests/api/api_base.py
diffstat 4 files changed, 51 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/docs/api/api.rst	Mon Mar 13 15:34:53 2017 +0100
+++ b/docs/api/api.rst	Wed Mar 29 22:10:27 2017 +0200
@@ -586,7 +586,8 @@
     api_key : "<api_key>"
     method :  "get_repo"
     args:     {
-                "repoid" : "<reponame or repo_id>"
+                "repoid" : "<reponame or repo_id>",
+                "with_revision_names": "<bool> = Optional(False)",
               }
 
 OUTPUT::
@@ -612,7 +613,7 @@
                                        "raw_id":   "<raw_id>",
                                        "revision": "<numeric_revision>",
                                        "short_id": "<short_id>"
-                                     }
+                                     },
                 "owner":             "<repo_owner>",
                 "fork_of":           "<name_of_fork_parent>",
                 "members" :     [
@@ -640,7 +641,7 @@
                                     "permission" : "repository.(read|write|admin)"
                                   },

-                                ]
+                                ],
                  "followers":   [
                                   {
                                     "user_id" :     "<user_id>",
@@ -657,7 +658,20 @@
                                     "last_login":   "<last_login>",
                                   },

-                 ]
+                                ],
+                 <if with_revision_names == True>
+                 "tags": {
+                            "<tagname>": "<raw_id>",
+                            ...
+                         },
+                 "branches": {
+                            "<branchname>": "<raw_id>",
+                            ...
+                         },
+                 "bookmarks": {
+                            "<bookmarkname>": "<raw_id>",
+                            ...
+                         },
             }
     error:  null
 
--- a/kallithea/controllers/api/api.py	Mon Mar 13 15:34:53 2017 +0100
+++ b/kallithea/controllers/api/api.py	Wed Mar 29 22:10:27 2017 +0200
@@ -1125,7 +1125,8 @@
             )
 
     # permission check inside
-    def get_repo(self, repoid):
+    def get_repo(self, repoid,
+                 with_revision_names=Optional(False)):
         """
         Gets an existing repository by it's name or repository_id. Members will return
         either users_group or user associated to that repository. This command can be
@@ -1175,8 +1176,20 @@
                                   },

                                 ]
-                 "followers":   [<user_obj>, ...]
-                 ]
+                 "followers":   [<user_obj>, ...],
+                 <if with_revision_names == True>
+                 "tags": {
+                            "<tagname>": "<raw_id>",
+                            ...
+                         },
+                 "branches": {
+                            "<branchname>": "<raw_id>",
+                            ...
+                         },
+                 "bookmarks": {
+                            "<bookmarkname>": "<raw_id>",
+                            ...
+                         },
             }
           }
           error :  null
@@ -1214,7 +1227,7 @@
             for uf in repo.followers
         ]
 
-        data = repo.get_api_data()
+        data = repo.get_api_data(with_revision_names=Optional.extract(with_revision_names))
         data['members'] = members
         data['followers'] = followers
         return data
--- a/kallithea/model/db.py	Mon Mar 13 15:34:53 2017 +0100
+++ b/kallithea/model/db.py	Wed Mar 29 22:10:27 2017 +0200
@@ -1246,10 +1246,10 @@
 
         return is_valid_repo(repo_name, cls.base_path())
 
-    def get_api_data(self):
+    def get_api_data(self, with_revision_names=False):
         """
-        Common function for generating repo api data
-
+        Common function for generating repo api data.
+        Optionally, also return tags, branches and bookmarks.
         """
         repo = self
         data = dict(
@@ -1272,6 +1272,13 @@
             locked_date=time_to_datetime(self.locked[1]) \
                 if self.locked[1] else None
         )
+        if with_revision_names:
+            scm_repo = repo.scm_instance_no_cache()
+            data.update(dict(
+                tags=scm_repo.tags,
+                branches=scm_repo.branches,
+                bookmarks=scm_repo.bookmarks,
+            ))
         rc_config = Setting.get_app_settings()
         repository_fields = str2bool(rc_config.get('repository_fields'))
         if repository_fields:
--- a/kallithea/tests/api/api_base.py	Mon Mar 13 15:34:53 2017 +0100
+++ b/kallithea/tests/api/api_base.py	Wed Mar 29 22:10:27 2017 +0200
@@ -776,6 +776,7 @@
         id_, params = _build_data(self.apikey, 'get_repo',
                                   repoid=self.REPO)
         response = api_call(self, params)
+        assert u"tags" not in response.json[u'result']
 
         repo = RepoModel().get_by_repo_name(self.REPO)
         ret = repo.get_api_data()
@@ -806,6 +807,11 @@
         self._compare_ok(id_, expected, given=response.body)
         fixture.destroy_user_group(new_group)
 
+        id_, params = _build_data(self.apikey, 'get_repo', repoid=self.REPO,
+                                  with_revision_names=True)
+        response = api_call(self, params)
+        assert u"v0.2.0" in response.json[u'result'][u'tags']
+
     @parametrize('grant_perm', [
         ('repository.admin'),
         ('repository.write'),