From e4a0ad0d75a06d360410aac2a5488156fc46306a Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Mon, 27 Feb 2023 20:15:07 -0800 Subject: [PATCH] Update structured output based on experience using in CI (#94) Update the formatting based on experience trying to use the old format in CI. This reverts the markdown change, just putting the file information in the diff. --- flux_local/tool/diff.py | 7 +++---- flux_local/tool/visitor.py | 4 ++-- tests/tool/test_diff.py | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/flux_local/tool/diff.py b/flux_local/tool/diff.py index 53eab93f..c9b0cf7e 100644 --- a/flux_local/tool/diff.py +++ b/flux_local/tool/diff.py @@ -78,6 +78,8 @@ def str_presenter(dumper: yaml.Dumper, data: Any) -> Any: diff_text = difflib.unified_diff( a=a_resources.get(resource_key, []), b=b_resources.get(resource_key, []), + fromfile=f"{kustomization_key.label} {resource_key.label}", + tofile=f"{kustomization_key.label} {resource_key.label}", n=n, ) diff_content = "\n".join(diff_text) @@ -85,10 +87,7 @@ def str_presenter(dumper: yaml.Dumper, data: Any) -> Any: continue obj = { **asdict(resource_key, dict_factory=omit_none), - "diff_markdown": f"""{resource_key.kind} {resource_key.namespace}/{resource_key.name} -```diff -{diff_content} -```""", # noqa: E501 + "diff": diff_content, } resource_diffs.append(obj) if resource_diffs: diff --git a/flux_local/tool/visitor.py b/flux_local/tool/visitor.py index d8ff20c6..46fbc684 100644 --- a/flux_local/tool/visitor.py +++ b/flux_local/tool/visitor.py @@ -39,9 +39,9 @@ def label(self) -> str: parts = [] if self.path: parts.append(self.path) - parts.append(" - ") + parts.append(" ") parts.append(self.kind) - parts.append("=") + parts.append(": ") if self.namespace: parts.append(self.namespace) parts.append("/") diff --git a/tests/tool/test_diff.py b/tests/tool/test_diff.py index 60b4051c..22c574b7 100644 --- a/tests/tool/test_diff.py +++ b/tests/tool/test_diff.py @@ -51,9 +51,9 @@ async def test_diff_ks() -> None: assert ( result - == """--- tests/testdata/cluster/apps/prod - Kustomization=flux-system/apps ConfigMap=podinfo/podinfo-config + == """--- tests/testdata/cluster/apps/prod Kustomization: flux-system/apps ConfigMap: podinfo/podinfo-config -+++ tests/testdata/cluster/apps/prod - Kustomization=flux-system/apps ConfigMap=podinfo/podinfo-config ++++ tests/testdata/cluster/apps/prod Kustomization: flux-system/apps ConfigMap: podinfo/podinfo-config @@ -1,9 +0,0 @@