Documentation
¶
Overview ¶
Package validate verifies that a repository → Slack-channel mapping is usable end-to-end before GitHub fires a real PR event: the mapping row exists, the channel ID is well-formed, the Slack bot has the right scopes and is a member of the channel, and (when GitHub credentials are available) the webhook is subscribed to the events notifycat needs.
The Validator depends only on the narrow interfaces declared below so tests can supply hand-written mocks without touching the real Slack or GitHub client packages.
Index ¶
Constants ¶
const WebhookURLPath = "/webhook/github"
WebhookURLPath is the path the GitHub webhook posts to. Used to identify which configured hook on a repository belongs to notifycat.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CheckResult ¶
CheckResult is one row of a Report.
type EntryResult ¶
EntryResult bundles every report produced for a single mapping entry, so callers can update the lock per-entry: an entry is "validated" only when every report it produced is OK.
func RunForEntries ¶
func RunForEntries( ctx context.Context, entries []mappings.Entry, lister OrgRepoLister, v RepoValidator, ) []EntryResult
RunForEntries validates a slice of mapping entries, expanding wildcard entries against lister. It never short-circuits: per-repo failures and lister errors surface as the entry's reports so the operator sees every mapping's outcome in one run.
lister may be nil; wildcard entries then produce a single Skip report.
func (EntryResult) OK ¶
func (r EntryResult) OK() bool
OK reports whether every contributed report passed.
type GitHubChecker ¶
type GitHubChecker interface {
ListHookEvents(ctx context.Context, owner, repo, urlSuffix string) ([]string, error)
}
GitHubChecker exposes the GitHub endpoints the validator needs.
ListHookEvents returns the union of events configured across active webhooks whose target URL matches urlSuffix, or an empty slice when no such hook exists. Implementations should not error when no hook matches — "no hook" is a validation outcome, not a transport failure.
type MappingLookup ¶
type MappingLookup interface {
Get(ctx context.Context, repository string) (store.RepoMapping, error)
PathChannels(repository string) []string
}
MappingLookup reads a single repository → channel mapping. The runner iterates entries explicitly (see RunForEntries), so no bulk-list method is needed here. PathChannels returns the extra channels a repo's per-path routing can post to, so the validator can confirm bot membership in each (empty for repos without `paths:`).
type OrgRepoLister ¶
OrgRepoLister enumerates a GitHub org's repositories. Used to expand "*" at validate time. May be nil; the runner reports a skip in that case.
type RepoValidator ¶
RepoValidator validates one repository at a time. *Validator satisfies it; the runner depends on this narrow surface so wildcard expansion can be tested without standing up real Slack/GitHub clients.
type Report ¶
type Report struct {
Repository string
Checks []CheckResult
}
Report aggregates the per-check results for a single mapping.
type SlackChecker ¶
type SlackChecker interface {
AuthTest(ctx context.Context) (userID string, scopes []string, err error)
ConversationsInfo(ctx context.Context, channel string) (slack.ChannelInfo, error)
}
SlackChecker exposes the Slack endpoints the validator needs.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator runs the per-mapping checks. Construct with NewValidator; the GitHubChecker may be nil, in which case webhook coverage is reported as skipped.
func NewValidator ¶
func NewValidator(m MappingLookup, s SlackChecker, gh GitHubChecker) *Validator
NewValidator builds a Validator. gh may be nil when no GitHub token is configured.