Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Commit ¶
Commit represents a Git commit message. It consists of a message, an optional description, and an optional footer. The Commit type provides methods to create new commits, check for equality with other commits, and format the commit as a string. NewCommit, DefaultCommit, [Equal], [Paragraphs], and [String] are the relevant functions for working with Commit objects.
func DefaultCommit ¶
func DefaultCommit() Commit
DefaultCommit returns a new Commit(#Commit) with a default commit message and footer. The message will be "docs: add missing documentation" and the footer will be "This commit was created by jotbot."
func NewCommit ¶
NewCommit [func] creates a new Commit object with the specified message and description. The function takes a string msg and a variadic slice of strings desc, and returns a Commit object. If no description is given, an empty slice is used instead.
func (Commit) Equal ¶
Equal determines whether two Commits are equal. Two Commits are considered equal if they have the same message, footer, and description(s) [Commit, strings].
func (Commit) Paragraphs ¶
Paragraphs returns a slice of strings representing the paragraphs of the commit message. The first string is the commit message itself, followed by any description lines, and ending with the footer line.
type CommitOption ¶
type CommitOption func(*commit)
CommitOption is a type representing a function that modifies the behavior of the Commit function in Repository. It can be used as an optional argument in the Commit function to specify additional options such as the branch to commit to. The Branch function returns a CommitOption that sets the branch name for the commit.
func Branch ¶
func Branch(branch string) CommitOption
Branch is a function that returns a CommitOption. The returned option sets the name of the branch to commit to when committing a patch. If not set, the branch name defaults to "jotbot-patch".
type Committer ¶
type Committer interface {
Commit() Commit
}
Committer represents an interface for a type that can commit changes to a Git repository. Any type implementing this interface must have a Commit method which returns a Commit. The Repository type has a Commit method which takes a Patch and optional CommitOptions and applies the patch to the repository, creates a new branch if necessary, adds the changes to the index, and commits them with the specified commit message. If the provided patch implements the Committer interface, its Commit method will be used to create the commit message.
type Option ¶
type Option func(*Repository)
Option is a type that represents an option for a Repository. It is used to configure Repository instances with optional parameters. Option functions modify the Repository instance passed to them.
func WithLogger ¶
WithLogger returns an Option that sets the logger for a Repository. The logger is used to log information about the git commands that are run during patching.
type Patch ¶
Patch represents a patch that can be applied to a Git repository. It is an interface that defines the Apply method. The Apply method takes a root string as argument, which specifies the root directory of the Git repository, and returns an error if the patch application fails.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository represents a Git repository. It provides methods for committing patches and accessing the root directory of the repository. The Repository type implements the Patch and Committer interfaces, allowing for patches to be applied to the repository and commits to be made on behalf of the repository, respectively. It can be initialized with options using Repo function.
func Repo ¶
func Repo(root string, opts ...Option) *Repository
Repo represents a Git repository. It provides methods for committing patches to the repository. Use the Repo function to create a new Repository.
func (*Repository) Commit ¶
func (r *Repository) Commit(p Patch, opts ...CommitOption) error
Commit commits a patch to the repository. It takes a Patch and optional CommitOptions. If no branch is specified in the options, "jotbot-patch" is used. If the branch already exists, the name will be suffixed with the current Unix timestamp in milliseconds. The patch is applied to the repository, and all changes are added and committed. If the Patch implements Committer, its Commit method will be called to obtain commit information.
func (*Repository) Root ¶
func (repo *Repository) Root() string
Root returns the root directory of the Repository Repository.