platform

package
v0.0.0-...-d9f3949 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGitHubHost  = "github.com"
	DefaultGitLabHost  = "gitlab.com"
	DefaultForgejoHost = "codeberg.org"
	DefaultGiteaHost   = "gitea.com"
)

Variables

View Source
var (
	ErrUnsupportedCapability = &Error{Code: ErrCodeUnsupportedCapability}
	ErrProviderNotConfigured = &Error{Code: ErrCodeProviderNotConfigured}
	ErrMissingToken          = &Error{Code: ErrCodeMissingToken}
	ErrInvalidRepoRef        = &Error{Code: ErrCodeInvalidRepoRef}
	ErrPermissionDenied      = &Error{Code: ErrCodePermissionDenied}
	ErrNotFound              = &Error{Code: ErrCodeNotFound}
	ErrRateLimited           = &Error{Code: ErrCodeRateLimited}
)

Functions

func AllowsNestedOwner

func AllowsNestedOwner(kind Kind) bool

func DBCIChecks

func DBCIChecks(checks []CICheck) []db.CICheck

func DBIssue

func DBIssue(repoID int64, issue Issue) *db.Issue

func DBIssueEvent

func DBIssueEvent(issueID int64, event IssueEvent) db.IssueEvent

func DBLabels

func DBLabels(labels []Label, updatedAt time.Time) []db.Label

func DBMREvent

func DBMREvent(mrID int64, event MergeRequestEvent) db.MREvent

func DBMergeRequest

func DBMergeRequest(repoID int64, mr MergeRequest) *db.MergeRequest

func DBRepoIdentity

func DBRepoIdentity(ref RepoRef) db.RepoIdentity

func DBRepositoryIdentity

func DBRepositoryIdentity(repo Repository) db.RepoIdentity

func DefaultHost

func DefaultHost(kind Kind) (string, bool)

func HostOrDefault

func HostOrDefault(kind Kind, host string) (string, bool)

func LowercaseRepoNames

func LowercaseRepoNames(kind Kind) bool

func ProviderNotConfigured

func ProviderNotConfigured(kind Kind, host string) error

func UnsupportedCapability

func UnsupportedCapability(kind Kind, host, capability string) error

Types

type CICheck

type CICheck struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	Name               string
	Status             string
	Conclusion         string
	URL                string
	App                string
	StartedAt          *time.Time
	CompletedAt        *time.Time
}

type CIReader

type CIReader interface {
	ListCIChecks(ctx context.Context, ref RepoRef, sha string) ([]CICheck, error)
}

type Capabilities

type Capabilities struct {
	ReadRepositories  bool
	ReadMergeRequests bool
	ReadIssues        bool
	ReadComments      bool
	ReadReleases      bool
	ReadCI            bool
	CommentMutation   bool
	StateMutation     bool
	MergeMutation     bool
	ReviewMutation    bool
	WorkflowApproval  bool
	ReadyForReview    bool
	IssueMutation     bool
}

type CommentMutator

type CommentMutator interface {
	CreateMergeRequestComment(
		ctx context.Context,
		ref RepoRef,
		number int,
		body string,
	) (MergeRequestEvent, error)
	EditMergeRequestComment(
		ctx context.Context,
		ref RepoRef,
		number int,
		commentID int64,
		body string,
	) (MergeRequestEvent, error)
	CreateIssueComment(ctx context.Context, ref RepoRef, number int, body string) (IssueEvent, error)
	EditIssueComment(ctx context.Context, ref RepoRef, number int, commentID int64, body string) (IssueEvent, error)
}

type Error

type Error struct {
	Code         PlatformErrorCode
	Provider     Kind
	PlatformHost string
	Capability   string
	TokenEnv     string
	Field        string
	ResetAt      *time.Time
	Err          error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Issue

type Issue struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	Number             int
	URL                string
	Title              string
	Author             string
	State              string
	Body               string
	CommentCount       int
	CreatedAt          time.Time
	UpdatedAt          time.Time
	LastActivityAt     time.Time
	ClosedAt           *time.Time
	Labels             []Label
}

type IssueEvent

type IssueEvent struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	IssueNumber        int
	EventType          string
	Author             string
	Summary            string
	Body               string
	MetadataJSON       string
	CreatedAt          time.Time
	DedupeKey          string
}

