git

package
v1.0.4-gitspaces-beta Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvActorName  = "GITNESS_HOOK_ACTOR_NAME"
	EnvActorEmail = "GITNESS_HOOK_ACTOR_EMAIL" //#nosec
	EnvRepoUID    = "GITNESS_HOOK_REPO_UID"
	EnvRequestID  = "GITNESS_HOOK_REQUEST_ID"
)
View Source
const (
	SortOrderDefault SortOrder = iota
	SortOrderAsc               = iota
	SortOrderDesc
)
View Source
const (
	DefaultGitleaksIgnorePath = ".gitleaksignore"
)
View Source
const (
	// TODO: this should be configurable
	FileTransferChunkSize = 1024
)
View Source
const (
	ReposGraveyardSubdirName = "cleanup"
)
View Source
const (
	RequestIDNone string = "git_none"
)

Variables

View Source
var (
	ErrNoParamsProvided = errors.InvalidArgument("params not provided")
)

WireSet provides a wire set for this package.

Functions

func CreateEnvironmentForPush

func CreateEnvironmentForPush(ctx context.Context, writeRequest WriteParams) []string

ASSUMPTION: writeRequst and writeRequst.Actor is never nil.

func GetRefPath

func GetRefPath(refName string, refType enum.RefType) (string, error)

func NewRepositoryUID

func NewRepositoryUID() (string, error)

func ProvideGITAdapter

func ProvideGITAdapter(
	config types.Config,
	lastCommitCache cache.Cache[api.CommitEntryKey, *api.Commit],
	githookFactory hook.ClientFactory,
) (*api.Git, error)

func RequestIDFrom

func RequestIDFrom(ctx context.Context) string

RequestIDFrom retrieves the request id from the context. If no request id exists, RequestIDNone is returned.

func ValidateCommitSHA

func ValidateCommitSHA(commitSHA string) bool

func WithRequestID

func WithRequestID(parent context.Context, v string) context.Context

WithRequestID returns a copy of parent in which the request id value is set. This can be used by external entities to pass request IDs.

Types

type ArchiveParams

type ArchiveParams struct {
	ReadParams
	api.ArchiveParams
}

func (*ArchiveParams) Validate

func (p *ArchiveParams) Validate() error

type BlameParams

type BlameParams struct {
	ReadParams
	GitRef string
	Path   string

	// LineFrom allows to restrict the blame output to only lines starting from the provided line number (inclusive).
	// Optional, ignored if value is 0.
	LineFrom int

	// LineTo allows to restrict the blame output to only lines up to the provided line number (inclusive).
	// Optional, ignored if value is 0.
	LineTo int
}

func (*BlameParams) Validate

func (params *BlameParams) Validate() error

type BlamePart

type BlamePart struct {
	Commit *Commit  `json:"commit"`
	Lines  []string `json:"lines"`
}

type Branch

type Branch struct {
	Name   string
	SHA    sha.SHA
	Commit *Commit
}

type BranchSortOption

type BranchSortOption int
const (
	BranchSortOptionDefault BranchSortOption = iota
	BranchSortOptionName
	BranchSortOptionDate
)

type Commit

type Commit struct {
	SHA        sha.SHA           `json:"sha"`
	ParentSHAs []sha.SHA         `json:"parent_shas,omitempty"`
	Title      string            `json:"title"`
	Message    string            `json:"message,omitempty"`
	Author     Signature         `json:"author"`
	Committer  Signature         `json:"committer"`
	FileStats  []CommitFileStats `json:"file_stats,omitempty"`
}

type CommitDivergence

type CommitDivergence struct {
	// Ahead is the count of commits the 'From' ref is ahead of the 'To' ref.
	Ahead int32
	// Behind is the count of commits the 'From' ref is behind the 'To' ref.
	Behind int32
}

CommitDivergence contains the information of the count of converging commits between two refs.

type CommitDivergenceRequest

type CommitDivergenceRequest struct {
	// From is the ref from which the counting of the diverging commits starts.
	From string
	// To is the ref at which the counting of the diverging commits ends.
	To string
}

CommitDivergenceRequest contains the refs for which the converging commits should be counted.

type CommitFileAction

type CommitFileAction struct {
	Action  FileAction
	Path    string
	Payload []byte
	SHA     sha.SHA
}

CommitFileAction holds file operation data.

type CommitFileStats

type CommitFileStats struct {
	Status     enum.FileDiffStatus
	Path       string
	OldPath    string // populated only in case of renames
	Insertions int64
	Deletions  int64
}

type CommitFilesParams

type CommitFilesParams struct {
	WriteParams
	Title     string
	Message   string
	Branch    string
	NewBranch string
	Actions   []CommitFileAction

	// Committer overwrites the git committer used for committing the files
	// (optional, default: actor)
	Committer *Identity
	// CommitterDate overwrites the git committer date used for committing the files
	// (optional, default: current time on server)
	CommitterDate *time.Time
	// Author overwrites the git author used for committing the files
	// (optional, default: committer)
	Author *Identity
	// AuthorDate overwrites the git author date used for committing the files
	// (optional, default: committer date)
	AuthorDate *time.Time
}

