Show More
@@ -1071,6 +1071,48 b' OUTPUT::' | |||||
1071 | } |
|
1071 | } | |
1072 | error: null |
|
1072 | error: null | |
1073 |
|
1073 | |||
|
1074 | get_changesets | |||
|
1075 | ^^^^^^^^^^^^^^ | |||
|
1076 | ||||
|
1077 | Get changesets of a given repository. This command can only be executed using the api_key | |||
|
1078 | of a user with read permissions to the repository. | |||
|
1079 | ||||
|
1080 | INPUT:: | |||
|
1081 | ||||
|
1082 | id : <id_for_response> | |||
|
1083 | api_key : "<api_key>" | |||
|
1084 | method : "get_changesets" | |||
|
1085 | args: { | |||
|
1086 | "repoid" : "<reponame or repo_id>", | |||
|
1087 | "start": "<revision number> = Optional(None)", | |||
|
1088 | "end": "<revision number> = Optional(None)", | |||
|
1089 | "start_date": "<date> = Optional(None)", # in "%Y-%m-%dT%H:%M:%S" format | |||
|
1090 | "end_date": "<date> = Optional(None)", # in "%Y-%m-%dT%H:%M:%S" format | |||
|
1091 | "branch_name": "<branch name filter> = Optional(None)", | |||
|
1092 | "reverse": "<bool> = Optional(False)", | |||
|
1093 | "with_file_list": "<bool> = Optional(False)" | |||
|
1094 | } | |||
|
1095 | ||||
|
1096 | OUTPUT:: | |||
|
1097 | ||||
|
1098 | id : <id_given_in_input> | |||
|
1099 | result: [ | |||
|
1100 | { | |||
|
1101 | "raw_id": "<raw_id>", | |||
|
1102 | "short_id": "short_id": "<short_id>", | |||
|
1103 | "author": "<full_author>", | |||
|
1104 | "date": "<date_time_of_commit>", | |||
|
1105 | "message": "<commit_message>", | |||
|
1106 | "revision": "<numeric_revision>", | |||
|
1107 | <if with_file_list == True> | |||
|
1108 | "added": [<list of added files>], | |||
|
1109 | "changed": [<list of changed files>], | |||
|
1110 | "removed": [<list of removed files>] | |||
|
1111 | }, | |||
|
1112 | ... | |||
|
1113 | ] | |||
|
1114 | error: null | |||
|
1115 | ||||
1074 | get_changeset |
|
1116 | get_changeset | |
1075 | ^^^^^^^^^^^^^ |
|
1117 | ^^^^^^^^^^^^^ | |
1076 |
|
1118 |
@@ -28,6 +28,8 b' Original author and date, and relevant c' | |||||
28 | import time |
|
28 | import time | |
29 | import traceback |
|
29 | import traceback | |
30 | import logging |
|
30 | import logging | |
|
31 | ||||
|
32 | from datetime import datetime | |||
31 | from sqlalchemy import or_ |
|
33 | from sqlalchemy import or_ | |
32 |
|
34 | |||
33 | from tg import request |
|
35 | from tg import request | |
@@ -56,7 +58,7 b' from kallithea.model.db import (' | |||||
56 | from kallithea.lib.compat import json |
|
58 | from kallithea.lib.compat import json | |
57 | from kallithea.lib.exceptions import ( |
|
59 | from kallithea.lib.exceptions import ( | |
58 | DefaultUserException, UserGroupsAssignedException) |
|
60 | DefaultUserException, UserGroupsAssignedException) | |
59 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError |
|
61 | from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError | |
60 | from kallithea.lib.vcs.backends.base import EmptyChangeset |
|
62 | from kallithea.lib.vcs.backends.base import EmptyChangeset | |
61 | from kallithea.lib.utils import action_logger |
|
63 | from kallithea.lib.utils import action_logger | |
62 |
|
64 | |||
@@ -2492,6 +2494,25 b' class ApiController(JSONRPCController):' | |||||
2492 | % (gist.gist_access_id,)) |
|
2494 | % (gist.gist_access_id,)) | |
2493 |
|
2495 | |||
2494 | # permission check inside |
|
2496 | # permission check inside | |
|
2497 | def get_changesets(self, repoid, start=None, end=None, start_date=None, | |||
|
2498 | end_date=None, branch_name=None, reverse=False, with_file_list=False): | |||
|
2499 | repo = get_repo_or_error(repoid) | |||
|
2500 | if not HasRepoPermissionLevel('read')(repo.repo_name): | |||
|
2501 | raise JSONRPCError('Access denied to repo %s' % repo.repo_name) | |||
|
2502 | ||||
|
2503 | format = "%Y-%m-%dT%H:%M:%S" | |||
|
2504 | try: | |||
|
2505 | return [e.__json__(with_file_list) for e in | |||
|
2506 | repo.scm_instance.get_changesets(start, | |||
|
2507 | end, | |||
|
2508 | datetime.strptime(start_date, format) if start_date else None, | |||
|
2509 | datetime.strptime(end_date, format) if end_date else None, | |||
|
2510 | branch_name, | |||
|
2511 | reverse)] | |||
|
2512 | except EmptyRepositoryError as e: | |||
|
2513 | raise JSONRPCError(e.message) | |||
|
2514 | ||||
|
2515 | # permission check inside | |||
2495 | def get_changeset(self, repoid, raw_id, with_reviews=Optional(False)): |
|
2516 | def get_changeset(self, repoid, raw_id, with_reviews=Optional(False)): | |
2496 | repo = get_repo_or_error(repoid) |
|
2517 | repo = get_repo_or_error(repoid) | |
2497 | if not HasRepoPermissionLevel('read')(repo.repo_name): |
|
2518 | if not HasRepoPermissionLevel('read')(repo.repo_name): |
@@ -384,15 +384,28 b' class BaseChangeset(object):' | |||||
384 | def __eq__(self, other): |
|
384 | def __eq__(self, other): | |
385 | return self.raw_id == other.raw_id |
|
385 | return self.raw_id == other.raw_id | |
386 |
|
386 | |||
387 | def __json__(self): |
|
387 | def __json__(self, with_file_list=False): | |
388 | return dict( |
|
388 | if with_file_list: | |
389 | short_id=self.short_id, |
|
389 | return dict( | |
390 |
|
|
390 | short_id=self.short_id, | |
391 |
|
|
391 | raw_id=self.raw_id, | |
392 |
|
|
392 | revision=self.revision, | |
393 |
|
|
393 | message=self.message, | |
394 |
|
|
394 | date=self.date, | |
395 | ) |
|
395 | author=self.author, | |
|
396 | added=[el.path for el in self.added], | |||
|
397 | changed=[el.path for el in self.changed], | |||
|
398 | removed=[el.path for el in self.removed], | |||
|
399 | ) | |||
|
400 | else: | |||
|
401 | return dict( | |||
|
402 | short_id=self.short_id, | |||
|
403 | raw_id=self.raw_id, | |||
|
404 | revision=self.revision, | |||
|
405 | message=self.message, | |||
|
406 | date=self.date, | |||
|
407 | author=self.author, | |||
|
408 | ) | |||
396 |
|
409 | |||
397 | @LazyProperty |
|
410 | @LazyProperty | |
398 | def last(self): |
|
411 | def last(self): |
@@ -2461,6 +2461,24 b' class _BaseTestApi(object):' | |||||
2461 | expected = Setting.get_server_info() |
|
2461 | expected = Setting.get_server_info() | |
2462 | self._compare_ok(id_, expected, given=response.body) |
|
2462 | self._compare_ok(id_, expected, given=response.body) | |
2463 |
|
2463 | |||
|
2464 | def test_api_get_changesets(self): | |||
|
2465 | id_, params = _build_data(self.apikey, 'get_changesets', | |||
|
2466 | repoid=self.REPO, start=0, end=2) | |||
|
2467 | response = api_call(self, params) | |||
|
2468 | result = json.loads(response.body)["result"] | |||
|
2469 | assert len(result) == 3 | |||
|
2470 | assert result[0].has_key('message') | |||
|
2471 | assert not result[0].has_key('added') | |||
|
2472 | ||||
|
2473 | def test_api_get_changesets_with_file_list(self): | |||
|
2474 | id_, params = _build_data(self.apikey, 'get_changesets', | |||
|
2475 | repoid=self.REPO, start_date="2010-04-07T23:30:30", end_date="2010-04-08T00:31:14", with_file_list=True) | |||
|
2476 | response = api_call(self, params) | |||
|
2477 | result = json.loads(response.body)["result"] | |||
|
2478 | assert len(result) == 3 | |||
|
2479 | assert result[0].has_key('message') | |||
|
2480 | assert result[0].has_key('added') | |||
|
2481 | ||||
2464 | def test_api_get_changeset(self): |
|
2482 | def test_api_get_changeset(self): | |
2465 | review = fixture.review_changeset(self.REPO, self.TEST_REVISION, "approved") |
|
2483 | review = fixture.review_changeset(self.REPO, self.TEST_REVISION, "approved") | |
2466 | id_, params = _build_data(self.apikey, 'get_changeset', |
|
2484 | id_, params = _build_data(self.apikey, 'get_changeset', |
General Comments 0
You need to be logged in to leave comments.
Login now