Documentation
¶
Overview ¶
Package repo provides GitHub repository operations.
Index ¶
- Variables
- func BranchExists(ctx context.Context, gh *github.Client, owner, repo, branch string) (bool, error)
- func CreateBranch(ctx context.Context, gh *github.Client, owner, repo, branch, baseSHA string) error
- func CreateCommit(ctx context.Context, gh *github.Client, owner, repo, branch, message string, ...) (string, error)
- func DeleteBranch(ctx context.Context, gh *github.Client, owner, repo, branch string) error
- func EnsureFork(ctx context.Context, gh *github.Client, ...) (string, string, error)
- func GetBranchSHA(ctx context.Context, gh *github.Client, owner, repo, branch string) (string, error)
- func GetDefaultBranch(ctx context.Context, gh *github.Client, owner, repo string) (string, error)
- func GetRepo(ctx context.Context, gh *github.Client, owner, repo string) (*github.Repository, error)
- func ListOrgRepos(ctx context.Context, gh *github.Client, org string) ([]*github.Repository, error)
- func ListUserRepos(ctx context.Context, gh *github.Client, user string) ([]*github.Repository, error)
- func ParseRepoName(fullName string) (owner, repo string, err error)
- type Batch
- type BatchError
- type BatchOperation
- type BatchOperationType
- type BatchOption
- type BranchError
- type CommitError
- type FileContent
- type ForkError
Constants ¶
This section is empty.
Variables ¶
var ErrBatchCommitted = errors.New("batch already committed")
ErrBatchCommitted is returned when operations are attempted on a committed batch.
var ErrEmptyPath = errors.New("empty path not allowed")
ErrEmptyPath is returned when an empty path is provided.
Functions ¶
func BranchExists ¶
BranchExists checks if a branch exists.
func CreateBranch ¶
func CreateBranch(ctx context.Context, gh *github.Client, owner, repo, branch, baseSHA string) error
CreateBranch creates a new branch from the given base SHA.
func CreateCommit ¶
func CreateCommit(ctx context.Context, gh *github.Client, owner, repo, branch, message string, files []FileContent) (string, error)
CreateCommit creates a commit with the given files using the Git tree API.
func DeleteBranch ¶
DeleteBranch deletes a branch.
func EnsureFork ¶
func EnsureFork(ctx context.Context, gh *github.Client, upstreamOwner, upstreamRepo, forkOwner string) (string, string, error)
EnsureFork ensures a fork exists for the given repository. Returns the fork owner and repo name.
func GetBranchSHA ¶
func GetBranchSHA(ctx context.Context, gh *github.Client, owner, repo, branch string) (string, error)
GetBranchSHA returns the SHA of the given branch.
func GetDefaultBranch ¶
GetDefaultBranch returns the default branch of a repository.
func GetRepo ¶
func GetRepo(ctx context.Context, gh *github.Client, owner, repo string) (*github.Repository, error)
GetRepo retrieves a repository by owner and name.
func ListOrgRepos ¶
ListOrgRepos lists all repositories for an organization with pagination.
func ListUserRepos ¶
func ListUserRepos(ctx context.Context, gh *github.Client, user string) ([]*github.Repository, error)
ListUserRepos lists all repositories for a user with pagination.
func ParseRepoName ¶
ParseRepoName splits a full repo name (owner/repo) into owner and repo.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch accumulates multiple file operations to be committed atomically. Use NewBatch to create a batch, then call Write/Delete to queue operations, and finally Commit to apply all changes in a single commit.
func NewBatch ¶
func NewBatch(ctx context.Context, gh *github.Client, owner, repo, branch, message string, opts ...BatchOption) (*Batch, error)
NewBatch creates a new batch for accumulating file operations. The message is used as the commit message when Commit is called.
func (*Batch) Commit ¶
Commit applies all queued operations in a single commit. This uses the Git Data API (Trees and Commits) to create an atomic commit.
The process:
- Get the current commit SHA from the branch reference
- Get the current tree SHA from that commit
- Create blobs for all new/updated file contents
- Create a new tree with the changes
- Create a new commit pointing to the new tree
- Update the branch reference to the new commit
Returns the new commit SHA on success.
func (*Batch) Delete ¶
Delete queues a file delete operation. The file will be deleted when Commit is called. If the file doesn't exist at commit time, it is ignored (no error).
func (*Batch) Operations ¶
func (b *Batch) Operations() []BatchOperation
Operations returns a copy of the queued operations.
type BatchError ¶
BatchError indicates a failure during batch operations.
func (*BatchError) Error ¶
func (e *BatchError) Error() string
func (*BatchError) Unwrap ¶
func (e *BatchError) Unwrap() error
type BatchOperation ¶
type BatchOperation struct {
Type BatchOperationType
Path string
Content []byte
}
BatchOperation represents a single operation in a batch.
type BatchOperationType ¶
type BatchOperationType int
BatchOperationType indicates the type of batch operation.
const ( // BatchOpWrite represents a write (create/update) operation. BatchOpWrite BatchOperationType = iota // BatchOpDelete represents a delete operation. BatchOpDelete )
type BatchOption ¶
type BatchOption func(*Batch)
BatchOption configures a Batch.
func WithCommitAuthor ¶
func WithCommitAuthor(name, email string) BatchOption
WithCommitAuthor sets the commit author for the batch.
type BranchError ¶
BranchError indicates a failure to create or update a branch.
func (*BranchError) Error ¶
func (e *BranchError) Error() string
func (*BranchError) Unwrap ¶
func (e *BranchError) Unwrap() error
type CommitError ¶
CommitError indicates a failure to create a commit.
func (*CommitError) Error ¶
func (e *CommitError) Error() string
func (*CommitError) Unwrap ¶
func (e *CommitError) Unwrap() error
type FileContent ¶
FileContent represents a file to be committed.
func ReadLocalFiles ¶
func ReadLocalFiles(dir, prefix string) ([]FileContent, error)
ReadLocalFiles reads all files from a local directory recursively. The prefix is prepended to relative paths for the destination.