Documentation
¶
Overview ¶
Package service provides business logic services for audit log queries.
Package service provides business logic services for commitgraph operations.
Index ¶
- Variables
- func ClearRepoExclusion(ctx context.Context, db Transactioner, provider, repoFullName string) error
- func ClearRepoExclusionWithActor(ctx context.Context, db Transactioner, provider, repoFullName, actor string) error
- func SetRepoExclusion(ctx context.Context, db Transactioner, provider, repoFullName, reason string) error
- func SetRepoExclusionWithActor(ctx context.Context, db Transactioner, ...) error
- type AuditLogQuerier
- type AuditLogQueryOptions
- type AuditLogQueryResult
- type AuditLogRecord
- type Execer
- type Querier
- type RepoChecker
- type RowScanner
- type SQLDB
- type SQLQuerier
- type SQLTx
- type Transactioner
- type Transactor
Constants ¶
This section is empty.
Variables ¶
var RecordExclusionAudit = func( ctx context.Context, tx Transactor, repoID int64, actor string, eventType string, oldExcludedAt *time.Time, oldExcludedReason *string, newExcludedAt *time.Time, newExcludedReason *string, ) error { return recordExclusionAuditImpl(ctx, tx, repoID, actor, eventType, oldExcludedAt, oldExcludedReason, newExcludedAt, newExcludedReason) }
RecordExclusionAudit is a variable that holds the current implementation. This allows tests to mock the function for verification.
Functions ¶
func ClearRepoExclusion ¶
func ClearRepoExclusion(ctx context.Context, db Transactioner, provider, repoFullName string) error
ClearRepoExclusion clears the exclusion status for a repository.
This function performs the following operations within a database transaction: 1. Validates that the repo exists (using RepoExists) 2. Queries the current exclusion state (excluded_at, excluded_reason, repo_id) BEFORE updating 3. Sets excluded_at to NULL and excluded_reason to NULL 4. Records an audit log entry with the before and after states
Parameters:
- ctx: Context for the operation
- db: Database connection (will be used to create a transaction)
- provider: Repository provider (e.g., "github")
- repoFullName: Repository full name (e.g., "owner/repo")
Returns:
- nil on success
- error if validation fails or database operation fails
The function uses a database transaction to ensure atomicity: - On success, the transaction is committed - On error, the transaction is rolled back
Note: Clearing exclusion on a repo that is not currently excluded is considered a no-op and will succeed (1 row affected).
func ClearRepoExclusionWithActor ¶
func ClearRepoExclusionWithActor(ctx context.Context, db Transactioner, provider, repoFullName, actor string) error
ClearRepoExclusionWithActor clears the exclusion status for a repository with a specific actor.
This function performs the following operations within a database transaction: 1. Validates that the repo exists (using RepoExists) 2. Queries the current exclusion state (excluded_at, excluded_reason, repo_id) BEFORE updating 3. Sets excluded_at to NULL and excluded_reason to NULL 4. Records an audit log entry with the before and after states
Parameters:
- ctx: Context for the operation
- db: Database connection (will be used to create a transaction)
- provider: Repository provider (e.g., "github")
- repoFullName: Repository full name (e.g., "owner/repo")
- actor: Who performed the action (e.g., 'admin', 'system')
Returns:
- nil on success
- error if validation fails or database operation fails
The function uses a database transaction to ensure atomicity: - On success, the transaction is committed - On error, the transaction is rolled back
Note: Clearing exclusion on a repo that is not currently excluded is considered a no-op and will succeed (1 row affected).
func SetRepoExclusion ¶
func SetRepoExclusion(ctx context.Context, db Transactioner, provider, repoFullName, reason string) error
SetRepoExclusion sets the exclusion status for a repository.
This function performs the following operations within a database transaction: 1. Validates that the repo exists (using RepoExists) 2. Validates that the reason is not empty 3. Sets excluded_at to NOW() and excluded_reason to the provided reason
Parameters:
- ctx: Context for the operation
- db: Database connection (will be used to create a transaction)
- provider: Repository provider (e.g., "github")
- repoFullName: Repository full name (e.g., "owner/repo")
- reason: Human-readable reason for exclusion (must not be empty)
Returns:
- nil on success
- error if validation fails or database operation fails
The function uses a database transaction to ensure atomicity: - On success, the transaction is committed - On error, the transaction is rolled back
func SetRepoExclusionWithActor ¶
func SetRepoExclusionWithActor(ctx context.Context, db Transactioner, provider, repoFullName, reason, actor string) error
SetRepoExclusionWithActor sets the exclusion status for a repository with a specific actor.
This function performs the following operations within a database transaction: 1. Validates that the repo exists (using RepoExists) 2. Validates that the reason is not empty 3. Queries the current exclusion state (excluded_at, excluded_reason, repo_id) BEFORE updating 4. Sets excluded_at to NOW() and excluded_reason to the provided reason 5. Records an audit log entry with the before and after states
Parameters:
- ctx: Context for the operation
- db: Database connection (will be used to create a transaction)
- provider: Repository provider (e.g., "github")
- repoFullName: Repository full name (e.g., "owner/repo")
- reason: Human-readable reason for exclusion (must not be empty)
- actor: Who performed the action (e.g., 'admin', 'system')
Returns:
- nil on success
- error if validation fails or database operation fails
The function uses a database transaction to ensure atomicity: - On success, the transaction is committed - On error, the transaction is rolled back
Types ¶
type AuditLogQuerier ¶
type AuditLogQuerier struct {
// contains filtered or unexported fields
}
AuditLogQuerier provides query functions for audit logs.
func NewAuditLogQuerier ¶
func NewAuditLogQuerier(db *sql.DB) *AuditLogQuerier
NewAuditLogQuerier creates a new audit log querier.
func (*AuditLogQuerier) QueryAllAuditLogs ¶
func (q *AuditLogQuerier) QueryAllAuditLogs(ctx context.Context, opts AuditLogQueryOptions) (*AuditLogQueryResult, error)
QueryAllAuditLogs retrieves audit logs across all repositories with pagination and filtering.
This is similar to QueryAuditLogs but doesn't filter by repo_id. Use with caution - may return many records.
Parameters:
- ctx: Context for the operation
- opts: Optional query parameters (pagination, filters)
Returns:
- AuditLogQueryResult: Structured result with records and pagination metadata
- error: Error if the query fails
func (*AuditLogQuerier) QueryAuditLogs ¶
func (q *AuditLogQuerier) QueryAuditLogs(ctx context.Context, repoID int64, opts AuditLogQueryOptions) (*AuditLogQueryResult, error)
QueryAuditLogs retrieves audit logs for a specific repository with pagination and filtering.
Parameters:
- ctx: Context for the operation
- repoID: Repository ID to query audit logs for
- opts: Optional query parameters (pagination, filters)
Returns:
- AuditLogQueryResult: Structured result with records and pagination metadata
- error: Error if the query fails
The function handles empty results gracefully (returns empty slice with zero count). Pagination uses offset-based pagination with configurable limit and offset.
type AuditLogQueryOptions ¶
type AuditLogQueryOptions struct {
// Pagination
Limit int // Maximum number of records to return (default: 100, max: 1000)
Offset int // Number of records to skip (for offset-based pagination)
// Filters
StartTime *time.Time // Filter by timestamp >= start_time (optional)
EndTime *time.Time // Filter by timestamp <= end_time (optional)
Actor string // Filter by actor (optional, exact match)
EventType string // Filter by event_type (optional, exact match: 'exclude' or 'unexclude')
}
AuditLogQueryOptions contains optional parameters for querying audit logs.
type AuditLogQueryResult ¶
type AuditLogQueryResult struct {
Records []AuditLogRecord // The audit log records
TotalCount int64 // Total count of matching records (for pagination)
Limit int // The limit used in the query
Offset int // The offset used in the query
}
AuditLogQueryResult contains the results of QueryAuditLogs with pagination metadata.
type AuditLogRecord ¶
type AuditLogRecord struct {
ID int64 // Unique identifier for the audit entry
RepoID int64 // Foreign key reference to the repos table
Actor string // Who performed the action
Timestamp time.Time // When the action was performed
EventType string // Type of event: 'exclude' or 'unexclude'
OldExcludedAt *time.Time // Previous excluded_at value before this action
OldExcludedReason *string // Previous excluded_reason value before this action
NewExcludedAt *time.Time // New excluded_at value after this action
NewExcludedReason *string // New excluded_reason value after this action
}
AuditLogRecord represents a structured audit log record returned by QueryAuditLogs.
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Execer is the database interface for executing statements.
type Querier ¶
type Querier interface {
QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
}
Querier is the database interface for queries. This matches database/sql's DB and Conn interfaces.
type RepoChecker ¶
type RepoChecker struct {
// contains filtered or unexported fields
}
RepoChecker validates repo existence and related business rules.
func NewRepoChecker ¶
func NewRepoChecker(db Querier) *RepoChecker
NewRepoChecker creates a new RepoChecker.
func NewRepoCheckerFromDB ¶
func NewRepoCheckerFromDB(db *sql.DB) *RepoChecker
NewRepoCheckerFromDB creates a RepoChecker from a *sql.DB.
func (*RepoChecker) RepoExists ¶
func (r *RepoChecker) RepoExists(ctx context.Context, provider, repoFullName string) bool
RepoExists checks if a repo exists in the repos table by provider and full_name.
Returns false if: - provider is empty - repoFullName is empty - repo is not found in the database - database query returns an error
This is a validation helper - it returns false on any error condition to fail-safe rather than propagate errors.
type RowScanner ¶
type RowScanner interface {
Scan(dest ...interface{}) error
}
RowScanner is the interface for scanning row results. This makes testing easier by allowing mock implementations.
type SQLDB ¶
type SQLDB struct {
// contains filtered or unexported fields
}
SQLDB wraps *sql.DB to implement Transactioner.
func (*SQLDB) QueryRowContext ¶
func (s *SQLDB) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
type SQLQuerier ¶
type SQLQuerier struct {
// contains filtered or unexported fields
}
SQLQuerier wraps *sql.DB to implement Querier.
func (*SQLQuerier) QueryRowContext ¶
func (s *SQLQuerier) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
type SQLTx ¶
type SQLTx struct {
// contains filtered or unexported fields
}
SQLTx wraps *sql.Tx to implement Transactor.
func (*SQLTx) ExecContext ¶
func (*SQLTx) QueryRowContext ¶
func (s *SQLTx) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
type Transactioner ¶
type Transactioner interface {
QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
BeginTx(ctx context.Context, opts *sql.TxOptions) (Transactor, error)
}
Transactioner is the interface for beginning transactions.