CommitFilesParams holds the data for file operations.

func (*CommitFilesParams) Validate

func (p *CommitFilesParams) Validate() error

type CommitFilesResponse

type CommitFilesResponse struct {
	CommitID sha.SHA
}

type CommitTag

type CommitTag struct {
	Name        string
	SHA         sha.SHA
	IsAnnotated bool
	Title       string
	Message     string
	Tagger      *Signature
	Commit      *Commit
}

type CreateBranchOutput

type CreateBranchOutput struct {
	Branch Branch
}

type CreateBranchParams

type CreateBranchParams struct {
	WriteParams
	// BranchName is the name of the branch
	BranchName string
	// Target is a git reference (branch / tag / commit SHA)
	Target string
}

type CreateCommitTagOutput

type CreateCommitTagOutput struct {
	CommitTag
}

type CreateCommitTagParams

type CreateCommitTagParams struct {
	WriteParams
	Name string

	// Target is the commit (or points to the commit) the new tag will be pointing to.
	Target string

	// Message is the optional message the tag will be created with - if the message is empty
	// the tag will be lightweight, otherwise it'll be annotated
	Message string

	// Tagger overwrites the git author used in case the tag is annotated
	// (optional, default: actor)
	Tagger *Identity
	// TaggerDate overwrites the git author date used in case the tag is annotated
	// (optional, default: current time on server)
	TaggerDate *time.Time
}

func (*CreateCommitTagParams) Validate

func (p *CreateCommitTagParams) Validate() error

type CreateRepositoryOutput

type CreateRepositoryOutput struct {
	UID string
}

type CreateRepositoryParams

type CreateRepositoryParams struct {
	// Create operation is different from all (from user side), as UID doesn't exist yet.
	// Only take actor and envars as input and create WriteParams manually
	RepoUID string
	Actor   Identity
	EnvVars map[string]string

	DefaultBranch string
	Files         []File

	// Committer overwrites the git committer used for committing the files
	// (optional, default: actor)
	Committer *Identity
	// CommitterDate overwrites the git committer date used for committing the files
	// (optional, default: current time on server)
	CommitterDate *time.Time
	// Author overwrites the git author used for committing the files
	// (optional, default: committer)
	Author *Identity
	// AuthorDate overwrites the git author date used for committing the files
	// (optional, default: committer date)
	AuthorDate *time.Time
}

func (*CreateRepositoryParams) Validate

func (p *CreateRepositoryParams) Validate() error

type DeleteBranchParams

type DeleteBranchParams struct {
	WriteParams
	// BranchName is the name of the branch
	BranchName string
}

type DeleteRepositoryParams

type DeleteRepositoryParams struct {
	WriteParams
}

type DeleteTagParams

type DeleteTagParams struct {
	WriteParams
	Name string
}

func (DeleteTagParams) Validate

func (p DeleteTagParams) Validate() error

type DiffCutOutput

type DiffCutOutput struct {
	Header       HunkHeader
	LinesHeader  string
	Lines        []string
	MergeBaseSHA sha.SHA
}

type DiffCutParams

type DiffCutParams struct {
	ReadParams
	SourceCommitSHA string
	TargetCommitSHA string
	Path            string
	LineStart       int
	LineStartNew    bool
	LineEnd         int
	LineEndNew      bool
	LineLimit       int
}

type DiffFileHeader

type DiffFileHeader struct {
	OldName    string
	NewName    string
	Extensions map[string]string
}

type DiffFileHunkHeaders

type DiffFileHunkHeaders struct {
	FileHeader  DiffFileHeader
	HunkHeaders []HunkHeader
}

type DiffFileNamesOutput

type DiffFileNamesOutput struct {
	Files []string
}

type DiffParams

type DiffParams struct {
	ReadParams
	BaseRef      string
	HeadRef      string
	MergeBase    bool
	IncludePatch bool
}

func (DiffParams) Validate

func (p DiffParams) Validate() error

type DiffShortStatOutput

type DiffShortStatOutput struct {
	Files     int
	Additions int
	Deletions int
}

type DiffStatsOutput

type DiffStatsOutput struct {
	Commits      int
	FilesChanged int
	Additions    int
	Deletions    int
}

type File

type File struct {
	Path    string
	Content []byte
}

type FileAction

type FileAction string
const (
	CreateAction    FileAction = "CREATE"
	UpdateAction    FileAction = "UPDATE"
	DeleteAction    FileAction = "DELETE"
	MoveAction      FileAction = "MOVE"
	PatchTextAction FileAction = "PATCH_TEXT"
)

func (FileAction) Enum

func (FileAction) Enum() []interface{}

type FileDiff

