git

package
v0.0.0-...-51d4900 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRepositoryNotFound  = errors.New("repository not found")
	ErrRepositoryCorrupted = errors.New("repository is corrupted")
	ErrReferenceNotFound   = errors.New("reference not found")
	ErrCommitNotFound      = errors.New("commit not found")
	ErrBranchNotFound      = errors.New("branch not found")
	ErrTagNotFound         = errors.New("tag not found")
	ErrFileNotFound        = errors.New("file not found")
	ErrPathNotFound        = errors.New("path not found")
)

Common Git errors

Functions

This section is empty.

Types

type Blob

type Blob struct {
	SHA      string `json:"sha"`
	Size     int64  `json:"size"`
	Content  []byte `json:"content"`
	Encoding string `json:"encoding"` // base64 for binary files
}

Blob represents a Git blob (file content)

type Branch

type Branch struct {
	Name      string    `json:"name"`
	SHA       string    `json:"sha"`
	Protected bool      `json:"protected"`
	IsDefault bool      `json:"is_default"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Branch represents a Git branch

type BranchComparison

type BranchComparison struct {
	BaseRef    string      `json:"base_ref"`
	HeadRef    string      `json:"head_ref"`
	Status     string      `json:"status"` // ahead, behind, identical, diverged
	AheadBy    int         `json:"ahead_by"`
	BehindBy   int         `json:"behind_by"`
	Commits    []*Commit   `json:"commits"`
	Files      []*DiffFile `json:"files"`
	Additions  int         `json:"additions"`
	Deletions  int         `json:"deletions"`
	TotalFiles int         `json:"total_files"`
}

BranchComparison represents a comparison between two branches

type CloneOptions

type CloneOptions struct {
	Depth    int
	Branch   string
	Mirror   bool
	Bare     bool
	Username string
	Password string
	SSHKey   string
}

CloneOptions represents options for cloning a repository

type Commit

type Commit struct {
	SHA       string        `json:"sha"`
	Message   string        `json:"message"`
	Author    CommitAuthor  `json:"author"`
	Committer CommitAuthor  `json:"committer"`
	Parents   []string      `json:"parents"`
	Tree      string        `json:"tree"`
	Stats     *CommitStats  `json:"stats,omitempty"`
	Files     []*CommitFile `json:"files,omitempty"`
}

Commit represents a Git commit

type CommitAuthor

type CommitAuthor struct {
	Name  string    `json:"name"`
	Email string    `json:"email"`
	Date  time.Time `json:"date"`
}

CommitAuthor represents the author or committer of a commit

type CommitFile

type CommitFile struct {
	Path      string `json:"path"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Changes   int    `json:"changes"`
	Status    string `json:"status"` // added, modified, deleted, renamed
	PrevPath  string `json:"prev_path,omitempty"`
}

CommitFile represents a file changed in a commit

type CommitOptions

type CommitOptions struct {
	Branch  string
	Since   *time.Time
	Until   *time.Time
	Author  string
	Message string
	Path    string
	Page    int
	PerPage int
}

CommitOptions represents options for retrieving commits

type CommitStats

type CommitStats struct {
	Additions int `json:"additions"`
	Deletions int `json:"deletions"`
	Total     int `json:"total"`
}

CommitStats represents statistics about a commit

type CreateFileRequest

type CreateFileRequest struct {
	Path      string       `json:"path"`
	Content   string       `json:"content"`
	Encoding  string       `json:"encoding,omitempty"` // base64 for binary files
	Message   string       `json:"message"`
	Branch    string       `json:"branch"`
	Author    CommitAuthor `json:"author"`
	Committer CommitAuthor `json:"committer,omitempty"`
}

CreateFileRequest represents a request to create a file

type DeleteFileRequest

type DeleteFileRequest struct {
	Path      string       `json:"path"`
	Message   string       `json:"message"`
	Branch    string       `json:"branch"`
	SHA       string       `json:"sha"` // Current file SHA for conflict detection
	Author    CommitAuthor `json:"author"`
	Committer CommitAuthor `json:"committer,omitempty"`
}

DeleteFileRequest represents a request to delete a file

type Diff

type Diff struct {
	FromSHA string      `json:"from_sha"`
	ToSHA   string      `json:"to_sha"`
	Files   []*DiffFile `json:"files"`
	Stats   DiffStats   `json:"stats"`
}

Diff represents differences between commits

type DiffFile

