Mercurial > libervia-backend
comparison sat/plugins/plugin_merge_req_mercurial.py @ 2623:49533de4540b
plugin merge request (mercurial): clean item_id for import (some chars are not accepted in name)
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 07:51:29 +0200 |
parents | 2f75830a8228 |
children | 163aab916bcf |
comparison
equal
deleted
inserted
replaced
2622:8fb99ed47db4 | 2623:49533de4540b |
---|---|
37 C.PI_HANDLER: "no", | 37 C.PI_HANDLER: "no", |
38 C.PI_DESCRIPTION: _(u"""Merge request handler for Mercurial""") | 38 C.PI_DESCRIPTION: _(u"""Merge request handler for Mercurial""") |
39 } | 39 } |
40 | 40 |
41 SHORT_DESC = D_(u"handle Mercurial repository") | 41 SHORT_DESC = D_(u"handle Mercurial repository") |
42 CLEAN_RE = re.compile(ur'[^\w -._]', flags=re.UNICODE) | |
42 | 43 |
43 | 44 |
44 class MercurialProtocol(protocol.ProcessProtocol): | 45 class MercurialProtocol(protocol.ProcessProtocol): |
45 """handle hg commands""" | 46 """handle hg commands""" |
46 hg = None | 47 hg = None |
130 | 131 |
131 def import_(self, repository, data, data_type, item_id, service, node, extra): | 132 def import_(self, repository, data, data_type, item_id, service, node, extra): |
132 parsed_data = self.parse(data) | 133 parsed_data = self.parse(data) |
133 try: | 134 try: |
134 parsed_name = parsed_data[0][u'commit_msg'].split(u'\n')[0] | 135 parsed_name = parsed_data[0][u'commit_msg'].split(u'\n')[0] |
135 parsed_name = re.sub(ur'[^\w -.:]', u'', parsed_name, flags=re.UNICODE)[:40] | 136 parsed_name = CLEAN_RE.sub(u'', parsed_name)[:40] |
136 except Exception: | 137 except Exception: |
137 parsed_name = u'' | 138 parsed_name = u'' |
138 name = u'mr_{item_id}_{parsed_name}'.format(item_id=item_id, | 139 name = u'mr_{item_id}_{parsed_name}'.format(item_id=CLEAN_RE.sub(u'', item_id), |
139 parsed_name=parsed_name) | 140 parsed_name=parsed_name) |
140 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, | 141 return MercurialProtocol.run(repository, 'qimport', '-g', '--name', name, |
141 '--encoding=utf-8', '-', stdin=data) | 142 '--encoding=utf-8', '-', stdin=data) |
142 | 143 |
143 def parse(self, data, data_type=None): | 144 def parse(self, data, data_type=None): |