vcs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Branch

func Branch(ref string) (string, error)

Branch is the helper function returns the branch name from reference name. For now, this method only supports branch reference. https://git-scm.com/book/en/v2/Git-Internals-Git-References

func Register

func Register(vcsType Type, f providerFunc)

Register makes a vcs provider available by the provided type. If Register is called twice with the same name or if provider is nil, it panics.

Types

type FileCommit

type FileCommit struct {
	ID         string `json:"id"`
	Title      string `json:"title"`
	Message    string `json:"message"`
	CreatedTs  int64  `json:"createdTs"`
	URL        string `json:"url"`
	AuthorName string `json:"authorName"`
	Added      string `json:"added"`
}

FileCommit is the API message for a VCS file commit.

type FileCommitCreate

type FileCommitCreate struct {
	Branch        string
	Content       string
	CommitMessage string
	LastCommitID  string
}

FileCommitCreate is the payload for committing a new file.

type FileMeta

type FileMeta struct {
	LastCommitID string
}

FileMeta records the file metadata.

type Provider

type Provider interface {
	// Returns the API URL for a given VCS instance URL
	APIURL(instanceURL string) string

	// Try to use this provider as an auth provider and fetch the user info from the OAuth context
	//
	// oauthCtx: OAuth context to write the file content
	// instanceURL: VCS instance URL
	TryLogin(ctx context.Context, oauthCtx common.OauthContext, instanceURL string) (*UserInfo, error)

	// Fetch the user info of the given userID
	//
	// oauthCtx: OAuth context to write the file content
	// instanceURL: VCS instance URL
	// userID: the ID of the desired user
	FetchUserInfo(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, userID int) (*UserInfo, error)

	// Fetch all active members of a given repository
	//
	// oauthCtx: OAuth context to write the file content
	// instanceURL: VCS instance URL
	// repositoryID: the repository ID from the external VCS system (note this is NOT the ID of Bytebase's own repository resource)
	FetchRepositoryActiveMemberList(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string) ([]*RepositoryMember, error)

	// Commits a new file
	//
	// oauthCtx: OAuth context to write the file content
	// instanceURL: VCS instance URL
	// repositoryID: the repository ID from the external VCS system (note this is NOT the ID of Bytebase's own repository resource)
	// filePath: file path to be written
	// fileCommit: the new file commit info
	CreateFile(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, fileCommit FileCommitCreate) error
	// Overwrites an existing file
	//
	// Similar to CreateFile except it overwrites an existing file. The fileCommit shoud includes the "LastCommitID" field which is used to detect conflicting writes.
	OverwriteFile(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, fileCommit FileCommitCreate) error
	// Reads the file content. Returns an io.ReadCloser on success. If file does not exist, returns NotFound error.
	//
	// oauthCtx: OAuth context to read the file content
	// instanceURL: VCS instance URL
	// repositoryID: the repository ID from the external VCS system (note this is NOT the ID of Bytebase's own repository resource)
	// filePath: file path to be read
	// commitID: the specific version to be read
	ReadFile(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, commitID string) (string, error)
	// Reads the file metadata. Returns the file meta on success.
	//
	// Similar to ReadFile except it specifies a branch instead of a commitID.
	ReadFileMeta(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, filePath string, branch string) (*FileMeta, error)
	// Creates a webhook. Returns the created webhook ID on succeess.
	//
	// oauthCtx: OAuth context to create the webhook
	// instanceURL: VCS instance URL
	// repositoryID: the repository ID from the external VCS system (note this is NOT the ID of Bytebase's own repository resource)
	// payload: the webhook payload
	CreateWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, payload []byte) (string, error)
	// Patches a webhook.
	//
	// The payload stores the patched field(s).
	PatchWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookID string, payload []byte) error
	// Deletes a webhook.
	DeleteWebhook(ctx context.Context, oauthCtx common.OauthContext, instanceURL string, repositoryID string, webhookID string) error
}

Provider is the interface for VCS provider.

func Get

func Get(vcsType Type, providerConfig ProviderConfig) Provider

Get returns a vcs provider specified by its vcs type

type ProviderConfig

type ProviderConfig struct {
	Logger *zap.Logger
}

ProviderConfig is the provider configuration.

type PushEvent

type PushEvent struct {
	VCSType            Type       `json:"vcsType"`
	BaseDirectory      string     `json:"baseDir"`
	Ref                string     `json:"ref"`
	RepositoryID       string     `json:"repositoryId"`
	RepositoryURL      string     `json:"repositoryUrl"`
	RepositoryFullPath string     `json:"repositoryFullPath"`
	AuthorName         string     `json:"authorName"`
	FileCommit         FileCommit `json:"fileCommit"`
}

PushEvent is the API message for a VCS push event.

type RepositoryMember

type RepositoryMember struct {
	Email        string             `json:"email"`
	Name         string             `json:"name"`
	State        State              `json:"state"`
	Role         common.ProjectRole `json:"role"`
	VCSRole      string             `json:"vcsRole"`
	RoleProvider Type               `json:"roleProvider"`
}

RepositoryMember is the API message for repository member info.

type State

type State string

State is the state of a VCS user account.

const (
	// StateActive is the active state for VCS user state.
	StateActive State = "active"
	// StateArchived is the archived state for VCS user state.
	StateArchived State = "archived"
)

type Type

type Type string

Type is the type of a VCS.

const (
	// GitLabSelfHost is the VCS type for gitlab self host.
	GitLabSelfHost Type = "GITLAB_SELF_HOST"
)

func (Type) String

func (e Type) String() string

type UserInfo

type UserInfo struct {
	Email string `json:"email"`
	Name  string `json:"name"`
	State State  `json:"state"`
}

UserInfo is the API message for user info.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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