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 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 GetWeeklyEventCount(ctx context.Context, db *sql.DB, tenantID string) (int, error)
- func HashToken(raw string) string
- func SaveInstallation(ctx context.Context, db *sql.DB, tenantID string, installationID int64, ...) error
- 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 GitHubAppConfig
- type Installation
- type InstallationToken
- type OrgRepo
- type OverviewResponse
- 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 TenantRepo
- type UsageSummary
Constants ¶
This section is empty.
Variables ¶
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. The count check and inserts are in the same transaction to prevent races.
func CleanExpiredSessions ¶
CleanExpiredSessions removes all expired sessions.
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 GetWeeklyEventCount ¶
GetWeeklyEventCount returns the total events this week for a tenant's repos.
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 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.
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 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.
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, months int) (*OverviewResponse, error)
GetOverview returns the full overview response with repo data and usage summary.
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"`
}
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
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 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 UsageSummary ¶
type UsageSummary struct {
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.