type FileDiff struct {
	SHA         string              `json:"sha"`
	OldSHA      string              `json:"old_sha,omitempty"`
	Path        string              `json:"path"`
	OldPath     string              `json:"old_path,omitempty"`
	Status      enum.FileDiffStatus `json:"status"`
	Additions   int64               `json:"additions"`
	Deletions   int64               `json:"deletions"`
	Changes     int64               `json:"changes"`
	Patch       []byte              `json:"patch,omitempty"`
	IsBinary    bool                `json:"is_binary"`
	IsSubmodule bool                `json:"is_submodule"`
}

type FileInfo

type FileInfo struct {
	SHA  sha.SHA
	Size int64
}

type FindOversizeFilesOutput

type FindOversizeFilesOutput struct {
	FileInfos []FileInfo
}

type FindOversizeFilesParams

type FindOversizeFilesParams struct {
	RepoUID       string
	GitObjectDirs []string
	SizeLimit     int64
}

type GeneratePipelineParams

type GeneratePipelineParams struct {
	ReadParams
}

type GeneratePipelinesOutput

type GeneratePipelinesOutput struct {
	PipelineYAML []byte
}

type GetBlobOutput

type GetBlobOutput struct {
	SHA sha.SHA
	// Size is the actual size of the blob.
	Size int64
	// ContentSize is the total number of bytes returned by the Content Reader.
	ContentSize int64
	// Content contains the (partial) content of the blob.
	Content io.ReadCloser
}

type GetBlobParams

type GetBlobParams struct {
	ReadParams
	SHA       string
	SizeLimit int64
}

type GetBranchOutput

type GetBranchOutput struct {
	Branch Branch
}

type GetBranchParams

type GetBranchParams struct {
	ReadParams
	// BranchName is the name of the branch
	BranchName string
}

type GetCommitDivergencesOutput

type GetCommitDivergencesOutput struct {
	Divergences []api.CommitDivergence
}

type GetCommitDivergencesParams

type GetCommitDivergencesParams struct {
	ReadParams
	MaxCount int32
	Requests []CommitDivergenceRequest
}

type GetCommitOutput

type GetCommitOutput struct {
	Commit Commit `json:"commit"`
}

type GetCommitParams

type GetCommitParams struct {
	ReadParams
	Revision string
}

type GetDiffHunkHeadersOutput

type GetDiffHunkHeadersOutput struct {
	Files []DiffFileHunkHeaders
}

type GetDiffHunkHeadersParams

type GetDiffHunkHeadersParams struct {
	ReadParams
	SourceCommitSHA string
	TargetCommitSHA string
}

type GetRefParams

type GetRefParams struct {
	ReadParams
	Name string
	Type enum.RefType
}

func (*GetRefParams) Validate

func (p *GetRefParams) Validate() error

type GetRefResponse

type GetRefResponse struct {
	SHA sha.SHA
}

type GetRepositorySizeOutput

type GetRepositorySizeOutput struct {
	// Total size of the repository in KiB.
	Size int64
}

type GetRepositorySizeParams

type GetRepositorySizeParams struct {
	ReadParams
}

type GetSubmoduleOutput

type GetSubmoduleOutput struct {
	Submodule Submodule
}

type GetSubmoduleParams

type GetSubmoduleParams struct {
	ReadParams
	// GitREF is a git reference (branch / tag / commit SHA)
	GitREF string
	Path   string
}

type GetTreeNodeOutput

type GetTreeNodeOutput struct {
	Node   TreeNode
	Commit *Commit
}

type GetTreeNodeParams

type GetTreeNodeParams struct {
	ReadParams
	// GitREF is a git reference (branch / tag / commit SHA)
	GitREF              string
	Path                string
	IncludeLatestCommit bool
}

type HashRepositoryOutput

type HashRepositoryOutput struct {
	Hash []byte
}

type HashRepositoryParams

type HashRepositoryParams struct {
	ReadParams
	HashType        hash.Type
	AggregationType hash.AggregationType
}

func (*HashRepositoryParams) Validate

func (p *HashRepositoryParams) Validate() error

type Hunk

type Hunk struct {
	HunkHeader
	Lines []string
}

type HunkHeader

type HunkHeader struct {
	OldLine int
	OldSpan int
	NewLine int
	NewSpan int
	Text    string
}

func (*HunkHeader) IsValid

func (h *HunkHeader) IsValid() bool

func (*HunkHeader) IsZero

func (h *HunkHeader) IsZero() bool

func (*HunkHeader) String

func (h *HunkHeader) String() string

type Identity

type Identity struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

func (*Identity) Validate

func (i *Identity) Validate() error

type InfoRefsParams

type InfoRefsParams struct {
	ReadParams
	Service     string
	Options     []string // (key, value) pair
	GitProtocol string
}

type Interface

