Documentation
¶
Overview ¶
Package slack talks to the Slack Web API for the PR notifier: posting, updating, and deleting messages, adding emoji reactions, and composing the blocks of the notification.
Index ¶
- type APIError
- type Block
- type ChannelInfo
- type Client
- func (c *Client) AddReaction(ctx context.Context, channel, ts, name string) error
- func (c *Client) AuthTest(ctx context.Context) (userID string, scopes []string, err error)
- func (c *Client) ConversationsInfo(ctx context.Context, channel string) (ChannelInfo, error)
- func (c *Client) DeleteMessage(ctx context.Context, channel, ts string) error
- func (c *Client) GetReactions(ctx context.Context, channel, ts string) ([]Reaction, error)
- func (c *Client) PostMessage(ctx context.Context, channel string, msg Message) (string, error)
- func (c *Client) UpdateMessage(ctx context.Context, channel, ts string, msg Message) error
- type Composer
- type Message
- type Option
- type PRDetails
- type Reaction
- type TextObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶ added in v0.15.0
type Block struct {
Type string `json:"type"`
Text *TextObject `json:"text,omitempty"`
Elements []TextObject `json:"elements,omitempty"`
}
Block is the narrow subset of Block Kit the notifier emits: a "section" (Text set) or a "context" line (Elements set). Exactly one of the two is populated per block. The struct marshals directly to the Slack blocks JSON.
type ChannelInfo ¶
ChannelInfo is the subset of conversations.info we need for validation.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin Slack Web API client covering only the endpoints needed by the notifier. It is safe for concurrent use.
func NewClient ¶
NewClient builds a Client. The httpClient is used as-is; callers should configure timeouts on it.
func (*Client) AddReaction ¶
AddReaction adds a reaction emoji to a message. "already_reacted" is treated as success — it means the reaction we wanted is already there.
func (*Client) AuthTest ¶
AuthTest returns the bot's user_id and the OAuth scopes Slack reports as granted to the token. Scopes are read from the X-OAuth-Scopes response header (comma-separated) and used by validation to verify required scopes are present.
func (*Client) ConversationsInfo ¶
ConversationsInfo returns metadata about a channel, including whether the bot is a member. The channel argument must be a Slack channel ID.
func (*Client) DeleteMessage ¶
DeleteMessage removes an existing message by ts.
func (*Client) GetReactions ¶
GetReactions returns the reactions attached to a message, or an empty slice if none are present.
func (*Client) PostMessage ¶
PostMessage posts a new message to channel and returns its ts. The Block Kit blocks render in-channel; msg.Fallback is sent as the top-level text Slack uses for the push preview and screen readers.
type Composer ¶
type Composer struct {
// contains filtered or unexported fields
}
Composer renders Slack-formatted notification messages.
func NewComposer ¶
NewComposer returns a Composer that prefixes new-PR messages with the given reaction-style emoji name (without colons).
func (*Composer) BotMessage ¶ added in v0.13.0
BotMessage renders the compact notification for a PR opened by a dependency bot. bot is the lowercase bot name ("dependabot" / "renovate"). When security is true it uses the rotating-light advisory template; otherwise the package routine-bump template. It stays deliberately compact — a single section, no context line — so bot bumps read as a one-liner. Mentions follow the same empty-list rule as NewMessage; the PR author is omitted because the bot name carries it.
func (*Composer) NewMessage ¶
NewMessage renders the initial notification for a PR: a headline section with the new-PR emoji, any mentions, and the linked title, plus a muted context line carrying repo, author, and the localized open time. Mentions stay in the section because Slack only reliably notifies on a mention in a section/ top-level text — a context block renders the mention as gray text but does not ping. When the mentions list is empty the prefix is omitted entirely so the message has no stranded ", ".
func (*Composer) UpdatedMessage ¶
UpdatedMessage renders the closed-PR decoration. Block Kit cannot wrap the whole prior message string the way the legacy plain-text format did, so the message is rebuilt from PR details: the title is struck through inside the section, the leading emoji is swapped to the merged/closed reaction emoji, and a [Merged]/[Closed] label is prepended. The context line is preserved.
type Message ¶ added in v0.15.0
Message is a composed Slack message: the Block Kit blocks rendered in the channel plus a plain-text Fallback. Slack uses Fallback for the mobile push preview and for screen readers — it does not read interior block text for either — so every Message carries one.
type Option ¶
type Option func(*Client)
Option configures Client construction.
func WithBaseURL ¶
WithBaseURL overrides the Slack API base URL — used in tests against an httptest.Server. The URL must NOT have a trailing slash.
type PRDetails ¶
type PRDetails struct {
Repository string
Number int
Title string
URL string
Author string
// CreatedAt is the PR's open time, rendered as a localized date token in
// the context line. The zero value omits the "opened …" clause.
CreatedAt time.Time
}
PRDetails is the subset of PR information the Composer needs to render a notification. It is detached from any HTTP payload type so the composer stays a pure function of its inputs.
type Reaction ¶
type Reaction struct {
Name string `json:"name"`
Count int `json:"count"`
Users []string `json:"users"`
}
Reaction is one entry from reactions.get.
type TextObject ¶ added in v0.15.0
TextObject is a Block Kit text object. The notifier only ever emits mrkdwn.