gitprovider

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 14 Imported by: 34

Documentation

Index

Constants

View Source
const (
	// TransportTypeHTTPS specifies a clone URL of the form:
	// https://<domain>/<org>/[<sub-orgs...>/]<repo>.git
	TransportTypeHTTPS = TransportType("https")
	// TransportTypeGit specifies a clone URL of the form:
	// git@<domain>:<org>/[<sub-orgs...>/]<repo>.git
	TransportTypeGit = TransportType("git")
	// TransportTypeSSH specifies a clone URL of the form:
	// ssh://git@<domain>/<org>/[<sub-orgs...>/]<repo>
	TransportTypeSSH = TransportType("ssh")
)
View Source
const (
	// RepositoryVisibilityPublic specifies that the repository should be publicly accessible.
	RepositoryVisibilityPublic = RepositoryVisibility("public")
	// RepositoryVisibilityInternal specifies that the repository should accessible within the
	// own organization.
	RepositoryVisibilityInternal = RepositoryVisibility("internal")
	// RepositoryVisibilityPrivate specifies that the repository should only be accessible by
	// specifically added team members.
	RepositoryVisibilityPrivate = RepositoryVisibility("private")
)
View Source
const (
	// RepositoryPermissionPull ("pull") - team members can pull, but not push to or administer this repository
	// This is called "guest" in GitLab.
	RepositoryPermissionPull = RepositoryPermission("pull")

	// RepositoryPermissionTriage ("triage") - team members can proactively manage issues and pull requests without write access.
	// This is called "reporter" in GitLab.
	RepositoryPermissionTriage = RepositoryPermission("triage")

	// RepositoryPermissionPush ("push") - team members can pull and push, but not administer this repository
	// This is called "developer" in GitLab.
	RepositoryPermissionPush = RepositoryPermission("push")

	// RepositoryPermissionMaintain ("maintain") - team members can manage the repository without access to sensitive or destructive actions.
	// This is called "maintainer" in GitLab.
	RepositoryPermissionMaintain = RepositoryPermission("maintain")

	// RepositoryPermissionAdmin ("admin") - team members can pull, push and administer this repository
	// This is called "admin" or "owner" in GitLab.
	RepositoryPermissionAdmin = RepositoryPermission("admin")
)
View Source
const (
	// LicenseTemplateApache2 specifies use of the Apache 2.0 license, see
	// https://choosealicense.com/licenses/apache-2.0/
	LicenseTemplateApache2 = LicenseTemplate("apache-2.0")
	// LicenseTemplateMIT specifies use of the MIT license, see
	// https://choosealicense.com/licenses/mit/
	LicenseTemplateMIT = LicenseTemplate("mit")
	// LicenseTemplateGPL3 specifies use of the GNU General Public License v3.0, see
	// https://choosealicense.com/licenses/gpl-3.0/
	LicenseTemplateGPL3 = LicenseTemplate("gpl-3.0")
)
View Source
const (
	// MergeMethodMerge causes a pull request merge to create a simple merge commit
	MergeMethodMerge = MergeMethod("merge")

	// MergeMethodSquash causes a pull request merge to first squash commits
	MergeMethodSquash = MergeMethod("squash")
)
View Source
const (
	// IdentityTypeUser represents an identity for a user account.
	IdentityTypeUser = IdentityType("user")
	// IdentityTypeOrganization represents an identity for an organization.
	IdentityTypeOrganization = IdentityType("organization")
	// IdentityTypeSuborganization represents an identity for a sub-organization.
	IdentityTypeSuborganization = IdentityType("suborganization")
)

Variables

View Source
var (
	// ErrNoProviderSupport describes that the provider doesn't support the requested feature.
	ErrNoProviderSupport = errors.New("no provider support for this feature")
	// ErrDomainUnsupported describes the case where e.g. a GitHub provider used for trying to get
	// information from e.g. "gitlab.com".
	ErrDomainUnsupported = errors.New("the client doesn't support handling requests for this domain")

	// ErrNotTopLevelOrganization describes the case where it's mandatory to specify a top-level organization
	// (e.g. to access teams), but a sub-organization was passed as the OrganizationRef.
	ErrNotTopLevelOrganization = errors.New("expected top-level organization, received sub-organization instead")
	// ErrInvalidArgument describes a generic error where an invalid argument have been specified to a function.
	ErrInvalidArgument = errors.New("invalid argument specified")
	// ErrUnexpectedEvent describes a case where something really unexpected happened in the program.
	ErrUnexpectedEvent = errors.New("an unexpected error occurred")

	// ErrAlreadyExists is returned by .Create() requests if the given resource already exists.
	// Use .Reconcile() instead if you want to idempotently create the resource.
	ErrAlreadyExists = errors.New("resource already exists, cannot create object. Use Reconcile() to create it idempotently")
	// ErrNotFound is returned by .Get() and .Update() calls if the given resource doesn't exist.
	ErrNotFound = errors.New("the requested resource was not found")
	// ErrInvalidServerData is returned when the server returned invalid data, e.g. missing required fields in the response.
	ErrInvalidServerData = errors.New("got invalid data from server, don't know how to handle")

	// ErrURLUnsupportedScheme is returned if an URL without the HTTPS scheme is parsed.
	ErrURLUnsupportedScheme = errors.New("unsupported URL scheme, only HTTPS supported")
	// ErrURLUnsupportedParts is returned if an URL with fragment, query values and/or user information is parsed.
	ErrURLUnsupportedParts = errors.New("URL cannot have fragments, query values nor user information")
	// ErrURLInvalid is returned if an URL is invalid when parsing.
	ErrURLInvalid = errors.New("invalid organization, user or repository URL")
	// ErrURLMissingRepoName is returned if there is no repository name in the URL.
	ErrURLMissingRepoName = errors.New("missing repository name")

	// ErrInvalidClientOptions is the error returned when calling NewClient() with
	// invalid options (e.g. specifying mutually exclusive options).
	ErrInvalidClientOptions = errors.New("invalid options given to NewClient()")
	// ErrDestructiveCallDisallowed happens when the client isn't set up with WithDestructiveAPICalls()
	// but a destructive action is called.
	ErrDestructiveCallDisallowed = errors.New("destructive call was blocked, disallowed by client")
	// ErrInvalidTransportChainReturn is returned if a ChainableRoundTripperFunc returns nil, which is invalid.
	ErrInvalidTransportChainReturn = errors.New("the return value of a ChainableRoundTripperFunc must not be nil")

	// ErrInvalidPermissionLevel is the error returned when there is no mapping
	// from the given level to the gitprovider levels.
	ErrInvalidPermissionLevel = errors.New("invalid permission level")
	// ErrMissingHeader is returned when an expected header is missing from the HTTP response.
	ErrMissingHeader = errors.New("header is missing")
	// ErrGroupNotFound is returned when the gitlab group does not exist
	ErrGroupNotFound = errors.New("404 Group Not Found")
)

