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