type DiffFile struct {
	Path      string `json:"path"`
	PrevPath  string `json:"prev_path,omitempty"`
	Status    string `json:"status"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Changes   int    `json:"changes"`
	Patch     string `json:"patch,omitempty"`
}

DiffFile represents a file in a diff

type DiffStats

type DiffStats struct {
	Files     int `json:"files"`
	Additions int `json:"additions"`
	Deletions int `json:"deletions"`
	Total     int `json:"total"`
}

DiffStats represents statistics about a diff

type File

type File struct {
	Name     string `json:"name"`
	Path     string `json:"path"`
	SHA      string `json:"sha"`
	Size     int64  `json:"size"`
	Type     string `json:"type"`
	Content  string `json:"content,omitempty"`
	Encoding string `json:"encoding,omitempty"`
}

File represents a file in the repository

type GitService

type GitService interface {
	// Repository operations
	InitRepository(ctx context.Context, repoPath string, bare bool) error
	CloneRepository(ctx context.Context, sourceURL, destPath string, options CloneOptions) error
	DeleteRepository(ctx context.Context, repoPath string) error

	// Commit operations
	GetCommits(ctx context.Context, repoPath string, opts CommitOptions) ([]*Commit, error)
	GetCommit(ctx context.Context, repoPath, sha string) (*Commit, error)
	GetCommitDiff(ctx context.Context, repoPath, fromSHA, toSHA string) (*Diff, error)

	// Branch operations
	GetBranches(ctx context.Context, repoPath string) ([]*Branch, error)
	GetBranch(ctx context.Context, repoPath, branchName string) (*Branch, error)
	CreateBranch(ctx context.Context, repoPath, branchName, fromRef string) error
	DeleteBranch(ctx context.Context, repoPath, branchName string) error

	// Tag operations
	GetTags(ctx context.Context, repoPath string) ([]*Tag, error)
	GetTag(ctx context.Context, repoPath, tagName string) (*Tag, error)
	CreateTag(ctx context.Context, repoPath, tagName, ref, message string) error
	DeleteTag(ctx context.Context, repoPath, tagName string) error

	// File operations
	GetTree(ctx context.Context, repoPath, ref, path string) (*Tree, error)
	GetBlob(ctx context.Context, repoPath, sha string) (*Blob, error)
	GetFile(ctx context.Context, repoPath, ref, path string) (*File, error)
	CreateFile(ctx context.Context, repoPath string, req CreateFileRequest) (*Commit, error)
	UpdateFile(ctx context.Context, repoPath string, req UpdateFileRequest) (*Commit, error)
	DeleteFile(ctx context.Context, repoPath string, req DeleteFileRequest) (*Commit, error)

	// Repository info
	GetRepositoryInfo(ctx context.Context, repoPath string) (*RepositoryInfo, error)
	GetRepositoryStats(ctx context.Context, repoPath string) (*RepositoryStats, error)

	// Pull request operations
	CompareRefs(repoPath, base, head string) (*BranchComparison, error)
	CanMerge(repoPath, base, head string) (bool, error)
	MergeBranches(repoPath, base, head string, mergeMethod, title, message string) (string, error)
	GetBranchCommit(repoPath, branch string) (string, error)
	ResolveSHA(ctx context.Context, repoPath, ref string) (string, error)
}

GitService provides Git operations for repositories

func NewGitService

func NewGitService(logger *logrus.Logger) GitService

NewGitService creates a new Git service instance

type LanguageDetector

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

LanguageDetector provides functionality to detect programming languages from file content and extensions

func NewLanguageDetector

func NewLanguageDetector() *LanguageDetector

NewLanguageDetector creates a new language detector with predefined mappings

func (*LanguageDetector) DetectLanguage

func (ld *LanguageDetector) DetectLanguage(filePath string, content []byte) string

DetectLanguage detects the programming language from a file path and optional content

type LanguageStats

type LanguageStats struct {
	Bytes      int64   `json:"bytes"`
	Percentage float64 `json:"percentage"`
}

LanguageStats represents statistics about a programming language in the repository

type RepositoryInfo

type RepositoryInfo struct {
	Path          string    `json:"path"`
	DefaultBranch string    `json:"default_branch"`
	IsBare        bool      `json:"is_bare"`
	IsEmpty       bool      `json:"is_empty"`
	LastCommit    *Commit   `json:"last_commit,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

RepositoryInfo represents basic information about a repository

type RepositoryStats

type RepositoryStats struct {
	Size         int64                    `json:"size"` // in bytes
	CommitCount  int                      `json:"commit_count"`
	BranchCount  int                      `json:"branch_count"`
	TagCount     int                      `json:"tag_count"`
	Contributors int                      `json:"contributors"`
	Languages    map[string]LanguageStats `json:"languages"`
	LastActivity time.Time                `json:"last_activity"`
}

RepositoryStats represents statistics about a repository

type Tag

type Tag struct {
	Name      string        `json:"name"`
	SHA       string        `json:"sha"`
	Message   string        `json:"message,omitempty"`
	Tagger    *CommitAuthor `json:"tagger,omitempty"`
	CreatedAt time.Time     `json:"created_at"`
}

Tag represents a Git tag

type Tree

type Tree struct {
	SHA     string       `json:"sha"`
	Path    string       `json:"path"`
	Entries []*TreeEntry `json:"entries"`
}

Tree represents a Git tree (directory)

type TreeEntry

type TreeEntry struct {
	Name string `json:"name"`
	Path string `json:"path"`
	SHA  string `json:"sha"`
	Size int64  `json:"size"`
	Type string `json:"type"` // blob, tree, commit (submodule)
	Mode string `json:"mode"`
}

TreeEntry represents an entry in a Git tree

type UpdateFileRequest

type UpdateFileRequest struct {
	Path      string       `json:"path"`
	Content   string       `json:"content"`
	Encoding  string       `json:"encoding,omitempty"`
	Message   string       `json:"message"`
	Branch    string       `json:"branch"`
	SHA       string       `json:"sha"` // Current file SHA for conflict detection
	Author    CommitAuthor `json:"author"`
	Committer CommitAuthor `json:"committer,omitempty"`
}

UpdateFileRequest represents a request to update a file

Jump to

Keyboard shortcuts

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