Skip to content

feat: slack blocks formatter#59

Merged
moshloop merged 8 commits intomainfrom
feat/slack-blocks
Jan 20, 2026
Merged

feat: slack blocks formatter#59
moshloop merged 8 commits intomainfrom
feat/slack-blocks

Conversation

@adityathebe
Copy link
Copy Markdown
Member

@adityathebe adityathebe commented Jan 15, 2026

Summary by CodeRabbit

  • New Features

    • Added Slack Block Kit as a supported output format across all formatting options.
    • Introduced button and button group rendering support with multi-format output capabilities.
  • Bug Fixes

    • Fixed race condition in batch timeout handling.
  • Documentation

    • Updated documentation to reflect Slack Block Kit as a supported output format.
  • Tests

    • Added comprehensive test coverage for Slack formatter.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 15, 2026

Walkthrough

This PR introduces Slack Block Kit formatting support by adding a Button/ButtonGroup API, enhancing parser and rendering logic with TypedValue handling, implementing a SlackFormatter that converts data structures to Slack Block Kit JSON, and integrating Slack format throughout the formatting pipeline.

Changes

Cohort / File(s) Summary
Button API
api/button.go
New Button and ButtonGroup types with rendering methods (String, ANSI, Markdown, HTML); supports clickable actions with label, href, ID, payload, and variant properties
Parser & Type Handling Enhancements
api/meta.go, api/parser.go, formatters/parser.go
Added compile-time assertion for Textable interface; TryTypedValue now recognizes and passes through TypedValue pointers; ParseDataWithSchema short-circuits processing for TypedValue-compatible values
Parse Tags & Field Options
api/parse_tags.go
Added label_set and title flags to FormatOptions; title configuration moved to flag-path handling for consistency
Table Rendering & Transformers
api/table.go
Introduced TextTransformer API (TransformerANSI, TransformerString, TransformerHTML, TransformerMarkdown); added Tailwind-to-lipgloss conversion via parseTailwindToLipgloss helper; Markdown rendering now uses dedicated transformer path
Slack Formatter Implementation
formatters/slack_formatter.go
New SlackFormatter type converting data to Slack Block Kit JSON; supports text, markdown, HTML, lists, buttons, tables, trees, and PrettyData with schema-aware block construction
Slack Format Integration
formatters/manager.go, formatters/options.go, formatters/http/http.go, formatters/doc.go
Added SlackFormatter field and Slack() method to FormatManager; integrated Slack option in FormatOptions with mutual-exclusivity handling; added Slack format recognition in HTTP (extension/MIME-type mappings); updated supported formats documentation
Slack Formatter Tests & Data
formatters/tests/slack_formatter_test.go, formatters/tests/testdata/slack-msg.json, formatters/tests/testdata/.gitignore
Added test validating Slack formatter output against expected JSON; test data file containing example Slack Block Kit payload
Documentation
README.md
Added Slack Block Kit to supported multi-format output list; updated list command flag description to include Slack
Task Test
task/batch_test.go
Added explicit batch-level timeout to ItemTimeout subtest to avoid race conditions

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant HTTP as HTTP Handler
    participant Manager as FormatManager
    participant Formatter as SlackFormatter
    participant Output

    Client->>HTTP: Request with Slack format
    HTTP->>Manager: Identify "slack" format
    Manager->>Manager: Resolve to Slack formatter
    Manager->>Formatter: Format(data)
    Formatter->>Formatter: Parse data structure
    Formatter->>Formatter: Build Slack blocks<br/>(text, sections, buttons)
    Formatter->>Formatter: Marshal to Block Kit JSON
    Formatter-->>Manager: JSON string
    Manager-->>HTTP: Formatted output
    HTTP-->>Output: Slack Block Kit JSON<br/>+ Content-Type header
Loading

Possibly related PRs

  • flanksource/clicky#60: Modifies TryTypedValue type-case handling and pass-through behavior for TypedValue variants
  • flanksource/clicky#50: Modifies FormatManager initialization and adds format-specific methods

Suggested labels

