infrastructure

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyDerivationIterations for PBKDF2.
	KeyDerivationIterations = 100000
	// SaltSize for PBKDF2.
	SaltSize = 32
	// KeySize for AES-256.
	KeySize = 32
)
View Source
const (
	// GitHub OAuth2 client ID for device flow
	// Note: In production, this should be configured via environment variable.
	DefaultClientID = "Ov23liJUZYB3K5BO6JGP"
)
View Source
const SyncStateDir = ".nexs-sync"

SyncStateDir is the directory where sync state is stored.

View Source
const SyncStateFile = "state.json"

SyncStateFile is the filename for the sync state.

Variables

This section is empty.

Functions

func BuildPRTemplate added in v0.8.0

func BuildPRTemplate(metadata map[string]interface{}) string

BuildPRTemplate builds a PR description from collection metadata.

func CalculateFileChecksum added in v1.0.1

func CalculateFileChecksum(filePath string) (string, error)

CalculateFileChecksum computes SHA256 checksum of a file.

func CompareChecksums added in v1.0.1

func CompareChecksums(checksum1, checksum2 string) bool

CompareChecksums compares two checksums.

func ParseRepoURL

func ParseRepoURL(url string) (owner, repo string, err error)

ParseRepoURL parses a GitHub repository URL into owner and repo name.

Types

type CloneOptions added in v0.8.0

type CloneOptions struct {
	URL       string // Repository URL
	Directory string // Local directory to clone into
	Branch    string // Optional: specific branch to clone
	Depth     int    // Optional: shallow clone depth (0 = full clone)
}

CloneOptions holds options for cloning.

type CommitInfo

type CommitInfo struct {
	SHA     string
	Message string
	Author  string
	Date    string
}

CommitInfo represents information about a commit.

type CommitOptions added in v0.8.0

type CommitOptions struct {
	RepoPath     string   // Local repository path
	Files        []string // Files to add (relative to repo root)
	Message      string   // Commit message
	AuthorName   string   // Author name
	AuthorEmail  string   // Author email
	Branch       string   // Branch to commit to (creates if doesn't exist)
	CreateBranch bool     // Create new branch from current HEAD
}

CommitOptions holds options for committing changes.

type ConflictDetector added in v1.0.1

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

ConflictDetector detects and resolves sync conflicts.

func NewConflictDetector added in v1.0.1

func NewConflictDetector(strategy ConflictResolutionStrategy) *ConflictDetector

NewConflictDetector creates a new conflict detector.

func (*ConflictDetector) DetectConflicts added in v1.0.1

func (cd *ConflictDetector) DetectConflicts(
	localElements map[string]domain.Element,
	remoteElements map[string]domain.Element,
	lastSyncTime time.Time,
) ([]SyncConflict, error)

DetectConflicts compares local and remote elements to find conflicts.

func (*ConflictDetector) ResolveConflict added in v1.0.1

func (cd *ConflictDetector) ResolveConflict(
	conflict SyncConflict,
	localElem, remoteElem domain.Element,
) (domain.Element, ConflictResolutionStrategy, error)

ResolveConflict resolves a single conflict based on the configured strategy.

type ConflictResolutionStrategy added in v1.0.1

type ConflictResolutionStrategy string

ConflictResolutionStrategy defines how to handle sync conflicts.

const (
	// LocalWins keeps the local version in case of conflict.
	LocalWins ConflictResolutionStrategy = "local-wins"
	// RemoteWins keeps the remote version in case of conflict.
	RemoteWins ConflictResolutionStrategy = "remote-wins"
	// Manual requires manual resolution of conflicts.
	Manual ConflictResolutionStrategy = "manual"
	// NewestWins keeps the version with the most recent timestamp.
	NewestWins ConflictResolutionStrategy = "newest-wins"
	// MergeContent attempts to merge non-conflicting changes.
	MergeContent ConflictResolutionStrategy = "merge-content"
)

type ConflictType added in v1.0.1

type ConflictType string

ConflictType categorizes the type of conflict.

const (
	// ModifyModify both local and remote were modified.
	ModifyModify ConflictType = "modify-modify"
	// DeleteModify local deleted, remote modified.
	DeleteModify ConflictType = "delete-modify"
	// ModifyDelete local modified, remote deleted.
	ModifyDelete ConflictType = "modify-delete"
	// DeleteDelete both deleted (not a real conflict).
	DeleteDelete ConflictType = "delete-delete"
)

type DeviceFlowResponse

type DeviceFlowResponse 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"`
}

DeviceFlowResponse represents the response from GitHub device flow initiation.

type EnhancedFileElementRepository

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

EnhancedFileElementRepository extends FileElementRepository with advanced features.

func NewEnhancedFileElementRepository

func NewEnhancedFileElementRepository(baseDir string, cacheSize int) (*EnhancedFileElementRepository, error)