type Interface interface {
	CreateRepository(ctx context.Context, params *CreateRepositoryParams) (*CreateRepositoryOutput, error)
	DeleteRepository(ctx context.Context, params *DeleteRepositoryParams) error
	GetTreeNode(ctx context.Context, params *GetTreeNodeParams) (*GetTreeNodeOutput, error)
	ListTreeNodes(ctx context.Context, params *ListTreeNodeParams) (*ListTreeNodeOutput, error)
	ListPaths(ctx context.Context, params *ListPathsParams) (*ListPathsOutput, error)
	GetSubmodule(ctx context.Context, params *GetSubmoduleParams) (*GetSubmoduleOutput, error)
	GetBlob(ctx context.Context, params *GetBlobParams) (*GetBlobOutput, error)
	CreateBranch(ctx context.Context, params *CreateBranchParams) (*CreateBranchOutput, error)
	CreateCommitTag(ctx context.Context, params *CreateCommitTagParams) (*CreateCommitTagOutput, error)
	DeleteTag(ctx context.Context, params *DeleteTagParams) error
	GetBranch(ctx context.Context, params *GetBranchParams) (*GetBranchOutput, error)
	DeleteBranch(ctx context.Context, params *DeleteBranchParams) error
	ListBranches(ctx context.Context, params *ListBranchesParams) (*ListBranchesOutput, error)
	UpdateDefaultBranch(ctx context.Context, params *UpdateDefaultBranchParams) error
	GetRef(ctx context.Context, params GetRefParams) (GetRefResponse, error)
	PathsDetails(ctx context.Context, params PathsDetailsParams) (PathsDetailsOutput, error)
	Summary(ctx context.Context, params SummaryParams) (SummaryOutput, error)

	// GetRepositorySize calculates the size of a repo in KiB.
	GetRepositorySize(ctx context.Context, params *GetRepositorySizeParams) (*GetRepositorySizeOutput, error)
	// UpdateRef creates, updates or deletes a git ref. If the OldValue is defined it must match the reference value
	// prior to the call. To remove a ref use the zero ref as the NewValue. To require the creation of a new one and
	// not update of an exiting one, set the zero ref as the OldValue.
	UpdateRef(ctx context.Context, params UpdateRefParams) error

	SyncRepository(ctx context.Context, params *SyncRepositoryParams) (*SyncRepositoryOutput, error)

	MatchFiles(ctx context.Context, params *MatchFilesParams) (*MatchFilesOutput, error)

	/*
	 * Commits service
	 */
	GetCommit(ctx context.Context, params *GetCommitParams) (*GetCommitOutput, error)
	ListCommits(ctx context.Context, params *ListCommitsParams) (*ListCommitsOutput, error)
	ListCommitTags(ctx context.Context, params *ListCommitTagsParams) (*ListCommitTagsOutput, error)
	GetCommitDivergences(ctx context.Context, params *GetCommitDivergencesParams) (*GetCommitDivergencesOutput, error)
	CommitFiles(ctx context.Context, params *CommitFilesParams) (CommitFilesResponse, error)
	MergeBase(ctx context.Context, params MergeBaseParams) (MergeBaseOutput, error)
	IsAncestor(ctx context.Context, params IsAncestorParams) (IsAncestorOutput, error)
	FindOversizeFiles(
		ctx context.Context,
		params *FindOversizeFilesParams,
	) (*FindOversizeFilesOutput, error)

	/*
	 * Git Cli Service
	 */
	GetInfoRefs(ctx context.Context, w io.Writer, params *InfoRefsParams) error
	ServicePack(ctx context.Context, params *ServicePackParams) error

	/*
	 * Diff services
	 */
	RawDiff(ctx context.Context, w io.Writer, in *DiffParams, files ...api.FileDiffRequest) error
	Diff(ctx context.Context, in *DiffParams, files ...api.FileDiffRequest) (<-chan *FileDiff, <-chan error)
	DiffFileNames(ctx context.Context, in *DiffParams) (DiffFileNamesOutput, error)
	CommitDiff(ctx context.Context, params *GetCommitParams, w io.Writer) error
	DiffShortStat(ctx context.Context, params *DiffParams) (DiffShortStatOutput, error)
	DiffStats(ctx context.Context, params *DiffParams) (DiffStatsOutput, error)

	GetDiffHunkHeaders(ctx context.Context, params GetDiffHunkHeadersParams) (GetDiffHunkHeadersOutput, error)
	DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOutput, error)

	/*
	 * Merge services
	 */
	Merge(ctx context.Context, in *MergeParams) (MergeOutput, error)

	/*
	 * Blame services
	 */
	Blame(ctx context.Context, params *BlameParams) (<-chan *BlamePart, <-chan error)
	PushRemote(ctx context.Context, params *PushRemoteParams) error

	GeneratePipeline(ctx context.Context, params *GeneratePipelineParams) (GeneratePipelinesOutput, error)

	/*
	 * Secret Scanning service
	 */
	ScanSecrets(ctx context.Context, param *ScanSecretsParams) (*ScanSecretsOutput, error)
	Archive(ctx context.Context, params ArchiveParams, w io.Writer) error
}

func ProvideService

func ProvideService(
	config types.Config,
	adapter *api.Git,
	hookClientFactory hook.ClientFactory,
	storage storage.Store,
) (Interface, error)

