repo

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package repo provides GitHub repository operations.

Index

Constants

This section is empty.

Variables

View Source
var ErrBatchCommitted = errors.New("batch already committed")

ErrBatchCommitted is returned when operations are attempted on a committed batch.

View Source
var ErrEmptyPath = errors.New("empty path not allowed")

ErrEmptyPath is returned when an empty path is provided.

Functions

func BranchExists

func BranchExists(ctx context.Context, gh *github.Client, owner, repo, branch string) (bool, error)

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

func DeleteBranch(ctx context.Context, gh *github.Client, owner, repo, branch string) error

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

func GetDefaultBranch(ctx context.Context, gh *github.Client, owner, repo string) (string, error)

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

func ListOrgRepos(ctx context.Context, gh *github.Client, org string) ([]*github.Repository, error)

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

func ParseRepoName(fullName string) (owner, repo string, err error)

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

func (b *Batch) Commit(ctx context.Context) (string, error)

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:

  1. Get the current commit SHA from the branch reference
  2. Get the current tree SHA from that commit
  3. Create blobs for all new/updated file contents
  4. Create a new tree with the changes
  5. Create a new commit pointing to the new tree
  6. Update the branch reference to the new commit

Returns the new commit SHA on success.

func (*Batch) Committed

func (b *Batch) Committed() bool

Committed returns whether the batch has been committed.

func (*Batch) Delete

func (b *Batch) Delete(filePath string) error

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

func (b *Batch) Len() int

Len returns the number of operations in the batch.

func (*Batch) Operations

func (b *Batch) Operations() []BatchOperation

Operations returns a copy of the queued operations.

func (*Batch) Write

func (b *Batch) Write(filePath string, content []byte) error

Write queues a file write operation. The file will be created or updated when Commit is called.

type BatchError

type BatchError struct {
	Op  string
	Err error
}

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

type BranchError struct {
	Branch string
	Err    error
}

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

type CommitError struct {
	Message string
	Err     error
}

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

type FileContent struct {
	Path    string
	Content []byte
}

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.

type ForkError

type ForkError struct {
	Owner string
	Repo  string
	Err   error
}

ForkError indicates a failure to fork a repository.

func (*ForkError) Error

func (e *ForkError) Error() string

func (*ForkError) Unwrap

func (e *ForkError) Unwrap() error

Jump to

Keyboard shortcuts

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