Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_merge_requests.py @ 2604:700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
if "update" is set, former patches data can be used, so it's not mandatory to specify a repository. In this case, empty string may be used as repository.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Jun 2018 12:23:43 +0200 |
parents | 5d4ac5415b40 |
children | 8fb99ed47db4 |
comparison
equal
deleted
inserted
replaced
2603:5d4ac5415b40 | 2604:700327fa9281 |
---|---|
204 """ | 204 """ |
205 if not node: | 205 if not node: |
206 node = NS_MERGE_REQUESTS | 206 node = NS_MERGE_REQUESTS |
207 if values is None: | 207 if values is None: |
208 values = {} | 208 values = {} |
209 update = extra.get('update', False) | |
210 if not repository and not update: | |
211 # in case of update, we may re-user former patches data | |
212 # so repository is not mandatory | |
213 raise exceptions.DataError(_(u"repository must be specified")) | |
209 | 214 |
210 if FIELD_DATA in values: | 215 if FIELD_DATA in values: |
211 raise exceptions.DataError(_(u"{field} is set by backend, you must not set it in frontend").format( | 216 raise exceptions.DataError(_(u"{field} is set by backend, you must not set it in frontend").format( |
212 field = FIELD_DATA)) | 217 field = FIELD_DATA)) |
213 | 218 |
214 if method == u'auto': | 219 if repository: |
215 for name in self._handlers_list: | 220 if method == u'auto': |
216 handler = self._handlers[name].handler | 221 for name in self._handlers_list: |
217 can_handle = yield handler.check(repository) | 222 handler = self._handlers[name].handler |
218 if can_handle: | 223 can_handle = yield handler.check(repository) |
219 log.info(_(u"{name} handler will be used").format(name=name)) | 224 if can_handle: |
220 break | 225 log.info(_(u"{name} handler will be used").format(name=name)) |
226 break | |
227 else: | |
228 log.warning(_(u"repository {path} can't be handled by any installed handler").format( | |
229 path = repository)) | |
230 raise exceptions.NotFound(_(u"no handler for this repository has been found")) | |
221 else: | 231 else: |
222 log.warning(_(u"repository {path} can't be handled by any installed handler").format( | 232 try: |
223 path = repository)) | 233 handler = self._handlers[name].handler |
224 raise exceptions.NotFound(_(u"no handler for this repository has been found")) | 234 except KeyError: |
225 else: | 235 raise exceptions.NotFound(_(u"No handler of this name found")) |
226 try: | 236 |
227 handler = self._handlers[name].handler | 237 data = yield handler.export(repository) |
228 except KeyError: | 238 if not data.strip(): |
229 raise exceptions.NotFound(_(u"No handler of this name found")) | 239 raise exceptions.DataError(_(u'export data is empty, do you have any change to send?')) |
230 | 240 |
231 data = yield handler.export(repository) | 241 if not values.get(u'title') or not values.get(u'body'): |
232 if not data.strip(): | 242 patches = yield handler.parse(data, values.get(FIELD_DATA_TYPE)) |
233 raise exceptions.DataError(_(u'export data is empty, do you have any change to send?')) | 243 commits_msg = patches[-1][self.META_COMMIT_MSG] |
234 | 244 msg_lines = commits_msg.splitlines() |
235 if not values.get(u'title') or not values.get(u'body'): | 245 if not values.get(u'title'): |
236 patches = yield handler.parse(data, values.get(FIELD_DATA_TYPE)) | 246 values[u'title'] = msg_lines[0] |
237 commits_msg = patches[-1][self.META_COMMIT_MSG] | 247 if not values.get(u'body'): |
238 msg_lines = commits_msg.splitlines() | 248 values[u'body'] = u'\n'.join(msg_lines[1:]) |
239 if not values.get(u'title'): | 249 |
240 values[u'title'] = msg_lines[0] | 250 values[FIELD_DATA] = data |
241 if not values.get(u'body'): | |
242 values[u'body'] = u'\n'.join(msg_lines[1:]) | |
243 | |
244 values[FIELD_DATA] = data | |
245 | 251 |
246 item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns=NS_MERGE_REQUESTS) | 252 item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns=NS_MERGE_REQUESTS) |
247 defer.returnValue(item_id) | 253 defer.returnValue(item_id) |
248 | 254 |
249 def _parseData(self, data_type, data): | 255 def _parseData(self, data_type, data): |