Documentation
¶
Overview ¶
Package git provides a unified interface for interacting with multiple Git providers.
Index ¶
- Variables
- type BitbucketProvider
- func (p *BitbucketProvider) Configure(ctx context.Context, config *ProviderConfig) error
- func (p *BitbucketProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, ...) (*Webhook, error)
- func (p *BitbucketProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
- func (p *BitbucketProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
- func (p *BitbucketProvider) GetAuthorizationURL(state, redirectURI string) string
- func (p *BitbucketProvider) GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
- func (p *BitbucketProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
- func (p *BitbucketProvider) GetUser(ctx context.Context, token string) (*User, error)
- func (p *BitbucketProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
- func (p *BitbucketProvider) Name() ProviderType
- type GitHubProvider
- func (p *GitHubProvider) Configure(ctx context.Context, config *ProviderConfig) error
- func (p *GitHubProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, ...) (*Webhook, error)
- func (p *GitHubProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
- func (p *GitHubProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
- func (p *GitHubProvider) GetAuthorizationURL(state, redirectURI string) string
- func (p *GitHubProvider) GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
- func (p *GitHubProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
- func (p *GitHubProvider) GetUser(ctx context.Context, token string) (*User, error)
- func (p *GitHubProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
- func (p *GitHubProvider) Name() ProviderType
- type GitLabProvider
- func (p *GitLabProvider) Configure(ctx context.Context, config *ProviderConfig) error
- func (p *GitLabProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, ...) (*Webhook, error)
- func (p *GitLabProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
- func (p *GitLabProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
- func (p *GitLabProvider) GetAuthorizationURL(state, redirectURI string) string
- func (p *GitLabProvider) GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
- func (p *GitLabProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
- func (p *GitLabProvider) GetUser(ctx context.Context, token string) (*User, error)
- func (p *GitLabProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
- func (p *GitLabProvider) Name() ProviderType
- type GiteaProvider
- func (p *GiteaProvider) Configure(ctx context.Context, config *ProviderConfig) error
- func (p *GiteaProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, ...) (*Webhook, error)
- func (p *GiteaProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
- func (p *GiteaProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
- func (p *GiteaProvider) GetAuthorizationURL(state, redirectURI string) string
- func (p *GiteaProvider) GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
- func (p *GiteaProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
- func (p *GiteaProvider) GetUser(ctx context.Context, token string) (*User, error)
- func (p *GiteaProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
- func (p *GiteaProvider) Name() ProviderType
- type OAuthToken
- type Provider
- type ProviderConfig
- type ProviderType
- type Repository
- type User
- type Webhook
Constants ¶
This section is empty.
Variables ¶
var ProviderRegistry = map[ProviderType]func() Provider{ ProviderGitHub: NewGitHubProvider, ProviderGitLab: NewGitLabProvider, ProviderBitbucket: NewBitbucketProvider, ProviderGitea: NewGiteaProvider, }
ProviderRegistry holds registered Git providers.
Functions ¶
This section is empty.
Types ¶
type BitbucketProvider ¶
type BitbucketProvider struct {
// contains filtered or unexported fields
}
BitbucketProvider implements the Provider interface for Bitbucket.
func (*BitbucketProvider) Configure ¶
func (p *BitbucketProvider) Configure(ctx context.Context, config *ProviderConfig) error
Configure sets up the provider with the given configuration.
func (*BitbucketProvider) CreateWebhook ¶
func (p *BitbucketProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, events []string) (*Webhook, error)
CreateWebhook creates a webhook for a repository.
func (*BitbucketProvider) DeleteWebhook ¶
func (p *BitbucketProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
DeleteWebhook removes a webhook from a repository.
func (*BitbucketProvider) ExchangeCode ¶
func (p *BitbucketProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
ExchangeCode exchanges an OAuth authorization code for access tokens.
func (*BitbucketProvider) GetAuthorizationURL ¶
func (p *BitbucketProvider) GetAuthorizationURL(state, redirectURI string) string
GetAuthorizationURL returns the OAuth authorization URL for user authentication.
func (*BitbucketProvider) GetCloneURL ¶
func (p *BitbucketProvider) GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
GetCloneURL returns the authenticated clone URL for a repository.
func (*BitbucketProvider) GetRepository ¶
func (p *BitbucketProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
GetRepository retrieves a specific repository by owner and name.
func (*BitbucketProvider) ListRepositories ¶
func (p *BitbucketProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
ListRepositories returns repositories the authenticated user has access to.
func (*BitbucketProvider) Name ¶
func (p *BitbucketProvider) Name() ProviderType
Name returns the provider type identifier.
type GitHubProvider ¶
type GitHubProvider struct {
// contains filtered or unexported fields
}
GitHubProvider implements the Provider interface for GitHub.
func (*GitHubProvider) Configure ¶
func (p *GitHubProvider) Configure(ctx context.Context, config *ProviderConfig) error
Configure sets up the provider with the given configuration.
func (*GitHubProvider) CreateWebhook ¶
func (p *GitHubProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, events []string) (*Webhook, error)
CreateWebhook creates a webhook for a repository.
func (*GitHubProvider) DeleteWebhook ¶
func (p *GitHubProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
DeleteWebhook removes a webhook from a repository.
func (*GitHubProvider) ExchangeCode ¶
func (p *GitHubProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
ExchangeCode exchanges an OAuth authorization code for access tokens.
func (*GitHubProvider) GetAuthorizationURL ¶
func (p *GitHubProvider) GetAuthorizationURL(state, redirectURI string) string
GetAuthorizationURL returns the OAuth authorization URL for user authentication.
func (*GitHubProvider) GetCloneURL ¶
func (p *GitHubProvider) GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
GetCloneURL returns the authenticated clone URL for a repository.
func (*GitHubProvider) GetRepository ¶
func (p *GitHubProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
GetRepository retrieves a specific repository by owner and name.
func (*GitHubProvider) ListRepositories ¶
func (p *GitHubProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
ListRepositories returns repositories the authenticated user has access to.
func (*GitHubProvider) Name ¶
func (p *GitHubProvider) Name() ProviderType
Name returns the provider type identifier.
type GitLabProvider ¶
type GitLabProvider struct {
// contains filtered or unexported fields
}
GitLabProvider implements the Provider interface for GitLab.
func (*GitLabProvider) Configure ¶
func (p *GitLabProvider) Configure(ctx context.Context, config *ProviderConfig) error
Configure sets up the provider with the given configuration.
func (*GitLabProvider) CreateWebhook ¶
func (p *GitLabProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, events []string) (*Webhook, error)
CreateWebhook creates a webhook for a repository.
func (*GitLabProvider) DeleteWebhook ¶
func (p *GitLabProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
DeleteWebhook removes a webhook from a repository.
func (*GitLabProvider) ExchangeCode ¶
func (p *GitLabProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
ExchangeCode exchanges an OAuth authorization code for access tokens.
func (*GitLabProvider) GetAuthorizationURL ¶
func (p *GitLabProvider) GetAuthorizationURL(state, redirectURI string) string
GetAuthorizationURL returns the OAuth authorization URL for user authentication.
func (*GitLabProvider) GetCloneURL ¶
func (p *GitLabProvider) GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
GetCloneURL returns the authenticated clone URL for a repository.
func (*GitLabProvider) GetRepository ¶
func (p *GitLabProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
GetRepository retrieves a specific repository by owner and name.
func (*GitLabProvider) ListRepositories ¶
func (p *GitLabProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
ListRepositories returns repositories the authenticated user has access to.
func (*GitLabProvider) Name ¶
func (p *GitLabProvider) Name() ProviderType
Name returns the provider type identifier.
type GiteaProvider ¶
type GiteaProvider struct {
// contains filtered or unexported fields
}
GiteaProvider implements the Provider interface for Gitea.
func (*GiteaProvider) Configure ¶
func (p *GiteaProvider) Configure(ctx context.Context, config *ProviderConfig) error
Configure sets up the provider with the given configuration.
func (*GiteaProvider) CreateWebhook ¶
func (p *GiteaProvider) CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, events []string) (*Webhook, error)
CreateWebhook creates a webhook for a repository.
func (*GiteaProvider) DeleteWebhook ¶
func (p *GiteaProvider) DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
DeleteWebhook removes a webhook from a repository.
func (*GiteaProvider) ExchangeCode ¶
func (p *GiteaProvider) ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
ExchangeCode exchanges an OAuth authorization code for access tokens.
func (*GiteaProvider) GetAuthorizationURL ¶
func (p *GiteaProvider) GetAuthorizationURL(state, redirectURI string) string
GetAuthorizationURL returns the OAuth authorization URL for user authentication.
func (*GiteaProvider) GetCloneURL ¶
GetCloneURL returns the authenticated clone URL for a repository.
func (*GiteaProvider) GetRepository ¶
func (p *GiteaProvider) GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
GetRepository retrieves a specific repository by owner and name.
func (*GiteaProvider) ListRepositories ¶
func (p *GiteaProvider) ListRepositories(ctx context.Context, token string) ([]*Repository, error)
ListRepositories returns repositories the authenticated user has access to.
func (*GiteaProvider) Name ¶
func (p *GiteaProvider) Name() ProviderType
Name returns the provider type identifier.
type OAuthToken ¶
type OAuthToken struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
TokenType string `json:"token_type"`
Expiry time.Time `json:"expiry,omitempty"`
}
OAuthToken represents OAuth token information.
type Provider ¶
type Provider interface {
// Name returns the provider type identifier.
Name() ProviderType
// Configure sets up the provider with the given configuration.
Configure(ctx context.Context, config *ProviderConfig) error
// GetAuthorizationURL returns the OAuth authorization URL for user authentication.
GetAuthorizationURL(state, redirectURI string) string
// ExchangeCode exchanges an OAuth authorization code for access tokens.
ExchangeCode(ctx context.Context, code, redirectURI string) (*OAuthToken, error)
// GetUser retrieves the authenticated user's information.
GetUser(ctx context.Context, token string) (*User, error)
// ListRepositories returns repositories the authenticated user has access to.
ListRepositories(ctx context.Context, token string) ([]*Repository, error)
// GetRepository retrieves a specific repository by owner and name.
GetRepository(ctx context.Context, token, owner, repo string) (*Repository, error)
// CreateWebhook creates a webhook for a repository.
CreateWebhook(ctx context.Context, token, owner, repo, webhookURL, secret string, events []string) (*Webhook, error)
// DeleteWebhook removes a webhook from a repository.
DeleteWebhook(ctx context.Context, token, owner, repo, webhookID string) error
// GetCloneURL returns the authenticated clone URL for a repository.
GetCloneURL(ctx context.Context, token, owner, repo string) (string, error)
}
Provider defines the interface for Git provider operations. All Git providers (GitHub, GitLab, Bitbucket, Gitea) must implement this interface.
func GetProvider ¶
func GetProvider(providerType ProviderType) (Provider, bool)
GetProvider returns a new instance of the specified provider.
func NewBitbucketProvider ¶
func NewBitbucketProvider() Provider
NewBitbucketProvider creates a new Bitbucket provider instance.
func NewGitHubProvider ¶
func NewGitHubProvider() Provider
NewGitHubProvider creates a new GitHub provider instance.
func NewGitLabProvider ¶
func NewGitLabProvider() Provider
NewGitLabProvider creates a new GitLab provider instance.
func NewGiteaProvider ¶
func NewGiteaProvider() Provider
NewGiteaProvider creates a new Gitea provider instance.
type ProviderConfig ¶
type ProviderConfig struct {
// InstanceURL is the base URL for self-hosted instances (GitLab, Gitea).
// For cloud providers (GitHub, Bitbucket), this can be empty.
InstanceURL string `json:"instance_url,omitempty"`
// ClientID is the OAuth application client ID.
ClientID string `json:"client_id"`
// ClientSecret is the OAuth application client secret.
ClientSecret string `json:"client_secret"`
// WebhookSecret is used to verify webhook payloads.
WebhookSecret string `json:"webhook_secret,omitempty"`
// PrivateKey is the private key for GitHub App authentication (GitHub only).
PrivateKey string `json:"private_key,omitempty"`
// AppID is the GitHub App ID (GitHub only).
AppID int64 `json:"app_id,omitempty"`
}
ProviderConfig holds the configuration for a Git provider.
type ProviderType ¶
type ProviderType string
ProviderType represents the type of Git provider.
const ( ProviderGitHub ProviderType = "github" ProviderGitLab ProviderType = "gitlab" ProviderBitbucket ProviderType = "bitbucket" ProviderGitea ProviderType = "gitea" )
type Repository ¶
type Repository struct {
ID string `json:"id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Description string `json:"description"`
HTMLURL string `json:"html_url"`
CloneURL string `json:"clone_url"`
SSHURL string `json:"ssh_url"`
DefaultBranch string `json:"default_branch"`
Private bool `json:"private"`
Archived bool `json:"archived"`
}
Repository represents a Git repository from any provider.