Mercurial > libervia-backend
comparison src/plugins/plugin_merge_req_mercurial.py @ 2559:1362cabad225
plugin merge-request mercurial: better name sanitization for import
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 08:45:08 +0200 |
parents | a64887289931 |
children | 6a31c67c562f |
comparison
equal
deleted
inserted
replaced
2558:501b0f827f63 | 2559:1362cabad225 |
---|---|
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core import exceptions | 22 from sat.core import exceptions |
23 from twisted.internet import reactor, defer, protocol | 23 from twisted.internet import reactor, defer, protocol |
24 from twisted.python.failure import Failure | 24 from twisted.python.failure import Failure |
25 from twisted.python.procutils import which | 25 from twisted.python.procutils import which |
26 import re | |
26 from sat.core.log import getLogger | 27 from sat.core.log import getLogger |
27 log = getLogger(__name__) | 28 log = getLogger(__name__) |
28 | 29 |
29 | 30 |
30 PLUGIN_INFO = { | 31 PLUGIN_INFO = { |
128 | 129 |
129 def import_(self, repository, data, data_type, item_id, service, node, extra): | 130 def import_(self, repository, data, data_type, item_id, service, node, extra): |
130 parsed_data = self.parse(data) | 131 parsed_data = self.parse(data) |
131 try: | 132 try: |
132 parsed_name = parsed_data[0][u'commit_msg'].split(u'\n')[0] | 133 parsed_name = parsed_data[0][u'commit_msg'].split(u'\n')[0] |
133 parsed_name = parsed_name.replace(u' ', u'_')[:20] | 134 parsed_name = re.sub(ur'[^\w-]', u'', parsed_name, flags=re.UNICODE)[:20] |
134 except Exception: | 135 except Exception: |
135 parsed_name = u'' | 136 parsed_name = u'' |
136 name = u'mr_{item_id}_{parsed_name}'.format(item_id=item_id, parsed_name=parsed_name) | 137 name = u'mr_{item_id}_{parsed_name}'.format(item_id=item_id, parsed_name=parsed_name) |
137 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, '--encoding=utf-8', '-', stdin=data) | 138 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, '--encoding=utf-8', '-', stdin=data) |
138 | 139 |