type IssueMutator

type IssueMutator interface {
	CreateIssue(ctx context.Context, ref RepoRef, title string, body string) (Issue, error)
}

type IssueReader

type IssueReader interface {
	ListOpenIssues(ctx context.Context, ref RepoRef) ([]Issue, error)
	GetIssue(ctx context.Context, ref RepoRef, number int) (Issue, error)
	ListIssueEvents(ctx context.Context, ref RepoRef, number int) ([]IssueEvent, error)
}

type Kind

type Kind string
const (
	KindGitHub  Kind = "github"
	KindGitLab  Kind = "gitlab"
	KindForgejo Kind = "forgejo"
	KindGitea   Kind = "gitea"
)

func NormalizeKind

func NormalizeKind(raw string) (Kind, error)

type Label

type Label struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	Name               string
	Description        string
	Color              string
	IsDefault          bool
}

type MergeMutator

type MergeMutator interface {
	MergeMergeRequest(
		ctx context.Context,
		ref RepoRef,
		number int,
		commitTitle string,
		commitMessage string,
		method string,
	) (MergeResult, error)
}

type MergeRequest

type MergeRequest struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	Number             int
	URL                string
	Title              string
	Author             string
	AuthorDisplayName  string
	State              string
	IsDraft            bool
	IsLocked           bool
	Body               string
	HeadBranch         string
	BaseBranch         string
	HeadSHA            string
	BaseSHA            string
	HeadRepoCloneURL   string
	Additions          int
	Deletions          int
	CommentCount       int
	ReviewDecision     string
	CIStatus           string
	CreatedAt          time.Time
	UpdatedAt          time.Time
	LastActivityAt     time.Time
	MergedAt           *time.Time
	ClosedAt           *time.Time
	Labels             []Label
}

type MergeRequestContentMutator

type MergeRequestContentMutator interface {
	EditMergeRequestContent(
		ctx context.Context,
		ref RepoRef,
		number int,
		title *string,
		body *string,
	) (MergeRequest, error)
}

type MergeRequestEvent

type MergeRequestEvent struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	MergeRequestNumber int
	EventType          string
	Author             string
	Summary            string
	Body               string
	MetadataJSON       string
	CreatedAt          time.Time
	DedupeKey          string
}

type MergeRequestReader

type MergeRequestReader interface {
	ListOpenMergeRequests(ctx context.Context, ref RepoRef) ([]MergeRequest, error)
	GetMergeRequest(ctx context.Context, ref RepoRef, number int) (MergeRequest, error)
	ListMergeRequestEvents(
		ctx context.Context,
		ref RepoRef,
		number int,
	) ([]MergeRequestEvent, error)
}

type MergeResult

type MergeResult struct {
	Merged  bool
	SHA     string
	Message string
}

type Metadata

type Metadata struct {
	Kind               Kind
	Label              string
	DefaultHost        string
	AllowNestedOwner   bool
	LowercaseRepoNames bool
}

func MetadataFor

func MetadataFor(kind Kind) (Metadata, bool)

type PlatformErrorCode

type PlatformErrorCode string
const (
	ErrCodeUnsupportedCapability PlatformErrorCode = "unsupported_capability"
	ErrCodeProviderNotConfigured PlatformErrorCode = "provider_not_configured"
	ErrCodeMissingToken          PlatformErrorCode = "missing_token"
	ErrCodeInvalidRepoRef        PlatformErrorCode = "invalid_repo_ref"
	ErrCodePermissionDenied      PlatformErrorCode = "permission_denied"
	ErrCodeNotFound              PlatformErrorCode = "not_found"
	ErrCodeRateLimited           PlatformErrorCode = "rate_limited"
)

type Provider

type Provider interface {
	Platform() Kind
	Host() string
	Capabilities() Capabilities
}

type ReadyForReviewMutator

type ReadyForReviewMutator interface {
	MarkReadyForReview(ctx context.Context, ref RepoRef, number int) (MergeRequest, error)
}

type Registry

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

func NewRegistry

func NewRegistry(providers ...Provider) (*Registry, error)

func (*Registry) CIReader

func (r *Registry) CIReader(kind Kind, host string) (CIReader, error)

func (*Registry) Capabilities