NewEnhancedFileElementRepository creates a new enhanced file-based repository.

func (*EnhancedFileElementRepository) Backup

func (r *EnhancedFileElementRepository) Backup(backupDir string) error

Backup creates a backup of the repository.

func (*EnhancedFileElementRepository) ConvertToTypedElement

func (r *EnhancedFileElementRepository) ConvertToTypedElement(stored *StoredElement) (domain.Element, error)

ConvertToTypedElement converts StoredElement to proper typed element (public wrapper).

func (*EnhancedFileElementRepository) Create

Create creates a new element with atomic write.

func (*EnhancedFileElementRepository) Delete

Delete removes an element by ID.

func (*EnhancedFileElementRepository) Exists

Exists checks if an element exists.

func (*EnhancedFileElementRepository) GetByID

GetByID retrieves an element by ID using LRU cache.

func (*EnhancedFileElementRepository) List

List returns all elements matching the filter criteria.

func (*EnhancedFileElementRepository) MarshalElement

func (r *EnhancedFileElementRepository) MarshalElement(stored *StoredElement) ([]byte, error)

MarshalElement marshals a StoredElement to YAML bytes.

func (*EnhancedFileElementRepository) Restore

func (r *EnhancedFileElementRepository) Restore(backupPath string) error

Restore restores the repository from a backup.

func (*EnhancedFileElementRepository) Search

Search performs full-text search on elements.

func (*EnhancedFileElementRepository) UnmarshalElement

func (r *EnhancedFileElementRepository) UnmarshalElement(data []byte) (*StoredElement, error)

UnmarshalElement unmarshals YAML bytes to a StoredElement.

func (*EnhancedFileElementRepository) Update

Update updates an existing element with atomic write.

type FileContent

type FileContent struct {
	Path    string
	Content string
	SHA     string
	Size    int
}

FileContent represents a file in a GitHub repository.

type FileElementRepository

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

FileElementRepository implements domain.ElementRepository using file-based storage with YAML.

func NewFileElementRepository

func NewFileElementRepository(baseDir string) (*FileElementRepository, error)

NewFileElementRepository creates a new file-based repository.

func (*FileElementRepository) Create

func (r *FileElementRepository) Create(element domain.Element) error

Create creates a new element.

func (*FileElementRepository) Delete

func (r *FileElementRepository) Delete(id string) error

Delete removes an element by ID.

func (*FileElementRepository) Exists

func (r *FileElementRepository) Exists(id string) (bool, error)

Exists checks if an element exists.

func (*FileElementRepository) GetByID

func (r *FileElementRepository) GetByID(id string) (domain.Element, error)

GetByID retrieves an element by ID.

func (*FileElementRepository) List

List returns all elements matching the filter criteria.

func (*FileElementRepository) SetAdaptiveCache added in v1.4.0

func (r *FileElementRepository) SetAdaptiveCache(cache domain.CacheService)

SetAdaptiveCache sets the adaptive cache for this repository.

func (*FileElementRepository) Update

func (r *FileElementRepository) Update(element domain.Element) error

Update updates an existing element.

type FileState added in v1.0.1

type FileState struct {
	FilePath     string    `json:"file_path"`
	Checksum     string    `json:"checksum"`
	LastSyncedAt time.Time `json:"last_synced_at"`
	SyncStatus   string    `json:"sync_status"` // "synced", "modified", "conflicted", "pending"
	ElementID    string    `json:"element_id"`
	ElementType  string    `json:"element_type"`
}

FileState represents the sync state of a single file.

type ForkRepositoryOptions added in v0.8.0

type ForkRepositoryOptions struct {
	Owner        string // Original repo owner
	Repo         string // Original repo name
	Organization string // Optional: fork to organization instead of user
}

ForkRepositoryOptions holds options for forking.

type GitHubClient

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

GitHubClient wraps the GitHub API client with high-level operations.

func NewGitHubClient

func NewGitHubClient(oauthClient *GitHubOAuthClient) *GitHubClient

NewGitHubClient creates a new GitHub API client.

func (*GitHubClient) CreateBranch added in v1.0.0

func (c *GitHubClient) CreateBranch(ctx context.Context, owner, repo, newBranch, baseBranch string) error

CreateBranch creates a new branch from a base branch.

func (*GitHubClient) CreateFile

func (c *GitHubClient) CreateFile(ctx context.Context, owner, repo, path, message, content, branch string) (*CommitInfo, error)

CreateFile creates a new file in a GitHub repository.

func (*GitHubClient) CreatePullRequest added in v1.0.0

func (c *GitHubClient) CreatePullRequest(ctx context.Context, owner, repo, title, body, head, base string) (*PullRequest, error)

CreatePullRequest creates a pull request.

func (*GitHubClient) CreateRepository

