##// END OF EJS Templates
api: add optional branches, tags and bookmarks information to get_repo API data...
domruf -
r6593:98d26beb default
parent child Browse files
Show More
@@ -586,7 +586,8 b' INPUT::'
586 api_key : "<api_key>"
586 api_key : "<api_key>"
587 method : "get_repo"
587 method : "get_repo"
588 args: {
588 args: {
589 "repoid" : "<reponame or repo_id>"
589 "repoid" : "<reponame or repo_id>",
590 "with_revision_names": "<bool> = Optional(False)",
590 }
591 }
591
592
592 OUTPUT::
593 OUTPUT::
@@ -612,7 +613,7 b' OUTPUT::'
612 "raw_id": "<raw_id>",
613 "raw_id": "<raw_id>",
613 "revision": "<numeric_revision>",
614 "revision": "<numeric_revision>",
614 "short_id": "<short_id>"
615 "short_id": "<short_id>"
615 }
616 },
616 "owner": "<repo_owner>",
617 "owner": "<repo_owner>",
617 "fork_of": "<name_of_fork_parent>",
618 "fork_of": "<name_of_fork_parent>",
618 "members" : [
619 "members" : [
@@ -640,7 +641,7 b' OUTPUT::'
640 "permission" : "repository.(read|write|admin)"
641 "permission" : "repository.(read|write|admin)"
641 },
642 },
642
643
643 ]
644 ],
644 "followers": [
645 "followers": [
645 {
646 {
646 "user_id" : "<user_id>",
647 "user_id" : "<user_id>",
@@ -657,7 +658,20 b' OUTPUT::'
657 "last_login": "<last_login>",
658 "last_login": "<last_login>",
658 },
659 },
659
660
660 ]
661 ],
662 <if with_revision_names == True>
663 "tags": {
664 "<tagname>": "<raw_id>",
665 ...
666 },
667 "branches": {
668 "<branchname>": "<raw_id>",
669 ...
670 },
671 "bookmarks": {
672 "<bookmarkname>": "<raw_id>",
673 ...
674 },
661 }
675 }
662 error: null
676 error: null
663
677
@@ -1125,7 +1125,8 b' class ApiController(JSONRPCController):'
1125 )
1125 )
1126
1126
1127 # permission check inside
1127 # permission check inside
1128 def get_repo(self, repoid):
1128 def get_repo(self, repoid,
1129 with_revision_names=Optional(False)):
1129 """
1130 """
1130 Gets an existing repository by it's name or repository_id. Members will return
1131 Gets an existing repository by it's name or repository_id. Members will return
1131 either users_group or user associated to that repository. This command can be
1132 either users_group or user associated to that repository. This command can be
@@ -1175,8 +1176,20 b' class ApiController(JSONRPCController):'
1175 },
1176 },
1176
1177
1177 ]
1178 ]
1178 "followers": [<user_obj>, ...]
1179 "followers": [<user_obj>, ...],
1179 ]
1180 <if with_revision_names == True>
1181 "tags": {
1182 "<tagname>": "<raw_id>",
1183 ...
1184 },
1185 "branches": {
1186 "<branchname>": "<raw_id>",
1187 ...
1188 },
1189 "bookmarks": {
1190 "<bookmarkname>": "<raw_id>",
1191 ...
1192 },
1180 }
1193 }
1181 }
1194 }
1182 error : null
1195 error : null
@@ -1214,7 +1227,7 b' class ApiController(JSONRPCController):'
1214 for uf in repo.followers
1227 for uf in repo.followers
1215 ]
1228 ]
1216
1229
1217 data = repo.get_api_data()
1230 data = repo.get_api_data(with_revision_names=Optional.extract(with_revision_names))
1218 data['members'] = members
1231 data['members'] = members
1219 data['followers'] = followers
1232 data['followers'] = followers
1220 return data
1233 return data
@@ -1246,10 +1246,10 b' class Repository(Base, BaseDbModel):'
1246
1246
1247 return is_valid_repo(repo_name, cls.base_path())
1247 return is_valid_repo(repo_name, cls.base_path())
1248
1248
1249 def get_api_data(self):
1249 def get_api_data(self, with_revision_names=False):
1250 """
1250 """
1251 Common function for generating repo api data
1251 Common function for generating repo api data.
1252
1252 Optionally, also return tags, branches and bookmarks.
1253 """
1253 """
1254 repo = self
1254 repo = self
1255 data = dict(
1255 data = dict(
@@ -1272,6 +1272,13 b' class Repository(Base, BaseDbModel):'
1272 locked_date=time_to_datetime(self.locked[1]) \
1272 locked_date=time_to_datetime(self.locked[1]) \
1273 if self.locked[1] else None
1273 if self.locked[1] else None
1274 )
1274 )
1275 if with_revision_names:
1276 scm_repo = repo.scm_instance_no_cache()
1277 data.update(dict(
1278 tags=scm_repo.tags,
1279 branches=scm_repo.branches,
1280 bookmarks=scm_repo.bookmarks,
1281 ))
1275 rc_config = Setting.get_app_settings()
1282 rc_config = Setting.get_app_settings()
1276 repository_fields = str2bool(rc_config.get('repository_fields'))
1283 repository_fields = str2bool(rc_config.get('repository_fields'))
1277 if repository_fields:
1284 if repository_fields:
@@ -776,6 +776,7 b' class _BaseTestApi(object):'
776 id_, params = _build_data(self.apikey, 'get_repo',
776 id_, params = _build_data(self.apikey, 'get_repo',
777 repoid=self.REPO)
777 repoid=self.REPO)
778 response = api_call(self, params)
778 response = api_call(self, params)
779 assert u"tags" not in response.json[u'result']
779
780
780 repo = RepoModel().get_by_repo_name(self.REPO)
781 repo = RepoModel().get_by_repo_name(self.REPO)
781 ret = repo.get_api_data()
782 ret = repo.get_api_data()
@@ -806,6 +807,11 b' class _BaseTestApi(object):'
806 self._compare_ok(id_, expected, given=response.body)
807 self._compare_ok(id_, expected, given=response.body)
807 fixture.destroy_user_group(new_group)
808 fixture.destroy_user_group(new_group)
808
809
810 id_, params = _build_data(self.apikey, 'get_repo', repoid=self.REPO,
811 with_revision_names=True)
812 response = api_call(self, params)
813 assert u"v0.2.0" in response.json[u'result'][u'tags']
814
809 @parametrize('grant_perm', [
815 @parametrize('grant_perm', [
810 ('repository.admin'),
816 ('repository.admin'),
811 ('repository.write'),
817 ('repository.write'),
General Comments 0
You need to be logged in to leave comments. Login now