Mercurial > libervia-backend
changeset 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 | 87f8cf51fca5 |
files | sat/plugins/plugin_misc_merge_requests.py |
diffstat | 1 files changed, 34 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_merge_requests.py Fri Jun 01 12:21:23 2018 +0200 +++ b/sat/plugins/plugin_misc_merge_requests.py Fri Jun 01 12:23:43 2018 +0200 @@ -206,42 +206,48 @@ node = NS_MERGE_REQUESTS if values is None: values = {} + update = extra.get('update', False) + if not repository and not update: + # in case of update, we may re-user former patches data + # so repository is not mandatory + raise exceptions.DataError(_(u"repository must be specified")) if FIELD_DATA in values: raise exceptions.DataError(_(u"{field} is set by backend, you must not set it in frontend").format( field = FIELD_DATA)) - if method == u'auto': - for name in self._handlers_list: - handler = self._handlers[name].handler - can_handle = yield handler.check(repository) - if can_handle: - log.info(_(u"{name} handler will be used").format(name=name)) - break + if repository: + if method == u'auto': + for name in self._handlers_list: + handler = self._handlers[name].handler + can_handle = yield handler.check(repository) + if can_handle: + log.info(_(u"{name} handler will be used").format(name=name)) + break + else: + log.warning(_(u"repository {path} can't be handled by any installed handler").format( + path = repository)) + raise exceptions.NotFound(_(u"no handler for this repository has been found")) else: - log.warning(_(u"repository {path} can't be handled by any installed handler").format( - path = repository)) - raise exceptions.NotFound(_(u"no handler for this repository has been found")) - else: - try: - handler = self._handlers[name].handler - except KeyError: - raise exceptions.NotFound(_(u"No handler of this name found")) + try: + handler = self._handlers[name].handler + except KeyError: + raise exceptions.NotFound(_(u"No handler of this name found")) + + data = yield handler.export(repository) + if not data.strip(): + raise exceptions.DataError(_(u'export data is empty, do you have any change to send?')) - data = yield handler.export(repository) - if not data.strip(): - raise exceptions.DataError(_(u'export data is empty, do you have any change to send?')) + if not values.get(u'title') or not values.get(u'body'): + patches = yield handler.parse(data, values.get(FIELD_DATA_TYPE)) + commits_msg = patches[-1][self.META_COMMIT_MSG] + msg_lines = commits_msg.splitlines() + if not values.get(u'title'): + values[u'title'] = msg_lines[0] + if not values.get(u'body'): + values[u'body'] = u'\n'.join(msg_lines[1:]) - if not values.get(u'title') or not values.get(u'body'): - patches = yield handler.parse(data, values.get(FIELD_DATA_TYPE)) - commits_msg = patches[-1][self.META_COMMIT_MSG] - msg_lines = commits_msg.splitlines() - if not values.get(u'title'): - values[u'title'] = msg_lines[0] - if not values.get(u'body'): - values[u'body'] = u'\n'.join(msg_lines[1:]) - - values[FIELD_DATA] = data + values[FIELD_DATA] = data item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns=NS_MERGE_REQUESTS) defer.returnValue(item_id)