func (c *GitHubClient) CreateRepository(ctx context.Context, name, description string, private bool) (*Repository, error)

CreateRepository creates a new repository for the authenticated user.

func (*GitHubClient) DeleteFile

func (c *GitHubClient) DeleteFile(ctx context.Context, owner, repo, path, message, sha, branch string) error

DeleteFile deletes a file from a GitHub repository.

func (*GitHubClient) ForkRepository added in v1.0.0

func (c *GitHubClient) ForkRepository(ctx context.Context, owner, repo string) (*Repository, error)

ForkRepository forks a repository to the authenticated user's account.

func (*GitHubClient) GetFile

func (c *GitHubClient) GetFile(ctx context.Context, owner, repo, path, branch string) (*FileContent, error)

GetFile retrieves a file from a GitHub repository.

func (*GitHubClient) GetUser

func (c *GitHubClient) GetUser(ctx context.Context) (string, error)

GetUser returns the authenticated user's information.

func (*GitHubClient) ListAllFiles

func (c *GitHubClient) ListAllFiles(ctx context.Context, owner, repo, branch string) ([]string, error)

ListAllFiles recursively lists all files in a repository tree.

func (*GitHubClient) ListFilesInDirectory

func (c *GitHubClient) ListFilesInDirectory(ctx context.Context, owner, repo, path, branch string) ([]string, error)

ListFilesInDirectory lists all files in a directory (non-recursive).

func (*GitHubClient) ListRepositories

func (c *GitHubClient) ListRepositories(ctx context.Context) ([]*Repository, error)

ListRepositories lists all repositories for the authenticated user.

func (*GitHubClient) SearchRepositories added in v1.1.0

func (c *GitHubClient) SearchRepositories(ctx context.Context, query string, options *SearchOptions) (*SearchResult, error)

SearchRepositories searches for repositories using GitHub's search API.

func (*GitHubClient) UpdateFile

func (c *GitHubClient) UpdateFile(ctx context.Context, owner, repo, path, message, content, sha, branch string) (*CommitInfo, error)

UpdateFile updates an existing file in a GitHub repository.

type GitHubClientInterface

type GitHubClientInterface interface {
	ListRepositories(ctx context.Context) ([]*Repository, error)
	SearchRepositories(ctx context.Context, query string, options *SearchOptions) (*SearchResult, error)
	GetFile(ctx context.Context, owner, repo, path, branch string) (*FileContent, error)
	CreateFile(ctx context.Context, owner, repo, path, message, content, branch string) (*CommitInfo, error)
	UpdateFile(ctx context.Context, owner, repo, path, message, content, sha, branch string) (*CommitInfo, error)
	DeleteFile(ctx context.Context, owner, repo, path, message, sha, branch string) error
	ListFilesInDirectory(ctx context.Context, owner, repo, path, branch string) ([]string, error)
	ListAllFiles(ctx context.Context, owner, repo, branch string) ([]string, error)
	GetUser(ctx context.Context) (string, error)
	CreateRepository(ctx context.Context, name, description string, private bool) (*Repository, error)
}

GitHubClientInterface defines the interface for GitHub operations.

type GitHubOAuthClient

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

GitHubOAuthClient handles GitHub OAuth2 authentication using device flow.

func NewGitHubOAuthClient

func NewGitHubOAuthClient(tokenPath string) (*GitHubOAuthClient, error)

NewGitHubOAuthClient creates a new GitHub OAuth client.

func (*GitHubOAuthClient) ClearToken

func (c *GitHubOAuthClient) ClearToken() error

ClearToken removes the stored token.

func (*GitHubOAuthClient) GetToken

func (c *GitHubOAuthClient) GetToken(ctx context.Context) (*oauth2.Token, error)

GetToken returns the current token, loading from disk if needed.

func (*GitHubOAuthClient) IsAuthenticated

func (c *GitHubOAuthClient) IsAuthenticated(ctx context.Context) bool

IsAuthenticated checks if there's a valid token available.

func (*GitHubOAuthClient) LoadToken

func (c *GitHubOAuthClient) LoadToken() (*oauth2.Token, error)

LoadToken loads and decrypts the OAuth2 token from disk.

func (*GitHubOAuthClient) PollForToken

func (c *GitHubOAuthClient) PollForToken(ctx context.Context, deviceCode string, interval int) (*oauth2.Token, error)

PollForToken polls GitHub for the OAuth2 token after user authorization.

func (*GitHubOAuthClient) SaveToken

func (c *GitHubOAuthClient) SaveToken(token *oauth2.Token) error

SaveToken saves the OAuth2 token to disk with encryption.

func (*GitHubOAuthClient) StartDeviceFlow

func (c *GitHubOAuthClient) StartDeviceFlow(ctx context.Context) (*DeviceFlowResponse, error)

StartDeviceFlow initiates the GitHub OAuth2 device flow.

type GitHubPublisher added in v0.8.0

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

GitHubPublisher handles GitHub operations for collection publishing.

func NewGitHubPublisher added in v0.8.0

func NewGitHubPublisher(token string) *GitHubPublisher

NewGitHubPublisher creates a new GitHub publisher.

func (*GitHubPublisher) CloneRepository added in v0.8.0

func (p *GitHubPublisher) CloneRepository(opts *CloneOptions) error

CloneRepository clones a repository locally.

func (*GitHubPublisher) CommitChanges added in v0.8.0

func (p *GitHubPublisher) CommitChanges(opts *CommitOptions) error

CommitChanges commits changes to a local repository.

func (*GitHubPublisher) CreatePullRequest added in v0.8.0

func (p *GitHubPublisher) CreatePullRequest(opts *PullRequestOptions) (*github.PullRequest, error)

CreatePullRequest creates a pull request.

func (*GitHubPublisher) CreateRelease added in v0.8.0

func (p *GitHubPublisher) CreateRelease(opts *ReleaseOptions) (*github.RepositoryRelease, error)

CreateRelease creates a GitHub release.

func (*GitHubPublisher) ForkRepository added in v0.8.0

func (p *GitHubPublisher) ForkRepository(opts *ForkRepositoryOptions) (*github.Repository, error)

ForkRepository forks a repository.

func (*GitHubPublisher) GetAuthenticatedUser added in v0.8.0

func (p *GitHubPublisher) GetAuthenticatedUser() (*github.User, error)

GetAuthenticatedUser returns the currently authenticated user.

func (*GitHubPublisher) GetForkHTTPSURL added in v0.8.0

func (p *GitHubPublisher) GetForkHTTPSURL(owner, repo, username string) string

GetForkHTTPSURL returns the HTTPS clone URL with token embedded.

func (*GitHubPublisher) GetForkURL added in v0.8.0

func (p *GitHubPublisher) GetForkURL(owner, repo, username string) string

GetForkURL returns the fork URL for a repository.

func (*GitHubPublisher) PushChanges added in v0.8.0

func (p *GitHubPublisher) PushChanges(opts *PushOptions) error

PushChanges pushes changes to remote repository.

type InMemoryElementRepository

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

InMemoryElementRepository implements ElementRepository using in-memory storage.

func NewInMemoryElementRepository

func NewInMemoryElementRepository() *InMemoryElementRepository

NewInMemoryElementRepository creates a new in-memory repository.

func (*InMemoryElementRepository) Clear

func (r *InMemoryElementRepository) Clear()

Clear removes all elements (useful for testing).

func (*InMemoryElementRepository) Count

func (r *InMemoryElementRepository) Count() int

Count returns the total number of elements.

func (*InMemoryElementRepository) Create

func (r *InMemoryElementRepository) Create(element domain.Element) error

Create creates a new element.

func (*InMemoryElementRepository) Delete

func (r *InMemoryElementRepository) Delete(id string) error

Delete deletes an element by its ID.

func (*InMemoryElementRepository) Exists

func (r *InMemoryElementRepository) Exists(id string) (bool, error)

Exists checks if an element exists.

func (*InMemoryElementRepository) GetByID

GetByID retrieves an element by its ID.

func (*InMemoryElementRepository) List

List lists all elements with optional filtering.

func (*InMemoryElementRepository) Update

func (r *InMemoryElementRepository) Update(element domain.Element) error

Update updates an existing element.

type IncrementalSync added in v1.0.1

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

IncrementalSync manages incremental synchronization with conflict detection.

func NewIncrementalSync added in v1.0.1

func NewIncrementalSync(
	baseDir string,
	repository *EnhancedFileElementRepository,
) *IncrementalSync

NewIncrementalSync creates a new incremental sync manager.

func (*IncrementalSync) ClearSyncState added in v1.0.1

func (is *IncrementalSync) ClearSyncState() error

ClearSyncState clears all sync metadata.

func (*IncrementalSync) DetectConflicts added in v1.0.1

func (is *IncrementalSync) DetectConflicts(
	localElements map[string]domain.Element,
	remoteElements map[string]domain.Element,
) ([]SyncConflict, error)

DetectConflicts checks for conflicts between local and remote elements.

func (*IncrementalSync) GetChangedFiles added in v1.0.1

func (is *IncrementalSync) GetChangedFiles(state *SyncState) ([]string, error)

GetChangedFiles returns files that have changed since last sync.

func (*IncrementalSync) GetSyncState added in v1.0.1

func (is *IncrementalSync) GetSyncState() (*SyncState, error)

GetSyncState returns the current sync state.

func (*IncrementalSync) ResolveConflicts added in v1.0.1

func (is *IncrementalSync) ResolveConflicts(
	conflicts []SyncConflict,
	localElements, remoteElements map[string]domain.Element,
	strategy ConflictResolutionStrategy,
) (map[string]domain.Element, error)

ResolveConflicts resolves conflicts using the specified strategy.

func (*IncrementalSync) SyncLocal added in v1.0.1

func (is *IncrementalSync) SyncLocal(
	ctx context.Context,
	remoteURL, remoteBranch string,
	options SyncOptions,
) (*SyncReport, error)

SyncLocal performs incremental sync of local files.

type LRUCache

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

LRUCache implements a simple Least Recently Used cache.

func NewLRUCache

func NewLRUCache(capacity int) *LRUCache

NewLRUCache creates a new LRU cache with given capacity.

func (*LRUCache) Clear

func (lru *LRUCache) Clear()

Clear removes all entries from the cache.

func (*LRUCache) Delete

func (lru *LRUCache) Delete(key string)

Delete removes a value from the cache.

func (*LRUCache) Get

func (lru *LRUCache) Get(key string) (*StoredElement, bool)

Get retrieves a value from the cache.

func (*LRUCache) Put

func (lru *LRUCache) Put(key string, value *StoredElement)

Put adds or updates a value in the cache.

type PRHistory added in v1.0.1

type PRHistory struct {
	Version     string                  `json:"version"`
	Submissions map[string]PRSubmission `json:"submissions"` // key is PR ID
	Stats       PRStats                 `json:"stats"`
	LastUpdated time.Time               `json:"last_updated"`
}

PRHistory contains all PR submissions.

type PRStats added in v1.0.1

type PRStats struct {
	TotalSubmissions int `json:"total_submissions"`
	Pending          int `json:"pending"`
	Merged           int `json:"merged"`
	Rejected         int `json:"rejected"`
	Draft            int `json:"draft"`
}

PRStats contains statistics about PR submissions.

type PRStatus added in v1.0.1

type PRStatus string

PRStatus represents the status of a pull request.

const (
	// PRStatusPending indicates PR is awaiting review.
	PRStatusPending PRStatus = "pending"
	// PRStatusMerged indicates PR has been merged.
	PRStatusMerged PRStatus = "merged"
	// PRStatusRejected indicates PR was rejected/closed.
	PRStatusRejected PRStatus = "rejected"
	// PRStatusDraft indicates PR is a draft.
	PRStatusDraft PRStatus = "draft"
)

type PRSubmission added in v1.0.1

type PRSubmission struct {
	ID              string                 `json:"id"` // Unique submission ID
	ElementID       string                 `json:"element_id"`
	ElementType     domain.ElementType     `json:"element_type"`
	ElementName     string                 `json:"element_name"`
	ElementVersion  string                 `json:"element_version"`
	RepositoryOwner string                 `json:"repository_owner"`
	RepositoryName  string                 `json:"repository_name"`
	PRNumber        int                    `json:"pr_number"`
	PRTitle         string                 `json:"pr_title"`
	PRURL           string                 `json:"pr_url"`
	Status          PRStatus               `json:"status"`
	SubmittedAt     time.Time              `json:"submitted_at"`
	UpdatedAt       time.Time              `json:"updated_at"`
	MergedAt        *time.Time             `json:"merged_at,omitempty"`
	ClosedAt        *time.Time             `json:"closed_at,omitempty"`
	SubmittedBy     string                 `json:"submitted_by"`
	ReviewComments  int                    `json:"review_comments"`
	Notes           string                 `json:"notes,omitempty"`
	Metadata        map[string]interface{} `json:"metadata,omitempty"`
}

PRSubmission represents a single PR submission.

type PRTracker added in v1.0.1

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

PRTracker tracks pull request submissions.

func NewPRTracker added in v1.0.1

func NewPRTracker(configDir string) *PRTracker

NewPRTracker creates a new PR tracker.

func (*PRTracker) AddReviewComment added in v1.0.1

func (t *PRTracker) AddReviewComment(prID string) error

AddReviewComment increments the review comment count for a submission.

func (*PRTracker) Clear added in v1.0.1

func (t *PRTracker) Clear() error

Clear clears all PR history.

func (*PRTracker) DeleteSubmission added in v1.0.1

func (t *PRTracker) DeleteSubmission(prID string) error

DeleteSubmission removes a submission from history.

func (*PRTracker) GetHistoryFile added in v1.0.1

func (t *PRTracker) GetHistoryFile() string

GetHistoryFile returns the path to the history file.

func (*PRTracker) GetRecentSubmissions added in v1.0.1

func (t *PRTracker) GetRecentSubmissions(limit int) ([]PRSubmission, error)

GetRecentSubmissions retrieves the N most recent submissions.

func (*PRTracker) GetStats added in v1.0.1

func (t *PRTracker) GetStats() (*PRStats, error)

GetStats returns current PR statistics.

func (*PRTracker) GetSubmissionByPRNumber added in v1.0.1

func (t *PRTracker) GetSubmissionByPRNumber(owner, repo string, prNumber int) (*PRSubmission, error)

GetSubmissionByPRNumber retrieves a submission by PR number.

func (*PRTracker) GetSubmissionsByElement added in v1.0.1

func (t *PRTracker) GetSubmissionsByElement(elementID string) ([]PRSubmission, error)

GetSubmissionsByElement retrieves all submissions for a specific element.

func (*PRTracker) GetSubmissionsByStatus added in v1.0.1

func (t *PRTracker) GetSubmissionsByStatus(status PRStatus) ([]PRSubmission, error)

GetSubmissionsByStatus retrieves all submissions with a specific status.

func (*PRTracker) LoadHistory added in v1.0.1

func (t *PRTracker) LoadHistory() (*PRHistory, error)

LoadHistory loads PR history from disk.

func (*PRTracker) SaveHistory added in v1.0.1

func (t *PRTracker) SaveHistory(history *PRHistory) error

SaveHistory saves PR history to disk.

func (*PRTracker) TrackSubmission added in v1.0.1

func (t *PRTracker) TrackSubmission(submission PRSubmission) error

TrackSubmission adds a new PR submission to history.

func (*PRTracker) UpdateNotes added in v1.0.1

func (t *PRTracker) UpdateNotes(prID string, notes string) error

UpdateNotes updates the notes for a submission.

func (*PRTracker) UpdateSubmissionStatus added in v1.0.1

func (t *PRTracker) UpdateSubmissionStatus(prID string, status PRStatus) error

UpdateSubmissionStatus updates the status of a PR submission.

type PullRequest added in v1.0.0

type PullRequest struct {
	Number int
	Title  string
	Body   string
	State  string
	URL    string
	Head   string
	Base   string
}

PullRequest represents a GitHub pull request.

type PullRequestOptions added in v0.8.0

type PullRequestOptions struct {
	Owner       string // Repository owner
	Repo        string // Repository name
	Title       string // PR title
	Body        string // PR description
	Head        string // Head branch (user:branch or org:branch)
	Base        string // Base branch (usually "main" or "master")
	Draft       bool   // Create as draft PR
	Maintainers bool   // Allow maintainers to edit
}

PullRequestOptions holds options for creating a pull request.

type PushOptions added in v0.8.0

type PushOptions struct {
	RepoPath string // Local repository path
	Remote   string // Remote name (default: "origin")
	Branch   string // Branch to push
	Force    bool   // Force push
}

PushOptions holds options for pushing.

type ReleaseOptions added in v0.8.0

type ReleaseOptions struct {
	Owner      string   // Repository owner
	Repo       string   // Repository name
	Tag        string   // Release tag
	Name       string   // Release name
	Body       string   // Release description
	Draft      bool     // Create as draft
	Prerelease bool     // Mark as prerelease
	Assets     []string // File paths to upload as assets
}

ReleaseOptions holds options for creating a release.

type Repository

type Repository struct {
	Owner         string
	Name          string
	FullName      string
	Description   string
	Private       bool
	URL           string
	DefaultBranch string
	Stars         int
	UpdatedAt     string
}

Repository represents a GitHub repository.

type SearchIndex

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

SearchIndex maintains an inverted index for full-text search.

func NewSearchIndex

func NewSearchIndex() *SearchIndex

NewSearchIndex creates a new search index.

func (*SearchIndex) Index

func (si *SearchIndex) Index(element domain.Element)

Index adds an element to the search index.

func (*SearchIndex) Remove

func (si *SearchIndex) Remove(elementID string)

Remove removes an element from the search index.

func (*SearchIndex) Search

func (si *SearchIndex) Search(query string) []string

Search performs a full-text search and returns matching element IDs.

type SearchOptions added in v1.1.0

type SearchOptions struct {
	SortBy          string // stars, updated, created, relevance
	IncludeArchived bool
	Limit           int
}

SearchOptions represents options for repository search.

type SearchResult added in v1.1.0

type SearchResult struct {
	Repositories []*Repository
	TotalCount   int
}

SearchResult represents search results.

type SimpleElement

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

SimpleElement is a basic implementation of Element for file operations.

func (*SimpleElement) Activate

func (s *SimpleElement) Activate() error

func (*SimpleElement) Deactivate

func (s *SimpleElement) Deactivate() error

func (*SimpleElement) GetID

func (s *SimpleElement) GetID() string

func (*SimpleElement) GetMetadata

func (s *SimpleElement) GetMetadata() domain.ElementMetadata

func (*SimpleElement) GetType

func (s *SimpleElement) GetType() domain.ElementType

func (*SimpleElement) IsActive

func (s *SimpleElement) IsActive() bool

func (*SimpleElement) Validate

