Skip to content

Add Result Builder API for declarative message construction#1

Merged
diegotl merged 5 commits intomainfrom
feature/result-builder-api
Feb 4, 2026
Merged

Add Result Builder API for declarative message construction#1
diegotl merged 5 commits intomainfrom
feature/result-builder-api

Conversation

@diegotl
Copy link
Owner

@diegotl diegotl commented Feb 4, 2026

Summary

This PR adds a result builder API for declarative message construction and comprehensive integration tests for end-to-end verification.

Result Builder API

Following SlackKit's architecture pattern, all builders use Swift's @resultBuilder attribute for clean, type-safe DSL syntax.

New Builder Files

  1. Message+Builder.swift - @AttachmentBuilder for building attachment arrays
  2. Attachment+Builder.swift - @FieldBuilder and @ActionBuilder for fields and actions
  3. Props+Builder.swift - @PropsBuilder for dynamic properties
  4. Confirmation+Builder.swift - @ConfirmationBuilder for confirmation dialogs

Key Features

  • Message Builder: Declarative attachment construction

    Message(text: "Deployment complete!") {
        Attachment(color: "#36a64f", title: "Build #123") {
            Field("Branch", value: "main")
            Field("Commit", value: "abc123")
        }
    }
  • Props Builder: Dynamic properties with type-safe convenience functions

    Props(card: "Info") {
        Property("app_id", value: "12345")
        Property("environment", value: "production")
    }
  • Confirmation Builder: Custom button configurations

    Confirmation(text: "Deploy to production?") {
        ConfirmButton(text: "Deploy", style: "primary")
        DenyButton(text: "Cancel")
    }
  • Conditional Logic: Native if/else and for-in support

  • Convenience Functions: Field(), Button(), Property(), ConfirmButton(), DenyButton()

Integration Tests

Added comprehensive end-to-end integration tests that send actual messages to Mattermost via Incoming Webhooks.

Test Coverage (47 tests)

  • Simple Text Messages: Plain text, markdown formatting, custom username/icons
  • Attachments: Single/multiple, with fields, author, images, thumbnails, footer
  • Action Buttons: Single/multiple buttons with different styles
  • Confirmation Dialogs: Buttons that require user confirmation
  • Builder API: Result builders with conditionals and loops
  • Message Priority: Important and urgent priority levels
  • Props and Card: Custom metadata and sidebar content
  • Special Characters: Emojis, unicode, code blocks
  • Complex Messages: Deployment notifications, error alerts, feature announcements

Running Integration Tests

Tests are disabled by default. Set environment variables to run:

MATTERMOST_INTEGRATION_TESTS=1 MATTERMOST_TEST_WEBHOOK_URL="https://your-server.com/hooks/xxx" swift test

All tests are serialized with delays between requests to avoid rate limits.

Documentation Updates

  • README.md updated to showcase the Result Builder API
  • Added examples for Props and Confirmation builders
  • Builder API Reference section with all builders
  • Cross-reference to SlackKit companion package added

Test plan

  • All existing tests pass
  • New result builder tests pass (20 tests)
  • Conditional logic (if/else) works correctly
  • For-in loops work for dynamic content
  • Encoding/decoding maintains data integrity
  • All integration tests pass (47 tests)
  • Integration tests verified against real Mattermost webhook

Follows SlackKit's architecture pattern with TypeName+Builder.swift files:

Message+Builder.swift:
- @AttachmentBuilder for building attachment arrays
- Message extension with result builder initializer
- Attachment extension with field builder initializer

Attachment+Builder.swift:
- @FieldBuilder for building field arrays
- @ActionBuilder for building action arrays
- Extension initializers for Attachment
- Convenience functions: Field(), Button()

Props+Builder.swift:
- @PropsBuilder for constructing dynamic property dictionaries
- Props initializer with result builder
- Property() convenience functions for all AnyCodable types

Confirmation+Builder.swift:
- @ConfirmationBuilder for building confirmation dialogs
- Confirmation initializer with result builder
- ConfirmButton() and DenyButton() convenience functions

README.md:
- Updated to showcase only the Result Builder API
- Added Props and Confirmation builder examples
- Updated Builder API Reference section

20 comprehensive tests for result builder functionality.
All 33 tests passing.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4171e6d9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Props+Builder: Store builder result once to avoid double evaluation
  which could cause inconsistent results or duplicate side effects
- Confirmation+Builder: Add buildArray() to enable for-in loop support
- Confirmation+Builder: Fix unused variable warning for style parameter
@diegotl diegotl force-pushed the feature/result-builder-api branch from 20a384d to b2ccc4e Compare February 4, 2026 13:32
Adds end-to-end integration tests that send actual messages to
Mattermost via Incoming Webhooks. Tests cover all major features
including text messages, attachments, actions, builder API,
priority, props, and special characters.

Tests are disabled by default and only run when
MATTERMOST_INTEGRATION_TESTS environment variable is set.
Repository owner deleted a comment from chatgpt-codex-connector bot Feb 4, 2026
@diegotl diegotl merged commit 7b5bc41 into main Feb 4, 2026
1 check passed
@diegotl diegotl deleted the feature/result-builder-api branch February 4, 2026 14:07
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.

1 participant