diff --git a/docs/api/api.rst b/docs/api/api.rst --- a/docs/api/api.rst +++ b/docs/api/api.rst @@ -588,6 +588,7 @@ INPUT:: args: { "repoid" : "", "with_revision_names": " = Optional(False)", + "with_pullrequests": " = Optional(False)", } OUTPUT:: @@ -672,6 +673,55 @@ OUTPUT:: "": "", ... }, + + "pull_requests": [ + { + "status": "", + "pull_request_id": , + "description": "", + "title": "", + "url": "", + "reviewers": [ + { + "username": "", + }, + ... + ], + "org_repo_url": "", + "org_ref_parts": [ + "", + "", + "" + ], + "other_ref_parts": [ + "", + "", + "" + ], + "comments": [ + { + "username": "", + "text": "", + "comment_id": "", + }, + ... + ], + "owner": "", + "statuses": [ + { + "status": "", # "under_review", "approved" or "rejected" + "reviewer": "", + "modified_at": "" # iso 8601 date, server's timezone + }, + ... + ], + "revisions": [ + "", + ... + ] + }, + ... + ] } error: null diff --git a/kallithea/controllers/api/api.py b/kallithea/controllers/api/api.py --- a/kallithea/controllers/api/api.py +++ b/kallithea/controllers/api/api.py @@ -1126,7 +1126,8 @@ class ApiController(JSONRPCController): # permission check inside def get_repo(self, repoid, - with_revision_names=Optional(False)): + with_revision_names=Optional(False), + with_pullrequests=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 @@ -1227,7 +1228,8 @@ class ApiController(JSONRPCController): for uf in repo.followers ] - data = repo.get_api_data(with_revision_names=Optional.extract(with_revision_names)) + data = repo.get_api_data(with_revision_names=Optional.extract(with_revision_names), + with_pullrequests=Optional.extract(with_pullrequests)) data['members'] = members data['followers'] = followers return data diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -1246,10 +1246,11 @@ class Repository(Base, BaseDbModel): return is_valid_repo(repo_name, cls.base_path()) - def get_api_data(self, with_revision_names=False): + def get_api_data(self, with_revision_names=False, + with_pullrequests=False): """ Common function for generating repo api data. - Optionally, also return tags, branches and bookmarks. + Optionally, also return tags, branches, bookmarks and PRs. """ repo = self data = dict( @@ -1279,6 +1280,8 @@ class Repository(Base, BaseDbModel): branches=scm_repo.branches, bookmarks=scm_repo.bookmarks, )) + if with_pullrequests: + data['pull_requests'] = repo.pull_requests_other rc_config = Setting.get_app_settings() repository_fields = str2bool(rc_config.get('repository_fields')) if repository_fields: diff --git a/kallithea/tests/api/api_base.py b/kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py +++ b/kallithea/tests/api/api_base.py @@ -777,6 +777,7 @@ class _BaseTestApi(object): repoid=self.REPO) response = api_call(self, params) assert u"tags" not in response.json[u'result'] + assert u'pull_requests' not in response.json[u'result'] repo = RepoModel().get_by_repo_name(self.REPO) ret = repo.get_api_data() @@ -808,9 +809,11 @@ class _BaseTestApi(object): fixture.destroy_user_group(new_group) id_, params = _build_data(self.apikey, 'get_repo', repoid=self.REPO, - with_revision_names=True) + with_revision_names=True, + with_pullrequests=True) response = api_call(self, params) assert u"v0.2.0" in response.json[u'result'][u'tags'] + assert u'pull_requests' in response.json[u'result'] @parametrize('grant_perm', [ ('repository.admin'),