slack

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 8 Imported by: 0

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 text of the notification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Method string
	Code   string
}

APIError represents a non-ok Slack API response.

func (*APIError) Error

func (e *APIError) Error() string

type ChannelInfo

type ChannelInfo struct {
	ID         string
	Name       string
	IsMember   bool
	IsArchived bool
}

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

func NewClient(hc *http.Client, token string, opts ...Option) *Client

NewClient builds a Client. The httpClient is used as-is; callers should configure timeouts on it.

func (*Client) AddReaction

func (c *Client) AddReaction(ctx context.Context, channel, ts, name string) error

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

func (c *Client) AuthTest(ctx context.Context) (userID string, scopes []string, err error)

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

func (c *Client) ConversationsInfo(ctx context.Context, channel string) (ChannelInfo, error)

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

func (c *Client) DeleteMessage(ctx context.Context, channel, ts string) error

DeleteMessage removes an existing message by ts.

func (*Client) GetReactions

func (c *Client) GetReactions(ctx context.Context, channel, ts string) ([]Reaction, error)

GetReactions returns the reactions attached to a message, or an empty slice if none are present.

func (*Client) PostMessage

func (c *Client) PostMessage(ctx context.Context, channel, text string) (string, error)

PostMessage posts a new message to channel and returns its ts.

func (*Client) UpdateMessage

func (c *Client) UpdateMessage(ctx context.Context, channel, ts, text string) error

UpdateMessage edits an existing message by ts.

type Composer

type Composer struct {
	// contains filtered or unexported fields
}

Composer renders Slack-formatted notification messages.

func NewComposer

func NewComposer(newPREmoji string) *Composer

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

func (c *Composer) BotMessage(pr PRDetails, mentions []string, bot string, security bool) string

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. Mentions follow the same empty-list rule as NewMessage. The PR author is intentionally omitted — the bot name carries it.

func (*Composer) NewMessage

func (c *Composer) NewMessage(pr PRDetails, mentions []string) string

NewMessage renders the initial Slack message for a PR. Mentions are joined with commas (matching the legacy PHP composer's wire format). When the mentions list is empty, the prefix is omitted entirely so the message has no stranded ", ".

func (*Composer) UpdatedMessage

func (c *Composer) UpdatedMessage(merged bool, original string) string

UpdatedMessage wraps the previous message in the closed-PR decoration: "[Merged] ~<original>~" or "[Closed] ~<original>~".

type Option

type Option func(*Client)

Option configures Client construction.

func WithBaseURL

func WithBaseURL(u string) Option

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
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL