Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_merge_request.py @ 3291:449dfbfcdbcc
component file sharing: don't initialise the plugin if not component use it
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 01 Jun 2020 11:15:16 +0200 |
parents | 559a625a236b |
children | 71761e9fb984 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2450 | 3 |
4 # jp: a SàT command line tool | |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
2450 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
3040 | 21 import os.path |
3028 | 22 from . import base |
2450 | 23 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
|
24 from sat.tools.common import data_format |
2450 | 25 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
|
26 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
|
27 from sat_frontends.jp import common |
2450 | 28 |
29 __commands__ = ["MergeRequest"] | |
30 | |
31 | |
32 class Set(base.CommandBase): | |
3040 | 33 |
2450 | 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, |
3028 | 40 pubsub_defaults={"service": _("auto"), "node": _("auto")}, |
41 help=_("publish or update a merge request"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 ) |
2450 | 43 |
44 def add_parser_options(self): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
45 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 "-i", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 "--item", |
3028 | 48 default="", |
49 help=_("id or URL of the request to update, or nothing for a new one"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 "-r", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 "--repository", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 metavar="PATH", |
3028 | 55 default=".", |
56 help=_("path of the repository (DEFAULT: current directory)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 action="store_true", |
3028 | 62 help=_("publish merge request without confirmation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 "--label", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 dest="labels", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 action="append", |
3028 | 69 help=_("labels to categorize your request"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 ) |
2450 | 71 |
3040 | 72 async def start(self): |
73 self.repository = os.path.expanduser(os.path.abspath(self.args.repository)) | |
74 await common.fill_well_known_uri(self, self.repository, "merge requests") | |
75 if not self.args.force: | |
76 message = _( | |
77 f"You are going to publish your changes to service " | |
78 f"[{self.args.service}], are you sure ?" | |
79 ) | |
80 await self.host.confirmOrQuit( | |
81 message, _("merge request publication cancelled")) | |
2450 | 82 |
2959
989b622faff6
plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
83 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
|
84 values = {} |
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2553
diff
changeset
|
85 if self.args.labels is not None: |
3028 | 86 values["labels"] = self.args.labels |
3040 | 87 try: |
88 published_id = await self.host.bridge.mergeRequestSet( | |
89 self.args.service, | |
90 self.args.node, | |
91 self.repository, | |
92 "auto", | |
93 values, | |
94 "", | |
95 self.args.item, | |
96 data_format.serialise(extra), | |
97 self.profile, | |
98 ) | |
99 except Exception as e: | |
100 self.disp(f"can't create merge requests: {e}", error=True) | |
101 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2450 | 102 |
3040 | 103 if published_id: |
104 self.disp(_(f"Merge request published at {published_id}")) | |
105 else: | |
106 self.disp(_("Merge request published")) | |
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
|
107 |
3040 | 108 self.host.quit(C.EXIT_OK) |
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
|
109 |
2450 | 110 |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
111 class Get(base.CommandBase): |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
112 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 pubsub_flags={C.MULTI_ITEMS}, |
3028 | 120 pubsub_defaults={"service": _("auto"), "node": _("auto")}, |
121 help=_("get a merge request"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 ) |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
123 |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
124 def add_parser_options(self): |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
125 pass |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
126 |
3040 | 127 async def start(self): |
128 await common.fill_well_known_uri( | |
129 self, os.getcwd(), "merge requests", meta_map={}) | |
130 extra = {} | |
131 try: | |
132 requests_data = await self.host.bridge.mergeRequestsGet( | |
133 self.args.service, | |
134 self.args.node, | |
135 self.args.max, | |
136 self.args.items, | |
137 "", | |
138 extra, | |
139 self.profile, | |
140 ) | |
141 except Exception as e: | |
142 self.disp(f"can't get merge request: {e}", error=True) | |
143 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
144 | |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
145 if self.verbosity >= 1: |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
146 whitelist = None |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
147 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 whitelist = {"id", "title", "body"} |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
149 for request_xmlui in requests_data[0]: |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
150 xmlui = xmlui_manager.create(self.host, request_xmlui, whitelist=whitelist) |
3040 | 151 await xmlui.show(values_only=True) |
3028 | 152 self.disp("") |
2542
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
153 self.host.quit(C.EXIT_OK) |
100563768196
jp (merge/get): "get" command first draft:
Goffi <goffi@goffi.org>
parents:
2532
diff
changeset
|
154 |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
155 |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
156 class Import(base.CommandBase): |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
157 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 "import", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
163 pubsub_flags={C.SINGLE_ITEM, C.ITEM}, |
3028 | 164 pubsub_defaults={"service": _("auto"), "node": _("auto")}, |
165 help=_("import a merge request"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
166 ) |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
167 |
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
168 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 "-r", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 "--repository", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 metavar="PATH", |
3028 | 173 default=".", |
174 help=_("path of the repository (DEFAULT: current directory)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
175 ) |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
176 |
3040 | 177 async def start(self): |
178 self.repository = os.path.expanduser(os.path.abspath(self.args.repository)) | |
179 await common.fill_well_known_uri( | |
180 self, self.repository, "merge requests", meta_map={}) | |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
181 extra = {} |
3040 | 182 try: |
183 await self.host.bridge.mergeRequestsImport( | |
184 self.repository, | |
185 self.args.item, | |
186 self.args.service, | |
187 self.args.node, | |
188 extra, | |
189 self.profile, | |
190 ) | |
191 except Exception as e: | |
192 self.disp(f"can't import merge request: {e}", error=True) | |
193 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
194 else: | |
195 self.host.quit() | |
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
|
196 |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
197 |
2450 | 198 class MergeRequest(base.CommandBase): |
2545
2df1ca79cb30
jp (merge-request/import): added import command
Goffi <goffi@goffi.org>
parents:
2542
diff
changeset
|
199 subcommands = (Set, Get, Import) |
2450 | 200 |
201 def __init__(self, host): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 super(MergeRequest, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
203 host, "merge-request", use_profile=False, help=_("merge-request management") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
204 ) |