Show More
@@ -86,7 +86,7 b' class TestApi(object):' | |||||
86 | def test_api_non_existing_method_have_similar(self, request): |
|
86 | def test_api_non_existing_method_have_similar(self, request): | |
87 | id_, params = build_data(self.apikey, 'comment', args='xx') |
|
87 | id_, params = build_data(self.apikey, 'comment', args='xx') | |
88 | response = api_call(self.app, params) |
|
88 | response = api_call(self.app, params) | |
89 | expected = 'No such method: comment. Similar methods: changeset_comment, comment_pull_request, comment_commit' |
|
89 | expected = 'No such method: comment. Similar methods: changeset_comment, comment_pull_request, get_pull_request_comments, comment_commit' | |
90 | assert_error(id_, expected, given=response.body) |
|
90 | assert_error(id_, expected, given=response.body) | |
91 |
|
91 | |||
92 | def test_api_disabled_user(self, request): |
|
92 | def test_api_disabled_user(self, request): |
@@ -70,10 +70,11 b' class TestClosePullRequest(object):' | |||||
70 | assert_error(id_, expected, given=response.body) |
|
70 | assert_error(id_, expected, given=response.body) | |
71 |
|
71 | |||
72 | @pytest.mark.backends("git", "hg") |
|
72 | @pytest.mark.backends("git", "hg") | |
73 | def test_api_close_pull_request_repo_error(self): |
|
73 | def test_api_close_pull_request_repo_error(self, pr_util): | |
|
74 | pull_request = pr_util.create_pull_request() | |||
74 | id_, params = build_data( |
|
75 | id_, params = build_data( | |
75 | self.apikey, 'close_pull_request', |
|
76 | self.apikey, 'close_pull_request', | |
76 |
repoid=666, pullrequestid= |
|
77 | repoid=666, pullrequestid=pull_request.pull_request_id) | |
77 | response = api_call(self.app, params) |
|
78 | response = api_call(self.app, params) | |
78 |
|
79 | |||
79 | expected = 'repository `666` does not exist' |
|
80 | expected = 'repository `666` does not exist' |
@@ -170,10 +170,11 b' class TestCommentPullRequest(object):' | |||||
170 | assert_error(id_, expected, given=response.body) |
|
170 | assert_error(id_, expected, given=response.body) | |
171 |
|
171 | |||
172 | @pytest.mark.backends("git", "hg") |
|
172 | @pytest.mark.backends("git", "hg") | |
173 | def test_api_comment_pull_request_repo_error(self): |
|
173 | def test_api_comment_pull_request_repo_error(self, pr_util): | |
|
174 | pull_request = pr_util.create_pull_request() | |||
174 | id_, params = build_data( |
|
175 | id_, params = build_data( | |
175 | self.apikey, 'comment_pull_request', |
|
176 | self.apikey, 'comment_pull_request', | |
176 |
repoid=666, pullrequestid= |
|
177 | repoid=666, pullrequestid=pull_request.pull_request_id) | |
177 | response = api_call(self.app, params) |
|
178 | response = api_call(self.app, params) | |
178 |
|
179 | |||
179 | expected = 'repository `666` does not exist' |
|
180 | expected = 'repository `666` does not exist' |
@@ -38,11 +38,12 b' class TestGetMethod(object):' | |||||
38 | response = api_call(self.app, params) |
|
38 | response = api_call(self.app, params) | |
39 |
|
39 | |||
40 | expected = ['changeset_comment', 'comment_pull_request', |
|
40 | expected = ['changeset_comment', 'comment_pull_request', | |
41 | 'comment_commit'] |
|
41 | 'get_pull_request_comments', 'comment_commit'] | |
42 | assert_ok(id_, expected, given=response.body) |
|
42 | assert_ok(id_, expected, given=response.body) | |
43 |
|
43 | |||
44 | def test_get_methods_on_single_match(self): |
|
44 | def test_get_methods_on_single_match(self): | |
45 |
id_, params = build_data(self.apikey, 'get_method', |
|
45 | id_, params = build_data(self.apikey, 'get_method', | |
|
46 | pattern='*comment_commit*') | |||
46 | response = api_call(self.app, params) |
|
47 | response = api_call(self.app, params) | |
47 |
|
48 | |||
48 | expected = ['comment_commit', |
|
49 | expected = ['comment_commit', |
@@ -38,7 +38,6 b' class TestGetPullRequest(object):' | |||||
38 | pull_request = pr_util.create_pull_request(mergeable=True) |
|
38 | pull_request = pr_util.create_pull_request(mergeable=True) | |
39 | id_, params = build_data( |
|
39 | id_, params = build_data( | |
40 | self.apikey, 'get_pull_request', |
|
40 | self.apikey, 'get_pull_request', | |
41 | repoid=pull_request.target_repo.repo_name, |
|
|||
42 | pullrequestid=pull_request.pull_request_id) |
|
41 | pullrequestid=pull_request.pull_request_id) | |
43 |
|
42 | |||
44 | response = api_call(self.app, params) |
|
43 | response = api_call(self.app, params) | |
@@ -115,10 +114,11 b' class TestGetPullRequest(object):' | |||||
115 | } |
|
114 | } | |
116 | assert_ok(id_, expected, response.body) |
|
115 | assert_ok(id_, expected, response.body) | |
117 |
|
116 | |||
118 | def test_api_get_pull_request_repo_error(self): |
|
117 | def test_api_get_pull_request_repo_error(self, pr_util): | |
|
118 | pull_request = pr_util.create_pull_request() | |||
119 | id_, params = build_data( |
|
119 | id_, params = build_data( | |
120 | self.apikey, 'get_pull_request', |
|
120 | self.apikey, 'get_pull_request', | |
121 |
repoid=666, pullrequestid= |
|
121 | repoid=666, pullrequestid=pull_request.pull_request_id) | |
122 | response = api_call(self.app, params) |
|
122 | response = api_call(self.app, params) | |
123 |
|
123 | |||
124 | expected = 'repository `666` does not exist' |
|
124 | expected = 'repository `666` does not exist' | |
@@ -126,9 +126,17 b' class TestGetPullRequest(object):' | |||||
126 |
|
126 | |||
127 | def test_api_get_pull_request_pull_request_error(self): |
|
127 | def test_api_get_pull_request_pull_request_error(self): | |
128 | id_, params = build_data( |
|
128 | id_, params = build_data( | |
129 | self.apikey, 'get_pull_request', |
|
129 | self.apikey, 'get_pull_request', pullrequestid=666) | |
130 | repoid=1, pullrequestid=666) |
|
|||
131 | response = api_call(self.app, params) |
|
130 | response = api_call(self.app, params) | |
132 |
|
131 | |||
133 | expected = 'pull request `666` does not exist' |
|
132 | expected = 'pull request `666` does not exist' | |
134 | assert_error(id_, expected, given=response.body) |
|
133 | assert_error(id_, expected, given=response.body) | |
|
134 | ||||
|
135 | def test_api_get_pull_request_pull_request_error_just_pr_id(self): | |||
|
136 | id_, params = build_data( | |||
|
137 | self.apikey, 'get_pull_request', | |||
|
138 | pullrequestid=666) | |||
|
139 | response = api_call(self.app, params) | |||
|
140 | ||||
|
141 | expected = 'pull request `666` does not exist' | |||
|
142 | assert_error(id_, expected, given=response.body) |
@@ -112,10 +112,11 b' class TestMergePullRequest(object):' | |||||
112 | assert_error(id_, expected, given=response.body) |
|
112 | assert_error(id_, expected, given=response.body) | |
113 |
|
113 | |||
114 | @pytest.mark.backends("git", "hg") |
|
114 | @pytest.mark.backends("git", "hg") | |
115 | def test_api_merge_pull_request_repo_error(self): |
|
115 | def test_api_merge_pull_request_repo_error(self, pr_util): | |
|
116 | pull_request = pr_util.create_pull_request() | |||
116 | id_, params = build_data( |
|
117 | id_, params = build_data( | |
117 | self.apikey, 'merge_pull_request', |
|
118 | self.apikey, 'merge_pull_request', | |
118 |
repoid=666, pullrequestid= |
|
119 | repoid=666, pullrequestid=pull_request.pull_request_id) | |
119 | response = api_call(self.app, params) |
|
120 | response = api_call(self.app, params) | |
120 |
|
121 | |||
121 | expected = 'repository `666` does not exist' |
|
122 | expected = 'repository `666` does not exist' |
@@ -168,10 +168,11 b' class TestUpdatePullRequest(object):' | |||||
168 |
|
168 | |||
169 | @pytest.mark.backends("git", "hg") |
|
169 | @pytest.mark.backends("git", "hg") | |
170 | def test_api_update_repo_error(self, pr_util): |
|
170 | def test_api_update_repo_error(self, pr_util): | |
|
171 | pull_request = pr_util.create_pull_request() | |||
171 | id_, params = build_data( |
|
172 | id_, params = build_data( | |
172 | self.apikey, 'update_pull_request', |
|
173 | self.apikey, 'update_pull_request', | |
173 | repoid='fake', |
|
174 | repoid='fake', | |
174 |
pullrequestid= |
|
175 | pullrequestid=pull_request.pull_request_id, | |
175 | reviewers=[{'username': 'bad_name'}]) |
|
176 | reviewers=[{'username': 'bad_name'}]) | |
176 | response = api_call(self.app, params) |
|
177 | response = api_call(self.app, params) | |
177 |
|
178 |
@@ -43,14 +43,14 b' log = logging.getLogger(__name__)' | |||||
43 |
|
43 | |||
44 |
|
44 | |||
45 | @jsonrpc_method() |
|
45 | @jsonrpc_method() | |
46 |
def get_pull_request(request, apiuser, |
|
46 | def get_pull_request(request, apiuser, pullrequestid, repoid=Optional(None)): | |
47 | """ |
|
47 | """ | |
48 | Get a pull request based on the given ID. |
|
48 | Get a pull request based on the given ID. | |
49 |
|
49 | |||
50 | :param apiuser: This is filled automatically from the |authtoken|. |
|
50 | :param apiuser: This is filled automatically from the |authtoken|. | |
51 | :type apiuser: AuthUser |
|
51 | :type apiuser: AuthUser | |
52 |
:param repoid: |
|
52 | :param repoid: Optional, repository name or repository ID from where | |
53 | request was opened. |
|
53 | the pull request was opened. | |
54 | :type repoid: str or int |
|
54 | :type repoid: str or int | |
55 | :param pullrequestid: ID of the requested pull request. |
|
55 | :param pullrequestid: ID of the requested pull request. | |
56 | :type pullrequestid: int |
|
56 | :type pullrequestid: int | |
@@ -121,11 +121,17 b' def get_pull_request(request, apiuser, r' | |||||
121 | }, |
|
121 | }, | |
122 | "error": null |
|
122 | "error": null | |
123 | """ |
|
123 | """ | |
124 | get_repo_or_error(repoid) |
|
124 | ||
125 | pull_request = get_pull_request_or_error(pullrequestid) |
|
125 | pull_request = get_pull_request_or_error(pullrequestid) | |
|
126 | if Optional.extract(repoid): | |||
|
127 | repo = get_repo_or_error(repoid) | |||
|
128 | else: | |||
|
129 | repo = pull_request.target_repo | |||
|
130 | ||||
126 | if not PullRequestModel().check_user_read( |
|
131 | if not PullRequestModel().check_user_read( | |
127 | pull_request, apiuser, api=True): |
|
132 | pull_request, apiuser, api=True): | |
128 |
raise JSONRPCError('repository `%s` |
|
133 | raise JSONRPCError('repository `%s` or pull request `%s` ' | |
|
134 | 'does not exist' % (repoid, pullrequestid)) | |||
129 | data = pull_request.get_api_data() |
|
135 | data = pull_request.get_api_data() | |
130 | return data |
|
136 | return data | |
131 |
|
137 | |||
@@ -137,7 +143,7 b' def get_pull_requests(request, apiuser, ' | |||||
137 |
|
143 | |||
138 | :param apiuser: This is filled automatically from the |authtoken|. |
|
144 | :param apiuser: This is filled automatically from the |authtoken|. | |
139 | :type apiuser: AuthUser |
|
145 | :type apiuser: AuthUser | |
140 |
:param repoid: |
|
146 | :param repoid: Optional repository name or repository ID. | |
141 | :type repoid: str or int |
|
147 | :type repoid: str or int | |
142 | :param status: Only return pull requests with the specified status. |
|
148 | :param status: Only return pull requests with the specified status. | |
143 | Valid options are. |
|
149 | Valid options are. | |
@@ -229,7 +235,7 b' def get_pull_requests(request, apiuser, ' | |||||
229 |
|
235 | |||
230 | @jsonrpc_method() |
|
236 | @jsonrpc_method() | |
231 | def merge_pull_request( |
|
237 | def merge_pull_request( | |
232 |
request, apiuser, |
|
238 | request, apiuser, pullrequestid, repoid=Optional(None), | |
233 | userid=Optional(OAttr('apiuser'))): |
|
239 | userid=Optional(OAttr('apiuser'))): | |
234 | """ |
|
240 | """ | |
235 | Merge the pull request specified by `pullrequestid` into its target |
|
241 | Merge the pull request specified by `pullrequestid` into its target | |
@@ -237,7 +243,7 b' def merge_pull_request(' | |||||
237 |
|
243 | |||
238 | :param apiuser: This is filled automatically from the |authtoken|. |
|
244 | :param apiuser: This is filled automatically from the |authtoken|. | |
239 | :type apiuser: AuthUser |
|
245 | :type apiuser: AuthUser | |
240 |
:param repoid: |
|
246 | :param repoid: Optional, repository name or repository ID of the | |
241 | target repository to which the |pr| is to be merged. |
|
247 | target repository to which the |pr| is to be merged. | |
242 | :type repoid: str or int |
|
248 | :type repoid: str or int | |
243 | :param pullrequestid: ID of the pull request which shall be merged. |
|
249 | :param pullrequestid: ID of the pull request which shall be merged. | |
@@ -263,7 +269,12 b' def merge_pull_request(' | |||||
263 | }, |
|
269 | }, | |
264 | "error": null |
|
270 | "error": null | |
265 | """ |
|
271 | """ | |
266 |
|
|
272 | pull_request = get_pull_request_or_error(pullrequestid) | |
|
273 | if Optional.extract(repoid): | |||
|
274 | repo = get_repo_or_error(repoid) | |||
|
275 | else: | |||
|
276 | repo = pull_request.target_repo | |||
|
277 | ||||
267 | if not isinstance(userid, Optional): |
|
278 | if not isinstance(userid, Optional): | |
268 | if (has_superadmin_permission(apiuser) or |
|
279 | if (has_superadmin_permission(apiuser) or | |
269 | HasRepoPermissionAnyApi('repository.admin')( |
|
280 | HasRepoPermissionAnyApi('repository.admin')( | |
@@ -272,8 +283,6 b' def merge_pull_request(' | |||||
272 | else: |
|
283 | else: | |
273 | raise JSONRPCError('userid is not the same as your user') |
|
284 | raise JSONRPCError('userid is not the same as your user') | |
274 |
|
285 | |||
275 | pull_request = get_pull_request_or_error(pullrequestid) |
|
|||
276 |
|
||||
277 | check = MergeCheck.validate( |
|
286 | check = MergeCheck.validate( | |
278 | pull_request, user=apiuser, translator=request.translate) |
|
287 | pull_request, user=apiuser, translator=request.translate) | |
279 | merge_possible = not check.failed |
|
288 | merge_possible = not check.failed | |
@@ -415,8 +424,8 b' def get_pull_request_comments(' | |||||
415 |
|
424 | |||
416 | @jsonrpc_method() |
|
425 | @jsonrpc_method() | |
417 | def comment_pull_request( |
|
426 | def comment_pull_request( | |
418 |
request, apiuser, |
|
427 | request, apiuser, pullrequestid, repoid=Optional(None), | |
419 | commit_id=Optional(None), status=Optional(None), |
|
428 | message=Optional(None), commit_id=Optional(None), status=Optional(None), | |
420 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), |
|
429 | comment_type=Optional(ChangesetComment.COMMENT_TYPE_NOTE), | |
421 | resolves_comment_id=Optional(None), |
|
430 | resolves_comment_id=Optional(None), | |
422 | userid=Optional(OAttr('apiuser'))): |
|
431 | userid=Optional(OAttr('apiuser'))): | |
@@ -427,7 +436,7 b' def comment_pull_request(' | |||||
427 |
|
436 | |||
428 | :param apiuser: This is filled automatically from the |authtoken|. |
|
437 | :param apiuser: This is filled automatically from the |authtoken|. | |
429 | :type apiuser: AuthUser |
|
438 | :type apiuser: AuthUser | |
430 |
:param repoid: |
|
439 | :param repoid: Optional repository name or repository ID. | |
431 | :type repoid: str or int |
|
440 | :type repoid: str or int | |
432 | :param pullrequestid: The pull request ID. |
|
441 | :param pullrequestid: The pull request ID. | |
433 | :type pullrequestid: int |
|
442 | :type pullrequestid: int | |
@@ -459,7 +468,12 b' def comment_pull_request(' | |||||
459 | }, |
|
468 | }, | |
460 | error : null |
|
469 | error : null | |
461 | """ |
|
470 | """ | |
462 |
|
|
471 | pull_request = get_pull_request_or_error(pullrequestid) | |
|
472 | if Optional.extract(repoid): | |||
|
473 | repo = get_repo_or_error(repoid) | |||
|
474 | else: | |||
|
475 | repo = pull_request.target_repo | |||
|
476 | ||||
463 | if not isinstance(userid, Optional): |
|
477 | if not isinstance(userid, Optional): | |
464 | if (has_superadmin_permission(apiuser) or |
|
478 | if (has_superadmin_permission(apiuser) or | |
465 | HasRepoPermissionAnyApi('repository.admin')( |
|
479 | HasRepoPermissionAnyApi('repository.admin')( | |
@@ -468,7 +482,6 b' def comment_pull_request(' | |||||
468 | else: |
|
482 | else: | |
469 | raise JSONRPCError('userid is not the same as your user') |
|
483 | raise JSONRPCError('userid is not the same as your user') | |
470 |
|
484 | |||
471 | pull_request = get_pull_request_or_error(pullrequestid) |
|
|||
472 | if not PullRequestModel().check_user_read( |
|
485 | if not PullRequestModel().check_user_read( | |
473 | pull_request, apiuser, api=True): |
|
486 | pull_request, apiuser, api=True): | |
474 | raise JSONRPCError('repository `%s` does not exist' % (repoid,)) |
|
487 | raise JSONRPCError('repository `%s` does not exist' % (repoid,)) | |
@@ -676,15 +689,15 b' def create_pull_request(' | |||||
676 |
|
689 | |||
677 | @jsonrpc_method() |
|
690 | @jsonrpc_method() | |
678 | def update_pull_request( |
|
691 | def update_pull_request( | |
679 |
request, apiuser, |
|
692 | request, apiuser, pullrequestid, repoid=Optional(None), | |
680 | description=Optional(''), reviewers=Optional(None), |
|
693 | title=Optional(''), description=Optional(''), reviewers=Optional(None), | |
681 | update_commits=Optional(None)): |
|
694 | update_commits=Optional(None)): | |
682 | """ |
|
695 | """ | |
683 | Updates a pull request. |
|
696 | Updates a pull request. | |
684 |
|
697 | |||
685 | :param apiuser: This is filled automatically from the |authtoken|. |
|
698 | :param apiuser: This is filled automatically from the |authtoken|. | |
686 | :type apiuser: AuthUser |
|
699 | :type apiuser: AuthUser | |
687 |
:param repoid: |
|
700 | :param repoid: Optional repository name or repository ID. | |
688 | :type repoid: str or int |
|
701 | :type repoid: str or int | |
689 | :param pullrequestid: The pull request ID. |
|
702 | :param pullrequestid: The pull request ID. | |
690 | :type pullrequestid: int |
|
703 | :type pullrequestid: int | |
@@ -729,8 +742,12 b' def update_pull_request(' | |||||
729 | error : null |
|
742 | error : null | |
730 | """ |
|
743 | """ | |
731 |
|
744 | |||
732 | repo = get_repo_or_error(repoid) |
|
|||
733 | pull_request = get_pull_request_or_error(pullrequestid) |
|
745 | pull_request = get_pull_request_or_error(pullrequestid) | |
|
746 | if Optional.extract(repoid): | |||
|
747 | repo = get_repo_or_error(repoid) | |||
|
748 | else: | |||
|
749 | repo = pull_request.target_repo | |||
|
750 | ||||
734 | if not PullRequestModel().check_user_update( |
|
751 | if not PullRequestModel().check_user_update( | |
735 | pull_request, apiuser, api=True): |
|
752 | pull_request, apiuser, api=True): | |
736 | raise JSONRPCError( |
|
753 | raise JSONRPCError( | |
@@ -808,7 +825,7 b' def update_pull_request(' | |||||
808 |
|
825 | |||
809 | @jsonrpc_method() |
|
826 | @jsonrpc_method() | |
810 | def close_pull_request( |
|
827 | def close_pull_request( | |
811 |
request, apiuser, |
|
828 | request, apiuser, pullrequestid, repoid=Optional(None), | |
812 | userid=Optional(OAttr('apiuser')), message=Optional('')): |
|
829 | userid=Optional(OAttr('apiuser')), message=Optional('')): | |
813 | """ |
|
830 | """ | |
814 | Close the pull request specified by `pullrequestid`. |
|
831 | Close the pull request specified by `pullrequestid`. | |
@@ -841,7 +858,12 b' def close_pull_request(' | |||||
841 | """ |
|
858 | """ | |
842 | _ = request.translate |
|
859 | _ = request.translate | |
843 |
|
860 | |||
844 |
|
|
861 | pull_request = get_pull_request_or_error(pullrequestid) | |
|
862 | if Optional.extract(repoid): | |||
|
863 | repo = get_repo_or_error(repoid) | |||
|
864 | else: | |||
|
865 | repo = pull_request.target_repo | |||
|
866 | ||||
845 | if not isinstance(userid, Optional): |
|
867 | if not isinstance(userid, Optional): | |
846 | if (has_superadmin_permission(apiuser) or |
|
868 | if (has_superadmin_permission(apiuser) or | |
847 | HasRepoPermissionAnyApi('repository.admin')( |
|
869 | HasRepoPermissionAnyApi('repository.admin')( | |
@@ -850,8 +872,6 b' def close_pull_request(' | |||||
850 | else: |
|
872 | else: | |
851 | raise JSONRPCError('userid is not the same as your user') |
|
873 | raise JSONRPCError('userid is not the same as your user') | |
852 |
|
874 | |||
853 | pull_request = get_pull_request_or_error(pullrequestid) |
|
|||
854 |
|
||||
855 | if pull_request.is_closed(): |
|
875 | if pull_request.is_closed(): | |
856 | raise JSONRPCError( |
|
876 | raise JSONRPCError( | |
857 | 'pull request `%s` is already closed' % (pullrequestid,)) |
|
877 | 'pull request `%s` is already closed' % (pullrequestid,)) |
General Comments 0
You need to be logged in to leave comments.
Login now