Skip to content

feat(yaml-diff): colourise diff output via ```diff fenced block#232

Merged
weatherhog merged 1 commit into
mainfrom
feat/yaml-diff-color
Jul 2, 2026
Merged

feat(yaml-diff): colourise diff output via ```diff fenced block#232
weatherhog merged 1 commit into
mainfrom
feat/yaml-diff-color

Conversation

@weatherhog

Copy link
Copy Markdown
Contributor

Summary

Makes the yaml-diff bot's semantic diff colourised in the PR comment, per giantswarm/roadmap#4121 (marians: "colour would really help to make changes stand out better").

GitHub PR comments can't render ANSI, so we use the ```diff code-fence highlighter instead:

  • Fence changed from ``` to ```diff — GitHub renders - lines red, + lines green, @@ … @@ as a header.
  • dyff's go-patch style prefixes changed values with an indented -/+, which the highlighter ignores. A sed moves the marker to column 0 while keeping the original indent after it, so nesting stays visible and the colouring fires.
  • Each file's section header becomes @@ <path> @@ for a coloured separator.

The sed only reorders leading whitespace → byte counts are unchanged, so the per-file / total truncation caps are unaffected. dyff's own ANSI colour stays off (auto-off in CI); we rely purely on GitHub highlighting.

Before / after

Before (plain fence):

    - ...not encrypted atm.
    + ...not encrypted yet.

After (```diff, markers at col 0 → red/green in the GitHub UI):

```diff
@@ .../configmaps/configmap.yaml @@
/data/values
  ± value change in multiline text (one insert, one deletion)
-     ...not encrypted atm.
+     ...not encrypted yet.
```

Test plan

  • Verified live by re-pointing gitops-template#134 (value change) and Update ncipollo/release-action action to v1.21.0 #138 (large/truncated) callers at this branch — comment renders red/green/cyan.
  • Added-file note, no-diff message and /no_diffs_printing opt-out unaffected.

🤖 Generated with Claude Code

GitHub PR comments can't render ANSI, so colour the semantic diff using
the `diff` code-fence highlighter instead: switch the fence to ```diff,
move dyff's indented go-patch `-`/`+` markers to column 0 (keeping the
indent after the marker) so removed/added values render red/green, and
emit each file header as `@@ <path> @@` for a coloured separator.

The sed rewrite only reorders leading whitespace, so byte counts — and
the per-file/total truncation caps computed earlier — are unchanged.
dyff's own colour stays off (auto-off in CI); we rely purely on GitHub's
syntax highlighting.

Requested in giantswarm/roadmap#4121.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@weatherhog weatherhog requested a review from a team as a code owner July 2, 2026 08:50

@mproffitt mproffitt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@weatherhog weatherhog merged commit 8a860a0 into main Jul 2, 2026
5 checks passed
@weatherhog weatherhog deleted the feat/yaml-diff-color branch July 2, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants