Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Commit ¶
Commit represents a set of changes or updates in a version control system with an associated message, optional extended description, and an optional footer. It provides the ability to compare itself with another commit for equality, generate a string representation consisting of its message, description paragraphs, and footer, and create default or custom commits with the provided message and description.
func DefaultCommit ¶
func DefaultCommit() Commit
DefaultCommit creates a new Commit with a predefined message and footer indicating that the commit was created automatically.
func NewCommit ¶
NewCommit creates a new Commit with a message and an optional description. It returns the created Commit.
func (Commit) Equal ¶
Equal reports whether two Commit instances are considered equivalent, comparing the message, footer, and description slices.
func (Commit) Paragraphs ¶
Paragraphs constructs a slice of strings representing the structured content of a commit, including its message, optional description paragraphs, and footer if present. Each element in the slice corresponds to a distinct section of the commit content. The message is always included as the first element, followed by the joined description lines as a single element if they exist, and finally the footer as the last element if it is not empty. The function ensures that even if the commit message is initially empty, a default message is provided. It returns a slice of strings where each string represents a separate paragraph or section of the commit.
type CommitOption ¶
type CommitOption func(*commit)
CommitOption represents a configuration modifier that customizes the behavior of a commit operation within a repository. It allows for setting various commit-related properties or parameters before finalizing the commit. This modifier is generally used when performing a commit to specify options such as the target branch, author information, or commit message, ensuring that the commit reflects the desired state and metadata.
func Branch ¶
func Branch(branch string) CommitOption
Branch configures the branch on which a commit should be made.
type Committer ¶
type Committer interface { // Commit creates a new commit in the repository to which the committer belongs, // incorporating changes from a provided patch. It applies the patch, stages the // changes, and then generates a commit with a message derived from the patch's // content. The function allows for specifying additional commit options, such // as the target branch. If any step of the process fails, an error detailing // the issue is returned. Commit() Commit }
Committer represents an entity capable of producing a commit, which encapsulates changes to be recorded in a version control system. It provides a way to generate a Commit that describes the modifications made.
type Option ¶
type Option func(*Repository)
Option configures a *Repository by setting its properties or initializing resources needed by the repository. It is typically passed to the Repo function to customize the returned *Repository instance.
func WithLogger ¶
WithLogger returns an Option that sets the logger of a Repository to a new logger using the provided slog.Handler.
type Patch ¶
type Patch interface { // Apply applies the patch to the repository at the given root path, using the // provided context for any necessary operations. It returns an error if the // patch cannot be applied successfully. Apply(ctx context.Context, root string) error }
Patch represents an operation that can be applied to a repository to modify its contents. It encapsulates the changes that should be made within the context of a given directory, and it is responsible for executing those changes when prompted. The Apply method is used to trigger the application of the patch to the repository, effectively altering the state of the repository's files and directories as intended by the patch.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository represents a version-controlled workspace where changes to files are tracked. It provides an interface to commit changesets, represented by the Patch interface, to the underlying version control system. It supports custom logging and branch naming through various options that can be passed during the creation or committing process. Additionally, it allows clients to retrieve the root directory of the repository.
func Repo ¶
func Repo(root string, opts ...Option) *Repository
Repo initializes a new instance of a *Repository with the provided root directory and applies any provided options. If no logger is provided in the options, a no-op logger is used by default. It returns the newly created *Repository.
func (*Repository) Commit ¶
func (r *Repository) Commit(ctx context.Context, p Patch, opts ...CommitOption) error
Commit applies the provided Patch to the repository, creating a new commit on a branch specified by the CommitOptions. If no branch is specified, a default one is created. The function records changes in the repository and logs the commit process. In case of failure during any step of the commit process, an error is returned detailing the issue encountered.
func (*Repository) Root ¶
func (repo *Repository) Root() string
Root retrieves the root directory path associated with the repository. It returns a string representing the filesystem path to the repository's root directory.