Skip to content

feat(template): make join template function more flexible#5233

Open
TheMeier wants to merge 1 commit into
prometheus:mainfrom
TheMeier:list_join
Open

feat(template): make join template function more flexible#5233
TheMeier wants to merge 1 commit into
prometheus:mainfrom
TheMeier:list_join

Conversation

@TheMeier

@TheMeier TheMeier commented May 10, 2026

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Please check all the applicable boxes.

Which user-facing changes does this PR introduce?

[ENHANCEMENT] TEMPLATE: allow `join` template function to receive slices/arrays of any type

@TheMeier TheMeier requested a review from a team as a code owner May 10, 2026 09:48
@coderabbitai

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b1b2c535-0222-423e-8cd7-a39d7320a251

📥 Commits

Reviewing files that changed from the base of the PR and between 084765b and 2ff6fc1.

📒 Files selected for processing (3)
  • docs/notifications.md
  • template/template.go
  • template/template_test.go
✅ Files skipped from review due to trivial changes (1)
  • docs/notifications.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • template/template_test.go
  • template/template.go

📝 Walkthrough

Walkthrough

The join template function now accepts any and uses reflection to join slice and array inputs, including mixed types. Documentation was updated to match the new signature, and tests cover list-based and mixed-type template expansion plus concurrent use.

Changes

Join Function Reflection Support

Layer / File(s) Summary
Core Implementation
template/template.go
DefaultFuncs["join"] now accepts any and returns (string, error). It handles invalid values, joins []string directly, converts other slice or array elements with fmt.Sprint, and errors for unsupported inputs.
Test Coverage
template/template_test.go
Added expansion cases for string and mixed-type list inputs and a concurrent template function case using join.
Documentation Update
docs/notifications.md
The join documentation now describes its any input, non-string conversion, error behavior, separator placement, and pipeline argument order.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TemplateCaller
  participant JoinFunc as join(sep, v)
  participant Reflect as reflect
  participant StringsJoin as strings.Join
  participant FmtSprint as fmt.Sprint

  TemplateCaller->>JoinFunc: invoke with sep + v
  JoinFunc->>Reflect: inspect v
  alt v is invalid
    JoinFunc-->>TemplateCaller: return ("", nil)
  else v is []string
    JoinFunc->>StringsJoin: join strings with sep
    StringsJoin-->>JoinFunc: concatenated string
    JoinFunc-->>TemplateCaller: return result
  else v is slice or array
    JoinFunc->>Reflect: iterate elements
    Reflect->>FmtSprint: convert elements to strings
    FmtSprint-->>JoinFunc: element strings
    JoinFunc-->>TemplateCaller: return joined result
  else v is unsupported
    JoinFunc-->>TemplateCaller: return error
  end
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and matches the main change: making the template join helper more flexible.
Description check ✅ Passed The description follows the template, includes checklist items, and fills in release notes; only some optional boxes are left unmarked.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/notifications.md`:
- Line 92: Update the docs for the join filter to explicitly state coercion
behavior: clarify that join (described as "join") accepts elements of type any
and will convert non-string elements to their string representation (e.g. via
standard stringification like fmt.Sprint) before concatenation, and that it does
not return an error on conversion (unless the implementation documents
otherwise); reference the existing strings.Join mention for string-only behavior
and note the argument order inversion for templates.

In `@template/template_test.go`:
- Around line 355-359: Add a test case in template_test.go that exercises join
with non-string elements to ensure elements are stringified: add a case similar
to the existing "Template using join with list" entry but with in set to `{{
list 1 true "x" | join "," }}` and exp set to `1,true,x`; place it alongside the
other cases in the same test table so the join behavior for mixed-type lists is
enforced when the test runner iterates over the cases.

In `@template/template.go`:
- Around line 201-204: The join implementation currently enforces elements be
strings by asserting elem.(string) and returning an error; change it to accept
any element type by removing the string type assertion and instead convert each
elem to a string (e.g. via fmt.Sprint or fmt.Sprintf("%v", elem)) before
concatenation so join accepts slices/arrays of any element type; update the code
in the join function where the variable elem is handled to perform this
conversion and remove the error path that checks for non-string types.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c597f3de-18ea-4227-9cb6-c49c470ec3fa

📥 Commits

Reviewing files that changed from the base of the PR and between 369a175 and 9d60bb794842f049a3750ae41670514d7676395d.

📒 Files selected for processing (3)
  • docs/notifications.md
  • template/template.go
  • template/template_test.go

Comment thread docs/notifications.md Outdated
Comment thread template/template_test.go
Comment thread template/template.go Outdated
Allow `join` template function to accept a slice of any type, not just
strings. The function will convert non-string elements to their string
representation before joining them. This provides more flexibility in
templating, e.g. creating slices with `list` and then joining them.

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant