# HG changeset patch # User domruf # Date 1490818227 -7200 # Node ID 98d26beb09651b47c439c23d630485a3888d5c0a # Parent b60fb9461b1839dd7c56f81ab6ca80b86037b4e4 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. diff -r b60fb9461b18 -r 98d26beb0965 docs/api/api.rst --- 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 : "" method : "get_repo" args: { - "repoid" : "" + "repoid" : "", + "with_revision_names": " = Optional(False)", } OUTPUT:: @@ -612,7 +613,7 @@ "raw_id": "", "revision": "", "short_id": "" - } + }, "owner": "", "fork_of": "", "members" : [ @@ -640,7 +641,7 @@ "permission" : "repository.(read|write|admin)" }, … - ] + ], "followers": [ { "user_id" : "", @@ -657,7 +658,20 @@ "last_login": "", }, … - ] + ], + + "tags": { + "": "", + ... + }, + "branches": { + "": "", + ... + }, + "bookmarks": { + "": "", + ... + }, } error: null diff -r b60fb9461b18 -r 98d26beb0965 kallithea/controllers/api/api.py --- 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": [, ...] - ] + "followers": [, ...], + + "tags": { + "": "", + ... + }, + "branches": { + "": "", + ... + }, + "bookmarks": { + "": "", + ... + }, } } 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 diff -r b60fb9461b18 -r 98d26beb0965 kallithea/model/db.py --- 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: diff -r b60fb9461b18 -r 98d26beb0965 kallithea/tests/api/api_base.py --- 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'),