released

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided; the required template sections are entirely missing. Add a comprehensive description following the repository template, including change summary, type of change, testing details, and any breaking changes or notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 42.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the primary change: adding Slack Block Kit formatter support throughout the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/slack-blocks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@adityathebe adityathebe changed the title feat/slack blocks feat: slack blocks formatter Jan 15, 2026
@adityathebe adityathebe marked this pull request as draft January 15, 2026 11:23
@adityathebe adityathebe force-pushed the feat/slack-blocks branch 2 times, most recently from 1388ab3 to 4d882cb Compare January 19, 2026 12:39
@adityathebe adityathebe marked this pull request as ready for review January 20, 2026 09:19
@adityathebe adityathebe requested a review from moshloop January 20, 2026 09:19
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
api/table.go (1)

192-206: Bug: Using Markdown-formatted text as map key will cause lookup failures.

Line 198 uses TransformerMarkdown(header) for fieldName, but the row map is keyed by plain string field names. If header.Markdown() returns different text than header.String() (e.g., with formatting), the map lookup on line 201 will fail to find matching cells.

The fieldName should use header.String() to match the map keys, while TransformerMarkdown should only be used for display values.

🐛 Proposed fix
 			if i < len(t.FieldNames) && t.FieldNames[i] != "" {
 				fieldName = t.FieldNames[i]
 			} else {
-				fieldName = TransformerMarkdown(header)
+				fieldName = header.String()
 			}
🤖 Fix all issues with AI agents
In `@formatters/slack_formatter.go`:
- Around line 631-640: The current byte-based splitting loop that breaks a long
string `line` into chunks using `line[start:end]` can split multi-byte UTF-8
runes; change the logic in the long-line handling (the loop that appends to
`parts`) to be rune-aware: convert `line` to a slice of runes (e.g., `runes :=
[]rune(line)`), compute chunk boundaries using `max` as a rune count (or derive
a rune-based limit), and append substrings using `string(runes[start:end])` so
multi-byte characters are preserved; keep the existing `flush()` and `parts`
append behavior but operate on rune slices instead of raw bytes.
- Around line 549-555: The truncateSlackHeader function currently slices bytes
and may split UTF-8 runes; change truncateSlackHeader to be rune-aware by
converting text to a []rune (e.g., runes := []rune(text)), compare len(runes) to
slackHeaderMax, and return string(runes[:slackHeaderMax]) when truncation is
needed so multi-byte characters are not split; keep the constant slackHeaderMax
but treat it as a rune/character limit within the function.
- Around line 557-563: The truncateSlackButton function currently slices bytes,
which can split multibyte UTF-8 characters; update
SlackFormatter.truncateSlackButton to perform rune-aware truncation using runes
(e.g., convert text to []rune or use utf8 utilities) and return the first
slackButtonMax runes so multi-byte characters are preserved (keep the
slackButtonMax constant and function name unchanged).
🧹 Nitpick comments (1)
api/table.go (1)

222-237: Consider moving type definition before variable declarations.

The TextTransformer type (line 237) is defined after the variables that use it (lines 222-235). While Go allows this, placing the type definition first improves readability and follows conventional Go code organization.

♻️ Suggested reordering
+type TextTransformer func(t Textable) string
+
 var TransformerANSI TextTransformer = func(t Textable) string {
 	return t.ANSI()
 }

 var TransformerString TextTransformer = func(t Textable) string {
 	return t.String()
 }
 var TransformerHTML TextTransformer = func(t Textable) string {
 	return t.HTML()
 }

 var TransformerMarkdown TextTransformer = func(t Textable) string {
 	return t.Markdown()
 }
-
-type TextTransformer func(t Textable) string

Comment thread formatters/slack_formatter.go
Comment thread formatters/slack_formatter.go
Comment thread formatters/slack_formatter.go Outdated
- Fix markdown key lookup bug in table.go by using header.String() instead
  of TransformerMarkdown(header) since row map is keyed by plain strings
- Fix UTF-8 truncation in truncateSlackHeader, truncateSlackButton, and
  splitSlackText by using rune-based operations to prevent multi-byte
  character corruption
- Reorder TextTransformer type definition before variables that use it
@moshloop moshloop merged commit b4203d3 into main Jan 20, 2026
10 checks passed
github-actions Bot pushed a commit that referenced this pull request Jan 20, 2026
## [1.13.0](v1.12.2...v1.13.0) (2026-01-20)

### ✨ Features

* slack blocks formatter ([#59](#59)) ([b4203d3](b4203d3))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 1.13.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants