model

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package model defines the data structures used throughout Clonr.

This package contains the core domain models that represent the application's data. These models are used by both the database layer and the gRPC layer, with appropriate conversions handled by each package.

Repository

The Repository struct represents a Git repository tracked by Clonr:

type Repository struct {
    UID         string    // Unique identifier (UUID)
    URL         string    // Remote repository URL
    Path        string    // Local filesystem path
    Favorite    bool      // Whether marked as favorite
    ClonedAt    time.Time // When the repository was cloned
    UpdatedAt   time.Time // Last update timestamp
    LastChecked time.Time // Last time checked for updates
}

Config

The Config struct holds application configuration:

type Config struct {
    DefaultCloneDir string // Base directory for cloning repositories
    Editor          string // Preferred editor command
    Terminal        string // Preferred terminal emulator
    MonitorInterval int    // Interval for checking updates (seconds)
    ServerPort      int    // gRPC server port
}

Index

Constants

View Source
const (
	// MinKeyRotationDays is the minimum allowed key rotation interval
	MinKeyRotationDays = 7
	// MaxKeyRotationDays is the maximum allowed key rotation interval
	MaxKeyRotationDays = 365
	// DefaultKeyRotationDays is the default key rotation interval
	DefaultKeyRotationDays = 30
)
View Source
const (
	EventClone    = "clone"
	EventPush     = "push"
	EventPull     = "pull"
	EventCommit   = "commit"
	EventPRCreate = "pr-create"
	EventPRMerge  = "pr-merge"
	EventCIPass   = "ci-pass"
	EventCIFail   = "ci-fail"
	EventRelease  = "release"
	EventSync     = "sync"
	EventError    = "error"
)

Supported event types for notifications.

View Source
const (
	PriorityLow    = "low"
	PriorityNormal = "normal"
	PriorityHigh   = "high"
)

Notification priorities.

Variables

This section is empty.

Functions

func DefaultHost

func DefaultHost() string

DefaultHost returns the default GitHub host

func DefaultScopes

func DefaultScopes() []string

DefaultScopes returns the default OAuth scopes for clonr

func DefaultWorkspaceName added in v0.3.0

func DefaultWorkspaceName() string

DefaultWorkspaceName returns the name of the default workspace

func ValidateKeyRotationDays added in v0.3.0

func ValidateKeyRotationDays(days int) int

ValidateKeyRotationDays ensures the rotation interval is within bounds. Returns the validated value (clamped to min/max if out of range).

Types

type ChannelType added in v0.3.0

type ChannelType string

ChannelType represents the type of notification channel.

const (
	ChannelSlack   ChannelType = "slack"
	ChannelTeams   ChannelType = "teams"
	ChannelDiscord ChannelType = "discord"
	ChannelEmail   ChannelType = "email"
	ChannelWebhook ChannelType = "webhook"
)

type Config

type Config struct {
	// DefaultCloneDir is the default directory where repositories will be cloned
	DefaultCloneDir string `json:"default_clone_dir"`

	// Editor is the default editor to open repositories
	Editor string `json:"editor"`

	// Terminal is the default terminal application
	Terminal string `json:"terminal"`

	// MonitorInterval is the interval in seconds for monitoring repositories
	MonitorInterval int `json:"monitor_interval"`

	// ServerPort is the port for the API server
	ServerPort int `json:"server_port"`

	// CustomEditors is a list of user-defined editors
	CustomEditors []Editor `json:"custom_editors,omitempty"`

	// KeyRotationDays is the number of days before encryption keys are auto-rotated.
	// Minimum is 7 days, maximum is 365 days. Default is 30 days.
	KeyRotationDays int `json:"key_rotation_days"`
}

Config holds the application configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults

type Editor

type Editor struct {
	// Name is the display name of the editor (e.g., "VS Code")
	Name string `json:"name"`

	// Command is the executable command (e.g., "code")
	Command string `json:"command"`

	// Icon is an optional icon for display (e.g., "󰨞")
	Icon string `json:"icon,omitempty"`
}

Editor represents a custom editor configuration.

type EventConfig added in v0.3.0

type EventConfig struct {
	// Event is the event type (push, pr-merge, ci-fail, etc.)
	Event string `json:"event"`

	// Filters are patterns to match (branch:main, repo:critical-*)
	Filters []string `json:"filters,omitempty"`

	// Target is the destination (channel name, email address, etc.)
	Target string `json:"target,omitempty"`

	// Priority is the notification priority (low, normal, high)
	Priority string `json:"priority,omitempty"`

	// Template is the custom template name to use
	Template string `json:"template,omitempty"`
}

EventConfig defines which events trigger notifications on a channel.

type NotifyChannel added in v0.3.0

type NotifyChannel struct {
	// ID is the unique identifier for this channel
	ID string `json:"id"`

	// Type is the channel type (slack, teams, discord, email, webhook)
	Type ChannelType `json:"type"`

	// Name is a user-friendly name for this channel
	Name string `json:"name"`

	// Config contains type-specific configuration (all encrypted with profile)
	// For Slack: webhook_url, bot_token, default_channel
	// For Teams: webhook_url, connector_token
	// For Discord: webhook_url, bot_token, default_channel
	// For Email: provider, host, port, username, password, api_key, from, to
	// For Webhook: url, method, headers, hmac_secret, template
	Config map[string]string `json:"config"`

	// Events contains the event configuration for this channel
	Events []EventConfig `json:"events"`

	// Enabled indicates if this channel is active
	Enabled bool `json:"enabled"`

	// CreatedAt is when the channel was created
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is when the channel was last updated
	UpdatedAt time.Time `json:"updated_at"`
}

NotifyChannel represents a notification channel attached to a profile. All sensitive data (tokens, webhooks, passwords) are encrypted with the profile.

type Profile

type Profile struct {
	// Name is the unique identifier for this profile
	Name string `json:"name"`

	// Host is the GitHub host (e.g., github.com or enterprise URL)
	Host string `json:"host"`

	// User is the authenticated GitHub username
	User string `json:"user"`

	// TokenStorage indicates how the token is stored (encrypted or open)
	TokenStorage TokenStorage `json:"token_storage"`

	// Scopes are the OAuth scopes granted to this token
	Scopes []string `json:"scopes"`

	// Default indicates if this is the default profile used when none specified
	Default bool `json:"default"`

	// EncryptedToken stores the token (with ENC: or OPEN: prefix)
	EncryptedToken []byte `json:"encrypted_token,omitempty"`

	// CreatedAt is when the profile was created
	CreatedAt time.Time `json:"created_at"`

	// LastUsedAt is when the profile was last used
	LastUsedAt time.Time `json:"last_used_at"`

	// Workspace is the associated workspace for this profile
	Workspace string `json:"workspace"`

	// NotifyChannels contains notification channels for this profile.
	// All channel credentials are encrypted with the profile's encryption key.
	NotifyChannels []NotifyChannel `json:"notify_channels,omitempty"`
}

Profile represents a GitHub authentication profile

type Repository

type Repository struct {
	// ID is the primary key
	ID uint `gorm:"primaryKey" json:"id"`

	// UID is the unique identifier for the repository
	UID string `json:"uid"`

	// URL is the remote repository URL
	URL string `json:"url"`

	// Path is the local path where the repository was cloned
	Path string `json:"path"`

	// Workspace is the name of the workspace this repository belongs to
	Workspace string `json:"workspace"`

	// Favorite indicates if the repository is a favorite
	Favorite bool `gorm:"default:false" json:"favorite"`

	// Timestamps for when the repository was last cloned and updated
	ClonedAt time.Time `json:"cloned_at"`

	// UpdatedAt is the last time the repository was checked for updates
	UpdatedAt time.Time `json:"updated_at"`

	// LastChecked is the last time the repository was checked for updates
	LastChecked time.Time `json:"last_checked"`
}

type TokenStorage

type TokenStorage string

TokenStorage indicates where the token is stored

const (
	// TokenStorageEncrypted stores TPM-encrypted token in database
	TokenStorageEncrypted TokenStorage = "encrypted"

	// TokenStorageOpen stores plain text token in database (no TPM available)
	TokenStorageOpen TokenStorage = "open"
)

type Workspace added in v0.3.0

type Workspace struct {
	// Name is the unique identifier for this workspace (e.g., "personal", "work")
	Name string `json:"name"`

	// Description is an optional description of the workspace
	Description string `json:"description"`

	// Path is the base clone directory for this workspace
	Path string `json:"path"`

	// Active indicates if this is the currently active workspace
	Active bool `json:"active"`

	// CreatedAt is when the workspace was created
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is when the workspace was last updated
	UpdatedAt time.Time `json:"updated_at"`
}

Workspace represents a logical grouping of repositories

Jump to

Keyboard shortcuts

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