Documentation ¶
Index ¶
- Constants
- func NewClient(optFns ...ClientOption) (gitprovider.Client, error)
- type Client
- func (c *Client) OrgRepositories() gitprovider.OrgRepositoriesClient
- func (c *Client) Organizations() gitprovider.OrganizationsClient
- func (c *Client) ProviderID() gitprovider.ProviderID
- func (c *Client) Raw() interface{}
- func (c *Client) SupportedDomain() string
- func (c *Client) UserRepositories() gitprovider.UserRepositoriesClient
- type ClientOption
- func WithConditionalRequests(conditionalRequests bool) ClientOption
- func WithDestructiveAPICalls(destructiveActions bool) ClientOption
- func WithDomain(domain string) ClientOption
- func WithOAuth2Token(oauth2Token string) ClientOption
- func WithPostChainTransportHook(postRoundTripperFunc gitprovider.ChainableRoundTripperFunc) ClientOption
- func WithPreChainTransportHook(preRoundTripperFunc gitprovider.ChainableRoundTripperFunc) ClientOption
- type DeployKeyClient
- func (c *DeployKeyClient) Create(ctx context.Context, req gitprovider.DeployKeyInfo) (gitprovider.DeployKey, error)
- func (c *DeployKeyClient) Get(ctx context.Context, name string) (gitprovider.DeployKey, error)
- func (c *DeployKeyClient) List(ctx context.Context) ([]gitprovider.DeployKey, error)
- func (c *DeployKeyClient) Reconcile(ctx context.Context, req gitprovider.DeployKeyInfo) (gitprovider.DeployKey, bool, error)
- type OrgRepositoriesClient
- func (c *OrgRepositoriesClient) Create(ctx context.Context, ref gitprovider.OrgRepositoryRef, ...) (gitprovider.OrgRepository, error)
- func (c *OrgRepositoriesClient) Get(ctx context.Context, ref gitprovider.OrgRepositoryRef) (gitprovider.OrgRepository, error)
- func (c *OrgRepositoriesClient) List(ctx context.Context, ref gitprovider.OrganizationRef) ([]gitprovider.OrgRepository, error)
- func (c *OrgRepositoriesClient) Reconcile(ctx context.Context, ref gitprovider.OrgRepositoryRef, ...) (gitprovider.OrgRepository, bool, error)
- type OrganizationsClient
- func (c *OrganizationsClient) Children(_ context.Context, _ gitprovider.OrganizationRef) ([]gitprovider.Organization, error)
- func (c *OrganizationsClient) Get(ctx context.Context, ref gitprovider.OrganizationRef) (gitprovider.Organization, error)
- func (c *OrganizationsClient) List(ctx context.Context) ([]gitprovider.Organization, error)
- type TeamAccessClient
- func (c *TeamAccessClient) Create(ctx context.Context, req gitprovider.TeamAccessInfo) (gitprovider.TeamAccess, error)
- func (c *TeamAccessClient) Get(ctx context.Context, name string) (gitprovider.TeamAccess, error)
- func (c *TeamAccessClient) List(ctx context.Context) ([]gitprovider.TeamAccess, error)
- func (c *TeamAccessClient) Reconcile(ctx context.Context, req gitprovider.TeamAccessInfo) (gitprovider.TeamAccess, bool, error)
- type TeamsClient
- type UserRepositoriesClient
- func (c *UserRepositoriesClient) Create(ctx context.Context, ref gitprovider.UserRepositoryRef, ...) (gitprovider.UserRepository, error)
- func (c *UserRepositoriesClient) Get(ctx context.Context, ref gitprovider.UserRepositoryRef) (gitprovider.UserRepository, error)
- func (c *UserRepositoriesClient) List(ctx context.Context, ref gitprovider.UserRef) ([]gitprovider.UserRepository, error)
- func (c *UserRepositoriesClient) Reconcile(ctx context.Context, ref gitprovider.UserRepositoryRef, ...) (gitprovider.UserRepository, bool, error)
Examples ¶
Constants ¶
const (
// DefaultDomain specifies the default domain used as the backend.
DefaultDomain = "github.com"
)
const ProviderID = gitprovider.ProviderID("github")
ProviderID is the provider ID for GitHub.
Variables ¶
This section is empty.
Functions ¶
func NewClient ¶
func NewClient(optFns ...ClientOption) (gitprovider.Client, error)
NewClient creates a new gitprovider.Client instance for GitHub API endpoints.
Using WithOAuth2Token you can specify authentication credentials, passing no such ClientOption will allow public read access only.
Password-based authentication is not supported because it is deprecated by GitHub, see https://developer.github.com/changes/2020-02-14-deprecating-password-auth/
GitHub Enterprise can be used if you specify the domain using WithDomain.
You can customize low-level HTTP Transport functionality by using the With{Pre,Post}ChainTransportHook options. You can also use conditional requests (and an in-memory cache) using WithConditionalRequests.
The chain of transports looks like this: github.com API <-> "Post Chain" <-> Authentication <-> Cache <-> "Pre Chain" <-> *github.Client.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an interface that allows talking to a Git provider.
func (*Client) OrgRepositories ¶
func (c *Client) OrgRepositories() gitprovider.OrgRepositoriesClient
OrgRepositories returns the OrgRepositoriesClient handling sets of repositories in an organization.
func (*Client) Organizations ¶
func (c *Client) Organizations() gitprovider.OrganizationsClient
Organizations returns the OrganizationsClient handling sets of organizations.
func (*Client) ProviderID ¶
func (c *Client) ProviderID() gitprovider.ProviderID
ProviderID returns the provider ID "github". This field is set at client creation time, and can't be changed.
func (*Client) Raw ¶
func (c *Client) Raw() interface{}
Raw returns the Go GitHub client (github.com/google/go-github/v32/github *Client) used under the hood for accessing GitHub.
func (*Client) SupportedDomain ¶
SupportedDomain returns the domain endpoint for this client, e.g. "github.com", "enterprise.github.com" or "my-custom-git-server.com:6443". This allows a higher-level user to know what Client to use for what endpoints. This field is set at client creation time, and can't be changed.
func (*Client) UserRepositories ¶
func (c *Client) UserRepositories() gitprovider.UserRepositoriesClient
UserRepositories returns the UserRepositoriesClient handling sets of repositories for a user.
type ClientOption ¶
type ClientOption interface { // ApplyToGithubClientOptions applies set fields of this object into target. ApplyToGithubClientOptions(target *clientOptions) error }
ClientOption is the interface to implement for passing options to NewClient. The clientOptions struct is private to force usage of the With... functions.
func WithConditionalRequests ¶
func WithConditionalRequests(conditionalRequests bool) ClientOption
WithConditionalRequests instructs the client to use Conditional Requests to GitHub, asking GitHub whether a resource has changed (without burning your quota), and using an in-memory cached "database" if so. See: https://developer.github.com/v3/#conditional-requests for more information.
func WithDestructiveAPICalls ¶
func WithDestructiveAPICalls(destructiveActions bool) ClientOption
WithDestructiveAPICalls tells the client whether it's allowed to do dangerous and possibly destructive actions, like e.g. deleting a repository.
func WithDomain ¶
func WithDomain(domain string) ClientOption
WithDomain initializes a Client for a custom GitHub Enterprise instance of the given domain. Only host and port information should be present in domain. domain must not be an empty string.
func WithOAuth2Token ¶
func WithOAuth2Token(oauth2Token string) ClientOption
WithOAuth2Token initializes a Client which authenticates with GitHub through an OAuth2 token. oauth2Token must not be an empty string.
func WithPostChainTransportHook ¶
func WithPostChainTransportHook(postRoundTripperFunc gitprovider.ChainableRoundTripperFunc) ClientOption
WithPostChainTransportHook registers a ChainableRoundTripperFunc "after" the cache and authentication transports in the chain. For more information, see NewClient, and gitprovider.CommonClientOptions.WithPostChainTransportHook.
func WithPreChainTransportHook ¶
func WithPreChainTransportHook(preRoundTripperFunc gitprovider.ChainableRoundTripperFunc) ClientOption
WithPreChainTransportHook registers a ChainableRoundTripperFunc "before" the cache and authentication transports in the chain. For more information, see NewClient, and gitprovider.CommonClientOptions.PreChainTransportHook.
type DeployKeyClient ¶
type DeployKeyClient struct {
// contains filtered or unexported fields
}
DeployKeyClient operates on the access deploy key list for a specific repository.
func (*DeployKeyClient) Create ¶
func (c *DeployKeyClient) Create(ctx context.Context, req gitprovider.DeployKeyInfo) (gitprovider.DeployKey, error)
Create creates a deploy key with the given specifications.
ErrAlreadyExists will be returned if the resource already exists.
func (*DeployKeyClient) Get ¶
func (c *DeployKeyClient) Get(ctx context.Context, name string) (gitprovider.DeployKey, error)
Get returns the repository at the given path.
ErrNotFound is returned if the resource does not exist.
func (*DeployKeyClient) List ¶
func (c *DeployKeyClient) List(ctx context.Context) ([]gitprovider.DeployKey, error)
List lists all repository deploy keys of the given deploy key type.
List returns all available repository deploy keys for the given type, using multiple paginated requests if needed.
func (*DeployKeyClient) Reconcile ¶
func (c *DeployKeyClient) Reconcile(ctx context.Context, req gitprovider.DeployKeyInfo) (gitprovider.DeployKey, bool, error)
Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.
If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be deleted and recreated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).
type OrgRepositoriesClient ¶
type OrgRepositoriesClient struct {
// contains filtered or unexported fields
}
OrgRepositoriesClient operates on repositories the user has access to.
func (*OrgRepositoriesClient) Create ¶
func (c *OrgRepositoriesClient) Create(ctx context.Context, ref gitprovider.OrgRepositoryRef, req gitprovider.RepositoryInfo, opts ...gitprovider.RepositoryCreateOption) (gitprovider.OrgRepository, error)
Create creates a repository for the given organization, with the data and options.
ErrAlreadyExists will be returned if the resource already exists.
func (*OrgRepositoriesClient) Get ¶
func (c *OrgRepositoriesClient) Get(ctx context.Context, ref gitprovider.OrgRepositoryRef) (gitprovider.OrgRepository, error)
Get returns the repository at the given path.
ErrNotFound is returned if the resource does not exist.
Example ¶
// Create a new client ctx := context.Background() c, err := github.NewClient() checkErr(err) // Parse the URL into an OrgRepositoryRef ref, err := gitprovider.ParseOrgRepositoryURL("https://github.com/fluxcd/flux") checkErr(err) // Get public information about the flux repository. repo, err := c.OrgRepositories().Get(ctx, *ref) checkErr(err) // Use .Get() to aquire a high-level gitprovider.OrganizationInfo struct repoInfo := repo.Get() // Cast the internal object to a *gogithub.Repository to access custom data internalRepo := repo.APIObject().(*gogithub.Repository) fmt.Printf("Description: %s. Homepage: %s", *repoInfo.Description, internalRepo.GetHomepage())
Output: Description: The GitOps Kubernetes operator. Homepage: https://docs.fluxcd.io
func (*OrgRepositoriesClient) List ¶
func (c *OrgRepositoriesClient) List(ctx context.Context, ref gitprovider.OrganizationRef) ([]gitprovider.OrgRepository, error)
List all repositories in the given organization.
List returns all available repositories, using multiple paginated requests if needed.
func (*OrgRepositoriesClient) Reconcile ¶
func (c *OrgRepositoriesClient) Reconcile(ctx context.Context, ref gitprovider.OrgRepositoryRef, req gitprovider.RepositoryInfo, opts ...gitprovider.RepositoryReconcileOption) (gitprovider.OrgRepository, bool, error)
Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.
If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be updated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).
type OrganizationsClient ¶
type OrganizationsClient struct {
// contains filtered or unexported fields
}
OrganizationsClient operates on organizations the user has access to.
func (*OrganizationsClient) Children ¶
func (c *OrganizationsClient) Children(_ context.Context, _ gitprovider.OrganizationRef) ([]gitprovider.Organization, error)
Children returns the immediate child-organizations for the specific OrganizationRef o. The OrganizationRef may point to any existing sub-organization.
This is not supported in GitHub.
Children returns all available organizations, using multiple paginated requests if needed.
func (*OrganizationsClient) Get ¶
func (c *OrganizationsClient) Get(ctx context.Context, ref gitprovider.OrganizationRef) (gitprovider.Organization, error)
Get a specific organization the user has access to. This can't refer to a sub-organization in GitHub, as those aren't supported.
ErrNotFound is returned if the resource does not exist.
Example ¶
package main import ( "context" "fmt" "log" "github.com/dinosk/go-git-providers/github" "github.com/dinosk/go-git-providers/gitprovider" gogithub "github.com/google/go-github/v32/github" ) // checkErr is used for examples in this repository. func checkErr(err error) { if err != nil { log.Fatal(err) } } func main() { // Create a new client ctx := context.Background() c, err := github.NewClient() checkErr(err) // Get public information about the fluxcd organization org, err := c.Organizations().Get(ctx, gitprovider.OrganizationRef{ Domain: github.DefaultDomain, Organization: "fluxcd", }) checkErr(err) // Use .Get() to aquire a high-level gitprovider.OrganizationInfo struct orgInfo := org.Get() // Cast the internal object to a *gogithub.Organization to access custom data internalOrg := org.APIObject().(*gogithub.Organization) fmt.Printf("Name: %s. Location: %s.", *orgInfo.Name, internalOrg.GetLocation()) }
Output: Name: Flux project. Location: CNCF sandbox.
func (*OrganizationsClient) List ¶
func (c *OrganizationsClient) List(ctx context.Context) ([]gitprovider.Organization, error)
List all top-level organizations the specific user has access to.
List returns all available organizations, using multiple paginated requests if needed.
type TeamAccessClient ¶
type TeamAccessClient struct {
// contains filtered or unexported fields
}
TeamAccessClient operates on the teams list for a specific repository.
func (*TeamAccessClient) Create ¶
func (c *TeamAccessClient) Create(ctx context.Context, req gitprovider.TeamAccessInfo) (gitprovider.TeamAccess, error)
Create adds a given team to the repo's team access control list.
ErrAlreadyExists will be returned if the resource already exists.
func (*TeamAccessClient) Get ¶
func (c *TeamAccessClient) Get(ctx context.Context, name string) (gitprovider.TeamAccess, error)
Get a team within the specific organization.
name may include slashes, but must not be an empty string. Teams are sub-groups in GitLab.
ErrNotFound is returned if the resource does not exist.
TeamAccess.APIObject will be nil, because there's no underlying Github struct.
func (*TeamAccessClient) List ¶
func (c *TeamAccessClient) List(ctx context.Context) ([]gitprovider.TeamAccess, error)
List lists the team access control list for this repository.
List returns all available team access lists, using multiple paginated requests if needed.
func (*TeamAccessClient) Reconcile ¶
func (c *TeamAccessClient) Reconcile(ctx context.Context, req gitprovider.TeamAccessInfo, ) (gitprovider.TeamAccess, bool, error)
Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.
If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be deleted and recreated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).
type TeamsClient ¶
type TeamsClient struct {
// contains filtered or unexported fields
}
TeamsClient handles teams organization-wide.
func (*TeamsClient) Get ¶
func (c *TeamsClient) Get(ctx context.Context, teamName string) (gitprovider.Team, error)
Get a team within the specific organization.
teamName may include slashes, to point to e.g. subgroups in GitLab. teamName must not be an empty string.
ErrNotFound is returned if the resource does not exist.
func (*TeamsClient) List ¶
func (c *TeamsClient) List(ctx context.Context) ([]gitprovider.Team, error)
List all teams (recursively, in terms of subgroups) within the specific organization.
List returns all available organizations, using multiple paginated requests if needed.
type UserRepositoriesClient ¶
type UserRepositoriesClient struct {
// contains filtered or unexported fields
}
UserRepositoriesClient operates on repositories the user has access to.
func (*UserRepositoriesClient) Create ¶
func (c *UserRepositoriesClient) Create(ctx context.Context, ref gitprovider.UserRepositoryRef, req gitprovider.RepositoryInfo, opts ...gitprovider.RepositoryCreateOption, ) (gitprovider.UserRepository, error)
Create creates a repository for the given organization, with the data and options
ErrAlreadyExists will be returned if the resource already exists.
func (*UserRepositoriesClient) Get ¶
func (c *UserRepositoriesClient) Get(ctx context.Context, ref gitprovider.UserRepositoryRef) (gitprovider.UserRepository, error)
Get returns the repository at the given path.
ErrNotFound is returned if the resource does not exist.
func (*UserRepositoriesClient) List ¶
func (c *UserRepositoriesClient) List(ctx context.Context, ref gitprovider.UserRef) ([]gitprovider.UserRepository, error)
List all repositories in the given organization.
List returns all available repositories, using multiple paginated requests if needed.
func (*UserRepositoriesClient) Reconcile ¶
func (c *UserRepositoriesClient) Reconcile(ctx context.Context, ref gitprovider.UserRepositoryRef, req gitprovider.RepositoryInfo, opts ...gitprovider.RepositoryReconcileOption) (gitprovider.UserRepository, bool, error)
Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.
If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be updated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).
Source Files ¶
- auth.go
- client.go
- client_organization_teams.go
- client_organizations.go
- client_repositories_org.go
- client_repositories_user.go
- client_repository_deploykey.go
- client_repository_teamaccess.go
- githubclient.go
- resource_deploykey.go
- resource_organization.go
- resource_repository.go
- resource_teamaccess.go
- util.go