annotate sat/plugins/plugin_misc_merge_requests.py @ 2617:81b70eeb710f

quick_frontend(contact list): refactored update: update is now called with appropriate constant value (C.UPDATE_ADD, C.UPDATE_DELETE, C.UPDATE_MODIFY and so on) when a widget change visibility according to current options. Before it was linked to cache only (C.UPDATE_ADD was only called when contact was first added to cache). This make widget handling in frontends more easy. Renamed entityToShow to entityVisible, which seems to correspond better. Started reducing lines lenght to 90 chars as a test. May become the new coding style soon.
author Goffi <goffi@goffi.org>
date Sun, 24 Jun 2018 21:59:29 +0200
parents 700327fa9281
children 8fb99ed47db4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for Pubsub Schemas
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2473
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core import exceptions
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat.core.log import getLogger
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 log = getLogger(__name__)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 NS_MERGE_REQUESTS = 'org.salut-a-toi.merge_requests:0'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 PLUGIN_INFO = {
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 C.PI_NAME: _("Merge requests management"),
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_IMPORT_NAME: "MERGE_REQUESTS",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_TYPE: "EXP",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_MAIN: "MergeRequests",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_HANDLER: "no",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_DESCRIPTION: _("""Merge requests management plugin""")
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 }
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 FIELD_DATA_TYPE = u'type'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 FIELD_DATA = u'request_data'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 MergeRequestHandler = namedtuple("MergeRequestHandler", ['name',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 'handler',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 'data_types',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 'short_desc',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 'priority'])
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 class MergeRequests(object):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 META_AUTHOR = u'author'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 META_EMAIL = u'email'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 META_TIMESTAMP = u'timestamp'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 META_HASH = u'hash'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 META_PARENT_HASH = u'parent_hash'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 META_COMMIT_MSG = u'commit_msg'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 META_DIFF = u'diff'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 # index of the diff in the whole data
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 # needed to retrieve comments location
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 META_DIFF_IDX = u'diff_idx'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def __init__(self, host):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 log.info(_(u"Merge requests plugin initialization"))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.host = host
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 host.registerNamespace('merge_requests', NS_MERGE_REQUESTS)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self._p = self.host.plugins["XEP-0060"]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self._handlers = {}
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self._handlers_list = [] # handlers sorted by priority
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self._type_handlers = {} # data type => handler map
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 host.bridge.addMethod("mergeRequestsGet", ".plugin",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 in_sign='ssiassa{ss}s', out_sign='(asa{ss}aaa{ss})',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 method=self._get,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 async=True
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 )
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 host.bridge.addMethod("mergeRequestSet", ".plugin",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 in_sign='ssssa{sas}ssa{ss}s', out_sign='s',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 method=self._set,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 async=True)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 host.bridge.addMethod("mergeRequestsSchemaGet", ".plugin",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 in_sign='sss', out_sign='s',
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
87 method=utils.partial(self._s._getUISchema, default_node=NS_MERGE_REQUESTS),
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 async=True)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 host.bridge.addMethod("mergeRequestParseData", ".plugin",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 in_sign='ss', out_sign='aa{ss}',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 method=self._parseData,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 async=True)
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
93 host.bridge.addMethod("mergeRequestsImport", ".plugin",
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
94 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
95 method=self._import,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
96 async=True
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
97 )
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 def register(self, name, handler, data_types, short_desc, priority=0):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 """register an merge request handler
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 @param name(unicode): name of the handler
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 @param handler(object): instance of the handler.
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 It must have the following methods, which may all return a Deferred:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 - check(repository): True if repository can be handled
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 - export(repository): return export data, i.e. the patches
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 - parse(export_data): parse report data and return a list of dict (1 per patch) with:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 - title: title of the commit message (first line)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 - body: body of the commit message
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 @aram data_types(list[unicode]): data types that his handler can generate or parse
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 """
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if name in self._handlers:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 raise exceptions.ConflictError(_(u"a handler with name {name} already exists!").format(
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 name = name))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self._handlers[name] = MergeRequestHandler(name,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 handler,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 data_types,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 short_desc,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 priority)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self._handlers_list.append(name)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 self._handlers_list.sort(key=lambda name: self._handlers[name].priority)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 if isinstance(data_types, basestring):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 data_types = [data_types]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 for data_type in data_types:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 if data_type in self._type_handlers:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 log.warning(_(u'merge requests of type {type} are already handled by {old_handler}, '
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 u'ignoring {new_handler}').format(
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 type = data_type,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 old_handler = self._type_handlers[data_type].name,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 new_handler = name))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 continue
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self._type_handlers[data_type] = self._handlers[name]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 if extra_dict and 'parse' in extra_dict:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 extra_dict['parse'] = C.bool(extra_dict['parse'])
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
137 client, service, node, max_items, extra, sub_id = self._s.prepareBridgeGet(service, node, max_items, sub_id, extra_dict, profile_key)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 d = self.get(client, service, node or None, max_items, item_ids, sub_id or None, extra.rsm_request, extra.extra)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 d.addCallback(lambda (tickets, metadata, parsed_patches): (
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 self._p.serItemsData((tickets, metadata)) +
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 ([[{key: unicode(value) for key, value in p.iteritems()}
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 for p in patches] for patches in parsed_patches],)))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 return d
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 @defer.inlineCallbacks
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 def get(self, client, service=None, node=None, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 """Retrieve merge requests and convert them to XMLUI
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 @param extra(XEP-0060.parse, None): can have following keys:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 - update(bool): if True, will return list of parsed request data
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 other params are the same as for [TICKETS._get]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 @return (tuple[list[unicode], list[dict[unicode, unicode]])): tuple with
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 - 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
154 - node metadata
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 - list of parsed request data (if extra['parse'] is set, else empty list)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 """
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 if not node:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 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
159 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
160 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
161 # 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
162 # 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
163 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
164 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
165 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
166 filters = {}
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
167 tickets_xmlui, metadata = yield self._s.getDataFormItems(
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
168 client,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
169 service,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
170 node,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
171 max_items=max_items,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
172 item_ids=item_ids,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
173 sub_id=sub_id,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
174 rsm_request=rsm_request,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
175 extra=extra,
2546
48820e4a1f8a plugin merge-requests: fixed labels (they were using textbox instead of list)
Goffi <goffi@goffi.org>
parents: 2544
diff changeset
176 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
177 filters = filters)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 parsed_patches = []
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 if extra.get('parse', False):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 for ticket in tickets_xmlui:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 request_type = ticket.named_widgets[FIELD_DATA_TYPE].value
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 request_data = ticket.named_widgets[FIELD_DATA].value
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 parsed_data = yield self.parseData(request_type, request_data)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 parsed_patches.append(parsed_data)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 defer.returnValue((tickets_xmlui, metadata, parsed_patches))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
186
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 def _set(self, service, node, repository, method, values, schema=None, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE):
2472
3f0a3a0ed290 plugins tickets, merge-requests: fixed call of prepareBridgeSet
Goffi <goffi@goffi.org>
parents: 2471
diff changeset
188 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(service, node, schema, item_id, extra, profile_key)
3f0a3a0ed290 plugins tickets, merge-requests: fixed call of prepareBridgeSet
Goffi <goffi@goffi.org>
parents: 2471
diff changeset
189 d = self.set(client, service, node, repository, method, values, schema, item_id, extra, deserialise=True)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 d.addCallback(lambda ret: ret or u'')
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 return d
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 @defer.inlineCallbacks
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 def set(self, client, service, node, repository, method=u'auto', values=None, schema=None, item_id=None, extra=None, deserialise=False):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 """Publish a tickets
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 @param service(None, jid.JID): Pubsub service to use
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 @param node(unicode, None): Pubsub node to use
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 None to use default tickets node
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 @param repository(unicode): path to the repository where the code stands
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 @param method(unicode): name of one of the registered handler, or "auto" to try autodetection.
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 other arguments are same as for [TICKETS.set]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 @return (unicode): id of the created item
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 """
2473
447c3de6b9e5 plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents: 2472
diff changeset
205 if not node:
447c3de6b9e5 plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents: 2472
diff changeset
206 node = NS_MERGE_REQUESTS
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 if values is None:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 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
209 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
210 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
211 # 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
212 # 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
213 raise exceptions.DataError(_(u"repository must be specified"))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 if FIELD_DATA in values:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 raise exceptions.DataError(_(u"{field} is set by backend, you must not set it in frontend").format(
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 field = FIELD_DATA))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218
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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 else:
700327fa9281 plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents: 2603
diff changeset
228 log.warning(_(u"repository {path} can't be handled by any installed handler").format(
700327fa9281 plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents: 2603
diff changeset
229 path = 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
230 raise exceptions.NotFound(_(u"no handler for this repository has been found"))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 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
232 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
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 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
235 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
236
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 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
238 if not data.strip():
700327fa9281 plugin merge-requests: allow to set empty repository when "update" is set in extra parameters:
Goffi <goffi@goffi.org>
parents: 2603
diff changeset
239 raise exceptions.DataError(_(u'export data is empty, do you have any change to send?'))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240
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 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
242 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
243 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
244 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
245 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
246 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
247 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
248 values[u'body'] = u'\n'.join(msg_lines[1:])
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
249
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
250 values[FIELD_DATA] = data
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251
2473
447c3de6b9e5 plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents: 2472
diff changeset
252 item_id = yield self._t.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns=NS_MERGE_REQUESTS)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 defer.returnValue(item_id)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 def _parseData(self, data_type, data):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 d = self.parseData(data_type, data)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 d.addCallback(lambda parsed_patches:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 {key: unicode(value) for key, value in parsed_patches.iteritems()})
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 return d
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 def parseData(self, data_type, data):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 """Parse a merge request data according to type
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 @param data_type(unicode): type of the data to parse
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 @param data(unicode): data to parse
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 @return(list[dict[unicode, unicode]]): parsed data
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 key of dictionary are self.META_* or keys specifics to handler
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 @raise NotFound: no handler can parse this data_type
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 """
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 try:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 handler = self._type_handlers[data_type]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 except KeyError:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 raise exceptions.NotFound(_(u'No handler can handle data type "{type}"').format(type=data_type))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 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
275
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
276 def _import(self, repository, item_id, service=None, node=None, extra=None, profile_key=C.PROF_KEY_NONE):
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
277 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
278 service = jid.JID(service) if service else None
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
279 d = self.import_request(client, repository, item_id, service, node or None, extra=extra or None)
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
280 return d
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
281
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
282 @defer.inlineCallbacks
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
283 def import_request(self, client, repository, item, service=None, node=None, extra=None):
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
284 """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
285
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
286 @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
287 """
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
288 if not node:
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
289 node = NS_MERGE_REQUESTS
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
290 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
291 client,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
292 service,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
293 node,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
294 max_items=1,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
295 item_ids=[item],
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
296 form_ns=NS_MERGE_REQUESTS)
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
297 ticket_xmlui = tickets_xmlui[0]
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
298 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
299 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
300 try:
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
301 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
302 except KeyError:
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
303 raise exceptions.NotFound(_(u'No handler found to import {data_type}').format(data_type=data_type))
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
304 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
305 item_id = item,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
306 name = handler.name))
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
307 yield handler.handler.import_(repository, data, data_type, item, service, node, extra)