gitprovider

package
v0.7.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProvider

func RegisterProvider(name string, reg ProviderRegistration)

RegisterProvider is called by provider implementation packages to register themselves as a git provider.

Types

type CreatePullRequestOpts

type CreatePullRequestOpts struct {
	Head        string
	Base        string
	Title       string
	Description string
}

type GitProviderService

type GitProviderService interface {
	// WithAuthToken sets an authorization token to the client
	WithAuthToken(token string) (GitProviderService, error)

	// CreatePullRequest creates a pull request
	CreatePullRequest(ctx context.Context, repoURL string, opts CreatePullRequestOpts) (*PullRequest, error)

	// Get gets an existing pull request by ID
	GetPullRequest(ctx context.Context, repoURL string, number int64) (*PullRequest, error)

	// ListPullRequests lists pull requests by the given options
	ListPullRequests(ctx context.Context, repoURL string, opts ListPullRequestOpts) ([]*PullRequest, error)

	// IsPullRequestMerged returns whether or not the pull request was merged
	IsPullRequestMerged(ctx context.Context, repoURL string, number int64) (bool, error)
}

GitProviderService is an abstracted interface for a git providers (GitHub, GitLab, BitBucket) when interacting against a single git repository (e.g. managing pull requests).

func NewGitProviderServiceFromName

func NewGitProviderServiceFromName(name string) (GitProviderService, error)

NewGitProviderServiceFromName returns a git provider service by it's registered name

func NewGitProviderServiceFromURL

func NewGitProviderServiceFromURL(repoURL string) (GitProviderService, error)

NewGitProviderServiceFromURL iterates all registered providers and instantiates the appropriate GitProvider service implementation (GitHub, GitLab, BitBucket) based on inference of the repo URL.

type ListPullRequestOpts

type ListPullRequestOpts struct {
	// State is the pull request state (one of: Open, Closed). Defaults to Open
	State PullRequestState
	Head  string
	Base  string
}

type ProviderRegistration

type ProviderRegistration struct {
	// Predicate is a function which should return true if the given repoURL is appropriate
	// for the provider to handle (e.g. github.com is the domain name)
	Predicate func(repoURL string) bool
	// NewService instantiates the git provider
	NewService func() (GitProviderService, error)
}

ProviderRegistration holds details on how to instantiate the correct git provider based on parameters (i.e. repo URL). It allows programs to selectively register GitProviderService implementations by anonymously importing implementation packages.

type PullRequest

type PullRequest struct {
	// Number is the numeric pull request number (not an ID)
	// Pull requests numbers are unique only within a repository
	Number int64 `json:"id"`
	// URL is the url to the pull request
	URL string `json:"url"`
	// State is the pull request state (one of: Open, Closed)
	State PullRequestState `json:"state"`
	// MergeCommitSHA is the SHA of the merge commit
	MergeCommitSHA string `json:"mergeCommitSHA"`
	// Object is the underlying object from the provider
	Object any `json:"-"`
}

func (*PullRequest) IsOpen

func (pr *PullRequest) IsOpen() bool

type PullRequestState

type PullRequestState string
const (
	PullRequestStateOpen   PullRequestState = "Open"
	PullRequestStateClosed PullRequestState = "Closed"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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