From 16eba2d27ef46bc8e9eca57997ed22c0119a9ac5 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:43:22 +0200 Subject: [PATCH] fix(openshift): Support etcd Dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit which also fixes test coverage 😇 --- nice-dev-refs/_manifest.yml | 2 +- scripts/label_for_url.py | 9 +++++---- test/test_openshift.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nice-dev-refs/_manifest.yml b/nice-dev-refs/_manifest.yml index ab01224..d9c224c 100644 --- a/nice-dev-refs/_manifest.yml +++ b/nice-dev-refs/_manifest.yml @@ -1,5 +1,5 @@ name: "nice-dev-refs" title: "Nice Developer References" description: Takes URLs from the clipboard and pastes them as nice links -version: 0.11.0 +version: 0.11.1 author: Raphael Reitzig diff --git a/scripts/label_for_url.py b/scripts/label_for_url.py index d33c332..a154e3c 100644 --- a/scripts/label_for_url.py +++ b/scripts/label_for_url.py @@ -228,14 +228,15 @@ def determine_label(input_url: str) -> str: return f"{namespace}/{resource_name}" if options := m.group("dashboard_options"): # noqa: RET503 -- false positive options = dict([option.split("=") for option in options.split("&")]) - cluster = f"{options['cluster']}/" if options.get("cluster") else "" if namespace := options.get("namespace"): + cluster = f"{options['cluster']}/" if options.get("cluster") else "" resource_type = f"{options['type'].title()}s " if options.get("type") else "" return f"{cluster}{namespace} > {resource_type}Dashboard" else: - host = m.group("host") + cluster = f"{options['cluster']}" if options.get("cluster") else "" + host = m.group("host") if not options.get("cluster") else "" dashboard = prettify(remove_prefix(m.group("dashboard"), "grafana-dashboard-")) - return f"{host} > {dashboard}" + return f"{host}{cluster} > {dashboard}" elif m := re.search(r"\w+://(www\d*\.)?(?P[^?]+)", input_url): return m.group("path").strip(" /") else: @@ -244,4 +245,4 @@ def determine_label(input_url: str) -> str: if __name__ == "__main__": - print(determine_label(sys.argv[1])) + print(determine_label(sys.argv[1])) # pragma: no cover diff --git a/test/test_openshift.py b/test/test_openshift.py index 233b9ce..a030dc0 100644 --- a/test/test_openshift.py +++ b/test/test_openshift.py @@ -94,3 +94,16 @@ def test_should_label_metrics_dashboard_api() -> None: # Then: assert_that(label).is_equal_to("console-openshift.some.org > Api Performance") + + +def test_should_label_metrics_dashboard_etcd() -> None: + # Given: + url = ( + "https://console-openshift.some.org/monitoring/dashboards/" "etcd-dashboard" "?cluster=etcd" + ) + + # When: + label = determine_label(url) + + # Then: + assert_that(label).is_equal_to("etcd > Etcd Dashboard")