Documentation
¶
Index ¶
- Variables
- func AcceptToS(ctx context.Context, db *sql.DB, tenantID string) error
- func AddTenantRepos(ctx context.Context, db *sql.DB, tenantID string, repos []OrgRepo) error
- func CleanExpiredSessions(ctx context.Context, db *sql.DB) (int64, error)
- func ClearUpgradeRequest(ctx context.Context, db *sql.DB, tenantID string) error
- func CreateAppJWT(cfg *GitHubAppConfig) (string, error)
- func CreateSession(ctx context.Context, db *sql.DB, tenantID string, ttl time.Duration) (string, error)
- func DeactivateTenantRepo(ctx context.Context, db *sql.DB, tenantID, org, repo string) error
- func DestroySession(ctx context.Context, db *sql.DB, rawToken string) error
- func GetTenantIDByUsername(ctx context.Context, db *sql.DB, username string) (string, error)
- func GetWeeklyEventCount(ctx context.Context, db *sql.DB, tenantID string) (int, error)
- func HashToken(raw string) string
- func IncrementImportErrors(ctx context.Context, db *sql.DB, id, errMsg string) error
- func InsertMinimalTenant(ctx context.Context, db *sql.DB, githubID int64, username string) (string, error)
- func MarkRepoDone(ctx context.Context, db *sql.DB, id string) error
- func PrepareImportQueue(ctx context.Context, db *sql.DB) error
- func ResetImportErrors(ctx context.Context, db *sql.DB, id string) error
- func SaveInstallation(ctx context.Context, db *sql.DB, tenantID string, installationID int64, ...) error
- func StartOfWeek() time.Time
- func SuspendInstallation(ctx context.Context, db *sql.DB, installationID int64) error
- func UpdatePlan(ctx context.Context, db *sql.DB, tenantID, plan string, ...) error
- type ActiveInstallation
- type ActiveRepo
- type ActiveTenant
- type ClaimedRepo
- type GitHubAppConfig
- type Installation
- type InstallationToken
- type OrgRepo
- type OverviewResponse
- type RepoDetail
- type RepoOverview
- type Tenant
- func GetTenantByGitHubID(ctx context.Context, db *sql.DB, githubID int64) (*Tenant, error)
- func GetTenantByID(ctx context.Context, db *sql.DB, tenantID string) (*Tenant, error)
- func UpsertTenant(ctx context.Context, db *sql.DB, githubID int64, ...) (*Tenant, error)
- func ValidateSession(ctx context.Context, db *sql.DB, rawToken string) (*Tenant, error)
- type TenantDetail
- type TenantRepo
- type TenantSummary
- type UpgradeRequest
- type UsageSummary
Constants ¶
This section is empty.
Variables ¶
var ErrNoWork = errors.New("no work available")
ErrNoWork is returned by ClaimNextRepo when the import queue is empty.
var ErrRepoLimitExceeded = errors.New("repo limit exceeded for plan")
ErrRepoLimitExceeded is returned when adding repos would exceed the tenant's plan limit.
var ErrSessionInvalid = errors.New("session expired or not found")
ErrSessionInvalid is returned when a session is expired or not found.
Functions ¶
func AddTenantRepos ¶
AddTenantRepos adds repos to a tenant's tracking list, enforcing the plan limit. Upserts run first (ON CONFLICT re-activates deactivated repos without inflating the count), then the resulting active count is checked against the plan limit and rolled back if exceeded. This prevents the previous bug where re-adding a deactivated repo at capacity was incorrectly rejected.
func CleanExpiredSessions ¶
CleanExpiredSessions removes all expired sessions.
func ClearUpgradeRequest ¶ added in v0.26.2
ClearUpgradeRequest removes a pending upgrade request for a tenant.
func CreateAppJWT ¶
func CreateAppJWT(cfg *GitHubAppConfig) (string, error)
CreateAppJWT creates a short-lived JWT signed with the GitHub App's private key.
func CreateSession ¶
func CreateSession(ctx context.Context, db *sql.DB, tenantID string, ttl time.Duration) (string, error)
CreateSession generates a random 256-bit token, stores its SHA-256 hash in the database, and returns the raw token for the cookie.
func DeactivateTenantRepo ¶
DeactivateTenantRepo marks a repo as inactive.
func DestroySession ¶
DestroySession removes a session by its raw token.
func GetTenantIDByUsername ¶ added in v0.26.2
GetTenantIDByUsername returns the tenant ID for a given GitHub username.
func GetWeeklyEventCount ¶
GetWeeklyEventCount returns the total events this week for a tenant's repos.
func IncrementImportErrors ¶ added in v0.22.0
IncrementImportErrors increments the consecutive error counter and stores the last error.
func InsertMinimalTenant ¶ added in v0.26.2
func InsertMinimalTenant(ctx context.Context, db *sql.DB, githubID int64, username string) (string, error)
InsertMinimalTenant creates a tenant with only GitHub ID and username (for admin invites).
func MarkRepoDone ¶ added in v0.8.0
MarkRepoDone marks a claimed repo as successfully imported.
func PrepareImportQueue ¶ added in v0.8.0
PrepareImportQueue resets stale claims (job died mid-run) and clears completed work from the prior cycle so all active repos are available for claiming. Only resets repos completed more than IMPORT_RESET_MINUTES ago (default 30). Safe to call concurrently — both UPDATEs are idempotent.
func ResetImportErrors ¶ added in v0.22.0
ResetImportErrors clears the error counter and last error after a successful import.
func SaveInstallation ¶
func SaveInstallation(ctx context.Context, db *sql.DB, tenantID string, installationID int64, targetType, targetLogin string, permissions []byte) error
SaveInstallation stores or updates a GitHub App installation for a tenant.
func StartOfWeek ¶ added in v0.12.0
StartOfWeek returns the Monday 00:00 UTC of the current week.
func SuspendInstallation ¶
SuspendInstallation marks an installation as suspended.
Types ¶
type ActiveInstallation ¶
ActiveInstallation holds the GitHub installation ID and target org login.
func GetActiveInstallations ¶
func GetActiveInstallations(ctx context.Context, db *sql.DB, tenantID string) ([]ActiveInstallation, error)
GetActiveInstallations returns non-suspended installations for a tenant.
func GetInstallationForOrg ¶ added in v0.3.1
func GetInstallationForOrg(ctx context.Context, db *sql.DB, tenantID, org string) (*ActiveInstallation, error)
GetInstallationForOrg returns the active installation for a tenant's org, if any.
type ActiveRepo ¶
ActiveRepo is a repo eligible for import.
func GetActiveReposForInstall ¶
func GetActiveReposForInstall(ctx context.Context, db *sql.DB, tenantID string, installationID int64) ([]ActiveRepo, error)
GetActiveReposForInstall returns active repos for a tenant's installation.
type ActiveTenant ¶
ActiveTenant represents a tenant with at least one active repo.
func GetActiveTenants ¶
GetActiveTenants returns all tenants that have accepted ToS and have active repos.
type ClaimedRepo ¶ added in v0.8.0
ClaimedRepo is a repo claimed from the import queue.
func ClaimNextRepo ¶ added in v0.8.0
ClaimNextRepo atomically claims one unclaimed active repo for import. Returns ErrNoWork when the queue is empty.
type GitHubAppConfig ¶
type GitHubAppConfig struct {
AppID int64
PrivateKey *rsa.PrivateKey
BaseURL string // override for testing, default: https://api.github.com
}
GitHubAppConfig holds the GitHub App credentials for minting installation tokens.
func LoadGitHubAppConfig ¶ added in v0.3.1
func LoadGitHubAppConfig() (*GitHubAppConfig, error)
LoadGitHubAppConfig reads GitHub App credentials from environment variables.
type Installation ¶
type Installation struct {
ID string
TenantID string
InstallationID int64
TargetType string
TargetLogin string
SuspendedAt *time.Time
CreatedAt time.Time
}
Installation represents a GitHub App installation for a tenant.
func ListInstallations ¶
ListInstallations returns all installations for a tenant.
type InstallationToken ¶
type InstallationToken struct {
Token string `json:"token"`
ExpiresAt time.Time `json:"expires_at"`
}
InstallationToken is a short-lived token scoped to a GitHub App installation.
func MintInstallationToken ¶
func MintInstallationToken(ctx context.Context, cfg *GitHubAppConfig, installationID int64) (*InstallationToken, error)
MintInstallationToken exchanges an App JWT for an installation-scoped access token. The returned token is valid for 1 hour and should never be persisted.
type OverviewResponse ¶
type OverviewResponse struct {
Usage UsageSummary `json:"usage"`
Repos []RepoOverview `json:"repos"`
}
OverviewResponse combines repo overview and usage summary.
func GetOverview ¶
func GetOverview(ctx context.Context, db *sql.DB, tenantID string, days int) (*OverviewResponse, error)
GetOverview returns the full overview response with repo data and usage summary.
type RepoDetail ¶ added in v0.26.2
RepoDetail holds per-repo statistics for admin inspection.
func GetTenantRepoDetails ¶ added in v0.26.2
func GetTenantRepoDetails(ctx context.Context, db *sql.DB, tenantID, since, weekStart string) ([]RepoDetail, error)
GetTenantRepoDetails returns per-repo statistics for a tenant.
type RepoOverview ¶
type RepoOverview struct {
Org string `json:"org"`
Repo string `json:"repo"`
Stars int `json:"stars"`
Forks int `json:"forks"`
OpenIssues int `json:"open_issues"`
Events int `json:"events"`
WeeklyEvents int `json:"weekly_events"`
WeeklyPct float64 `json:"weekly_pct"`
Contributors int `json:"contributors"`
Scored int `json:"scored"`
Language string `json:"language"`
License string `json:"license"`
LastImport string `json:"last_import"`
LimitReached bool `json:"limit_reached"`
ImportErrors int `json:"import_errors"`
ImportLastError string `json:"import_last_error,omitempty"`
}
RepoOverview holds repo metadata and activity stats for the dashboard table.
type Tenant ¶
type Tenant struct {
ID string
GitHubID int64
Username string
Email string
AvatarURL string
MaxRepos int
MaxEventsPerWeek int
Plan string
ToSAcceptedAt *time.Time
UpgradeRequestedAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
Tenant represents a registered SaaS tenant.
func GetTenantByGitHubID ¶
GetTenantByGitHubID returns a tenant by their GitHub user ID.
func GetTenantByID ¶
GetTenantByID returns a tenant by their internal ID.
type TenantDetail ¶ added in v0.26.2
type TenantDetail struct {
ID string
Username string
Email string
Plan string
MaxRepos int
MaxEventsPerWeek int
CreatedAt time.Time
LastSignIn *time.Time
}
TenantDetail is a full tenant record for admin inspection.
func GetTenantDetailByUsername ¶ added in v0.26.2
func GetTenantDetailByUsername(ctx context.Context, db *sql.DB, username string) (*TenantDetail, error)
GetTenantDetailByUsername returns detailed tenant info including email and last sign-in.
type TenantRepo ¶
type TenantRepo struct {
ID string `json:"id"`
TenantID string `json:"tenant_id"`
Org string `json:"org"`
Repo string `json:"repo"`
Active bool `json:"active"`
LastImportAt *string `json:"last_import_at"`
}
TenantRepo represents a repo tracked by a tenant.
func ListTenantRepos ¶
ListTenantRepos returns all active repos for a tenant.
type TenantSummary ¶ added in v0.26.2
type TenantSummary struct {
Username string
Plan string
MaxRepos int
MaxEventsPerWeek int
CreatedAt time.Time
LastSignIn *time.Time
}
TenantSummary is a lightweight tenant record for admin listing.
func ListTenantSummaries ¶ added in v0.26.2
ListTenantSummaries returns all tenants with their last sign-in time.
type UpgradeRequest ¶ added in v0.6.0
UpgradeRequest holds details returned when an upgrade is first requested.
func RequestUpgrade ¶ added in v0.6.0
RequestUpgrade idempotently records an upgrade request for a tenant. Returns the request details on first call, nil on subsequent calls.
type UsageSummary ¶
type UsageSummary struct {
Plan string `json:"plan"`
MaxRepos int `json:"max_repos"`
ActiveRepos int `json:"active_repos"`
MaxEventsPerWeek int `json:"max_events_per_week"`
WeeklyEvents int `json:"weekly_events"`
WeeklyPct float64 `json:"weekly_pct"`
LimitReached bool `json:"limit_reached"`
}
UsageSummary holds tenant-level usage stats for the dashboard.