Repository navigation
Export a notify package for sending from Go programs - #47
Merged
Merged
Conversation
github.com/suprbdev/noty/notify loads the same YAML config as the CLI and sends messages in-process: Load/Parse, New with options for the HTTP client, exec runner, timeout, retries and clock, and Client.Send with per-channel results. Provider internals stay internal. The CLI now sends through the package, so both share one code path. CLI flags, output and exit codes are unchanged.
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.
Summary
Adds a public package,
github.com/suprbdev/noty/notify, so Go programs can send notifications in-process with the same config format and behaviour as the CLI. kickly-generated projects will use it.notify.Load/notify.Parseread the existing YAML config, with the same${VAR},${VAR:-default}and$$handling.WithLookupEnvinjects the env lookup for tests.notify.New(cfg, opts...)builds aClient. Options:WithHTTPClient,WithExecRunner,WithTimeout,WithRetries,WithBackoff,WithClock.Client.Send(ctx, Message)fans out to channels concurrently and keeps going past failures. It returns per-channelResults, and a*SendErrorthat unwraps to each channel's error.ErrInvalidConfig,ErrNoChannel,ErrUnknownChannel.internal/.The CLI now sends through the package, so there is one code path. Flags, output and exit codes are unchanged.
Testing
go vet ./...,go test -race ./...and golangci-lint (0 issues) pass. Existing CLI tests are unchanged.notify/cover config parsing, env injection, fan-out against an httptest server and a fake exec runner, retries and backoff, dry-run masking, and unknown channels. There are also runnable examples.mainand this branch and ran both on 28 CLI cases: dry-run variants,--list, error paths, retries,--versionand piped stdin. After normalising timestamps, stdout, stderr and exit codes are identical.Suggested release:
v0.3.0. It adds a public API and has no breaking change for CLI users.