Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_merge_requests.py @ 2690:56bfe1b79204
jp: new command "ping"
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 10 Nov 2018 10:16:38 +0100 |
parents | 8fb99ed47db4 |
children | 003b8b4b56a7 |
rev | line source |
---|---|
2448 | 1 #!/usr/bin/env python2 |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT plugin for Pubsub Schemas | |
2483 | 5 # Copyright (C) 2009-2018 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 |
2471
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
26 from sat.tools import utils |
2448 | 27 from sat.core.log import getLogger |
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: [], | |
2473
447c3de6b9e5
plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents:
2472
diff
changeset
|
37 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "TICKETS"], |
2448 | 38 C.PI_MAIN: "MergeRequests", |
39 C.PI_HANDLER: "no", | |
40 C.PI_DESCRIPTION: _("""Merge requests management plugin""") | |
41 } | |
42 | |
43 FIELD_DATA_TYPE = u'type' | |
44 FIELD_DATA = u'request_data' | |
45 | |
46 | |
47 MergeRequestHandler = namedtuple("MergeRequestHandler", ['name', | |
48 'handler', | |
49 'data_types', | |
50 'short_desc', | |
51 'priority']) | |
52 | |
53 | |
54 class MergeRequests(object): | |
55 META_AUTHOR = u'author' | |
56 META_EMAIL = u'email' | |
57 META_TIMESTAMP = u'timestamp' | |
58 META_HASH = u'hash' | |
59 META_PARENT_HASH = u'parent_hash' | |
60 META_COMMIT_MSG = u'commit_msg' | |
61 META_DIFF = u'diff' | |
62 # index of the diff in the whole data | |
63 # needed to retrieve comments location | |
64 META_DIFF_IDX = u'diff_idx' | |
65 | |
66 def __init__(self, host): | |
67 log.info(_(u"Merge requests plugin initialization")) | |
68 self.host = host | |
69 host.registerNamespace('merge_requests', NS_MERGE_REQUESTS) | |
70 self._p = self.host.plugins["XEP-0060"] | |
71 self._s = self.host.plugins["PUBSUB_SCHEMA"] | |
2473
447c3de6b9e5
plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents:
2472
diff
changeset
|
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, | |
79 async=True | |
80 ) | |
81 host.bridge.addMethod("mergeRequestSet", ".plugin", | |
82 in_sign='ssssa{sas}ssa{ss}s', out_sign='s', | |
83 method=self._set, | |
84 async=True) | |
85 host.bridge.addMethod("mergeRequestsSchemaGet", ".plugin", | |
86 in_sign='sss', out_sign='s', | |
2622 | 87 method=utils.partial(self._s._getUISchema, |
88 default_node=NS_MERGE_REQUESTS), | |
2448 | 89 async=True) |
90 host.bridge.addMethod("mergeRequestParseData", ".plugin", | |
91 in_sign='ss', out_sign='aa{ss}', | |
92 method=self._parseData, | |
93 async=True) | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
94 host.bridge.addMethod("mergeRequestsImport", ".plugin", |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
95 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
|
96 method=self._import, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
97 async=True |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
98 ) |
2448 | 99 |
100 def register(self, name, handler, data_types, short_desc, priority=0): | |
101 """register an merge request handler | |
102 | |
103 @param name(unicode): name of the handler | |
104 @param handler(object): instance of the handler. | |
105 It must have the following methods, which may all return a Deferred: | |
106 - check(repository): True if repository can be handled | |
107 - export(repository): return export data, i.e. the patches | |
2622 | 108 - parse(export_data): parse report data and return a list of dict |
109 (1 per patch) with: | |
2448 | 110 - title: title of the commit message (first line) |
111 - body: body of the commit message | |
112 @aram data_types(list[unicode]): data types that his handler can generate or parse | |
113 """ | |
114 if name in self._handlers: | |
2622 | 115 raise exceptions.ConflictError(_(u"a handler with name {name} already " |
116 u"exists!").format(name = name)) | |
2448 | 117 self._handlers[name] = MergeRequestHandler(name, |
118 handler, | |
119 data_types, | |
120 short_desc, | |
121 priority) | |
122 self._handlers_list.append(name) | |
123 self._handlers_list.sort(key=lambda name: self._handlers[name].priority) | |
124 if isinstance(data_types, basestring): | |
125 data_types = [data_types] | |
126 for data_type in data_types: | |
127 if data_type in self._type_handlers: | |
2622 | 128 log.warning(_(u'merge requests of type {type} are already handled by ' |
129 u'{old_handler}, ignoring {new_handler}').format( | |
130 type = data_type, | |
2448 | 131 old_handler = self._type_handlers[data_type].name, |
132 new_handler = name)) | |
133 continue | |
134 self._type_handlers[data_type] = self._handlers[name] | |
135 | |
2622 | 136 def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, |
137 extra_dict=None, profile_key=C.PROF_KEY_NONE): | |
2448 | 138 if extra_dict and 'parse' in extra_dict: |
139 extra_dict['parse'] = C.bool(extra_dict['parse']) | |
2622 | 140 client, service, node, max_items, extra, sub_id = self._s.prepareBridgeGet( |
141 service, node, max_items, sub_id, extra_dict, profile_key) | |
142 d = self.get(client, service, node or None, max_items, item_ids, sub_id or None, | |
143 extra.rsm_request, extra.extra) | |
2448 | 144 d.addCallback(lambda (tickets, metadata, parsed_patches): ( |
145 self._p.serItemsData((tickets, metadata)) + | |
146 ([[{key: unicode(value) for key, value in p.iteritems()} | |
147 for p in patches] for patches in parsed_patches],))) | |
148 return d | |
149 | |
150 @defer.inlineCallbacks | |
2622 | 151 def get(self, client, service=None, node=None, max_items=None, item_ids=None, |
152 sub_id=None, rsm_request=None, extra=None): | |
2448 | 153 """Retrieve merge requests and convert them to XMLUI |
154 | |
155 @param extra(XEP-0060.parse, None): can have following keys: | |
156 - update(bool): if True, will return list of parsed request data | |
157 other params are the same as for [TICKETS._get] | |
158 @return (tuple[list[unicode], list[dict[unicode, unicode]])): tuple with | |
159 - 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
|
160 - node metadata |
2448 | 161 - list of parsed request data (if extra['parse'] is set, else empty list) |
162 """ | |
163 if not node: | |
164 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
|
165 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
|
166 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
|
167 # 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
|
168 # 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
|
169 if C.bool(extra.get('labels_as_list', C.BOOL_FALSE)): |
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 filters = {u'labels': self._s.textbox2ListFilter} |
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 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
|
172 filters = {} |
2471
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
173 tickets_xmlui, metadata = yield self._s.getDataFormItems( |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
174 client, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
175 service, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
176 node, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
177 max_items=max_items, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
178 item_ids=item_ids, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
179 sub_id=sub_id, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
180 rsm_request=rsm_request, |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2448
diff
changeset
|
181 extra=extra, |
2546
48820e4a1f8a
plugin merge-requests: fixed labels (they were using textbox instead of list)
Goffi <goffi@goffi.org>
parents:
2544
diff
changeset
|
182 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
|
183 filters = filters) |
2448 | 184 parsed_patches = [] |
185 if extra.get('parse', False): | |
186 for ticket in tickets_xmlui: | |
187 request_type = ticket.named_widgets[FIELD_DATA_TYPE].value | |
188 request_data = ticket.named_widgets[FIELD_DATA].value | |
189 parsed_data = yield self.parseData(request_type, request_data) | |
190 parsed_patches.append(parsed_data) | |
191 defer.returnValue((tickets_xmlui, metadata, parsed_patches)) | |
192 | |
2622 | 193 def _set(self, service, node, repository, method, values, schema=None, item_id=None, |
194 extra=None, profile_key=C.PROF_KEY_NONE): | |
195 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( | |
196 service, node, schema, item_id, extra, profile_key) | |
197 d = self.set(client, service, node, repository, method, values, schema, item_id, | |
198 extra, deserialise=True) | |
2448 | 199 d.addCallback(lambda ret: ret or u'') |
200 return d | |
201 | |
202 @defer.inlineCallbacks | |
2622 | 203 def set(self, client, service, node, repository, method=u'auto', values=None, |
204 schema=None, item_id=None, extra=None, deserialise=False): | |
2448 | 205 """Publish a tickets |
206 | |
207 @param service(None, jid.JID): Pubsub service to use | |
208 @param node(unicode, None): Pubsub node to use | |
209 None to use default tickets node | |
210 @param repository(unicode): path to the repository where the code stands | |
2622 | 211 @param method(unicode): name of one of the registered handler, |
212 or "auto" to try autodetection. | |
2448 | 213 other arguments are same as for [TICKETS.set] |
214 @return (unicode): id of the created item | |
215 """ | |
2473
447c3de6b9e5
plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents:
2472
diff
changeset
|
216 if not node: |
447c3de6b9e5
plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents:
2472
diff
changeset
|
217 node = NS_MERGE_REQUESTS |
2448 | 218 if values is None: |
219 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
|
220 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
|
221 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
|
222 # 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
|
223 # so repository is not mandatory |
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 raise exceptions.DataError(_(u"repository must be specified")) |
2448 | 225 |
226 if FIELD_DATA in values: | |
2622 | 227 raise exceptions.DataError(_(u"{field} is set by backend, you must not set " |
228 u"it in frontend").format(field = FIELD_DATA)) | |
2448 | 229 |
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
|
230 if 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
|
231 if method == u'auto': |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
232 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
|
233 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
|
234 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
|
235 if can_handle: |
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 log.info(_(u"{name} handler will be used").format(name=name)) |
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 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
|
238 else: |
2622 | 239 log.warning(_(u"repository {path} can't be handled by any installed " |
240 u"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
|
241 path = repository)) |
2622 | 242 raise exceptions.NotFound(_(u"no handler for this repository has " |
243 u"been found")) | |
2448 | 244 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
|
245 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
|
246 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
|
247 except KeyError: |
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 raise exceptions.NotFound(_(u"No handler of this name found")) |
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 |
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 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
|
251 if not data.strip(): |
2622 | 252 raise exceptions.DataError(_(u'export data is empty, do you have any ' |
253 u'change to send?')) | |
2448 | 254 |
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
|
255 if not values.get(u'title') or not values.get(u'body'): |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
256 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
|
257 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
|
258 msg_lines = commits_msg.splitlines() |
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 if not values.get(u'title'): |
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 values[u'title'] = msg_lines[0] |
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 if not values.get(u'body'): |
700327fa9281
plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
262 values[u'body'] = u'\n'.join(msg_lines[1:]) |
2448 | 263 |
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
|
264 values[FIELD_DATA] = data |
2448 | 265 |
2622 | 266 item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, |
267 deserialise, form_ns=NS_MERGE_REQUESTS) | |
2448 | 268 defer.returnValue(item_id) |
269 | |
270 def _parseData(self, data_type, data): | |
271 d = self.parseData(data_type, data) | |
272 d.addCallback(lambda parsed_patches: | |
273 {key: unicode(value) for key, value in parsed_patches.iteritems()}) | |
274 return d | |
275 | |
276 def parseData(self, data_type, data): | |
277 """Parse a merge request data according to type | |
278 | |
279 @param data_type(unicode): type of the data to parse | |
280 @param data(unicode): data to parse | |
281 @return(list[dict[unicode, unicode]]): parsed data | |
282 key of dictionary are self.META_* or keys specifics to handler | |
283 @raise NotFound: no handler can parse this data_type | |
284 """ | |
285 try: | |
286 handler = self._type_handlers[data_type] | |
287 except KeyError: | |
2622 | 288 raise exceptions.NotFound(_(u'No handler can handle data type "{type}"') |
289 .format(type=data_type)) | |
2448 | 290 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
|
291 |
2622 | 292 def _import(self, repository, item_id, service=None, node=None, extra=None, |
293 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
|
294 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
|
295 service = jid.JID(service) if service else None |
2622 | 296 d = self.import_request(client, repository, item_id, service, node or None, |
297 extra=extra or None) | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
298 return d |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
299 |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
300 @defer.inlineCallbacks |
2622 | 301 def import_request(self, client, repository, item, service=None, node=None, |
302 extra=None): | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
303 """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
|
304 |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
305 @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
|
306 """ |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
307 if not node: |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
308 node = NS_MERGE_REQUESTS |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
309 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
|
310 client, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
311 service, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
312 node, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
313 max_items=1, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
314 item_ids=[item], |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
315 form_ns=NS_MERGE_REQUESTS) |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
316 ticket_xmlui = tickets_xmlui[0] |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
317 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
|
318 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
|
319 try: |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
320 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
|
321 except KeyError: |
2622 | 322 raise exceptions.NotFound(_(u'No handler found to import {data_type}') |
323 .format(data_type=data_type)) | |
2544
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
324 log.info(_(u"Importing patch [{item_id}] using {name} handler").format( |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
325 item_id = item, |
a64887289931
plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents:
2541
diff
changeset
|
326 name = handler.name)) |
2622 | 327 yield handler.handler.import_(repository, data, data_type, item, service, node, |
328 extra) |