Add Mastodon alert provider - #1372
Open
xchose wants to merge 1 commit into
Open
Conversation
Add the mastodon Provider type for posting Flux events as statuses on a Mastodon account. Events are published with a plain HTTP POST to the /api/v1/statuses endpoint of the server given in the address, using an OAuth access token with the write:statuses scope as a bearer token. The status text carries a severity emoji, the involved object, the event message and the event metadata as key-value lines, truncated to the 500-character default server limit. An Idempotency-Key header derived from the event guards against duplicate statuses when the HTTP client retries a request whose response was lost. An optional visibility query parameter on the address maps to the status visibility field, since the Provider API has no dedicated field for it. Assisted-by: Claude Code/claude-fable-5 Signed-off-by: Chose Carreras <xchose@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #447
Adds a
mastodonProvider type for posting Flux events as statuses on a Mastodon account, via a plain HTTPPOSTto the/api/v1/statusesendpoint — no SDK dependency (the issue suggestsmattn/go-mastodon, but like every other notifier this only needs the sharedpostMessageclient).Implementation
addressis the server root URL (e.g.https://mastodon.social); the/api/v1/statusespath is appended automatically (and preserved if already present).write:statusesscope (Secret keytoken), sent as a bearer token.💫/🚨, same convention as the Telegram provider), involved objectkind/name.namespace, event message, and event metadata as key-value lines. Truncated to 500 characters — the default Mastodon server limit, which cannot be discovered without an extra API call, and exceeding it fails the post with a 422.Idempotency-Keyheader (SHA-256 over object UID, reason, timestamp and status text) guards against duplicate statuses when the retrying HTTP client loses a response.visibilityquery parameter on the address (public/unlisted/private) maps to the payload'svisibilityfield and is stripped from the request URL — the Provider API has no dedicated field for it, and alert floods on the public timeline are likely unwanted.Sample rendered payload:
{ "status": "💫 gitrepository/podinfo.flux-system\nstored artifact for commit 'master@sha1:eec06d1...'\n\nrevision: master@sha1:eec06d1...", "visibility": "unlisted" }Testing
internal/notifier/mastodon_test.go: asserts endpoint path, bearer auth header, Idempotency-Key presence, payload shape, severity emoji, visibility query-param mapping (including URL stripping), 500-char truncation, path preservation, and constructor validation against anhttptestserver.make generate manifests tidy fmt vetleave a clean tree.Manual e2e testing
kind cluster, controller image + CRD from this PR, real mastodon.social account. Secret:
address: https://mastodon.social?visibility=unlisted,tokenwithwrite:statuses. Info/error/recovery events from a podinfoGitRepository→ 3× HTTP 2xx, statuses posted as unlisted:🤖 Generated with Claude Code
Full MD with testing:
e2e-comment.md