Documentation
¶
Overview ¶
Package gitprovider provides a provider-agnostic interface for Git repository operations, including creating repos, pushing files, and deleting repos.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedProvider is returned when an unsupported Git provider is specified. ErrUnsupportedProvider = errors.New("unsupported git provider") // ErrTokenRequired is returned when a token is required but not provided. ErrTokenRequired = errors.New("git provider API token is required") // ErrInvalidRepoFormat is returned when the repo format is invalid. ErrInvalidRepoFormat = errors.New("invalid repo format") // ErrInvalidRepoVisibility is returned when the repo visibility is invalid. ErrInvalidRepoVisibility = errors.New("invalid repo-visibility") // ErrGitHubAPI is returned when the GitHub API returns an error. ErrGitHubAPI = errors.New("GitHub API error") // ErrRepoAlreadyExists is returned when the repository already exists. ErrRepoAlreadyExists = errors.New("repository already exists") // ErrOwnerMismatch is returned when the token user does not match the requested owner. ErrOwnerMismatch = errors.New("authenticated user does not match requested owner") // ErrBranchAlreadyExists is returned when the branch already exists. ErrBranchAlreadyExists = errors.New("branch already exists") )
Functions ¶
func ParseOwnerRepo ¶
ParseOwnerRepo splits "owner/repo-name" into owner and repo.
func ResolveProviderHost ¶
ResolveProviderHost maps a git provider name to its hostname. Unknown providers are returned as-is (assumed to be a custom host).
func ResolveToken ¶
ResolveToken resolves the API token using the fallback chain: 1. Explicit token parameter (--git-token flag) 2. Provider SDK auto-detection:
- GitHub: go-gh SDK (checks GH_TOKEN, GITHUB_TOKEN env vars and GitHub CLI config)
- GitLab: GITLAB_TOKEN env var
- Gitea: GITEA_TOKEN env var
Types ¶
type PROptions ¶
type PROptions struct {
// Title is the pull request title.
Title string
// Body is the pull request description.
Body string
// Head is the source branch name.
Head string
// Base is the target branch name.
Base string
}
PROptions holds options for creating a pull request.
type Provider ¶
type Provider interface {
// CreateRepo creates a new repository.
CreateRepo(ctx context.Context, owner, name string, visibility RepoVisibility) error
// PushFiles pushes files to a repository's default branch (one commit per file via Contents API).
PushFiles(
ctx context.Context,
owner, name string,
files map[string][]byte,
commitMsg string,
) error
// DeleteRepo deletes a repository.
DeleteRepo(ctx context.Context, owner, name string) error
// GetDefaultBranch returns the default branch name of a repository.
GetDefaultBranch(ctx context.Context, owner, repo string) (string, error)
// CreateBranch creates a new branch from the given base branch.
CreateBranch(ctx context.Context, owner, repo, branchName, baseBranch string) error
// PushFilesToBranch pushes files to a specific branch (one commit per file via Contents API).
PushFilesToBranch(
ctx context.Context,
owner, repo, branch string,
files map[string][]byte,
commitMsg string,
) error
// CreatePullRequest creates a pull request and returns the PR URL.
CreatePullRequest(ctx context.Context, owner, repo string, opts PROptions) (string, error)
}
Provider is the interface for Git provider operations.
type RepoVisibility ¶
type RepoVisibility string
RepoVisibility defines the visibility of a Git repository.
const ( // VisibilityPrivate creates a private repository. VisibilityPrivate RepoVisibility = "Private" // VisibilityInternal creates an internal repository (org-visible). VisibilityInternal RepoVisibility = "Internal" // VisibilityPublic creates a public repository. VisibilityPublic RepoVisibility = "Public" )
func ParseVisibility ¶
func ParseVisibility(value string) (RepoVisibility, error)
ParseVisibility validates and normalizes a repo visibility string (case-insensitive).