type IsAncestorOutput

type IsAncestorOutput struct {
	Ancestor bool
}

type IsAncestorParams

type IsAncestorParams struct {
	ReadParams
	AncestorCommitSHA   sha.SHA
	DescendantCommitSHA sha.SHA
}

type ListBranchesOutput

type ListBranchesOutput struct {
	Branches []Branch
}

type ListBranchesParams

type ListBranchesParams struct {
	ReadParams
	IncludeCommit bool
	Query         string
	Sort          BranchSortOption
	Order         SortOrder
	Page          int32
	PageSize      int32
}

type ListCommitTagsOutput

type ListCommitTagsOutput struct {
	Tags []CommitTag
}

type ListCommitTagsParams

type ListCommitTagsParams struct {
	ReadParams
	IncludeCommit bool
	Query         string
	Sort          TagSortOption
	Order         SortOrder
	Page          int32
	PageSize      int32
}

type ListCommitsOutput

type ListCommitsOutput struct {
	Commits       []Commit
	RenameDetails []*RenameDetails
	TotalCommits  int
}

type ListCommitsParams

type ListCommitsParams struct {
	ReadParams
	// GitREF is a git reference (branch / tag / commit SHA)
	GitREF string
	// After is a git reference (branch / tag / commit SHA)
	// If provided, commits only up to that reference will be returned (exlusive)
	After string
	Page  int32
	Limit int32
	Path  string

	// Since allows to filter for commits since the provided UNIX timestamp - Optional, ignored if value is 0.
	Since int64

	// Until allows to filter for commits until the provided UNIX timestamp - Optional, ignored if value is 0.
	Until int64

	// Committer allows to filter for commits based on the committer - Optional, ignored if string is empty.
	Committer string

	// IncludeStats allows to include information about inserted, deletions and status for changed files.
	IncludeStats bool
}

type ListPathsOutput

type ListPathsOutput struct {
	Files       []string
	Directories []string
}

type ListPathsParams

type ListPathsParams struct {
	ReadParams
	// GitREF is a git reference (branch / tag / commit SHA)
	GitREF             string
	IncludeDirectories bool
}

type ListTreeNodeOutput

type ListTreeNodeOutput struct {
	Nodes []TreeNode
}

type ListTreeNodeParams

type ListTreeNodeParams struct {
	ReadParams
	// GitREF is a git reference (branch / tag / commit SHA)
	GitREF              string
	Path                string
	IncludeLatestCommit bool
}

type MatchFilesOutput

type MatchFilesOutput struct {
	Files []api.FileContent
}

type MatchFilesParams

type MatchFilesParams struct {
	ReadParams
	Ref     string
	DirPath string
	Pattern string
	MaxSize int
}

type MergeBaseOutput

type MergeBaseOutput struct {
	MergeBaseSHA sha.SHA
}

type MergeBaseParams

type MergeBaseParams struct {
	ReadParams
	Ref1 string
	Ref2 string
}

func (*MergeBaseParams) Validate

func (p *MergeBaseParams) Validate() error

type MergeOutput

type MergeOutput struct {
	// BaseSHA is the sha of the latest commit on the base branch that was used for merging.
	BaseSHA sha.SHA
	// HeadSHA is the sha of the latest commit on the head branch that was used for merging.
	HeadSHA sha.SHA
	// MergeBaseSHA is the sha of the merge base of the HeadSHA and BaseSHA
	MergeBaseSHA sha.SHA
	// MergeSHA is the sha of the commit after merging HeadSHA with BaseSHA.
	MergeSHA sha.SHA

	CommitCount      int
	ChangedFileCount int
	Additions        int
	Deletions        int
	ConflictFiles    []string
}

MergeOutput is result object from merging and returns base, head and commit sha.

type MergeParams

type MergeParams struct {
	WriteParams
	BaseBranch string
	// HeadRepoUID specifies the UID of the repo that contains the head branch (required for forking).
	// WARNING: This field is currently not supported yet!
	HeadRepoUID string
	HeadBranch  string
	Title       string
	Message     string

	// Committer overwrites the git committer used for committing the files
	// (optional, default: actor)
	Committer *Identity
	// CommitterDate overwrites the git committer date used for committing the files
	// (optional, default: current time on server)
	CommitterDate *time.Time
	// Author overwrites the git author used for committing the files
	// (optional, default: committer)
	Author *Identity
	// AuthorDate overwrites the git author date used for committing the files
	// (optional, default: committer date)
	AuthorDate *time.Time

	RefType enum.RefType
	RefName string

	// HeadExpectedSHA is commit sha on the head branch, if HeadExpectedSHA is older
	// than the HeadBranch latest sha then merge will fail.
	HeadExpectedSHA sha.SHA

	Force            bool
	DeleteHeadBranch bool

	Method enum.MergeMethod
}

MergeParams is input structure object for merging operation.

func (*MergeParams) Validate

