Documentation
¶
Overview ¶
Package pubbrew reconciles one generated Homebrew cask into a protected tap through a reviewable GitHub pull request.
The package owns publication policy and idempotency. Repository reads, branch writes, and pull-request creation remain behind narrow ports so the state machine is deterministic and testable without network access.
Index ¶
- Variables
- type BaseSnapshot
- type BlobSHA
- type BranchName
- type BranchSnapshot
- type CaskToken
- type ChangeStatus
- type ChangedFile
- type CommitSHA
- type File
- type FilePath
- type PublicationState
- type PublishInput
- type PublishResult
- type PullRequest
- type PullRequestInput
- type PullRequestState
- type Repository
- type RepositoryReader
- type RepositoryWriter
- type SleepFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConflict reports remote state that the publisher cannot safely // overwrite or reconcile. ErrConflict = errors.New("homebrew publication conflict") // ErrRetryable reports a transient repository failure that may succeed on // a bounded retry. ErrRetryable = errors.New("retryable homebrew repository failure") )
Publication sentinel errors.
Functions ¶
This section is empty.
Types ¶
type BaseSnapshot ¶
type BaseSnapshot struct {
// Branch is the tap's current default branch.
Branch BranchName
// Commit is the default branch head commit.
Commit CommitSHA
// File is the cask at Commit.
File File
}
BaseSnapshot is the tap default branch and cask observed together.
type BranchSnapshot ¶
type BranchSnapshot struct {
// Present reports whether the branch exists.
Present bool
// Commit is the branch head commit when Present is true.
Commit CommitSHA
// Parent is the sole parent of Commit. It is empty unless Commit has
// exactly one parent.
Parent CommitSHA
// Files are the paths changed by Commit.
Files []ChangedFile
// File is the cask at Commit.
File File
}
BranchSnapshot is the publication branch head and cask.
type CaskToken ¶
type CaskToken string
CaskToken is a safe Homebrew cask token and filename stem.
func ParseCaskToken ¶
ParseCaskToken constructs a CaskToken from a lowercase token.
type ChangeStatus ¶
type ChangeStatus string
ChangeStatus describes how one commit changed a path.
const ( // ChangeAdded means the commit created a path. ChangeAdded ChangeStatus = "added" // ChangeModified means the commit replaced an existing path. ChangeModified ChangeStatus = "modified" )
type ChangedFile ¶
type ChangedFile struct {
// Path is the repository-relative changed path.
Path FilePath
// Status is the GitHub change classification.
Status ChangeStatus
}
ChangedFile is one path changed by a branch-head commit.
type File ¶
type File struct {
// Present reports whether the path exists at the observed ref.
Present bool
// Content is the decoded file body when Present is true.
Content []byte
// SHA is the blob object ID when Present is true.
SHA BlobSHA
}
File is one observed repository file.
type PublicationState ¶
type PublicationState string
PublicationState is the reconciled tap outcome.
const ( // StateCreated means this invocation created the pull request. StateCreated PublicationState = "created" // StateOpen means the exact pull request already existed. StateOpen PublicationState = "open" // StatePublished means the tap default branch already contains the cask. StatePublished PublicationState = "published" )
type PublishInput ¶
type PublishInput struct {
// Tap is the Homebrew tap repository to update.
Tap Repository
// Source is the producer repository that owns the release.
Source Repository
// Version is the stable released version.
Version rel.Version
// Commit is the producer commit that built the release.
Commit CommitSHA
// Cask is the expected cask token and filename stem.
Cask CaskToken
// Content is the generated cask Ruby source.
Content []byte
// Sleep waits between retryable observations. Nil selects a
// context-aware timer.
Sleep SleepFunc
}
PublishInput is the closed input to Publish.
type PublishResult ¶
type PublishResult struct {
// Tap is the target owner/repository.
Tap string `json:"tap"`
// Cask is the published cask token.
Cask string `json:"cask"`
// Branch is the deterministic publication branch.
Branch string `json:"branch"`
// PullRequestURL is the review URL. It can be empty when matching content
// reached the default branch outside a discoverable pull request.
PullRequestURL string `json:"pull_request_url"`
// State is created, open, or published.
State PublicationState `json:"state"`
}
PublishResult is the JSON payload produced by a successful Publish.
func Publish ¶
func Publish( ctx context.Context, input PublishInput, reader RepositoryReader, writer RepositoryWriter, ) (PublishResult, error)
Publish reconciles one generated cask through a tap pull request.
It never writes the default branch, force-updates a branch, deletes a path, or enables auto-merge. Remote write errors are followed by a fresh read before retry so an accepted request with a lost response cannot duplicate a commit or pull request.
type PullRequest ¶
type PullRequest struct {
// State is the observed pull-request lifecycle.
State PullRequestState
// URL is the human-facing pull-request URL when State is not absent.
URL string
}
PullRequest is the unique pull request for a publication branch.
type PullRequestInput ¶
type PullRequestInput struct {
// Base is the tap default branch.
Base BranchName
// Head is the publication branch.
Head BranchName
// Title is the pull-request title.
Title string
// Body is the pull-request description.
Body string
}
PullRequestInput is the closed request used to open a publication review.
type PullRequestState ¶
type PullRequestState string
PullRequestState is the observed lifecycle state of one publication pull request.
const ( // PullRequestAbsent means no pull request uses the publication branch. PullRequestAbsent PullRequestState = "absent" // PullRequestOpen means the pull request awaits review or merge. PullRequestOpen PullRequestState = "open" // PullRequestMerged means the pull request was merged. PullRequestMerged PullRequestState = "merged" // PullRequestClosed means the pull request was closed without merging. PullRequestClosed PullRequestState = "closed" )
type Repository ¶
type Repository struct {
// Owner is the repository owner or organization.
Owner string
// Name is the repository name.
Name string
}
Repository is a validated GitHub owner/name pair.
func ParseRepository ¶
func ParseRepository(value string) (Repository, error)
ParseRepository constructs a Repository from owner/name.
type RepositoryReader ¶
type RepositoryReader interface {
// ReadBase returns the default branch, its head, and path at that head.
ReadBase(ctx context.Context, repository Repository, path FilePath) (BaseSnapshot, error)
// ReadBranch returns branch head metadata and path at that head. An absent
// branch is a successful snapshot with Present false.
ReadBranch(
ctx context.Context,
repository Repository,
branch BranchName,
path FilePath,
) (BranchSnapshot, error)
// ReadPullRequest returns the unique pull request from head into base. No
// match is a successful result with State absent.
ReadPullRequest(
ctx context.Context,
repository Repository,
base BranchName,
head BranchName,
) (PullRequest, error)
}
RepositoryReader observes tap branches, casks, and pull requests.
type RepositoryWriter ¶
type RepositoryWriter interface {
// CreateBranch creates branch at from without updating an existing ref.
CreateBranch(
ctx context.Context,
repository Repository,
branch BranchName,
from CommitSHA,
) error
// PutFile creates one commit on branch that creates or replaces path.
// Previous is empty for a new path and the current base blob for an update.
PutFile(
ctx context.Context,
repository Repository,
branch BranchName,
path FilePath,
previous BlobSHA,
content []byte,
message string,
) error
// CreatePullRequest opens a non-draft pull request without auto-merge.
CreatePullRequest(
ctx context.Context,
repository Repository,
input PullRequestInput,
) (string, error)
}
RepositoryWriter creates publisher-owned branches, commits, and pull requests.