# HG changeset patch # User domruf # Date 1496770818 -7200 # Node ID 19bc05bd8cf78e40b7bce46fc4ca2ff9268ccbf9 # Parent d18dfba3c245668506b7bec76247148dcb85a2c6 api: add get_changesets diff -r d18dfba3c245 -r 19bc05bd8cf7 docs/api/api.rst --- a/docs/api/api.rst Tue Jun 13 22:55:58 2017 +0200 +++ b/docs/api/api.rst Tue Jun 06 19:40:18 2017 +0200 @@ -1071,6 +1071,48 @@ } error: null +get_changesets +^^^^^^^^^^^^^^ + +Get changesets of a given repository. This command can only be executed using the api_key +of a user with read permissions to the repository. + +INPUT:: + + id : + api_key : "" + method : "get_changesets" + args: { + "repoid" : "", + "start": " = Optional(None)", + "end": " = Optional(None)", + "start_date": " = Optional(None)", # in "%Y-%m-%dT%H:%M:%S" format + "end_date": " = Optional(None)", # in "%Y-%m-%dT%H:%M:%S" format + "branch_name": " = Optional(None)", + "reverse": " = Optional(False)", + "with_file_list": " = Optional(False)" + } + +OUTPUT:: + + id : + result: [ + { + "raw_id": "", + "short_id": "short_id": "", + "author": "", + "date": "", + "message": "", + "revision": "", + + "added": [], + "changed": [], + "removed": [] + }, + ... + ] + error: null + get_changeset ^^^^^^^^^^^^^ diff -r d18dfba3c245 -r 19bc05bd8cf7 kallithea/controllers/api/api.py --- a/kallithea/controllers/api/api.py Tue Jun 13 22:55:58 2017 +0200 +++ b/kallithea/controllers/api/api.py Tue Jun 06 19:40:18 2017 +0200 @@ -28,6 +28,8 @@ import time import traceback import logging + +from datetime import datetime from sqlalchemy import or_ from tg import request @@ -56,7 +58,7 @@ from kallithea.lib.compat import json from kallithea.lib.exceptions import ( DefaultUserException, UserGroupsAssignedException) -from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError +from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError from kallithea.lib.vcs.backends.base import EmptyChangeset from kallithea.lib.utils import action_logger @@ -2492,6 +2494,25 @@ % (gist.gist_access_id,)) # permission check inside + def get_changesets(self, repoid, start=None, end=None, start_date=None, + end_date=None, branch_name=None, reverse=False, with_file_list=False): + repo = get_repo_or_error(repoid) + if not HasRepoPermissionLevel('read')(repo.repo_name): + raise JSONRPCError('Access denied to repo %s' % repo.repo_name) + + format = "%Y-%m-%dT%H:%M:%S" + try: + return [e.__json__(with_file_list) for e in + repo.scm_instance.get_changesets(start, + end, + datetime.strptime(start_date, format) if start_date else None, + datetime.strptime(end_date, format) if end_date else None, + branch_name, + reverse)] + except EmptyRepositoryError as e: + raise JSONRPCError(e.message) + + # permission check inside def get_changeset(self, repoid, raw_id, with_reviews=Optional(False)): repo = get_repo_or_error(repoid) if not HasRepoPermissionLevel('read')(repo.repo_name): diff -r d18dfba3c245 -r 19bc05bd8cf7 kallithea/lib/vcs/backends/base.py --- a/kallithea/lib/vcs/backends/base.py Tue Jun 13 22:55:58 2017 +0200 +++ b/kallithea/lib/vcs/backends/base.py Tue Jun 06 19:40:18 2017 +0200 @@ -384,15 +384,28 @@ def __eq__(self, other): return self.raw_id == other.raw_id - def __json__(self): - return dict( - short_id=self.short_id, - raw_id=self.raw_id, - revision=self.revision, - message=self.message, - date=self.date, - author=self.author, - ) + def __json__(self, with_file_list=False): + if with_file_list: + return dict( + short_id=self.short_id, + raw_id=self.raw_id, + revision=self.revision, + message=self.message, + date=self.date, + author=self.author, + added=[el.path for el in self.added], + changed=[el.path for el in self.changed], + removed=[el.path for el in self.removed], + ) + else: + return dict( + short_id=self.short_id, + raw_id=self.raw_id, + revision=self.revision, + message=self.message, + date=self.date, + author=self.author, + ) @LazyProperty def last(self): diff -r d18dfba3c245 -r 19bc05bd8cf7 kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py Tue Jun 13 22:55:58 2017 +0200 +++ b/kallithea/tests/api/api_base.py Tue Jun 06 19:40:18 2017 +0200 @@ -2461,6 +2461,24 @@ expected = Setting.get_server_info() self._compare_ok(id_, expected, given=response.body) + def test_api_get_changesets(self): + id_, params = _build_data(self.apikey, 'get_changesets', + repoid=self.REPO, start=0, end=2) + response = api_call(self, params) + result = json.loads(response.body)["result"] + assert len(result) == 3 + assert result[0].has_key('message') + assert not result[0].has_key('added') + + def test_api_get_changesets_with_file_list(self): + id_, params = _build_data(self.apikey, 'get_changesets', + repoid=self.REPO, start_date="2010-04-07T23:30:30", end_date="2010-04-08T00:31:14", with_file_list=True) + response = api_call(self, params) + result = json.loads(response.body)["result"] + assert len(result) == 3 + assert result[0].has_key('message') + assert result[0].has_key('added') + def test_api_get_changeset(self): review = fixture.review_changeset(self.REPO, self.TEST_REVISION, "approved") id_, params = _build_data(self.apikey, 'get_changeset',