func (p *MergeParams) Validate() error

type PathDetails

type PathDetails struct {
	Path       string  `json:"path"`
	LastCommit *Commit `json:"last_commit,omitempty"`
}

type PathsDetailsOutput

type PathsDetailsOutput struct {
	Details []PathDetails
}

type PathsDetailsParams

type PathsDetailsParams struct {
	ReadParams
	GitREF string
	Paths  []string
}

type PushRemoteParams

type PushRemoteParams struct {
	ReadParams
	RemoteURL string
}

func (*PushRemoteParams) Validate

func (p *PushRemoteParams) Validate() error

type ReadParams

type ReadParams struct {
	RepoUID             string
	AlternateObjectDirs []string
}

ReadParams contains the base parameters for read operations.

func CreateReadParams

func CreateReadParams(repo Repository) ReadParams

CreateReadParams creates base read parameters for git read operations. IMPORTANT: repo is assumed to be not nil!

func (ReadParams) Validate

func (p ReadParams) Validate() error

type RenameDetails

type RenameDetails struct {
	OldPath         string
	NewPath         string
	CommitShaBefore sha.SHA
	CommitShaAfter  sha.SHA
}

type Repository

type Repository interface {
	GetGitUID() string
}

type ScanSecretsFinding

type ScanSecretsFinding struct {
	Description string   `json:"description"`
	StartLine   int64    `json:"start_line"`
	EndLine     int64    `json:"end_line"`
	StartColumn int64    `json:"start_column"`
	EndColumn   int64    `json:"end_column"`
	Match       string   `json:"match"`
	Secret      string   `json:"secret"`
	File        string   `json:"file"`
	SymlinkFile string   `json:"symlink_file"`
	Commit      string   `json:"commit"`
	Entropy     float64  `json:"entropy"`
	Author      string   `json:"author"`
	Email       string   `json:"email"`
	Date        string   `json:"date"`
	Message     string   `json:"message"`
	Tags        []string `json:"tags"`
	RuleID      string   `json:"rule_id"`
	// Fingerprint is the unique identifier of the secret that can be used in .gitleaksignore files.
	Fingerprint string `json:"fingerprint"`
}

type ScanSecretsOutput

type ScanSecretsOutput struct {
	Findings []ScanSecretsFinding
}

type ScanSecretsParams

type ScanSecretsParams struct {
	ReadParams

	BaseRev string // optional to scan for secrets on diff between baseRev and Rev
	Rev     string

	GitleaksIgnorePath string // optional, keep empty to skip using .gitleaksignore file.
}

type Service

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

func New

func New(
	config types.Config,
	adapter *api.Git,
	hookClientFactory hook.ClientFactory,
	storage storage.Store,
) (*Service, error)

func (*Service) Archive

func (s *Service) Archive(ctx context.Context, params ArchiveParams, w io.Writer) error

func (*Service) Blame

func (s *Service) Blame(ctx context.Context, params *BlameParams) (<-chan *BlamePart, <-chan error)

Blame processes and streams the git blame output data. The function returns two channels: The data channel and the error channel. If any error happens during the operation it will be put to the error channel and the streaming will stop. Maximum of one error can be put on the channel.

func (*Service) CommitDiff

func (s *Service) CommitDiff(ctx context.Context, params *GetCommitParams, out io.Writer) error

func (*Service) CommitFiles

func (s *Service) CommitFiles(ctx context.Context, params *CommitFilesParams) (CommitFilesResponse, error)

func (*Service) CreateBranch

func (s *Service) CreateBranch(ctx context.Context, params *CreateBranchParams) (*CreateBranchOutput, error)

func (*Service) CreateCommitTag

func (s *Service) CreateCommitTag(ctx context.Context, params *CreateCommitTagParams) (*CreateCommitTagOutput, error)

func (*Service) CreateRepository

func (s *Service) CreateRepository(
	ctx context.Context,
	params *CreateRepositoryParams,
) (*CreateRepositoryOutput, error)

func (*Service) DeleteBranch

func (s *Service) DeleteBranch(ctx context.Context, params *DeleteBranchParams) error

func (*Service) DeleteRepository

func (s *Service) DeleteRepository(ctx context.Context, params *DeleteRepositoryParams) error

func (*Service) DeleteRepositoryBestEffort

func (s *Service) DeleteRepositoryBestEffort(ctx context.Context, repoUID string) error

func (*Service) DeleteTag

func (s *Service) DeleteTag(ctx context.Context, params *DeleteTagParams) error

func (*Service) Diff

func (s *Service) Diff(
	ctx context.Context,
	params *DiffParams,
	files ...api.FileDiffRequest,
) (<-chan *FileDiff, <-chan error)

func (*Service) DiffCut

func (s *Service) DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOutput, error)

DiffCut extracts diff snippet from a git diff hunk. The snippet is from the diff between the specified commit SHAs.

func (*Service) DiffFileNames

func (s *Service) DiffFileNames(ctx context.Context, params *DiffParams) (DiffFileNamesOutput, error)

