validate

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
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

type CheckResult struct {
	Name   string
	Status Status
	Detail string
}

CheckResult is one row of a Report.

type EntryResult

type EntryResult struct {
	Entry   mappings.Entry
	Reports []Report
}

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)
}

MappingLookup reads a single repository → channel mapping. The runner iterates entries explicitly (see RunForEntries), so no bulk-list method is needed here.

type OrgRepoLister

type OrgRepoLister interface {
	ListOrgRepos(ctx context.Context, org string) ([]string, error)
}

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

type RepoValidator interface {
	Validate(ctx context.Context, repository string) Report
}

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.

func (Report) OK

func (r Report) OK() bool

OK returns true when no check failed. Skipped checks do not count as failures.

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 Status

type Status int

Status is the outcome of a single check.

const (
	// StatusOK means the check passed.
	StatusOK Status = iota
	// StatusFail means the check found a problem the operator must fix.
	StatusFail
	// StatusSkip means the check could not run (e.g., GitHub token absent).
	StatusSkip
)

func (Status) String

func (s Status) String() string

String renders Status as OK / FAIL / SKIP for greppable CLI output.

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.

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, repository string) Report

Validate runs every check for a single repository.

Jump to

Keyboard shortcuts

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