go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/lucicfg/starlark/stdlib/internal/luci/rules/external_console_view.star (about) 1 # Copyright 2020 The LUCI Authors. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 """Defines luci.external_console_view(...) rule.""" 16 17 load("@stdlib//internal/lucicfg.star", "lucicfg") 18 load("@stdlib//internal/validate.star", "validate") 19 load("@stdlib//internal/luci/common.star", "keys", "view") 20 21 def _external_console_view( 22 ctx, # @unused 23 *, 24 name = None, 25 title = None, 26 source = None): 27 """Includes a Milo console view from another project. 28 29 This console will be listed in the Milo UI on the project page, alongside 30 the consoles native to this project. 31 32 In the following example, we include a console from the 'chromium' project 33 called 'main', and we give it a local name of 'cr-main' and title of 34 'Chromium Main Console'. 35 36 luci.external_console_view( 37 name = 'cr-main', 38 title = 'Chromium Main Console', 39 source = 'chromium:main' 40 ) 41 42 Args: 43 ctx: the implicit rule context, see lucicfg.rule(...). 44 name: a local name for this console. Will be used for sorting consoles on 45 the project page. Note that the name must not clash with existing 46 consoles or list views in this project. Required. 47 title: a title for this console, will show up in UI. Defaults to `name`. 48 source: a string referring to the external console to be included, in the 49 format `project:console_id`. Required. 50 """ 51 chunks = validate.string("source", source, regexp = r"^[^:]+:[^:]+$").split(":", 1) 52 external_project, external_id = chunks[0], chunks[1] 53 54 return view.add_view( 55 key = keys.external_console_view(name), 56 entry_kind = None, 57 entry_ctor = None, 58 entries = [], 59 props = { 60 "name": validate.string("name", name), 61 "title": validate.string("title", title, default = name, required = False), 62 "external_project": external_project, 63 "external_id": external_id, 64 }, 65 ) 66 67 external_console_view = lucicfg.rule(impl = _external_console_view)