func (*Service) DiffShortStat

func (s *Service) DiffShortStat(ctx context.Context, params *DiffParams) (DiffShortStatOutput, error)

DiffShortStat returns files changed, additions and deletions metadata.

func (*Service) DiffStats

func (s *Service) DiffStats(ctx context.Context, params *DiffParams) (DiffStatsOutput, error)

func (*Service) FindOversizeFiles

func (s *Service) FindOversizeFiles(
	ctx context.Context,
	params *FindOversizeFilesParams,
) (*FindOversizeFilesOutput, error)

func (*Service) GeneratePipeline

func (s *Service) GeneratePipeline(ctx context.Context,
	params *GeneratePipelineParams,
) (GeneratePipelinesOutput, error)

func (*Service) GetBlob

func (s *Service) GetBlob(ctx context.Context, params *GetBlobParams) (*GetBlobOutput, error)

func (*Service) GetBranch

func (s *Service) GetBranch(ctx context.Context, params *GetBranchParams) (*GetBranchOutput, error)

func (*Service) GetCommit

func (s *Service) GetCommit(ctx context.Context, params *GetCommitParams) (*GetCommitOutput, error)

func (*Service) GetCommitDivergences

func (s *Service) GetCommitDivergences(
	ctx context.Context,
	params *GetCommitDivergencesParams,
) (*GetCommitDivergencesOutput, error)

func (*Service) GetDiffHunkHeaders

func (s *Service) GetDiffHunkHeaders(
	ctx context.Context,
	params GetDiffHunkHeadersParams,
) (GetDiffHunkHeadersOutput, error)

func (*Service) GetInfoRefs

func (s *Service) GetInfoRefs(ctx context.Context, w io.Writer, params *InfoRefsParams) error

func (*Service) GetRef

func (s *Service) GetRef(ctx context.Context, params GetRefParams) (GetRefResponse, error)

func (*Service) GetRepositorySize

func (s *Service) GetRepositorySize(
	ctx context.Context,
	params *GetRepositorySizeParams,
) (*GetRepositorySizeOutput, error)

GetRepositorySize accumulates the sizes of counted Git objects.

func (*Service) GetSubmodule

func (s *Service) GetSubmodule(ctx context.Context, params *GetSubmoduleParams) (*GetSubmoduleOutput, error)

func (*Service) GetTreeNode

func (s *Service) GetTreeNode(ctx context.Context, params *GetTreeNodeParams) (*GetTreeNodeOutput, error)

func (*Service) HashRepository

func (s *Service) HashRepository(ctx context.Context, params *HashRepositoryParams) (*HashRepositoryOutput, error)

func (*Service) IsAncestor

func (s *Service) IsAncestor(
	ctx context.Context,
	params IsAncestorParams,
) (IsAncestorOutput, error)

func (*Service) ListBranches

func (s *Service) ListBranches(ctx context.Context, params *ListBranchesParams) (*ListBranchesOutput, error)

func (*Service) ListCommitTags

func (s *Service) ListCommitTags(
	ctx context.Context,
	params *ListCommitTagsParams,
) (*ListCommitTagsOutput, error)

func (*Service) ListCommits

func (s *Service) ListCommits(ctx context.Context, params *ListCommitsParams) (*ListCommitsOutput, error)

func (*Service) ListPaths

func (s *Service) ListPaths(ctx context.Context, params *ListPathsParams) (*ListPathsOutput, error)

func (*Service) ListTreeNodes

func (s *Service) ListTreeNodes(ctx context.Context, params *ListTreeNodeParams) (*ListTreeNodeOutput, error)

func (*Service) MatchFiles

func (s *Service) MatchFiles(ctx context.Context,
	params *MatchFilesParams,
) (*MatchFilesOutput, error)

func (*Service) Merge

func (s *Service) Merge(ctx context.Context, params *MergeParams) (MergeOutput, error)

Merge method executes git merge operation. Refs can be sha, branch or tag. Based on input params.RefType merge can do checking or final merging of two refs. some examples:

params.RefType = Undefined -> discard merge commit (only performs a merge check).
params.RefType = Raw and params.RefName = refs/pull/1/ref will push to refs/pullreq/1/ref
params.RefType = RefTypeBranch and params.RefName = "somebranch" -> merge and push to refs/heads/somebranch
params.RefType = RefTypePullReqHead and params.RefName = "1" -> merge and push to refs/pullreq/1/head
params.RefType = RefTypePullReqMerge and params.RefName = "1" -> merge and push to refs/pullreq/1/merge

There are cases when you want to block merging and for that you will need to provide params.HeadExpectedSHA which will be compared with the latest sha from head branch if they are not the same error will be returned.

func (*Service) MergeBase

func (s *Service) MergeBase(
	ctx context.Context,
	params MergeBaseParams,
) (MergeBaseOutput, error)

func (*Service) PathsDetails

