Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_merge_requests.py @ 3156:0318802dfe28
core (memory/disco): fixed checkFeature return Failure:
it seems that instanciating a Failure with a class name is not working anymore, so the
exceptions.FeatureNotFound is instanciated now.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2020 19:59:42 +0100 |
parents | 559a625a236b |
children | 71761e9fb984 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2448 | 3 |
4 # SAT plugin for Pubsub Schemas | |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
2448 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.i18n import _ | |
21 from sat.core.constants import Const as C | |
22 from sat.core import exceptions | |
23 from twisted.internet import defer | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
24 from twisted.words.protocols.jabber import jid |
2448 | 25 from collections import namedtuple |
26 from sat.core.log import getLogger | |
3028 | 27 |
2448 | 28 log = getLogger(__name__) |
29 | |
30 NS_MERGE_REQUESTS = 'org.salut-a-toi.merge_requests:0' | |
31 | |
32 PLUGIN_INFO = { | |
33 C.PI_NAME: _("Merge requests management"), | |
34 C.PI_IMPORT_NAME: "MERGE_REQUESTS", | |
35 C.PI_TYPE: "EXP", | |
36 C.PI_PROTOCOLS: [], | |
2785
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
37 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "TICKETS", "TEXT_SYNTAXES"], |
2448 | 38 C.PI_MAIN: "MergeRequests", |
39 C.PI_HANDLER: "no", | |
40 C.PI_DESCRIPTION: _("""Merge requests management plugin""") | |
41 } | |
42 | |
3028 | 43 FIELD_DATA_TYPE = 'type' |
44 FIELD_DATA = 'request_data' | |
2448 | 45 |
46 | |
47 MergeRequestHandler = namedtuple("MergeRequestHandler", ['name', | |
48 'handler', | |
49 'data_types', | |
50 'short_desc', | |
51 'priority']) | |
52 | |
53 | |
54 class MergeRequests(object): | |
3028 | 55 META_AUTHOR = 'author' |
56 META_EMAIL = 'email' | |
57 META_TIMESTAMP = 'timestamp' | |
58 META_HASH = 'hash' | |
59 META_PARENT_HASH = 'parent_hash' | |
60 META_COMMIT_MSG = 'commit_msg' | |
61 META_DIFF = 'diff' | |
2448 | 62 # index of the diff in the whole data |
63 # needed to retrieve comments location | |
3028 | 64 META_DIFF_IDX = 'diff_idx' |
2448 | 65 |
66 def __init__(self, host): | |
3028 | 67 log.info(_("Merge requests plugin initialization")) |
2448 | 68 self.host = host |
69 host.registerNamespace('merge_requests', NS_MERGE_REQUESTS) | |
3028 | 70 self._p = self.host.plugins["XEP-0060"] |
71 self._s = self.host.plugins["PUBSUB_SCHEMA"] | |
72 self._t = self.host.plugins["TICKETS"] | |
2448 | 73 self._handlers = {} |
74 self._handlers_list = [] # handlers sorted by priority | |
75 self._type_handlers = {} # data type => handler map | |
76 host.bridge.addMethod("mergeRequestsGet", ".plugin", | |
77 in_sign='ssiassa{ss}s', out_sign='(asa{ss}aaa{ss})', | |
78 method=self._get, | |
3028 | 79 async_=True |
2448 | 80 ) |
81 host.bridge.addMethod("mergeRequestSet", ".plugin", | |
2959
989b622faff6
plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents:
2910
diff
changeset
|
82 in_sign='ssssa{sas}ssss', out_sign='s', |
2448 | 83 method=self._set, |
3028 | 84 async_=True) |
2448 | 85 host.bridge.addMethod("mergeRequestsSchemaGet", ".plugin", |
86 in_sign='sss', out_sign='s', | |
3028 | 87 method=lambda service, nodeIdentifier, profile_key: |
88 self._s._getUISchema(service, | |
89 nodeIdentifier, | |
90 default_node=NS_MERGE_REQUESTS, | |
91 profile_key=profile_key), | |
92 async_=True) | |
2448 | 93 host.bridge.addMethod("mergeRequestParseData", ".plugin", |
94 in_sign='ss', out_sign='aa{ss}', | |
95 method=self._parseData, | |
3028 | 96 async_=True) |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
97 host.bridge.addMethod("mergeRequestsImport", ".plugin", |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
98 in_sign='ssssa{ss}s', out_sign='', |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
99 method=self._import, |
3028 | 100 async_=True |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
101 ) |
2448 | 102 |
103 def register(self, name, handler, data_types, short_desc, priority=0): | |
104 """register an merge request handler | |
105 | |
106 @param name(unicode): name of the handler | |
107 @param handler(object): instance of the handler. | |
108 It must have the following methods, which may all return a Deferred: | |
3040 | 109 - check(repository)->bool: True if repository can be handled |
110 - export(repository)->str: return export data, i.e. the patches | |
2622 | 111 - parse(export_data): parse report data and return a list of dict |
112 (1 per patch) with: | |
2448 | 113 - title: title of the commit message (first line) |
114 - body: body of the commit message | |
115 @aram data_types(list[unicode]): data types that his handler can generate or parse | |
116 """ | |
117 if name in self._handlers: | |
3028 | 118 raise exceptions.ConflictError(_("a handler with name {name} already " |
119 "exists!").format(name = name)) | |
2448 | 120 self._handlers[name] = MergeRequestHandler(name, |
121 handler, | |
122 data_types, | |
123 short_desc, | |
124 priority) | |
125 self._handlers_list.append(name) | |
126 self._handlers_list.sort(key=lambda name: self._handlers[name].priority) | |
3028 | 127 if isinstance(data_types, str): |
2448 | 128 data_types = [data_types] |
129 for data_type in data_types: | |
130 if data_type in self._type_handlers: | |
3028 | 131 log.warning(_('merge requests of type {type} are already handled by ' |
132 '{old_handler}, ignoring {new_handler}').format( | |
2622 | 133 type = data_type, |
2448 | 134 old_handler = self._type_handlers[data_type].name, |
135 new_handler = name)) | |
136 continue | |
137 self._type_handlers[data_type] = self._handlers[name] | |
138 | |
2622 | 139 def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, |
140 extra_dict=None, profile_key=C.PROF_KEY_NONE): | |
2448 | 141 if extra_dict and 'parse' in extra_dict: |
142 extra_dict['parse'] = C.bool(extra_dict['parse']) | |
2622 | 143 client, service, node, max_items, extra, sub_id = self._s.prepareBridgeGet( |
144 service, node, max_items, sub_id, extra_dict, profile_key) | |
145 d = self.get(client, service, node or None, max_items, item_ids, sub_id or None, | |
146 extra.rsm_request, extra.extra) | |
3028 | 147 d.addCallback(lambda tickets_metadata_parsed_patches: ( |
148 self._p.transItemsData((tickets_metadata_parsed_patches[0], tickets_metadata_parsed_patches[1])) + | |
149 ([[{key: str(value) for key, value in p.items()} | |
150 for p in patches] for patches in tickets_metadata_parsed_patches[2]],))) | |
2448 | 151 return d |
152 | |
153 @defer.inlineCallbacks | |
2622 | 154 def get(self, client, service=None, node=None, max_items=None, item_ids=None, |
155 sub_id=None, rsm_request=None, extra=None): | |
2448 | 156 """Retrieve merge requests and convert them to XMLUI |
157 | |
158 @param extra(XEP-0060.parse, None): can have following keys: | |
159 - update(bool): if True, will return list of parsed request data | |
160 other params are the same as for [TICKETS._get] | |
161 @return (tuple[list[unicode], list[dict[unicode, unicode]])): tuple with | |
162 - XMLUI of the tickets, like [TICKETS._get] | |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
163 - node metadata |
2448 | 164 - list of parsed request data (if extra['parse'] is set, else empty list) |
165 """ | |
166 if not node: | |
167 node = NS_MERGE_REQUESTS | |
2603
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 if extra is None: |
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 extra = {} |
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 # XXX: Q&D way to get list for labels when displaying them, but text when we |
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 # have to modify them |
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 if C.bool(extra.get('labels_as_list', C.BOOL_FALSE)): |
3028 | 173 filters = {'labels': self._s.textbox2ListFilter} |
2603
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 else: |
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
175 filters = {} |
2471
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
176 tickets_xmlui, metadata = yield self._s.getDataFormItems( |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
177 client, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
178 service, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
179 node, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
180 max_items=max_items, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
181 item_ids=item_ids, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
182 sub_id=sub_id, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
183 rsm_request=rsm_request, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
184 extra=extra, |
2546
48820e4a1f8a
plugin merge-requests: fixed labels (they were using textbox instead of list)
Goffi <goffi@goffi.org>
parents:
2544
diff
changeset
|
185 form_ns=NS_MERGE_REQUESTS, |
2603
5d4ac5415b40
plugins schema, merge-requests, tickets: convert labels from textbox to list only when "labels_as_list" is set in extra parameters.
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 filters = filters) |
2448 | 187 parsed_patches = [] |
188 if extra.get('parse', False): | |
189 for ticket in tickets_xmlui: | |
190 request_type = ticket.named_widgets[FIELD_DATA_TYPE].value | |
191 request_data = ticket.named_widgets[FIELD_DATA].value | |
192 parsed_data = yield self.parseData(request_type, request_data) | |
193 parsed_patches.append(parsed_data) | |
194 defer.returnValue((tickets_xmlui, metadata, parsed_patches)) | |
195 | |
2622 | 196 def _set(self, service, node, repository, method, values, schema=None, item_id=None, |
3028 | 197 extra="", profile_key=C.PROF_KEY_NONE): |
2622 | 198 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( |
199 service, node, schema, item_id, extra, profile_key) | |
2910
b2f323237fce
jp, plugin merge-requests: used u'' as default for item id in pubsub arguments + fixed some required arguments:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
200 d = self.set(client, service, node, repository, method, values, schema, |
b2f323237fce
jp, plugin merge-requests: used u'' as default for item id in pubsub arguments + fixed some required arguments:
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
201 item_id or None, extra, deserialise=True) |
3028 | 202 d.addCallback(lambda ret: ret or '') |
2448 | 203 return d |
204 | |
205 @defer.inlineCallbacks | |
3028 | 206 def set(self, client, service, node, repository, method='auto', values=None, |
2622 | 207 schema=None, item_id=None, extra=None, deserialise=False): |
2448 | 208 """Publish a tickets |
209 | |
210 @param service(None, jid.JID): Pubsub service to use | |
211 @param node(unicode, None): Pubsub node to use | |
212 None to use default tickets node | |
213 @param repository(unicode): path to the repository where the code stands | |
2622 | 214 @param method(unicode): name of one of the registered handler, |
215 or "auto" to try autodetection. | |
2448 | 216 other arguments are same as for [TICKETS.set] |
217 @return (unicode): id of the created item | |
218 """ | |
2473
447c3de6b9e5
plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents:
2472
diff
changeset
|
219 if not node: |
447c3de6b9e5
plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents:
2472
diff
changeset
|
220 node = NS_MERGE_REQUESTS |
2448 | 221 if values is None: |
222 values = {} | |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
223 update = extra.get('update', False) |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
224 if not repository and not update: |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
225 # in case of update, we may re-user former patches data |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
226 # so repository is not mandatory |
3028 | 227 raise exceptions.DataError(_("repository must be specified")) |
2448 | 228 |
229 if FIELD_DATA in values: | |
3028 | 230 raise exceptions.DataError(_("{field} is set by backend, you must not set " |
231 "it in frontend").format(field = FIELD_DATA)) | |
2448 | 232 |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
233 if repository: |
3028 | 234 if method == 'auto': |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
235 for name in self._handlers_list: |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
236 handler = self._handlers[name].handler |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
237 can_handle = yield handler.check(repository) |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
238 if can_handle: |
3028 | 239 log.info(_("{name} handler will be used").format(name=name)) |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
240 break |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
241 else: |
3028 | 242 log.warning(_("repository {path} can't be handled by any installed " |
243 "handler").format( | |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
244 path = repository)) |
3028 | 245 raise exceptions.NotFound(_("no handler for this repository has " |
246 "been found")) | |
2448 | 247 else: |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
248 try: |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
249 handler = self._handlers[name].handler |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
250 except KeyError: |
3028 | 251 raise exceptions.NotFound(_("No handler of this name found")) |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
252 |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
253 data = yield handler.export(repository) |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
254 if not data.strip(): |
3028 | 255 raise exceptions.DataError(_('export data is empty, do you have any ' |
256 'change to send?')) | |
2448 | 257 |
3028 | 258 if not values.get('title') or not values.get('body'): |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
259 patches = yield handler.parse(data, values.get(FIELD_DATA_TYPE)) |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
260 commits_msg = patches[-1][self.META_COMMIT_MSG] |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
261 msg_lines = commits_msg.splitlines() |
3028 | 262 if not values.get('title'): |
263 values['title'] = msg_lines[0] | |
264 if not values.get('body'): | |
2785
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
265 ts = self.host.plugins['TEXT_SYNTAXES'] |
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
266 xhtml = yield ts.convert( |
3028 | 267 '\n'.join(msg_lines[1:]), |
2785
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
268 syntax_from = ts.SYNTAX_TEXT, |
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
269 syntax_to = ts.SYNTAX_XHTML, |
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
270 profile = client.profile) |
3028 | 271 values['body'] = '<div xmlns="{ns}">{xhtml}</div>'.format( |
2785
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
272 ns=C.NS_XHTML, xhtml=xhtml) |
2448 | 273 |
2604
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
274 values[FIELD_DATA] = data |
2448 | 275 |
2622 | 276 item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, |
277 deserialise, form_ns=NS_MERGE_REQUESTS) | |
2448 | 278 defer.returnValue(item_id) |
279 | |
280 def _parseData(self, data_type, data): | |
281 d = self.parseData(data_type, data) | |
282 d.addCallback(lambda parsed_patches: | |
3028 | 283 {key: str(value) for key, value in parsed_patches.items()}) |
2448 | 284 return d |
285 | |
286 def parseData(self, data_type, data): | |
287 """Parse a merge request data according to type | |
288 | |
289 @param data_type(unicode): type of the data to parse | |
290 @param data(unicode): data to parse | |
291 @return(list[dict[unicode, unicode]]): parsed data | |
292 key of dictionary are self.META_* or keys specifics to handler | |
293 @raise NotFound: no handler can parse this data_type | |
294 """ | |
295 try: | |
296 handler = self._type_handlers[data_type] | |
297 except KeyError: | |
3028 | 298 raise exceptions.NotFound(_('No handler can handle data type "{type}"') |
2622 | 299 .format(type=data_type)) |
2448 | 300 return defer.maybeDeferred(handler.handler.parse, data, data_type) |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
301 |
2622 | 302 def _import(self, repository, item_id, service=None, node=None, extra=None, |
303 profile_key=C.PROF_KEY_NONE): | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
304 client = self.host.getClient(profile_key) |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
305 service = jid.JID(service) if service else None |
2622 | 306 d = self.import_request(client, repository, item_id, service, node or None, |
307 extra=extra or None) | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
308 return d |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
309 |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
310 @defer.inlineCallbacks |
2622 | 311 def import_request(self, client, repository, item, service=None, node=None, |
312 extra=None): | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
313 """Import a merge request in specified directory |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
314 |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
315 @param repository(unicode): path to the repository where the code stands |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
316 """ |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
317 if not node: |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
318 node = NS_MERGE_REQUESTS |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
319 tickets_xmlui, metadata = yield self._s.getDataFormItems( |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
320 client, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
321 service, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
322 node, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
323 max_items=1, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
324 item_ids=[item], |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
325 form_ns=NS_MERGE_REQUESTS) |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
326 ticket_xmlui = tickets_xmlui[0] |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
327 data = ticket_xmlui.named_widgets[FIELD_DATA].value |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
328 data_type = ticket_xmlui.named_widgets[FIELD_DATA_TYPE].value |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
329 try: |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
330 handler = self._type_handlers[data_type] |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
331 except KeyError: |
3028 | 332 raise exceptions.NotFound(_('No handler found to import {data_type}') |
2622 | 333 .format(data_type=data_type)) |
3028 | 334 log.info(_("Importing patch [{item_id}] using {name} handler").format( |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
335 item_id = item, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
336 name = handler.name)) |
2622 | 337 yield handler.handler.import_(repository, data, data_type, item, service, node, |
338 extra) |