Functions

func BoolVar

func BoolVar(b bool) *bool

BoolVar returns a pointer to the given bool.

func BuildClientFromTransportChain

func BuildClientFromTransportChain(chain []ChainableRoundTripperFunc) (*http.Client, error)

BuildClientFromTransportChain builds a *http.Client from a chain of ChainableRoundTripperFuncs. The first function in the chain is called with "in" == nil. "out" of the first function in the chain, is passed as "in" to the second function, and so on. "out" of the last function in the chain is used as net/http Client.Transport.

func GetCloneURL

func GetCloneURL(rs RepositoryRef, transport TransportType) string

GetCloneURL returns the URL to clone a repository for a given transport type. If the given TransportType isn't known an empty string is returned.

func GetDomainURL added in v0.1.0

func GetDomainURL(d string) string

GetDomainURL returns the domain URL prepended with https:// if a scheme is not set.

func ParseTypeGit added in v0.3.2

func ParseTypeGit(domain, identity, repository string) string

ParseTypeGit returns the URL to clone a repository using the Git protocol.

func ParseTypeHTTPS added in v0.3.2

func ParseTypeHTTPS(url string) string

ParseTypeHTTPS returns the HTTPS URL to clone a repository.

func ParseTypeSSH added in v0.3.2

func ParseTypeSSH(domain, identity, repository string) string

ParseTypeSSH returns the URL to clone a repository using the SSH protocol.

func StringVar

func StringVar(s string) *string

StringVar returns a pointer to the given string.

func ValidateAndDefaultInfo

func ValidateAndDefaultInfo(info DefaultedInfoRequest) error

ValidateAndDefaultInfo can be used in client Create() and Reconcile() functions, where the request object, which implements InfoRequest, shall be first validated, and then defaulted. Defaulting happens at Create(), because we want to consistently apply this library's defaults across providers. Defaulting also happens at Reconcile(), because as the object has been created with defaults, the actual state fetched from the server will contain those defaults, and would result in a diff between the (possibly non-defaulted) request and actual state. TODO: Unit and integration test this. TODO: Document in Create() and Reconcile() that req is modified (?) and should not be used anymore.

func ValidateLicenseTemplate

func ValidateLicenseTemplate(t LicenseTemplate) error

ValidateLicenseTemplate validates a given LicenseTemplate. Use as errs.Append(ValidateLicenseTemplate(template), template, "FieldName").

func ValidateRepositoryPermission

func ValidateRepositoryPermission(p RepositoryPermission) error

ValidateRepositoryPermission validates a given RepositoryPermission. Use as errs.Append(ValidateRepositoryPermission(permission), permission, "FieldName").

func ValidateRepositoryVisibility

func ValidateRepositoryVisibility(r RepositoryVisibility) error

ValidateRepositoryVisibility validates a given RepositoryVisibility. Use as errs.Append(ValidateRepositoryVisibility(visibility), visibility, "FieldName").

Types

type BranchClient added in v0.1.0

type BranchClient interface {
	// Create creates a branch with the given specifications.
	Create(ctx context.Context, branch, sha string) error
}

BranchClient operates on the branches for a specific repository. This client can be accessed through Repository.Branches().

type ChainableRoundTripperFunc

type ChainableRoundTripperFunc func(in http.RoundTripper) (out http.RoundTripper)

ChainableRoundTripperFunc is a function that returns a higher-level "out" RoundTripper, chained to call the "in" RoundTripper internally, with extra logic. This function must be able to handle "in" being nil, and use the http.DefaultTransport default RoundTripper in that case. "out" must never be nil.

type Client

type Client interface {
	// The Client allows accessing all known resources.
	ResourceClient

	// SupportedDomain returns the domain endpoint for this client, e.g. "github.com", "gitlab.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.
	SupportedDomain() string

	// ProviderID returns the provider ID (e.g. "github", "gitlab") for this client.
	// This field is set at client creation time, and can't be changed.
	ProviderID() ProviderID

	// HasTokenPermission returns a boolean indicating whether the supplied token has the requested
	// permission. Permissions should be coarse-grained and applicable to *all* providers.
	HasTokenPermission(ctx context.Context, permission TokenPermission) (bool, error)

	// Raw returns the Go client used under the hood to access the Git provider.
	Raw() interface{}
}

Client is an interface that allows talking to a Git provider.

type ClientOption added in v0.3.0

