Changeset - 98d26beb0965
[Not reviewed]
default
0 4 0
domruf - 9 years ago 2017-03-29 22:10:27
dominikruf@gmail.com
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.
4 files changed with 51 insertions and 11 deletions:
0 comments (0 inline, 0 general)
docs/api/api.rst
Show inline comments
 
@@ -586,7 +586,8 @@ INPUT::
 
    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 @@ OUTPUT::
 
                                       "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 @@ OUTPUT::
 
                                    "permission" : "repository.(read|write|admin)"
 
                                  },
 
 
                                ]
 
                                ],
 
                 "followers":   [
 
                                  {
 
                                    "user_id" :     "<user_id>",
 
@@ -657,7 +658,20 @@ OUTPUT::
 
                                    "last_login":   "<last_login>",
 
                                  },
 
 
                 ]
 
                                ],
 
                 <if with_revision_names == True>
 
                 "tags": {
 
                            "<tagname>": "<raw_id>",
 
                            ...
 
                         },
 
                 "branches": {
 
                            "<branchname>": "<raw_id>",
 
                            ...
 
                         },
 
                 "bookmarks": {
 
                            "<bookmarkname>": "<raw_id>",
 
                            ...
 
                         },
 
            }
 
    error:  null
 

	
kallithea/controllers/api/api.py
Show inline comments
 
@@ -1125,7 +1125,8 @@ class ApiController(JSONRPCController):
 
            )
 

	
 
    # 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 @@ class ApiController(JSONRPCController):
 
                                  },
 
 
                                ]
 
                 "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 @@ class ApiController(JSONRPCController):
 
            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
kallithea/model/db.py
Show inline comments
 
@@ -1246,10 +1246,10 @@ class Repository(Base, BaseDbModel):
 

	
 
        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 @@ class Repository(Base, BaseDbModel):
 
            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:
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -776,6 +776,7 @@ class _BaseTestApi(object):
 
        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 @@ class _BaseTestApi(object):
 
        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'),
0 comments (0 inline, 0 general)