git

package
v0.0.0-...-6aa0b0e Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package git provides git operations for the data entry app.

Package git provides git operations for the data entry app.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthorizationPending = errors.New("authorization pending")
	ErrSlowDown             = errors.New("slow down")
	ErrExpiredToken         = errors.New("device code expired")
	ErrAccessDenied         = errors.New("access denied by user")
)

Common OAuth errors.

View Source
var ErrConflictInProgress = errors.New("merge conflict in progress, resolve before syncing")

ErrConflictInProgress indicates a merge conflict that must be resolved first.

Functions

func Clone

func Clone(opts CloneOptions) error

Clone clones a git repository to the specified path. For private repositories, set Token from OAuth device flow.

func ExtractRepoName

func ExtractRepoName(repoURL string) string

ExtractRepoName extracts repository name from URL. e.g., "https://github.com/user/repo.git" -> "repo"

func IsRepo

func IsRepo(root string) bool

IsRepo checks if the directory is a git repository with a remote.

func IsValidRepoURL

func IsValidRepoURL(repoURL string) bool

IsValidRepoURL checks if the URL looks like a valid git repository URL.

Types

type ChangeSet

type ChangeSet struct {
	Added     []EntityChange
	Modified  []EntityChange
	Deleted   []EntityRef
	Relations []RelationChange
}

ChangeSet represents analyzed changes for commit message generation.

func (*ChangeSet) GenerateCommitMessage

func (cs *ChangeSet) GenerateCommitMessage() string

GenerateCommitMessage creates a human-readable commit message from changes.

type CloneOptions

type CloneOptions struct {
	URL      string // Repository URL (HTTPS)
	Path     string // Local path to clone into
	Branch   string // Branch to checkout (optional, defaults to default branch)
	Token    string // OAuth token for authentication (optional for public repos)
	Username string // Username for authentication (defaults to "oauth2" when token is set)
}

CloneOptions configures the clone operation.

type Config

type Config struct {
	Enabled       bool   `yaml:"enabled"`
	Mode          string `yaml:"mode"`           // "direct" or "pr"
	Branch        string `yaml:"branch"`         // for direct mode
	BaseBranch    string `yaml:"base_branch"`    // for pr mode: merge from this
	PushBranch    string `yaml:"push_branch"`    // for pr mode: push to this
	FetchInterval int    `yaml:"fetch_interval"` // seconds, 0 = disabled
	Token         string `yaml:"-"`              // OAuth token for auth (not persisted)
	Username      string `yaml:"-"`              // Username for auth (not persisted)
}

Config holds git configuration for the data entry app.

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
}

DeviceCodeResponse is returned when initiating the device flow.

type EntityChange

type EntityChange struct {
	Type         string
	ID           string
	PropsChanged []string
	BodyChanged  bool
	IsNew        bool
}

EntityChange represents a changed entity.

type EntityRef

type EntityRef struct {
	Type string
	ID   string
}

EntityRef is a reference to an entity.

type OAuth

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

OAuth provides GitHub OAuth device flow authentication.

func NewOAuth

func NewOAuth(cfg OAuthConfig) *OAuth

NewOAuth creates a new OAuth instance.

func (*OAuth) PollForToken

func (o *OAuth) PollForToken(ctx context.Context, deviceCode string) (*TokenResponse, error)

PollForToken polls GitHub until the user authorizes the device or the code expires. Returns ErrAuthorizationPending if still waiting, ErrExpiredToken if expired.

func (*OAuth) RequestDeviceCode

func (o *OAuth) RequestDeviceCode(ctx context.Context) (*DeviceCodeResponse, error)

RequestDeviceCode initiates the device flow and returns a code for the user.

func (*OAuth) WaitForAuthorization

func (o *OAuth) WaitForAuthorization(ctx context.Context, deviceCode string, interval int) (*TokenResponse, error)

WaitForAuthorization polls until authorized or context cancelled. It respects the interval from the device code response.

type OAuthConfig

type OAuthConfig struct {
	ClientID string // GitHub OAuth App client ID
}

OAuthConfig holds GitHub OAuth configuration.

type Ops

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

Ops provides git operations for a repository.

func NewOps

func NewOps(root string, cfg Config) *Ops

NewOps creates a new git operations instance.

func (*Ops) AbortMerge

func (g *Ops) AbortMerge() error

AbortMerge aborts an in-progress merge.

func (*Ops) AnalyzeChanges

func (g *Ops) AnalyzeChanges() (*ChangeSet, error)

AnalyzeChanges examines staged/unstaged changes and returns a ChangeSet.

func (*Ops) Fetch

func (g *Ops) Fetch() error

Fetch fetches from remote.

func (*Ops) GetStatus

func (g *Ops) GetStatus() (*Status, error)

GetStatus returns the current git status.

func (*Ops) Sync

func (g *Ops) Sync(message string) error

Sync performs commit + merge + push.

type RelationChange

type RelationChange struct {
	From    string
	RelType string
	To      string
	IsNew   bool
}

RelationChange represents a changed relation.

type Status

type Status struct {
	Available     bool     // true if git repo with remote
	Branch        string   // current branch name
	LocalChanges  int      // number of uncommitted files
	RemoteAhead   int      // commits ahead on remote
	Syncing       bool     // true if sync in progress
	Conflict      bool     // true if merge conflict
	ConflictFiles []string // files with conflicts
}

Status represents the current git state.

type TokenErrorResponse

type TokenErrorResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

TokenErrorResponse is returned when polling for token fails.

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
}

TokenResponse is returned when the device is authorized.

Jump to

Keyboard shortcuts

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