type ClientOption interface {
	// ApplyToClientOptions applies set fields of this object into target.
	ApplyToClientOptions(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 added in v0.3.0

func WithConditionalRequests(conditionalRequests bool) ClientOption

WithConditionalRequests instructs the client to use Conditional Requests to Stash. See: https://gitlab.com/gitlab.org/gitlab.foss/-/issues/26926, and https://docs.gitlab.com/ee/development/polling.html for more info.

func WithCustomCAPostChainTransportHook added in v0.4.0

func WithCustomCAPostChainTransportHook(caBundle []byte) ClientOption

WithCustomCAPostChainTransportHook registers a ChainableRoundTripperFunc "after" the cache and authentication transports in the chain.

func WithDestructiveAPICalls added in v0.3.0

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 added in v0.3.0

func WithDomain(domain string) ClientOption

WithDomain initializes a Client for a custom instance of the given domain. Only host and port information should be present in domain. domain must not be an empty string.

func WithLogger added in v0.3.0

func WithLogger(log *logr.Logger) ClientOption

WithLogger initializes a Client for a custom Stash instance with a logger.

func WithOAuth2Token added in v0.3.0

func WithOAuth2Token(oauth2Token string) ClientOption

WithOAuth2Token initializes a Client which authenticates with Stash through an OAuth2 token. oauth2Token must not be an empty string.

func WithPostChainTransportHook added in v0.3.0

func WithPostChainTransportHook(postRoundTripperFunc 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 added in v0.3.0

func WithPreChainTransportHook(preRoundTripperFunc 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 ClientOptions added in v0.4.0

type ClientOptions struct {
	// clientOptions shares all the common options
	CommonClientOptions
	// contains filtered or unexported fields
}

ClientOptions is the struct that tracks data about what options have been set.

func MakeClientOptions added in v0.3.0

func MakeClientOptions(opts ...ClientOption) (*ClientOptions, error)

MakeClientOptions assembles a clientOptions struct from ClientOption mutator functions.

func (*ClientOptions) ApplyToClientOptions added in v0.4.0

func (opts *ClientOptions) ApplyToClientOptions(target *ClientOptions) error

ApplyToClientOptions implements ClientOption, and applies the set fields of opts into target. If both opts and target has the same specific field set, ErrInvalidClientOptions is returned.

func (*ClientOptions) GetTransportChain added in v0.4.0

func (opts *ClientOptions) GetTransportChain() (chain []ChainableRoundTripperFunc)

GetTransportChain builds the full chain of transports (from left to right, as per gitprovider.BuildClientFromTransportChain) of the form described in NewClient.

type CloneableURL added in v0.3.2

type CloneableURL interface {
	GetCloneURL(prefix string, transport TransportType) string
}

CloneableURL returns the HTTPS URL to clone the repository.

type Commit added in v0.1.0

type Commit interface {
	// Object implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object

	// Get returns high-level information about this commit.
	Get() CommitInfo
}

Commit represents a git commit.

type CommitClient added in v0.1.0

type CommitClient interface {

	// ListPage lists repository commits of the given page and page size.
	ListPage(ctx context.Context, branch string, perPage int, page int) ([]Commit, error)
	// Create creates a commit with the given specifications.
	Create(ctx context.Context, branch string, message string, files []CommitFile) (Commit, error)
}

CommitClient operates on the commits list for a specific repository. This client can be accessed through Repository.Commits().

type CommitFile added in v0.1.0

type CommitFile struct {
	// Path is path where this file is located.
	// +required
	Path *string `json:"path"`

	// Content is the content of the file.
	// +required
	Content *string `json:"content"`
}

CommitFile contains high-level information about a file added to a commit.

type CommitInfo added in v0.1.0

type CommitInfo struct {
	// Sha is the git sha for this commit.
	// +required
	Sha string `json:"sha"`

	// TreeSha is the tree sha this commit belongs to.
	// +required
	TreeSha string `json:"tree_sha"`

	// Author is the author of the commit
	Author string `json:"author"`

	// Message is the commit message
	Message string `json:"message"`

	// CreatedAt is the time the commit was created
	CreatedAt time.Time `json:"created_at"`

	// URL is the link for the commit
	URL string `json:"url"`
}

CommitInfo contains high-level information about a deploy key.

type CommonClientOptions

type CommonClientOptions struct {
	// Domain specifies the target domain for the client. If unset, the default domain for the
	// given provider will be used (often exposed as DefaultDomain in respective package).
	// The behaviour when setting this flag might vary between providers, read the documentation on
	// NewClient for more information.
	Domain *string

	// EnableDestructiveAPICalls is a flag specifying whether destructive API calls (like
	// deleting a repository) are allowed in the Client. Default: false
	EnableDestructiveAPICalls *bool

	// PreChainTransportHook is a function to get a custom RoundTripper that is given as the Transport
	// to the *http.Client given to the provider-specific Client. It can be set for doing arbitrary
	// modifications to HTTP requests. "in" might be nil, if so http.DefaultTransport is recommended.
	// The "chain" looks like follows:
	// Git provider API <-> "Post Chain" <-> Provider Specific (e.g. auth, caching) (in) <-> "Pre Chain" (out) <-> *http.Client
	PreChainTransportHook ChainableRoundTripperFunc

	// PostChainTransportHook is a function to get a custom RoundTripper that is the "final" Transport
	// in the chain before talking to the backing API. It can be set for doing arbitrary
	// modifications to HTTP requests. "in" is always nil. It's recommended to internally use http.DefaultTransport.
	// The "chain" looks like follows:
	// Git provider API (in==nil) <-> "Post Chain" (out) <-> Provider Specific (e.g. auth, caching) <-> "Pre Chain" <-> *http.Client
	PostChainTransportHook ChainableRoundTripperFunc

	// Logger allows the caller to pass a logger for use by the provider
	Logger *logr.Logger

	// CABundle is a []byte containing the CA bundle to use for the client.
	CABundle []byte
}

CommonClientOptions is a struct containing options that are generic to all clients.

func (*CommonClientOptions) ApplyToCommonClientOptions

func (opts *CommonClientOptions) ApplyToCommonClientOptions(target *CommonClientOptions) error

ApplyToCommonClientOptions applies the currently set fields in opts to target. If both opts and target has the same specific field set, ErrInvalidClientOptions is returned.

type DefaultedInfoRequest

type DefaultedInfoRequest interface {
	// DefaultedInfoRequest is a superset of InfoRequest
	InfoRequest

	// Default will be run after validation, setting optional pointer fields to their
	// default values before doing the POST request. This function MUST be registered with
	// the base struct as a pointer receiver.
	Default()
}

DefaultedInfoRequest is a superset of InfoRequest, also including a Default() function that can modify the underlying object, adding default values. ValidateAndDefaultInfo() can be used to first validate, and then default.

type Deletable

type Deletable interface {
	// Delete deletes the current resource irreversibly.
	//
	// ErrNotFound is returned if the resource doesn't exist anymore.
	Delete(ctx context.Context) error
}

Deletable is an interface which all objects that can be deleted using the Client implement.

type DeployKey

type DeployKey interface {
	// DeployKey implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object
	// The deploy key can be updated.
	Updatable
	// The deploy key can be reconciled.
	Reconcilable
	// The deploy key can be deleted.
	Deletable
	// RepositoryBound returns repository reference details.
	RepositoryBound

	// Get returns high-level information about this deploy key.
	Get() DeployKeyInfo
	// Set sets high-level desired state for this deploy key. In order to apply these changes in
	// the Git provider, run .Update() or .Reconcile().
	Set(DeployKeyInfo) error
}

DeployKey represents a short-lived credential (e.g. an SSH public key) used to access a repository.

type DeployKeyClient

type DeployKeyClient interface {
	// Get a DeployKey by its name.
	//
	// ErrNotFound is returned if the resource does not exist.
	Get(ctx context.Context, name string) (DeployKey, error)

	// List all deploy keys for the given repository.
	//
	// List returns all available deploy keys for the given type,
	// using multiple paginated requests if needed.
	List(ctx context.Context) ([]DeployKey, error)

	// Create a deploy key with the given specifications.
	//
	// ErrAlreadyExists will be returned if the resource already exists.
	Create(ctx context.Context, req DeployKeyInfo) (DeployKey, 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).
	Reconcile(ctx context.Context, req DeployKeyInfo) (resp DeployKey, actionTaken bool, err error)
}

DeployKeyClient operates on the access credential list for a specific repository. This client can be accessed through Repository.DeployKeys().

type DeployKeyInfo

type DeployKeyInfo struct {
	// Name is the human-friendly interpretation of what the key is for (and does).
	// +required
	Name string `json:"name"`

	// Key specifies the public part of the deploy (e.g. SSH) key.
	// +required
	Key []byte `json:"key"`

	// ReadOnly specifies whether this DeployKey can write to the repository or not.
	// Default value at POST-time: true.
	// +optional
	ReadOnly *bool `json:"readOnly,omitempty"`
}

DeployKeyInfo contains high-level information about a deploy key.

func (*DeployKeyInfo) Default

func (dk *DeployKeyInfo) Default()

Default defaults the DeployKey fields.

func (DeployKeyInfo) Equals

func (dk DeployKeyInfo) Equals(actual InfoRequest) bool

Equals can be used to check if this *Info request (the desired state) matches the actual passed in as the argument.

func (DeployKeyInfo) ValidateInfo

func (dk DeployKeyInfo) ValidateInfo() error

ValidateInfo validates the object at {Object}.Set() and POST-time.

type DeployToken added in v0.15.0

type DeployToken interface {
	// DeployToken implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object
	// The deploy token can be updated.
	Updatable
	// The deploy token can be reconciled.
	Reconcilable
	// The deploy token can be deleted.
	Deletable
	// RepositoryBound returns repository reference details.
	RepositoryBound

	// Get returns high-level information about this deploy token.
	Get() DeployTokenInfo
	// Set sets high-level desired state for this deploy token. In order to apply these changes in
	// the Git provider, run .Update() or .Reconcile().
	Set(DeployTokenInfo) error
}

DeployToken represents a short-lived credential used to access a repository.

type DeployTokenClient added in v0.15.0

type DeployTokenClient interface {
	// Get a DeployToken by its name.
	//
	// ErrNotFound is returned if the resource does not exist.
	Get(ctx context.Context, name string) (DeployToken, error)

	// List all deploy tokens for the given repository.
	//
	// List returns all available deploy tokens for the given type,
	// using multiple paginated requests if needed.
	List(ctx context.Context) ([]DeployToken, error)

	// Create a deploy token with the given specifications.
	//
	// ErrAlreadyExists will be returned if the resource already exists.
	Create(ctx context.Context, req DeployTokenInfo) (DeployToken, 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).
	Reconcile(ctx context.Context, req DeployTokenInfo) (resp DeployToken, actionTaken bool, err error)
}

DeployTokenClient operates on the deploy token list of a specific repository. This client can be accessed through Repository.DeployTokens().

type DeployTokenInfo added in v0.15.0

type DeployTokenInfo struct {
	// Name is the human-friendly interpretation of what the token is for (and does).
	// +required
	Name string `json:"name"`

	// Username is the generated Deploy Token Username by the API
	// +optional
	Username string `json:"username"`

	// Token is the generated Deploy Token by the API
	// +optional
	Token string `json:"token"`
}

DeployTokenInfo contains high-level information about a deploy token.

func (*DeployTokenInfo) Default added in v0.15.0

func (dk *DeployTokenInfo) Default()

Default defaults the DeployToken fields.

func (DeployTokenInfo) Equals added in v0.15.0

func (dk DeployTokenInfo) Equals(actual InfoRequest) bool

Equals can be used to check if this *Info request (the desired state) matches the actual passed in as the argument.

func (DeployTokenInfo) ValidateInfo added in v0.15.0

func (dk DeployTokenInfo) ValidateInfo() error

ValidateInfo validates the object at {Object}.Set() and POST-time.

type EditOptions added in v0.10.0

type EditOptions struct {
	// Title is set to a non-nil value to request a pull request's title to be changed.
	Title *string
}

EditOptions is provided to a PullRequestClient's "Edit" method for updating an existing pull request.

type ErrIncorrectUser added in v0.19.0

type ErrIncorrectUser struct {
	// contains filtered or unexported fields
}

ErrIncorrectUser describes that the user provided was incorrect

It is returned by `UserRepositories().Create` when an incorrect UserLogin is passed in

func NewErrIncorrectUser added in v0.19.0

func NewErrIncorrectUser(user string) *ErrIncorrectUser

Error implements the error interface.

func (*ErrIncorrectUser) Error added in v0.19.0

func (e *ErrIncorrectUser) Error() string

Error implements the error interface.

type FileClient added in v0.5.3

type FileClient interface {
	// GetFiles fetch files content from specific path and branch
	Get(ctx context.Context, path, branch string, optFns ...FilesGetOption) ([]*CommitFile, error)
}

FileClient operates on the branches for a specific repository. This client can be accessed through Repository.Branches().

type FilesGetOption added in v0.9.0

type FilesGetOption interface {
	ApplyFilesGetOptions(target *FilesGetOptions)
}

FilesGetOption is an interface for applying options when fetching/getting files

type FilesGetOptions added in v0.9.0

type FilesGetOptions struct {
	Recursive bool
}

FilesGetOptions specifies optional options when fetcing files.

func (*FilesGetOptions) ApplyFilesGetOptions added in v0.9.0

func (opts *FilesGetOptions) ApplyFilesGetOptions(target *FilesGetOptions)

ApplyFilesGetOptions applies target options onto the invoked opts

type HTTPError

type HTTPError struct {
	// HTTP response that caused this error.
	Response *http.Response `json:"-"`
	// Full error message, human-friendly and formatted.
	ErrorMessage string `json:"errorMessage"`
	// Message about what happened.
	Message string `json:"message"`
	// Where to find more information about the error.
	DocumentationURL string `json:"documentationURL"`
}

HTTPError is an error that contains context about the HTTP request/response that failed.

func (*HTTPError) Error

func (e *HTTPError) Error() string

Error implements the error interface.

type IdentityRef

type IdentityRef interface {
	// IdentityRef implements ValidateTarget so it can easily be validated as a field.
	validation.ValidateTarget

	// GetDomain returns the URL-domain for the Git provider backend,
	// e.g. "github.com" or "self-hosted-gitlab.com:6443".
	GetDomain() string

	// GetIdentity returns the user account name or a slash-separated path of the
	// <organization-name>[/<sub-organization-name>...] form. This can be used as
	// an identifier for this specific actor in the system.
	GetIdentity() string

	// GetType returns what type of identity this instance represents. If IdentityTypeUser is returned
	// this IdentityRef can safely be casted to an UserRef. If any of IdentityTypeOrganization or
	// IdentityTypeSuborganization are returned, this IdentityRef can be casted to a OrganizationRef.
	GetType() IdentityType

	// String returns the URL, and implements fmt.Stringer.
	String() string
}

IdentityRef references an organization or user account in a Git provider.

type IdentityType

type IdentityType string

IdentityType is a typed string for what kind of identity type an IdentityRef is.

type InfoRequest

type InfoRequest interface {
	// ValidateInfo validates the object at {Object}.Set() and POST-time, before defaulting.
	// Set (non-nil) and required fields should be validated.
	ValidateInfo() error

	// Equals can be used to check if this *Info request (the desired state) matches the actual
	// passed in as the argument.
	Equals(actual InfoRequest) bool
}

InfoRequest is an interface which all {Object}Info objects that can be used as Create() or Reconcile() requests in the Client should implement. Most likely, the struct should also implement DefaultedInfoRequest, as most objects have optional, defaulted fields.

type InvalidCredentialsError

type InvalidCredentialsError struct {
	// InvalidCredentialsError extends HTTPError.
	HTTPError `json:",inline"`
}

InvalidCredentialsError describes that that the request login credentials (e.g. an Oauth2 token) was invalid (i.e. a 401 Unauthorized or 403 Forbidden status was returned). This does NOT mean that "the login was successful but you don't have permission to access this resource". In that case, a 404 Not Found error would be returned.

type Keyer added in v0.3.0

type Keyer interface {
	// Key returns a unique key for this object.
	Key() string
}

Keyer is an interface that can be used to get a unique key for an object.

type LicenseTemplate

type LicenseTemplate string

LicenseTemplate is an enum specifying a license template that can be used when creating a repository. Examples of available licenses are here: https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/licensing-a-repository#searching-github-by-license-type

func LicenseTemplateVar

func LicenseTemplateVar(t LicenseTemplate) *LicenseTemplate

LicenseTemplateVar returns a pointer to a LicenseTemplate.

type MergeMethod added in v0.3.0

type MergeMethod string

MergeMethod is an enum specifying the merge method for a pull request.

type Object

type Object interface {
	// APIObject returns the underlying value that was returned from the server.
	// This is always a pointer to a struct.
	APIObject() interface{}
}

Object is the interface all types should implement.

type OrgRepositoriesClient

type OrgRepositoriesClient interface {
	// Get returns the repository for the given reference.
	//
	// ErrNotFound is returned if the resource does not exist.
	Get(ctx context.Context, r OrgRepositoryRef) (OrgRepository, error)

	// List all repositories in the given organization.
	//
	// List returns all available repositories, using multiple paginated requests if needed.
	List(ctx context.Context, o OrganizationRef) ([]OrgRepository, error)

	// Create creates a repository for the given organization, with the data and options.
	//
	// ErrAlreadyExists will be returned if the resource already exists.
	Create(ctx context.Context, r OrgRepositoryRef, req RepositoryInfo, opts ...RepositoryCreateOption) (OrgRepository, 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).
	Reconcile(ctx context.Context, r OrgRepositoryRef, req RepositoryInfo, opts ...RepositoryReconcileOption) (resp OrgRepository, actionTaken bool, err error)
}

OrgRepositoriesClient operates on repositories for organizations.

type OrgRepository

type OrgRepository interface {
	// OrgRepository is a superset of UserRepository.
	UserRepository

	// TeamAccess returns a TeamsAccessClient for operating on teams' access to this specific repository.
	TeamAccess() TeamAccessClient
}

OrgRepository describes a repository owned by an organization.

type OrgRepositoryRef

type OrgRepositoryRef struct {
	// OrgRepositoryRef embeds OrganizationRef inline.
	OrganizationRef `json:",inline"`

	// RepositoryName specifies the Git repository name. This field is URL-friendly,
	// e.g. "kubernetes" or "cluster-api-provider-aws".
	// +required
	RepositoryName string `json:"repositoryName"`
	// contains filtered or unexported fields
}

OrgRepositoryRef is a struct with information about a specific repository owned by an organization.

func ParseOrgRepositoryURL

func ParseOrgRepositoryURL(r string) (*OrgRepositoryRef, error)

ParseOrgRepositoryURL parses a HTTPS clone URL into a OrgRepositoryRef object.

func (OrgRepositoryRef) GetCloneURL

func (r OrgRepositoryRef) GetCloneURL(transport TransportType) string

GetCloneURL gets the clone URL for the specified transport type.

func (OrgRepositoryRef) GetRepository

func (r OrgRepositoryRef) GetRepository() string

GetRepository returns the repository name for this repo.

func (*OrgRepositoryRef) SetSlug added in v0.3.0

func (r *OrgRepositoryRef) SetSlug(slug string)

SetSlug sets the unique slug for this object.

func (OrgRepositoryRef) Slug added in v0.3.0

func (r OrgRepositoryRef) Slug() string

Slug returns the unique slug for this object.

func (OrgRepositoryRef) String

func (r OrgRepositoryRef) String() string

String returns the HTTPS URL to access the repository.

func (OrgRepositoryRef) ValidateFields

func (r OrgRepositoryRef) ValidateFields(validator validation.Validator)

ValidateFields validates its own fields for a given validator.

type Organization

type Organization interface {
	// Organization implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object
	// OrganizationBound returns organization reference details.
	OrganizationBound

	// Get returns high-level information about the organization.
	Get() OrganizationInfo

	// Teams gives access to the TeamsClient for this specific organization
	Teams() TeamsClient
}

Organization represents an organization in a Git provider. For now, the organization is read-only, i.e. there aren't set/update methods.

type OrganizationBound

type OrganizationBound interface {
	// Organization returns the OrganizationRef associated with this object.
	Organization() OrganizationRef
}

OrganizationBound describes an object that is bound to a given organization, e.g. a team.

type OrganizationInfo

type OrganizationInfo struct {
	// Name is the human-friendly name of this organization, e.g. "Flux" or "Kubernetes SIGs".
	Name *string `json:"name"`

	// Description returns a description for the organization.
	Description *string `json:"description"`
}

OrganizationInfo represents an (top-level- or sub-) organization.

type OrganizationRef

type OrganizationRef struct {
	// Domain returns e.g. "github.com", "gitlab.com" or a custom domain like "self-hosted-gitlab.com" (GitLab)
	// The domain _might_ contain port information, in the form of "host:port", if applicable.
	// +required
	Domain string `json:"domain"`

	// Organization specifies the URL-friendly, lowercase name of the organization or user account name,
	// e.g. "fluxcd" or "kubernetes-sigs".
	// +required
	Organization string `json:"organization"`

	// SubOrganizations point to optional sub-organizations (or sub-groups) of the given top-level organization
	// in the Organization field. E.g. "gitlab.com/fluxcd/engineering/frontend" would yield ["engineering", "frontend"]
	// +optional
	SubOrganizations []string `json:"subOrganizations,omitempty"`
	// contains filtered or unexported fields
}

OrganizationRef is an implementation of OrganizationRef.

func ParseOrganizationURL

func ParseOrganizationURL(o string) (*OrganizationRef, error)

ParseOrganizationURL parses an URL to an organization into a OrganizationRef object.

func (OrganizationRef) GetDomain

func (o OrganizationRef) GetDomain() string

GetDomain returns the the domain part of the endpoint, can include port information.

func (OrganizationRef) GetIdentity

func (o OrganizationRef) GetIdentity() string

GetIdentity returns the identity of this actor, which in this case is the user login name.

func (OrganizationRef) GetType

func (o OrganizationRef) GetType() IdentityType

GetType marks this UserRef as being a IdentityTypeUser.

func (OrganizationRef) Key added in v0.3.0

func (o OrganizationRef) Key() string

Key returns the unique key for this OrganizationRef.

func (*OrganizationRef) SetKey added in v0.3.0

func (o *OrganizationRef) SetKey(key string)

SetKey sets the unique key for this OrganizationRef.

func (OrganizationRef) String

func (o OrganizationRef) String() string

String returns the URL to access the Organization.

func (OrganizationRef) ValidateFields

func (o OrganizationRef) ValidateFields(validator validation.Validator)

ValidateFields validates its own fields for a given validator.

type OrganizationsClient

type OrganizationsClient interface {
	// Get a specific organization the user has access to.
	// This might also refer to a sub-organization.
	//
	// ErrNotFound is returned if the resource does not exist.
	Get(ctx context.Context, o OrganizationRef) (Organization, error)

	// List all top-level organizations the specific user has access to.
	//
	// List returns all available organizations, using multiple paginated requests if needed.
	List(ctx context.Context) ([]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.
	Children(ctx context.Context, o OrganizationRef) ([]Organization, error)
}

OrganizationsClient operates on organizations the user has access to.

type ProviderID

type ProviderID string

ProviderID is a typed string for a given Git provider The provider constants are defined in their respective packages.

type PullRequest added in v0.2.0

type PullRequest interface {
	// Object implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object

	// Get returns high-level information about this pull request.
	Get() PullRequestInfo
}

PullRequest represents a pull request.

type PullRequestClient added in v0.1.0

type PullRequestClient interface {
	// List lists all pull requests in the repository
	List(ctx context.Context) ([]PullRequest, error)
	// Create creates a pull request with the given specifications.
	Create(ctx context.Context, title, branch, baseBranch, description string) (PullRequest, error)
	// Edit allows for changing an existing pull request using the given options. Please refer to "EditOptions" for details on which data can be
	// edited.
	Edit(ctx context.Context, number int, opts EditOptions) (PullRequest, error)
	// Get retrieves an existing pull request by number
	Get(ctx context.Context, number int) (PullRequest, error)
	// Merge merges a pull request with via either the "Squash" or "Merge" method
	Merge(ctx context.Context, number int, mergeMethod MergeMethod, message string) error
}

PullRequestClient operates on the pull requests for a specific repository. This client can be accessed through Repository.PullRequests().

type PullRequestInfo added in v0.2.0

type PullRequestInfo struct {
	// Title is the title of the pull request.
	Title string `json:"title"`

	// Description is the description of the pull request.
	Description string `json:"description"`

	// Merged specifes whether or not this pull request has been merged
	Merged bool `json:"merged"`

	// Number is the number of the pull request that can be used to merge
	Number int `json:"number"`

	// WebURL is the URL of the pull request in the git provider web interface.
	// +required
	WebURL string `json:"web_url"`

	// SourceBranch is the branch from which the pull request has been created.
	SourceBranch string `json:"source_branch"`
}

PullRequestInfo contains high-level information about a pull request.

type RateLimitError

type RateLimitError struct {
	// RateLimitError extends HTTPError.
	HTTPError `json:",inline"`

	// The number of requests per hour the client is currently limited to.
	Limit int `json:"limit"`
	// The number of remaining requests the client can make this hour.
	Remaining int `json:"remaining"`
	// The timestamp at which point the current rate limit will reset.
	Reset time.Time `json:"reset"`
}

RateLimitError is an error, extending HTTPError, that contains context about rate limits.

type Reconcilable

type Reconcilable interface {
	// Reconcile makes sure the desired state in this object (called "req" here) 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).
	//
	// The internal API object will be overridden with the received server data if actionTaken == true.
	Reconcile(ctx context.Context) (actionTaken bool, err error)
}

Reconcilable is an interface which all objects that can be reconciled using the Client implement.

type RepositoryBound

type RepositoryBound interface {
	// Repository returns the RepositoryRef associated with this object.
	Repository() RepositoryRef
}

RepositoryBound describes an object that is bound to a given repository, e.g. a deploy key.

type RepositoryCreateOption

type RepositoryCreateOption interface {
	// ApplyToRepositoryCreateOptions should apply relevant options to the target.
	ApplyToRepositoryCreateOptions(target *RepositoryCreateOptions)
}

RepositoryCreateOption is an interface for applying options to when creating repositories.

type RepositoryCreateOptions

type RepositoryCreateOptions struct {
	// AutoInit can be set to true in order to automatically initialize the Git repo with a
	// README.md and optionally a license in the first commit.
	// Default: nil (which means "false, don't create")
	AutoInit *bool

	// LicenseTemplate lets the user specify a license template to use when AutoInit is true.
	// Default: nil.
	// Available options: See the LicenseTemplate enum.
	LicenseTemplate *LicenseTemplate
}

RepositoryCreateOptions specifies optional options when creating a repository.

func MakeRepositoryCreateOptions

func MakeRepositoryCreateOptions(opts ...RepositoryCreateOption) (RepositoryCreateOptions, error)

MakeRepositoryCreateOptions returns a RepositoryCreateOptions based off the mutator functions given to e.g. RepositoriesClient.Create(). The returned validation error may be ignored in the case that the client allows e.g. other license templates than those that are common. validation.ErrFieldEnumInvalid is returned if the license template doesn't match known values.

func (*RepositoryCreateOptions) ApplyToRepositoryCreateOptions

func (opts *RepositoryCreateOptions) ApplyToRepositoryCreateOptions(target *RepositoryCreateOptions)

ApplyToRepositoryCreateOptions applies the options defined in the options struct to the target struct that is being completed.

func (*RepositoryCreateOptions) ValidateOptions

func (opts *RepositoryCreateOptions) ValidateOptions() error

ValidateOptions validates that the options are valid.

type RepositoryInfo

type RepositoryInfo struct {
	// Description returns a description for the repository.
	// No default value at POST-time.
	// +optional
	Description *string `json:"description"`

	// DefaultBranch describes the default branch for the given repository. This has
	// historically been "master" (and is as of writing still the Git default), but is
	// expected to be changed to e.g. "main" shortly in the future.
	// Default value at POST-time: master (but this can and will change in future library versions!).
	// +optional
	DefaultBranch *string `json:"defaultBranch"`

	// Visibility returns the desired visibility for the repository.
	// Default value at POST-time: RepositoryVisibilityPrivate.
	// +optional
	Visibility *RepositoryVisibility `json:"visibility"`
}

RepositoryInfo represents a Git repository provided by a Git provider.

func (*RepositoryInfo) Default

func (r *RepositoryInfo) Default()

Default defaults the Repository, implementing the InfoRequest interface.

func (RepositoryInfo) Equals

func (r RepositoryInfo) Equals(actual InfoRequest) bool

Equals can be used to check if this *Info request (the desired state) matches the actual passed in as the argument.

func (RepositoryInfo) ValidateInfo

func (r RepositoryInfo) ValidateInfo() error

ValidateInfo validates the object at {Object}.Set() and POST-time.

type RepositoryPermission

type RepositoryPermission string

RepositoryPermission is an enum specifying the access level for a certain team or person for a given repository.

func RepositoryPermissionVar

func RepositoryPermissionVar(p RepositoryPermission) *RepositoryPermission

RepositoryPermissionVar returns a pointer to a RepositoryPermission.

type RepositoryReconcileOption

type RepositoryReconcileOption interface {
	// RepositoryCreateOption is embedded, as reconcile uses the create options.
	RepositoryCreateOption
}

RepositoryReconcileOption is an interface for applying options to when reconciling repositories.

type RepositoryRef

type RepositoryRef interface {
	// RepositoryRef is a superset of IdentityRef.
	IdentityRef

	// GetRepository returns the repository name for this repo.
	GetRepository() string

	// GetCloneURL gets the clone URL for the specified transport type.
	GetCloneURL(transport TransportType) string
}

RepositoryRef describes a reference to a repository owned by either a user account or organization.

type RepositoryVisibility

type RepositoryVisibility string

RepositoryVisibility is an enum specifying the visibility of a repository.

func RepositoryVisibilityVar

func RepositoryVisibilityVar(r RepositoryVisibility) *RepositoryVisibility

RepositoryVisibilityVar returns a pointer to a RepositoryVisibility.

type ResourceClient

type ResourceClient interface {
	// Organizations returns the OrganizationsClient handling sets of organizations.
	Organizations() OrganizationsClient

	// OrgRepositories returns the OrgRepositoriesClient handling sets of repositories in an organization.
	OrgRepositories() OrgRepositoriesClient

	// UserRepositories returns the UserRepositoriesClient handling sets of repositories for a user.
	UserRepositories() UserRepositoriesClient
}

ResourceClient allows access to resource-specific sub-clients.

type Slugger added in v0.3.0

type Slugger interface {
	// Slug returns the unique slug for this object.
	Slug() string
}

Slugger is an interface that can be used to get a unique slug for an object.

type Team

type Team interface {
	// Team implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object
	// OrganizationBound returns organization reference details.
	OrganizationBound

	// Get returns high-level information about this team.
	Get() TeamInfo
}

Team represents a team in an organization in a Git provider. For now, the team is read-only, i.e. there aren't set/update methods.

type TeamAccess

type TeamAccess interface {
	// TeamAccess implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object
	// The deploy key can be updated.
	Updatable
	// The deploy key can be reconciled.
	Reconcilable
	// The deploy key can be deleted.
	Deletable
	// RepositoryBound returns repository reference details.
	RepositoryBound

	// Get returns high-level information about this team access for the repository.
	Get() TeamAccessInfo
	// Set sets high-level desired state for this team access object. In order to apply these changes in
	// the Git provider, run .Update() or .Reconcile().
	Set(TeamAccessInfo) error
}

TeamAccess describes a binding between a repository and a team.

type TeamAccessClient

type TeamAccessClient interface {
	// Get a team's permission level of this given repository.
	//
	// ErrNotFound is returned if the resource does not exist.
	Get(ctx context.Context, name string) (TeamAccess, error)

	// List the team access control list for this repository.
	//
	// List returns all available team access lists, using multiple paginated requests if needed.
	List(ctx context.Context) ([]TeamAccess, error)

	// Create adds a given team to the repository's team access control list.
	//
	// ErrAlreadyExists will be returned if the resource already exists.
	Create(ctx context.Context, req TeamAccessInfo) (TeamAccess, 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).
	Reconcile(ctx context.Context, req TeamAccessInfo) (resp TeamAccess, actionTaken bool, err error)
}

TeamAccessClient operates on the teams list for a specific repository. This client can be accessed through Repository.TeamAccess().

type TeamAccessInfo

type TeamAccessInfo struct {
	// Name describes the name of the team. The team name may contain slashes.
	// +required
	Name string `json:"name"`

	// Permission describes the permission level for which the team is allowed to operate.
	// Default: pull.
	// Available options: See the RepositoryPermission enum.
	// +optional
	Permission *RepositoryPermission `json:"permission,omitempty"`
}

TeamAccessInfo contains high-level information about a team's access to a repository.

func (*TeamAccessInfo) Default

func (ta *TeamAccessInfo) Default()

Default defaults the TeamAccess fields.

func (TeamAccessInfo) Equals

func (ta TeamAccessInfo) Equals(actual InfoRequest) bool

Equals can be used to check if this *Info request (the desired state) matches the actual passed in as the argument.

func (TeamAccessInfo) ValidateInfo

func (ta TeamAccessInfo) ValidateInfo() error

ValidateInfo validates the object at {Object}.Set() and POST-time.

type TeamInfo

type TeamInfo struct {
	// Name describes the name of the team. The team name may contain slashes.
	Name string `json:"name"`

	// Members points to a set of user names (logins) of the members of this team.
	Members []string `json:"members"`
}

TeamInfo is a representation for a team of users inside of an organization.

type TeamsClient

type TeamsClient interface {
	// 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.
	Get(ctx context.Context, name string) (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.
	List(ctx context.Context) ([]Team, error)
}

TeamsClient allows reading teams for a specific organization. This client can be accessed through Organization.Teams().

type TokenPermission added in v0.0.3

type TokenPermission int

TokenPermission is an enum specifying the permissions for a token.

const (
	// TokenPermissionRWRepository Read/Write permission for public/private repositories.
	TokenPermissionRWRepository TokenPermission = iota + 1
)

type TransportType

type TransportType string

TransportType is an enum specifying the transport type used when cloning a repository.

type Tree added in v0.9.0

type Tree interface {
	// Object implements the Object interface,
	// allowing access to the underlying object returned from the API.
	Object

	// Get returns high-level information about this tree.
	Get() TreeInfo
	// List files (blob) in a tree
	List() TreeEntry
}

Tree represents a git tree which is the hierarchical structure of your git data.

type TreeClient added in v0.9.0

type TreeClient interface {
	// Get retrieves tree information and items
	Get(ctx context.Context, sha string, recursive bool) (*TreeInfo, error)
	// List retrieves list of tree files (files/blob) from given tree sha/id or path+branch
	List(ctx context.Context, sha string, path string, recursive bool) ([]*TreeEntry, error)
}

TreeClient operates on the trees for a Git repository which describe the hierarchy between files in the repository This client can be accessed through Repository.Trees()

type TreeEntry added in v0.9.0

type TreeEntry struct {
	// Path is the path of the file/blob or sub tree in a tree
	Path string `json:"path"`
	// Mode of the file/tree.
	// (100644:file (blob), 100755:executable (blob), 040000:subdirectory(tree),160000:submodule(commit),120000:blob that specifies the path of a symlink)
	Mode string `json:"mode"`
	// Type is the item type, It is either blob, tree, or commit.
	Type string `json:"type"`
	// Size is the size of the file/blob if the type is a blob, it is not populated if the type is a tree
	Size int `json:"size"`
	// SHA is the SHA1 checksum ID of the object in the tree
	SHA string `json:"sha"`
	// Content is the content of a blob file, either content aor sha are set. If both are using Github will return an error
	Content string `json:"content"`
	// URL is the url that can be used to retrieve the details of the blob, tree of commit
	URL string `json:"url"`
	// Id is the id of the tree entry retrieved from Gitlab (Optional)
	ID string `json:"id"`
}

TreeEntry contains info about each tree object's structure in TreeInfo whether it is a file or tree

type TreeInfo added in v0.9.0

type TreeInfo struct {
	// SHA is the SHA1 checksum ID of the tree, or the branch name
	SHA string `json:"sha"`
	// Tree is the list of TreeEntry objects describing the structure of the tree
	Tree []*TreeEntry `json:"tree"`
	// Truncated represents whether a tree is truncated when fetching a tree
	// If truncated is true in the response when fetching a tree, then the number of items in the tree array exceeded the maximum limit
	Truncated bool `json:"truncated"`
}

TreeInfo contains high-level information about a git Tree representing the hierarchy between files in a Git repository

type Updatable

type Updatable interface {
	// Update will apply the desired state in this object to the server.
	// Only set fields will be respected (i.e. PATCH behaviour).
	// In order to apply changes to this object, use the .Set({Resource}Info) error
	// function, or cast .APIObject() to a pointer to the provider-specific type
	// and set custom fields there.
	//
	// ErrNotFound is returned if the resource does not exist.
	//
	// The internal API object will be overridden with the received server data.
	Update(ctx context.Context) error
}

Updatable is an interface which all objects that can be updated using the Client implement.

type UserRef

type UserRef struct {
	// Domain returns e.g. "github.com", "gitlab.com" or a custom domain like "self-hosted-gitlab.com" (GitLab)
	// The domain _might_ contain port information, in the form of "host:port", if applicable
	// +required
	Domain string `json:"domain"`

	// UserLogin returns the user account login name.
	// +required
	UserLogin string `json:"userLogin"`
}

UserRef represents a user account in a Git provider.

func ParseUserURL

func ParseUserURL(u string) (*UserRef, error)

ParseUserURL parses an URL to an organization into a UserRef object.

func (UserRef) GetDomain

func (u UserRef) GetDomain() string

GetDomain returns the the domain part of the endpoint, can include port information.

func (UserRef) GetIdentity

func (u UserRef) GetIdentity() string

GetIdentity returns the identity of this actor, which in this case is the user login name.

func (UserRef) GetType

func (u UserRef) GetType() IdentityType

GetType marks this UserRef as being a IdentityTypeUser.

func (UserRef) String

func (u UserRef) String() string

String returns the HTTPS URL to access the User.

func (UserRef) ValidateFields

func (u UserRef) ValidateFields(validator validation.Validator)

ValidateFields validates its own fields for a given validator.

type UserRepositoriesClient

type UserRepositoriesClient interface {
	// Get returns the repository at the given path.
	//
	// ErrNotFound is returned if the resource does not exist.
	Get(ctx context.Context, r UserRepositoryRef) (UserRepository, error)

	// List all repositories for the given user.
	//
	// List returns all available repositories, using multiple paginated requests if needed.
	List(ctx context.Context, o UserRef) ([]UserRepository, error)

	// Create creates a repository for the given user, with the data and options
	//
	// ErrAlreadyExists will be returned if the resource already exists.
	Create(ctx context.Context, r UserRepositoryRef, req RepositoryInfo, opts ...RepositoryCreateOption) (UserRepository, error)

	// GetUserLogin returns the current authenticated user.
	GetUserLogin(ctx context.Context) (IdentityRef, 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).
	Reconcile(ctx context.Context, r UserRepositoryRef, req RepositoryInfo, opts ...RepositoryReconcileOption) (resp UserRepository, actionTaken bool, err error)
}

UserRepositoriesClient operates on repositories for users.

type UserRepository

type UserRepository interface {
	// UserRepository and OrgRepository implement the Object interface,
	// allowing access to the underlying object returned from the API.
	Object
	// The repository can be updated.
	Updatable
	// The repository can be reconciled.
	Reconcilable
	// The repository can be deleted.
	Deletable
	// RepositoryBound returns repository reference details.
	RepositoryBound

	// Get returns high-level information about this repository.
	Get() RepositoryInfo
	// Set sets high-level desired state for this repository. In order to apply these changes in
	// the Git provider, run .Update() or .Reconcile().
	Set(RepositoryInfo) error

	// DeployKeys gives access to manipulating deploy keys to access this specific repository.
	DeployKeys() DeployKeyClient

	// DeployTokens gives access to manipulating deploy tokens to access this specific repository.
	// Returns "ErrNoProviderSupport" if the provider doesn't support deploy tokens.
	DeployTokens() (DeployTokenClient, error)

	// Commits gives access to this specific repository commits
	Commits() CommitClient

	// Branches gives access to this specific repository branches
	Branches() BranchClient

	// PullRequests gives access to this specific repository pull requests
	PullRequests() PullRequestClient

	// Files gives access to this specific repository files
	Files() FileClient

	// Trees gives access to this specific repository trees.
	Trees() TreeClient
}

UserRepository describes a repository owned by an user.

type UserRepositoryRef

type UserRepositoryRef struct {
	// UserRepositoryRef embeds UserRef inline.
	UserRef `json:",inline"`

	// RepositoryName specifies the Git repository name. This field is URL-friendly,
	// e.g. "kubernetes" or "cluster-api-provider-aws".
	// +required
	RepositoryName string `json:"repositoryName"`
	// contains filtered or unexported fields
}

UserRepositoryRef is a struct with information about a specific repository owned by a user.

func ParseUserRepositoryURL

func ParseUserRepositoryURL(r string) (*UserRepositoryRef, error)

ParseUserRepositoryURL parses a HTTPS clone URL into a UserRepositoryRef object.

func (UserRepositoryRef) GetCloneURL

func (r UserRepositoryRef) GetCloneURL(transport TransportType) string

GetCloneURL gets the clone URL for the specified transport type.

func (UserRepositoryRef) GetRepository

func (r UserRepositoryRef) GetRepository() string

GetRepository returns the repository name for this repo.

func (*UserRepositoryRef) SetSlug added in v0.3.0

func (r *UserRepositoryRef) SetSlug(slug string)

SetSlug sets the unique slug for this object.

func (UserRepositoryRef) Slug added in v0.3.2

func (r UserRepositoryRef) Slug() string

Slug returns the unique slug for this object.

func (UserRepositoryRef) String

func (r UserRepositoryRef) String() string

String returns the URL to access the repository.

func (UserRepositoryRef) ValidateFields

func (r UserRepositoryRef) ValidateFields(validator validation.Validator)

ValidateFields validates its own fields for a given validator.

type ValidationError

type ValidationError struct {
	// RateLimitError extends HTTPError.
	HTTPError `json:",inline"`

	// Errors contain context about what validation(s) failed.
	Errors []ValidationErrorItem `json:"errors"`
}

ValidationError is an error, extending HTTPError, that contains context about failed server-side validation.

type ValidationErrorItem

type ValidationErrorItem struct {
	// Resource on which the error occurred.
	Resource string `json:"resource"`
	// Field on which the error occurred.
	Field string `json:"field"`
	// Code for the validation error.
	Code string `json:"code"`
	// Message describing the error. Errors with Code == "custom" will always have this set.
	Message string `json:"message"`
}

ValidationErrorItem represents a single invalid field in an invalid request.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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