annotate sat_frontends/jp/cmd_merge_request.py @ 2959:989b622faff6

plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
author Goffi <goffi@goffi.org>
date Fri, 14 Jun 2019 12:37:34 +0200
parents 003b8b4b56a7
children ab2696e34d29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import base
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
23 from sat.tools.common import data_format
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat_frontends.jp.constants import Const as C
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
25 from sat_frontends.jp import xmlui_manager
2551
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
26 from sat_frontends.jp import common
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from functools import partial
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import os.path
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 __commands__ = ["MergeRequest"]
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 class Set(base.CommandBase):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 help=_(u"publish or update a merge request"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 self.need_loop = True
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 "-i",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 "--item",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 default=u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 help=_(u"id or URL of the request to update, or nothing for a new one"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 "-r",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 "--repository",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 metavar="PATH",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 default=u".",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 help=_(u"path of the repository (DEFAULT: current directory)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 "--force",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 action="store_true",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 help=_(u"publish merge request without confirmation"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 "-l",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 "--label",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 dest="labels",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 help=_(u"labels to categorize your request"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 )
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 def mergeRequestSetCb(self, published_id):
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 if published_id:
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.disp(u"Merge request published at {pub_id}".format(pub_id=published_id))
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 else:
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.disp(u"Merge request published")
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.host.quit(C.EXIT_OK)
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82
2551
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
83 def sendRequest(self):
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
84 extra = {"update": True} if self.args.item else {}
2554
0062d3e79d12 plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents: 2553
diff changeset
85 values = {}
0062d3e79d12 plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents: 2553
diff changeset
86 if self.args.labels is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 values[u"labels"] = self.args.labels
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.host.bridge.mergeRequestSet(
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.args.service,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 self.args.node,
2551
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
91 self.repository,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 u"auto",
2554
0062d3e79d12 plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents: 2553
diff changeset
93 values,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 u"",
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 self.args.item,
2959
989b622faff6 plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
96 data_format.serialise(extra),
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self.profile,
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 callback=self.mergeRequestSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 msg=_(u"can't create merge request: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 )
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
2551
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
106 def askConfirmation(self):
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
107 if not self.args.force:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 message = _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 u"You are going to publish your changes to service [{service}], are you sure ?"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 ).format(service=self.args.service)
2551
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
111 self.host.confirmOrQuit(message, _(u"merge request publication cancelled"))
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
112 self.sendRequest()
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
113
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
114 def start(self):
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
115 self.repository = os.path.expanduser(os.path.abspath(self.args.repository))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 common.URIFinder(self, self.repository, "merge requests", self.askConfirmation)
2551
b27165bf160c jp (merge-request/set): if service and node are not specified, URIFinder is now used + ask confirmation before publishing
Goffi <goffi@goffi.org>
parents: 2545
diff changeset
117
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
119 class Get(base.CommandBase):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
120 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 pubsub_flags={C.MULTI_ITEMS},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 help=_(u"get a merge request"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 self.need_loop = True
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
132
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
133 def add_parser_options(self):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
134 pass
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
135
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
136 def mergeRequestGetCb(self, requests_data):
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
137 if self.verbosity >= 1:
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
138 whitelist = None
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
139 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 whitelist = {"id", "title", "body"}
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
141 for request_xmlui in requests_data[0]:
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
142 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist)
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
143 xmlui.show(values_only=True)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 self.disp(u"")
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
145 self.host.quit(C.EXIT_OK)
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
146
2553
39b10475f56b jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents: 2551
diff changeset
147 def getRequests(self):
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
148 extra = {}
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
149 self.host.bridge.mergeRequestsGet(
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
150 self.args.service,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
151 self.args.node,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
152 self.args.max,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
153 self.args.items,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 u"",
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
155 extra,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
156 self.profile,
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
157 callback=self.mergeRequestGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 msg=_(u"can't get merge request: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 )
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
164
2553
39b10475f56b jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents: 2551
diff changeset
165 def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 common.URIFinder(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 self, os.getcwd(), "merge requests", self.getRequests, meta_map={}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 )
2542
100563768196 jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents: 2532
diff changeset
169
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
170
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
171 class Import(base.CommandBase):
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
172 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 "import",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 pubsub_flags={C.SINGLE_ITEM, C.ITEM},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 pubsub_defaults={u"service": _(u"auto"), u"node": _(u"auto")},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 help=_(u"import a merge request"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 self.need_loop = True
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
183
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
184 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
185 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 "-r",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 "--repository",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 metavar="PATH",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 default=u".",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 help=_(u"path of the repository (DEFAULT: current directory)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 )
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
193
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
194 def mergeRequestImportCb(self):
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
195 self.host.quit(C.EXIT_OK)
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
196
2553
39b10475f56b jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents: 2551
diff changeset
197 def importRequest(self):
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
198 extra = {}
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
199 self.host.bridge.mergeRequestsImport(
2553
39b10475f56b jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents: 2551
diff changeset
200 self.repository,
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
201 self.args.item,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
202 self.args.service,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
203 self.args.node,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
204 extra,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
205 self.profile,
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
206 callback=self.mergeRequestImportCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209 msg=_(u"can't import merge request: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 )
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
213
2553
39b10475f56b jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents: 2551
diff changeset
214 def start(self):
39b10475f56b jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents: 2551
diff changeset
215 self.repository = os.path.expanduser(os.path.abspath(self.args.repository))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 common.URIFinder(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
217 self, self.repository, "merge requests", self.importRequest, meta_map={}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 )
2553
39b10475f56b jp (merge-request): find URIs when --service and --node are not specified for get and import:
Goffi <goffi@goffi.org>
parents: 2551
diff changeset
219
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
220
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 class MergeRequest(base.CommandBase):
2545
2df1ca79cb30 jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents: 2542
diff changeset
222 subcommands = (Set, Get, Import)
2450
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223
124f5db998f2 jp (merge-request): first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
225 super(MergeRequest, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 host, "merge-request", use_profile=False, help=_("merge-request management")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 )