func (s *SimpleElement) Validate() error

type StoredElement

type StoredElement struct {
	Metadata domain.ElementMetadata `yaml:"metadata"`
	// Type-specific data stored as raw YAML to preserve all fields
	Data map[string]interface{} `yaml:"data,omitempty"`
}

StoredElement represents an element as stored in YAML files.

type SyncConflict added in v1.0.1

type SyncConflict struct {
	ElementID       string                     `json:"element_id"`
	FilePath        string                     `json:"file_path"`
	ConflictType    ConflictType               `json:"conflict_type"`
	LocalVersion    *domain.ElementMetadata    `json:"local_version"`
	RemoteVersion   *domain.ElementMetadata    `json:"remote_version"`
	LocalChecksum   string                     `json:"local_checksum"`
	RemoteChecksum  string                     `json:"remote_checksum"`
	DetectedAt      time.Time                  `json:"detected_at"`
	Resolution      ConflictResolutionStrategy `json:"resolution,omitempty"`
	ResolvedAt      *time.Time                 `json:"resolved_at,omitempty"`
	ResolvedBy      string                     `json:"resolved_by,omitempty"`
	ResolutionNotes string                     `json:"resolution_notes,omitempty"`
}

SyncConflict represents a conflict between local and remote versions.

func (*SyncConflict) GetConflictSummary added in v1.0.1

func (c *SyncConflict) GetConflictSummary() string

GetConflictSummary returns a human-readable summary of the conflict.

func (*SyncConflict) IsResolved added in v1.0.1

func (c *SyncConflict) IsResolved() bool

IsResolved returns true if the conflict has been resolved.

func (*SyncConflict) MarkResolved added in v1.0.1

func (c *SyncConflict) MarkResolved(strategy ConflictResolutionStrategy, resolvedBy, notes string)

MarkResolved marks the conflict as resolved.

type SyncDirection added in v1.0.1

type SyncDirection string

SyncDirection indicates the direction of synchronization.

const (
	// SyncDirectionPush syncs from local to remote.
	SyncDirectionPush SyncDirection = "push"
	// SyncDirectionPull syncs from remote to local.
	SyncDirectionPull SyncDirection = "pull"
	// SyncDirectionBidirectional syncs in both directions.
	SyncDirectionBidirectional SyncDirection = "bidirectional"
)

type SyncHistory added in v1.0.1

type SyncHistory struct {
	Timestamp    time.Time         `json:"timestamp"`
	Direction    string            `json:"direction"` // "push", "pull"
	FilesChanged int               `json:"files_changed"`
	Status       string            `json:"status"` // "success", "partial", "failed"
	Error        string            `json:"error,omitempty"`
	Details      map[string]string `json:"details,omitempty"`
}

SyncHistory represents a single sync operation.

type SyncMetadataManager added in v1.0.1

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

SyncMetadataManager manages sync metadata persistence.

func NewSyncMetadataManager added in v1.0.1

func NewSyncMetadataManager(baseDir string) *SyncMetadataManager

NewSyncMetadataManager creates a new sync metadata manager.

func (*SyncMetadataManager) AddConflict added in v1.0.1

func (m *SyncMetadataManager) AddConflict(state *SyncState, conflict SyncConflict)

AddConflict adds a conflict to the state.

func (*SyncMetadataManager) AddHistory added in v1.0.1

func (m *SyncMetadataManager) AddHistory(state *SyncState, history SyncHistory)

AddHistory adds a sync operation to the history.

func (*SyncMetadataManager) Clear added in v1.0.1

func (m *SyncMetadataManager) Clear() error

Clear clears all sync state.

func (*SyncMetadataManager) GetConflictedFiles added in v1.0.1

func (m *SyncMetadataManager) GetConflictedFiles(state *SyncState) []string

GetConflictedFiles returns all files that have conflicts.

func (*SyncMetadataManager) GetFileState added in v1.0.1

func (m *SyncMetadataManager) GetFileState(state *SyncState, filePath string) (FileState, bool)

GetFileState returns the state of a specific file.

func (*SyncMetadataManager) GetModifiedFiles added in v1.0.1

func (m *SyncMetadataManager) GetModifiedFiles(state *SyncState) []string

GetModifiedFiles returns all files that have been modified since last sync.

func (*SyncMetadataManager) GetStatePath added in v1.0.1

func (m *SyncMetadataManager) GetStatePath() string

GetStatePath returns the path to the sync state file.

func (*SyncMetadataManager) GetSyncDir added in v1.0.1

func (m *SyncMetadataManager) GetSyncDir() string

GetSyncDir returns the path to the sync directory.

func (*SyncMetadataManager) GetTrackedFilesCount added in v1.0.1

func (m *SyncMetadataManager) GetTrackedFilesCount(state *SyncState) int