func (r *Registry) Capabilities(kind Kind, host string) (Capabilities, error)

func (*Registry) CommentMutator

func (r *Registry) CommentMutator(kind Kind, host string) (CommentMutator, error)

func (*Registry) IssueMutator

func (r *Registry) IssueMutator(kind Kind, host string) (IssueMutator, error)

func (*Registry) IssueReader

func (r *Registry) IssueReader(kind Kind, host string) (IssueReader, error)

func (*Registry) MergeMutator

func (r *Registry) MergeMutator(kind Kind, host string) (MergeMutator, error)

func (*Registry) MergeRequestContentMutator

func (r *Registry) MergeRequestContentMutator(
	kind Kind,
	host string,
) (MergeRequestContentMutator, error)

func (*Registry) MergeRequestReader

func (r *Registry) MergeRequestReader(kind Kind, host string) (MergeRequestReader, error)

func (*Registry) Provider

func (r *Registry) Provider(kind Kind, host string) (Provider, error)

func (*Registry) ReadyForReviewMutator

func (r *Registry) ReadyForReviewMutator(kind Kind, host string) (ReadyForReviewMutator, error)

func (*Registry) Register

func (r *Registry) Register(provider Provider) error

func (*Registry) ReleaseReader

func (r *Registry) ReleaseReader(kind Kind, host string) (ReleaseReader, error)

func (*Registry) RepositoryReader

func (r *Registry) RepositoryReader(kind Kind, host string) (RepositoryReader, error)

func (*Registry) ReviewMutator

func (r *Registry) ReviewMutator(kind Kind, host string) (ReviewMutator, error)

func (*Registry) StateMutator

func (r *Registry) StateMutator(kind Kind, host string) (StateMutator, error)

func (*Registry) TagReader

func (r *Registry) TagReader(kind Kind, host string) (TagReader, error)

func (*Registry) WorkflowApprovalMutator

func (r *Registry) WorkflowApprovalMutator(kind Kind, host string) (WorkflowApprovalMutator, error)

type Release

type Release struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	TagName            string
	Name               string
	URL                string
	TargetCommitish    string
	Prerelease         bool
	PublishedAt        *time.Time
	CreatedAt          time.Time
}

type ReleaseReader

type ReleaseReader interface {
	ListReleases(ctx context.Context, ref RepoRef) ([]Release, error)
}

type RepoRef

type RepoRef struct {
	Platform           Kind
	Host               string
	Owner              string
	Name               string
	RepoPath           string
	PlatformID         int64
	PlatformExternalID string
	WebURL             string
	CloneURL           string
	DefaultBranch      string
}

func (RepoRef) DisplayName

func (r RepoRef) DisplayName() string

type Repository

type Repository struct {
	Ref                RepoRef
	PlatformID         int64
	PlatformExternalID string
	Description        string
	Private            bool
	Archived           bool
	DefaultBranch      string
	WebURL             string
	CloneURL           string
	CreatedAt          time.Time
	UpdatedAt          time.Time
}

type RepositoryListOptions

type RepositoryListOptions struct {
	Limit  int
	Offset int
}

type RepositoryReader

type RepositoryReader interface {
	GetRepository(ctx context.Context, ref RepoRef) (Repository, error)
	ListRepositories(
		ctx context.Context,
		owner string,
		opts RepositoryListOptions,
	) ([]Repository, error)
}

type ReviewMutator

type ReviewMutator interface {
	ApproveMergeRequest(ctx context.Context, ref RepoRef, number int, body string) (MergeRequestEvent, error)
}

type StateMutator

type StateMutator interface {
	SetMergeRequestState(ctx context.Context, ref RepoRef, number int, state string) (MergeRequest, error)
	SetIssueState(ctx context.Context, ref RepoRef, number int, state string) (Issue, error)
}

type Tag

type Tag struct {
	Repo               RepoRef
	PlatformID         int64
	PlatformExternalID string
	Name               string
	SHA                string
	URL                string
}

type TagReader

type TagReader interface {
	ListTags(ctx context.Context, ref RepoRef) ([]Tag, error)
}

type WorkflowApprovalMutator

type WorkflowApprovalMutator interface {
	ApproveWorkflow(ctx context.Context, ref RepoRef, runID string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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