##// END OF EJS Templates
API: Added option to rescann repositories via api call
marcink -
r2697:4565e655 beta
parent child Browse files
Show More
@@ -127,6 +127,31 b' OUTPUT::'
127 error : null
127 error : null
128
128
129
129
130 rescan_repos
131 ------------
132
133 Dispatch rescan repositories action. If remove_obsolete is set
134 RhodeCode will delete repos that are in database but not in the filesystem.
135 This command can be executed only using api_key belonging to user with admin
136 rights.
137
138 INPUT::
139
140 id : <id_for_response>
141 api_key : "<api_key>"
142 method : "rescan_repos"
143 args : {
144 "remove_obsolete" : "<boolean = Optional(False)>"
145 }
146
147 OUTPUT::
148
149 id : <id_given_in_input>
150 result : "{'added': [<list of names of added repos>],
151 'removed': [<list of names of removed repos>]}"
152 error : null
153
154
130 get_user
155 get_user
131 --------
156 --------
132
157
@@ -31,7 +31,7 b' import logging'
31 from rhodecode.controllers.api import JSONRPCController, JSONRPCError
31 from rhodecode.controllers.api import JSONRPCController, JSONRPCError
32 from rhodecode.lib.auth import HasPermissionAllDecorator, \
32 from rhodecode.lib.auth import HasPermissionAllDecorator, \
33 HasPermissionAnyDecorator, PasswordGenerator, AuthUser
33 HasPermissionAnyDecorator, PasswordGenerator, AuthUser
34 from rhodecode.lib.utils import map_groups
34 from rhodecode.lib.utils import map_groups, repo2db_mapper
35 from rhodecode.model.meta import Session
35 from rhodecode.model.meta import Session
36 from rhodecode.model.scm import ScmModel
36 from rhodecode.model.scm import ScmModel
37 from rhodecode.model.repo import RepoModel
37 from rhodecode.model.repo import RepoModel
@@ -162,6 +162,28 b' class ApiController(JSONRPCController):'
162 )
162 )
163
163
164 @HasPermissionAllDecorator('hg.admin')
164 @HasPermissionAllDecorator('hg.admin')
165 def rescan_repos(self, apiuser, remove_obsolete=Optional(False)):
166 """
167 Dispatch rescan repositories action. If remove_obsolete is set
168 than also delete repos that are in database but not in the filesystem.
169 aka "clean zombies"
170
171 :param apiuser:
172 :param remove_obsolete:
173 """
174
175 try:
176 rm_obsolete = Optional.extract(remove_obsolete)
177 added, removed = repo2db_mapper(ScmModel().repo_scan(),
178 remove_obsolete=rm_obsolete)
179 return {'added': added, 'removed': removed}
180 except Exception:
181 log.error(traceback.format_exc())
182 raise JSONRPCError(
183 'Unable to rescan repositories'
184 )
185
186 @HasPermissionAllDecorator('hg.admin')
165 def get_user(self, apiuser, userid):
187 def get_user(self, apiuser, userid):
166 """"
188 """"
167 Get a user by username
189 Get a user by username
@@ -9,6 +9,7 b' from rhodecode.model.user import UserMod'
9 from rhodecode.model.users_group import UsersGroupModel
9 from rhodecode.model.users_group import UsersGroupModel
10 from rhodecode.model.repo import RepoModel
10 from rhodecode.model.repo import RepoModel
11 from rhodecode.model.meta import Session
11 from rhodecode.model.meta import Session
12 from rhodecode.model.scm import ScmModel
12
13
13 API_URL = '/_admin/api'
14 API_URL = '/_admin/api'
14
15
@@ -215,6 +216,23 b' class BaseTestApi(object):'
215 expected = 'Unable to pull changes from `%s`' % self.REPO
216 expected = 'Unable to pull changes from `%s`' % self.REPO
216 self._compare_error(id_, expected, given=response.body)
217 self._compare_error(id_, expected, given=response.body)
217
218
219 def test_api_rescan_repos(self):
220 id_, params = _build_data(self.apikey, 'rescan_repos')
221 response = self.app.post(API_URL, content_type='application/json',
222 params=params)
223
224 expected = {'added': [], 'removed': []}
225 self._compare_ok(id_, expected, given=response.body)
226
227 @mock.patch.object(ScmModel, 'repo_scan', crash)
228 def test_api_rescann_error(self):
229 id_, params = _build_data(self.apikey, 'rescan_repos',)
230 response = self.app.post(API_URL, content_type='application/json',
231 params=params)
232
233 expected = 'Unable to rescan repositories'
234 self._compare_error(id_, expected, given=response.body)
235
218 def test_api_create_existing_user(self):
236 def test_api_create_existing_user(self):
219 id_, params = _build_data(self.apikey, 'create_user',
237 id_, params = _build_data(self.apikey, 'create_user',
220 username=TEST_USER_ADMIN_LOGIN,
238 username=TEST_USER_ADMIN_LOGIN,
General Comments 0
You need to be logged in to leave comments. Login now