GetTrackedFilesCount returns the number of tracked files.

func (*SyncMetadataManager) GetUnresolvedConflicts added in v1.0.1

func (m *SyncMetadataManager) GetUnresolvedConflicts(state *SyncState) []SyncConflict

GetUnresolvedConflicts returns all unresolved conflicts.

func (*SyncMetadataManager) IsFileTracked added in v1.0.1

func (m *SyncMetadataManager) IsFileTracked(state *SyncState, filePath string) bool

IsFileTracked checks if a file is tracked in the sync state.

func (*SyncMetadataManager) LoadState added in v1.0.1

func (m *SyncMetadataManager) LoadState() (*SyncState, error)

LoadState loads the sync state from disk.

func (*SyncMetadataManager) MarkFileConflicted added in v1.0.1

func (m *SyncMetadataManager) MarkFileConflicted(state *SyncState, filePath string) error

MarkFileConflicted marks a file as conflicted in the sync state.

func (*SyncMetadataManager) MarkFileModified added in v1.0.1

func (m *SyncMetadataManager) MarkFileModified(state *SyncState, filePath string) error

MarkFileModified marks a file as modified in the sync state.

func (*SyncMetadataManager) ResolveConflict added in v1.0.1

func (m *SyncMetadataManager) ResolveConflict(state *SyncState, elementID string)

ResolveConflict removes a conflict from the state.

func (*SyncMetadataManager) SaveState added in v1.0.1

func (m *SyncMetadataManager) SaveState(state *SyncState) error

SaveState saves the sync state to disk.

func (*SyncMetadataManager) TrackFile added in v1.0.1

func (m *SyncMetadataManager) TrackFile(state *SyncState, filePath, checksum, elementID, elementType string) error

TrackFile adds or updates a file in the sync state.

func (*SyncMetadataManager) UntrackFile added in v1.0.1

func (m *SyncMetadataManager) UntrackFile(state *SyncState, filePath string) error

UntrackFile removes a file from the sync state.

func (*SyncMetadataManager) UpdateLastSync added in v1.0.1

func (m *SyncMetadataManager) UpdateLastSync(state *SyncState)

UpdateLastSync updates the last sync timestamp.

type SyncOptions added in v1.0.1

type SyncOptions struct {
	Direction            SyncDirection
	ConflictStrategy     ConflictResolutionStrategy
	DryRun               bool
	ProgressCallback     SyncProgressCallback
	IncludeTypes         []domain.ElementType // If empty, sync all types
	ExcludeTypes         []domain.ElementType
	ForceFullSync        bool // If true, ignore metadata and sync everything
	AutoResolveConflicts bool // If true, automatically resolve using strategy
}

SyncOptions contains options for incremental sync.

type SyncProgressCallback added in v1.0.1

type SyncProgressCallback func(message string, current, total int)

SyncProgressCallback is called during sync to report progress.

type SyncReport added in v1.0.1

type SyncReport struct {
	Direction         SyncDirection
	FilesScanned      int
	FilesChanged      int
	FilesAdded        int
	FilesDeleted      int
	FilesSkipped      int
	ConflictsFound    int
	ConflictsResolved int
	Errors            []string
	Conflicts         []SyncConflict
	StartTime         string
	EndTime           string
	Duration          string
}

SyncReport contains the results of a sync operation.

type SyncState added in v1.0.1

type SyncState struct {
	Version      string                 `json:"version"`
	LastSyncAt   time.Time              `json:"last_sync_at"`
	RemoteURL    string                 `json:"remote_url"`
	RemoteBranch string                 `json:"remote_branch"`
	Files        map[string]FileState   `json:"files"` // key is file path
	History      []SyncHistory          `json:"history"`
	Conflicts    []SyncConflict         `json:"conflicts,omitempty"`
	Metadata     map[string]interface{} `json:"metadata,omitempty"`
}

SyncState represents the complete sync state for a repository.

func NewSyncState added in v1.0.1

func NewSyncState(remoteURL, remoteBranch string) *SyncState

NewSyncState creates a new SyncState.

type TokenEncryptor added in v1.0.0

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

TokenEncryptor handles encryption and decryption of OAuth tokens.

func NewTokenEncryptor added in v1.0.0

func NewTokenEncryptor() (*TokenEncryptor, error)

NewTokenEncryptor creates a new token encryptor The encryption key is derived from machine ID and user's home directory This provides reasonable security without requiring user to manage passwords.

func (*TokenEncryptor) Decrypt added in v1.0.0

func (e *TokenEncryptor) Decrypt(ciphertext string) ([]byte, error)

Decrypt decrypts data using AES-256-GCM.

func (*TokenEncryptor) Encrypt added in v1.0.0

func (e *TokenEncryptor) Encrypt(plaintext []byte) (string, error)

Encrypt encrypts data using AES-256-GCM.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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