annotate sat/plugins/plugin_misc_merge_requests.py @ 3375:b41ed8d9d40b

i18n: renamed template file to get the correct '.pot' extension
author Goffi <goffi@goffi.org>
date Mon, 28 Sep 2020 21:10:33 +0200
parents 71761e9fb984
children bb0225aaf4e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2448
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
3136
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
5 # Copyright (C) 2009-2020 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
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
20 from collections import namedtuple
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
21 from twisted.internet import defer
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
22 from twisted.words.protocols.jabber import jid
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core.constants import Const as C
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core import exceptions
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
26 from sat.tools.common import data_format
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat.core.log import getLogger
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
28
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
29
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 log = getLogger(__name__)
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 NS_MERGE_REQUESTS = 'org.salut-a-toi.merge_requests:0'
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 PLUGIN_INFO = {
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_NAME: _("Merge requests management"),
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_IMPORT_NAME: "MERGE_REQUESTS",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_TYPE: "EXP",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_PROTOCOLS: [],
2785
f18d8315929e merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
39 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "TICKETS", "TEXT_SYNTAXES"],
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_MAIN: "MergeRequests",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_HANDLER: "no",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_DESCRIPTION: _("""Merge requests management plugin""")
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 }
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
45 FIELD_DATA_TYPE = 'type'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
46 FIELD_DATA = 'request_data'
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 MergeRequestHandler = namedtuple("MergeRequestHandler", ['name',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 'handler',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 'data_types',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 'short_desc',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 'priority'])
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 class MergeRequests(object):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
57 META_AUTHOR = 'author'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
58 META_EMAIL = 'email'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
59 META_TIMESTAMP = 'timestamp'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
60 META_HASH = 'hash'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
61 META_PARENT_HASH = 'parent_hash'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
62 META_COMMIT_MSG = 'commit_msg'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
63 META_DIFF = 'diff'
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 # index of the diff in the whole data
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 # needed to retrieve comments location
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
66 META_DIFF_IDX = 'diff_idx'
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
69 log.info(_("Merge requests plugin initialization"))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.host = host
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 host.registerNamespace('merge_requests', NS_MERGE_REQUESTS)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
72 self._p = self.host.plugins["XEP-0060"]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
73 self._s = self.host.plugins["PUBSUB_SCHEMA"]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
74 self._t = self.host.plugins["TICKETS"]
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self._handlers = {}
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self._handlers_list = [] # handlers sorted by priority
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self._type_handlers = {} # data type => handler map
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 host.bridge.addMethod("mergeRequestsGet", ".plugin",
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
79 in_sign='ssiassa{ss}s', out_sign='s',
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 method=self._get,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
81 async_=True
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 )
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 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
84 in_sign='ssssa{sas}ssss', out_sign='s',
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 method=self._set,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
86 async_=True)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 host.bridge.addMethod("mergeRequestsSchemaGet", ".plugin",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 in_sign='sss', out_sign='s',
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
89 method=lambda service, nodeIdentifier, profile_key:
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
90 self._s._getUISchema(service,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
91 nodeIdentifier,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
92 default_node=NS_MERGE_REQUESTS,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
93 profile_key=profile_key),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
94 async_=True)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 host.bridge.addMethod("mergeRequestParseData", ".plugin",
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 in_sign='ss', out_sign='aa{ss}',
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 method=self._parseData,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
98 async_=True)
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
99 host.bridge.addMethod("mergeRequestsImport", ".plugin",
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
100 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
101 method=self._import,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
102 async_=True
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
103 )
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 def register(self, name, handler, data_types, short_desc, priority=0):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 """register an merge request handler
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 @param name(unicode): name of the handler
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 @param handler(object): instance of the handler.
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 It must have the following methods, which may all return a Deferred:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
111 - check(repository)->bool: True if repository can be handled
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
112 - export(repository)->str: return export data, i.e. the patches
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
113 - parse(export_data): parse report data and return a list of dict
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
114 (1 per patch) with:
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 - title: title of the commit message (first line)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 - body: body of the commit message
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 @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
118 """
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 if name in self._handlers:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
120 raise exceptions.ConflictError(_("a handler with name {name} already "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
121 "exists!").format(name = name))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self._handlers[name] = MergeRequestHandler(name,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 handler,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 data_types,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 short_desc,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 priority)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 self._handlers_list.append(name)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 self._handlers_list.sort(key=lambda name: self._handlers[name].priority)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
129 if isinstance(data_types, str):
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 data_types = [data_types]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 for data_type in data_types:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if data_type in self._type_handlers:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
133 log.warning(_('merge requests of type {type} are already handled by '
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
134 '{old_handler}, ignoring {new_handler}').format(
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
135 type = data_type,
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 old_handler = self._type_handlers[data_type].name,
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 new_handler = name))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 continue
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 self._type_handlers[data_type] = self._handlers[name]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
141 def serialise(self, get_data):
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
142 tickets_xmlui, metadata, items_patches = get_data
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
143 tickets_xmlui_s, metadata = self._p.transItemsData((tickets_xmlui, metadata))
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
144 return data_format.serialise({
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
145 "items": tickets_xmlui_s,
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
146 "metadata": metadata,
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
147 "items_patches": items_patches,
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
148 })
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
149
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
150 def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
151 extra_dict=None, profile_key=C.PROF_KEY_NONE):
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 if extra_dict and 'parse' in extra_dict:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 extra_dict['parse'] = C.bool(extra_dict['parse'])
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
154 client, service, node, max_items, extra, sub_id = self._s.prepareBridgeGet(
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
155 service, node, max_items, sub_id, extra_dict, profile_key)
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
156 d = self.get(client, service, node or None, max_items, item_ids, sub_id or None,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
157 extra.rsm_request, extra.extra)
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
158 d.addCallback(self.serialise)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 return d
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 @defer.inlineCallbacks
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
162 def get(self, client, service=None, node=None, max_items=None, item_ids=None,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
163 sub_id=None, rsm_request=None, extra=None):
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 """Retrieve merge requests and convert them to XMLUI
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 @param extra(XEP-0060.parse, None): can have following keys:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 - update(bool): if True, will return list of parsed request data
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 other params are the same as for [TICKETS._get]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 @return (tuple[list[unicode], list[dict[unicode, unicode]])): tuple with
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 - 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
171 - node metadata
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 - 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
173 """
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 if not node:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 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
176 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
177 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
178 # 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
179 # 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
180 if C.bool(extra.get('labels_as_list', C.BOOL_FALSE)):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
181 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
182 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
183 filters = {}
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
184 tickets_xmlui, metadata = yield self._s.getDataFormItems(
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
185 client,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
186 service,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
187 node,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
188 max_items=max_items,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
189 item_ids=item_ids,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
190 sub_id=sub_id,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
191 rsm_request=rsm_request,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2448
diff changeset
192 extra=extra,
2546
48820e4a1f8a plugin merge-requests: fixed labels (they were using textbox instead of list)
Goffi <goffi@goffi.org>
parents: 2544
diff changeset
193 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
194 filters = filters)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 parsed_patches = []
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 if extra.get('parse', False):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 for ticket in tickets_xmlui:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 request_type = ticket.named_widgets[FIELD_DATA_TYPE].value
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 request_data = ticket.named_widgets[FIELD_DATA].value
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 parsed_data = yield self.parseData(request_type, request_data)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 parsed_patches.append(parsed_data)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 defer.returnValue((tickets_xmlui, metadata, parsed_patches))
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
204 def _set(self, service, node, repository, method, values, schema=None, item_id=None,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
205 extra="", profile_key=C.PROF_KEY_NONE):
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
206 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
207 service, node, schema, item_id, extra, profile_key)
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
208 d = defer.ensureDeferred(
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
209 self.set(
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
210 client, service, node, repository, method, values, schema,
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
211 item_id or None, extra, deserialise=True
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
212 )
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
213 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
214 d.addCallback(lambda ret: ret or '')
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 return d
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
217 async def set(self, client, service, node, repository, method='auto', values=None,
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
218 schema=None, item_id=None, extra=None, deserialise=False):
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 """Publish a tickets
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 @param service(None, jid.JID): Pubsub service to use
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 @param node(unicode, None): Pubsub node to use
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 None to use default tickets node
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 @param repository(unicode): path to the repository where the code stands
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
225 @param method(unicode): name of one of the registered handler,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
226 or "auto" to try autodetection.
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 other arguments are same as for [TICKETS.set]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 @return (unicode): id of the created item
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 """
2473
447c3de6b9e5 plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents: 2472
diff changeset
230 if not node:
447c3de6b9e5 plugin merge-requests: fixed "set" method
Goffi <goffi@goffi.org>
parents: 2472
diff changeset
231 node = NS_MERGE_REQUESTS
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 if values is None:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 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
234 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
235 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
236 # 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
237 # so repository is not mandatory
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
238 raise exceptions.DataError(_("repository must be specified"))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
239
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 if FIELD_DATA in values:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
241 raise exceptions.DataError(_("{field} is set by backend, you must not set "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
242 "it in frontend").format(field = FIELD_DATA))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
243
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 if repository:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
245 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
246 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
247 handler = self._handlers[name].handler
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
248 can_handle = await handler.check(repository)
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
249 if can_handle:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
250 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
251 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
252 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
253 log.warning(_("repository {path} can't be handled by any installed "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
254 "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
255 path = repository))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
256 raise exceptions.NotFound(_("no handler for this repository has "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
257 "been found"))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 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
259 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
260 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
261 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
262 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
263
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
264 data = await handler.export(repository)
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
265 if not data.strip():
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
266 raise exceptions.DataError(_('export data is empty, do you have any '
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
267 'change to send?'))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
268
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
269 if not values.get('title') or not values.get('body'):
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
270 patches = await handler.parse(data, values.get(FIELD_DATA_TYPE))
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
271 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
272 msg_lines = commits_msg.splitlines()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
273 if not values.get('title'):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
274 values['title'] = msg_lines[0]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
275 if not values.get('body'):
2785
f18d8315929e merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
276 ts = self.host.plugins['TEXT_SYNTAXES']
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
277 xhtml = await ts.convert(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
278 '\n'.join(msg_lines[1:]),
2785
f18d8315929e merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
279 syntax_from = ts.SYNTAX_TEXT,
f18d8315929e merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
280 syntax_to = ts.SYNTAX_XHTML,
f18d8315929e merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
281 profile = client.profile)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
282 values['body'] = '<div xmlns="{ns}">{xhtml}</div>'.format(
2785
f18d8315929e merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
283 ns=C.NS_XHTML, xhtml=xhtml)
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
284
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
285 values[FIELD_DATA] = data
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
286
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
287 item_id = await self._t.set(client, service, node, values, schema, item_id, extra,
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
288 deserialise, form_ns=NS_MERGE_REQUESTS)
3309
71761e9fb984 plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
289 return item_id
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
290
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 def _parseData(self, data_type, data):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 d = self.parseData(data_type, data)
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 d.addCallback(lambda parsed_patches:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
294 {key: str(value) for key, value in parsed_patches.items()})
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 return d
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
296
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 def parseData(self, data_type, data):
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 """Parse a merge request data according to type
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
299
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 @param data_type(unicode): type of the data to parse
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 @param data(unicode): data to parse
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 @return(list[dict[unicode, unicode]]): parsed data
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 key of dictionary are self.META_* or keys specifics to handler
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 @raise NotFound: no handler can parse this data_type
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 """
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 try:
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 handler = self._type_handlers[data_type]
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
309 raise exceptions.NotFound(_('No handler can handle data type "{type}"')
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
310 .format(type=data_type))
2448
637ac234424f plugin merge requests: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 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
312
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
313 def _import(self, repository, item_id, service=None, node=None, extra=None,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
314 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
315 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
316 service = jid.JID(service) if service else None
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
317 d = self.import_request(client, repository, item_id, service, node or None,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
318 extra=extra or None)
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
319 return d
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
320
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
321 @defer.inlineCallbacks
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
322 def import_request(self, client, repository, item, service=None, node=None,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
323 extra=None):
2544
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
324 """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
325
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
326 @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
327 """
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
328 if not node:
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
329 node = NS_MERGE_REQUESTS
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
330 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
331 client,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
332 service,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
333 node,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
334 max_items=1,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
335 item_ids=[item],
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
336 form_ns=NS_MERGE_REQUESTS)
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
337 ticket_xmlui = tickets_xmlui[0]
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
338 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
339 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
340 try:
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
341 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
342 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
343 raise exceptions.NotFound(_('No handler found to import {data_type}')
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
344 .format(data_type=data_type))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2959
diff changeset
345 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
346 item_id = item,
a64887289931 plugin merge-requests, mercurial merge-requests: merge request import implementation
Goffi <goffi@goffi.org>
parents: 2541
diff changeset
347 name = handler.name))
2622
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
348 yield handler.handler.import_(repository, data, data_type, item, service, node,
8fb99ed47db4 core: lines limit
Goffi <goffi@goffi.org>
parents: 2604
diff changeset
349 extra)