func (s *Service) PathsDetails(ctx context.Context, params PathsDetailsParams) (PathsDetailsOutput, error)

func (*Service) PushRemote

func (s *Service) PushRemote(ctx context.Context, params *PushRemoteParams) error

func (*Service) RawDiff

func (s *Service) RawDiff(
	ctx context.Context,
	out io.Writer,
	params *DiffParams,
	files ...api.FileDiffRequest,
) error

func (*Service) ScanSecrets

func (s *Service) ScanSecrets(ctx context.Context, params *ScanSecretsParams) (*ScanSecretsOutput, error)

func (*Service) ServicePack

func (s *Service) ServicePack(ctx context.Context, params *ServicePackParams) error

func (*Service) Summary

func (s *Service) Summary(
	ctx context.Context,
	params SummaryParams,
) (SummaryOutput, error)

func (*Service) SyncRepository

func (s *Service) SyncRepository(
	ctx context.Context,
	params *SyncRepositoryParams,
) (*SyncRepositoryOutput, error)

func (*Service) UpdateDefaultBranch

func (s *Service) UpdateDefaultBranch(
	ctx context.Context,
	params *UpdateDefaultBranchParams,
) error

UpdateDefaultBranch updates the default barnch of the repo.

func (*Service) UpdateRef

func (s *Service) UpdateRef(ctx context.Context, params UpdateRefParams) error

type ServicePackParams

type ServicePackParams struct {
	*ReadParams
	*WriteParams
	api.ServicePackOptions
}

func (*ServicePackParams) Validate

func (p *ServicePackParams) Validate() error

type Signature

type Signature struct {
	Identity Identity  `json:"identity"`
	When     time.Time `json:"when"`
}

type SortOrder

type SortOrder int

type StreamReader

type StreamReader[T any] struct {
	// contains filtered or unexported fields
}

StreamReader is a helper utility to ease reading from streaming channel pair (the data and the error channel).

func NewStreamReader

func NewStreamReader[T any](chData <-chan T, chErr <-chan error) *StreamReader[T]

NewStreamReader creates new StreamReader.

func (*StreamReader[T]) Next

func (str *StreamReader[T]) Next() (T, error)

Next returns the next element or error. In case the end has been reached, an io.EOF is returned.

type Submodule

type Submodule struct {
	Name string
	URL  string
}

type SummaryOutput

type SummaryOutput struct {
	CommitCount int
	BranchCount int
	TagCount    int
}

type SummaryParams

type SummaryParams struct {
	ReadParams
}

type SyncRepositoryOutput

type SyncRepositoryOutput struct {
	DefaultBranch string
}

type SyncRepositoryParams

type SyncRepositoryParams struct {
	WriteParams
	Source            string
	CreateIfNotExists bool

	// RefSpecs [OPTIONAL] allows to override the refspecs that are being synced from the remote repository.
	// By default all references present on the remote repository will be fetched (including scm internal ones).
	RefSpecs []string
}

type TagSortOption

type TagSortOption int
const (
	TagSortOptionDefault TagSortOption = iota
	TagSortOptionName
	TagSortOptionDate
)

type TreeNode

type TreeNode struct {
	Type TreeNodeType
	Mode TreeNodeMode
	SHA  string // TODO: make sha.SHA
	Name string
	Path string
}

type TreeNodeMode

type TreeNodeMode string

TreeNodeMode specifies the different modes of a node in a git tree. IMPORTANT: has to be consistent with rpc.TreeNodeMode (proto).

const (
	TreeNodeModeFile    TreeNodeMode = "file"
	TreeNodeModeSymlink TreeNodeMode = "symlink"
	TreeNodeModeExec    TreeNodeMode = "exec"
	TreeNodeModeTree    TreeNodeMode = "tree"
	TreeNodeModeCommit  TreeNodeMode = "commit"
)

type TreeNodeType

type TreeNodeType string

TreeNodeType specifies the different types of nodes in a git tree. IMPORTANT: has to be consistent with rpc.TreeNodeType (proto).

const (
	TreeNodeTypeTree   TreeNodeType = "tree"
	TreeNodeTypeBlob   TreeNodeType = "blob"
	TreeNodeTypeCommit TreeNodeType = "commit"
)

type UpdateDefaultBranchParams

type UpdateDefaultBranchParams struct {
	WriteParams
	// BranchName is the name of the branch
	BranchName string
}

type UpdateRefParams

type UpdateRefParams struct {
	WriteParams
	Type enum.RefType
	Name string
	// NewValue specified the new value the reference should point at.
	// An empty value will lead to the deletion of the branch.
	NewValue sha.SHA
	// OldValue is an optional value that can be used to ensure that the reference
	// is updated iff its current value is matching the provided value.
	OldValue sha.SHA
}

type WriteParams

type WriteParams struct {
	RepoUID string
	Actor   Identity
	EnvVars map[string]string
}

WriteParams contains the base parameters for write operations.

func (*WriteParams) Validate

func (p *WriteParams) Validate() error

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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