store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: 0BSD Imports: 16 Imported by: 0

Documentation

Overview

Package store owns SQLite access and schema migrations.

Index

Constants

View Source
const MaxBuildLog = 2 << 20

MaxBuildLog caps a build's stored log; appends past it are dropped.

Variables

View Source
var ErrDuplicateKey = errors.New("that key is already registered to another account; remove it there first or use a different key")

ErrDuplicateKey carries the exact user-facing message from the spec. It deliberately does not name the owning account (enumeration oracle).

View Source
var ErrExists = errors.New("already exists")

ErrExists marks unique-constraint refusals callers turn into messages.

View Source
var ErrNotFound = errors.New("not found")

Functions

func CombinedStatus added in v0.2.0

func CombinedStatus(statuses []CommitStatus) string

func HashToken

func HashToken(token string) string

func NewToken

func NewToken() (token, hash string, err error)

NewToken returns a fresh random token and its storage hash. Only the hash is persisted; the token itself goes to the user once.

Types

type APIToken

type APIToken struct {
	Name       string
	Scope      string
	CreatedAt  string
	ExpiresAt  *time.Time
	LastUsedAt *time.Time
}

type AccessEntry

type AccessEntry struct {
	Username string
	Role     string
}

type AuditEntry added in v0.2.0

type AuditEntry struct {
	ID        int64  `json:"id"`
	Actor     string `json:"actor,omitempty"`
	Action    string `json:"action"`
	Data      string `json:"data"`
	CreatedAt string `json:"created_at"`
}

type Build added in v0.3.0

type Build struct {
	ID         int64
	RepoID     int64
	Number     int64
	Job        string
	SHA        string
	Ref        string
	Steps      string // JSON array of shell commands
	Status     string // pending|running|success|failure
	CreatedAt  string
	StartedAt  string
	FinishedAt string
}

Build is one CI job execution for one commit.

type CommitStatus added in v0.2.0

type CommitStatus struct {
	Context     string
	State       string // pending | success | failure | error
	Description string
	TargetURL   string
	Creator     string
	UpdatedAt   string
}

type Counts added in v0.2.0

type Counts struct {
	Users      int64 `json:"users"`
	Orgs       int64 `json:"orgs"`
	Repos      int64 `json:"repos"`
	Issues     int64 `json:"issues"`
	OpenIssues int64 `json:"open_issues"`
	MRs        int64 `json:"mrs"`
	OpenMRs    int64 `json:"open_mrs"`
}

type DashboardItem added in v0.2.0

type DashboardItem struct {
	RepoPath  string
	Number    int64
	Title     string
	Author    string
	State     string
	UpdatedAt string
}

DashboardItem is one open issue or MR row on the logged-in homepage.

type Delivery

type Delivery struct {
	ID        int64
	WebhookID int64
	URL       string
	Secret    string
	EventID   int64
	EventKind string
	RepoPath  string
	Actor     string
	DataJSON  string
	EventAt   string
	Attempts  int
}

type DeliveryStatus

type DeliveryStatus struct {
	ID         int64
	URL        string
	EventKind  string
	Status     string // pending | delivered | failed
	Attempts   int
	LastStatus int
	LastError  string
	CreatedAt  string
}

type DiffComment added in v0.2.0

type DiffComment struct {
	ID         int64
	Author     string
	HeadSHA    string
	Path       string
	Side       string
	Line       int64
	Body       string
	ReplyTo    int64 // 0 for thread roots
	ResolvedBy string
	CreatedAt  string
}

type Email added in v1.0.0

type Email struct {
	Address    string
	Verified   bool
	VerifiedBy string // smtp | admin, empty when unverified
	Primary    bool
}

Email is one address on an account, with the state the signature rules and notification routing depend on.

type FeedEvent added in v0.5.0

type FeedEvent struct {
	RepoPath  string
	Actor     string
	Kind      string
	Data      string
	CreatedAt string
}

FeedEvent is one line of the dashboard's activity feed.

type Issue

type Issue struct {
	ID        int64
	RepoID    int64
	Number    int64
	Author    string
	Title     string
	Body      string
	State     string // open | closed
	Milestone string
	CreatedAt string
	UpdatedAt string
	Labels    []string
	Assignees []string
}

type IssueComment

type IssueComment struct {
	Author    string
	Body      string
	CreatedAt string
	Kind      string // comment | system
}

type MR

type MR struct {
	ID           int64
	RepoID       int64
	Number       int64
	Author       string
	SourceRepoID int64  // 0 when the source repo is gone
	SourcePath   string // owner/name of source repo, "" when gone
	SourceRef    string
	TargetRef    string
	Title        string
	Body         string
	State        string // open | merged | closed | source_gone
	Milestone    string
	HeadSHA      string
	MergedBase   string // target tip at merge time; base for historical diffs
	CreatedAt    string
	UpdatedAt    string
}

type MRReview

type MRReview struct {
	Reviewer  string
	Verdict   string
	HeadSHA   string
	Stale     bool
	CreatedAt string
}

type Milestone added in v0.2.0

type Milestone struct {
	ID          int64
	RepoID      int64
	Title       string
	Description string
	DueDate     string
	State       string // open | closed
	CreatedAt   string
	OpenItems   int // open issues + open MRs attached
	ClosedItems int // closed issues + merged/closed MRs attached
}

type Mirror added in v0.2.0

type Mirror struct {
	ID        int64
	RepoID    int64
	Direction string // push | pull
	URL       string
	Username  string
	Token     string
	Dirty     bool
	LastSync  string
	LastError string
}

Mirror propagates refs to (push) or from (pull) a foreign remote. The token is stored server-side — unlike import, mirroring is recurring — and must never be echoed back in listings.

type Org

type Org struct {
	ID   int64
	Name string
}

type OrgMember

type OrgMember struct {
	Username string
	Role     string // member | admin
}

type PGPKey

type PGPKey struct {
	Fingerprint string
	UIDsJSON    string
	ExpiresAt   *time.Time
	RevokedAt   *time.Time
}

type PageDomain added in v0.3.0

type PageDomain struct {
	Domain     string
	RepoID     int64
	UserID     int64
	Token      string
	CreatedAt  string
	VerifiedAt string
}

PageDomain is one custom-domain claim. A claim starts pending — it holds the domain but serves nothing — and activates when the DNS challenge verifies. Pending claims expire so a squatted claim frees itself.

func (PageDomain) Verified added in v0.3.0

func (d PageDomain) Verified() bool

type Profile

type Profile struct {
	Description string `json:"description,omitempty"`
	Website     string `json:"website,omitempty"`
}

Profile is the presentational half of a user or org.

type QueuedMail added in v0.2.0

type QueuedMail struct {
	ID        int64
	Recipient string
	Subject   string
	Body      string
	Attempts  int
}

type Release added in v0.2.0

type Release struct {
	ID        int64
	RepoID    int64
	Tag       string
	Title     string
	Notes     string
	Author    string
	CreatedAt string
	Assets    []ReleaseAsset
}

type ReleaseAsset added in v0.2.0

type ReleaseAsset struct {
	ID         int64
	Name       string
	Size       int64
	SHA256     string
	UploadedAt string
}

type Repo

type Repo struct {
	ID            int64
	OwnerKind     string // user | org
	OwnerID       int64
	OwnerName     string // resolved for display and disk paths
	Name          string
	Visibility    string // public | private
	DefaultBranch string
	ForkOf        int64 // 0 when not a fork
	Settings      RepoSettings
}

func (Repo) Path

func (r Repo) Path() string

Path returns the canonical owner/name form.

type RepoSettings

type RepoSettings struct {
	ProtectedBranches    []string `json:"protected_branches,omitempty"`
	RequireSignedCommits bool     `json:"require_signed_commits,omitempty"`
	RequireChecks        bool     `json:"require_checks,omitempty"`
	RequireApprovals     int      `json:"require_approvals,omitempty"`
	RequireResolved      bool     `json:"require_resolved,omitempty"`
	GitDaemon            bool     `json:"git_daemon,omitempty"`
	Archived             bool     `json:"archived,omitempty"`
	Website              string   `json:"website,omitempty"`
}

type SSHKey

type SSHKey struct {
	ID          int64
	UserID      int64
	Fingerprint string
	Algo        string
	Blob        []byte
	Scope       string
}

type Schedule added in v0.3.0

type Schedule struct {
	RepoID  int64
	Job     string
	Cron    string
	NextRun string
}

Schedule is one repo job's cron entry.

type SigDB

type SigDB struct{ *Store }

SigDB adapts Store to the verifier's interface and owns the epoch cache.

func (SigDB) PGPKeyByIssuer

func (d SigDB) PGPKeyByIssuer(keyIDHex string) (sig.PGPKeyInfo, string, bool, error)

func (SigDB) SSHSignerByFingerprint

func (d SigDB) SSHSignerByFingerprint(fp string) (sig.SSHKeyInfo, bool, error)

func (SigDB) VerifiedEmails

func (d SigDB) VerifiedEmails(userID int64) ([]string, error)

type Store

type Store struct {
	DB *sql.DB
}

func Open

func Open(path string) (*Store, error)

Open opens (creating if needed) the database at path with WAL mode and foreign keys enforced. Use ":memory:" in tests.

func (*Store) APITokenUser

func (s *Store) APITokenUser(tokenHash string) (User, string, error)

APITokenUser resolves a presented token to its user and scope; expired and unknown tokens fail identically.

func (*Store) AccessRole

func (s *Store) AccessRole(repoID, userID int64) (string, error)

AccessRole returns the user's effective role on the repo ("" if none): the strongest of any explicit grant, the role derived from org membership (org admin -> admin; plain member -> the org's members_role, 'write' by default so the pre-teams model is the degenerate case), and any team grants on the repo.

func (*Store) ActivityByDay added in v0.3.0

func (s *Store) ActivityByDay(userID int64, sinceDay string) (map[string]int, error)

ActivityByDay aggregates a user's activity per day since the given day: commits landed on default branches plus everything the events table attributes to them (issues, MRs, comments, releases, pushes).

func (*Store) AddDiffComment added in v0.2.0

func (s *Store) AddDiffComment(mrID, authorID int64, headSHA, path, side string, line int64, body string, replyTo int64) (int64, error)

AddDiffComment creates a thread root (replyTo 0) or a reply. Replies inherit the root's anchor and must belong to the same MR.

func (*Store) AddEmail

func (s *Store) AddEmail(userID int64, address, verifiedBy string, primary bool) error

AddEmail adds an address; verifiedBy is "" (unverified), "smtp", or "admin". Adding an already-verified address bumps the key epoch: it is a trust input for signature states.

func (*Store) AddIssueComment

func (s *Store) AddIssueComment(issueID, authorID int64, body string) error

func (*Store) AddIssueSystemComment added in v0.2.0

func (s *Store) AddIssueSystemComment(issueID, actorID int64, body string) error

AddIssueSystemComment records an informational entry (commit references, automated closes). The actor is kept for provenance but the entry displays as coming from the system, not the user.

func (*Store) AddMRComment

func (s *Store) AddMRComment(mrID, authorID int64, body string) error

func (*Store) AddMRReview

func (s *Store) AddMRReview(mrID, reviewerID int64, verdict, headSHA string) error

func (*Store) AddMRSystemComment added in v0.2.0

func (s *Store) AddMRSystemComment(mrID, actorID int64, body string) error

AddMRSystemComment is the informational counterpart of AddMRComment.

func (*Store) AddMirror added in v0.2.0

func (s *Store) AddMirror(repoID int64, direction, url, username, token string) (int64, error)

func (*Store) AddPGPKey

func (s *Store) AddPGPKey(userID int64, fingerprint, armored, uidsJSON string, expiresAt, revokedAt *time.Time) error

AddPGPKey registers an OpenPGP key and bumps the key epoch.

func (*Store) AddPageDomain added in v0.3.0

func (s *Store) AddPageDomain(domain string, repoID, userID int64, token string, ttlSeconds int) error

AddPageDomain claims a domain for a repo. Expired pending claims (any repo's) are cleared first, so abandonment frees the name; live claims make the insert fail with ErrExists.

func (*Store) AddReleaseAsset added in v0.2.0

func (s *Store) AddReleaseAsset(releaseID int64, name string, size int64, sha256 string) error

func (*Store) AddSSHKey

func (s *Store) AddSSHKey(userID int64, fingerprint, algo string, blob []byte, scope string) error

AddSSHKey registers a key and bumps the key epoch in one transaction.

func (*Store) AddTeamMember added in v0.3.0

func (s *Store) AddTeamMember(teamID, userID int64) error

func (*Store) AddTopic added in v0.2.0

func (s *Store) AddTopic(repoID int64, topic string) error

AddTopic is idempotent: adding an existing topic is not an error.

func (*Store) AddWebhook

func (s *Store) AddWebhook(repoID int64, url, secret, events string) (int64, error)

func (*Store) AppendBuildLog added in v0.3.0

func (s *Store) AppendBuildLog(id int64, chunk []byte) error

AppendBuildLog adds a chunk to the build's log, dropping bytes past the cap.

func (*Store) AssignedIssues added in v0.5.0

func (s *Store) AssignedIssues(userID int64) ([]DashboardItem, error)

AssignedIssues returns open issues assigned to the user, wherever they live. Assignment is a direct request for someone's attention, so it is not narrowed by the involvement rule the other lists use.

func (*Store) Audit added in v0.2.0

func (s *Store) Audit(actorID int64, action string, data map[string]any)

Audit appends to the security feed. Events are the product feed; this records who did what, from where, for an operator. actorID 0 means the host admin (gitbayd admin commands) or an unauthenticated source.

func (*Store) AuditEntries added in v0.2.0

func (s *Store) AuditEntries(limit int) ([]AuditEntry, error)

func (*Store) BuildByID added in v0.3.0

func (s *Store) BuildByID(id int64) (Build, error)

func (*Store) BuildByNumber added in v0.3.0

func (s *Store) BuildByNumber(repoID, number int64) (Build, error)

func (*Store) BuildLog added in v0.3.0

func (s *Store) BuildLog(id int64) ([]byte, error)

BuildLog returns the stored log bytes.

func (*Store) BuildSecrets added in v0.3.0

func (s *Store) BuildSecrets(repoID int64) (map[string]string, error)

BuildSecrets returns the values, for injection into a claimed build.

func (*Store) CachedSignature

func (s *Store) CachedSignature(repoID int64, sha string, epoch int64) (sig.Result, bool, error)

CachedSignature returns a cached result and whether it is current at the given epoch.

func (*Store) ClaimBuild added in v0.3.0

func (s *Store) ClaimBuild() (Build, bool, error)

ClaimBuild atomically hands the oldest pending build to a runner.

func (*Store) ClearPending

func (s *Store) ClearPending(userID int64) error

ClearPending activates a pending account.

func (*Store) Close

func (s *Store) Close() error

func (*Store) CombinedStatusFor added in v1.0.0

func (s *Store) CombinedStatusFor(repoID int64, shas []string) (map[string]string, error)

CombinedStatus reduces per-context states to one: error/failure dominate, then pending, then success; "" when no statuses exist. CombinedStatusFor returns the combined state for each of several commits in one query. The log lists fifty commits at a time; asking per commit turns one page into fifty round trips.

func (*Store) ConsumeEmailToken

func (s *Store) ConsumeEmailToken(userID int64, tokenHash string) (string, error)

ConsumeEmailToken redeems a verification code for the given user.

func (*Store) ConsumeInvite

func (s *Store) ConsumeInvite(codeHash string) (string, error)

ConsumeInvite redeems an invite exactly once, returning the address it was issued for. Used and unknown codes fail identically.

func (*Store) ConsumeLoginToken

func (s *Store) ConsumeLoginToken(hash string) (int64, error)

ConsumeLoginToken redeems a token exactly once; expired or used tokens fail identically.

func (*Store) CreateAPIToken

func (s *Store) CreateAPIToken(userID int64, name, tokenHash, scope string, expires *time.Time) error

CreateAPIToken stores a token hash; expires nil means no expiry.

func (*Store) CreateBuild added in v0.3.0

func (s *Store) CreateBuild(repoID int64, job, sha, ref, stepsJSON string) (int64, error)

CreateBuild allocates the per-repo build number in the same transaction as the insert, like issue and MR numbers.

func (*Store) CreateEmailToken

func (s *Store) CreateEmailToken(userID int64, address, tokenHash string, ttl time.Duration) error

CreateEmailToken stores a verification code hash for one address.

func (*Store) CreateInvite

func (s *Store) CreateInvite(codeHash, email string) error

CreateInvite stores an invite code hash bound to an email address.

func (*Store) CreateIssue

func (s *Store) CreateIssue(repoID, authorID int64, title, body string) (int64, error)

CreateIssue allocates the per-repo number from the repo counter inside the same transaction as the insert — MAX(number)+1 races.

func (*Store) CreateLoginToken

func (s *Store) CreateLoginToken(userID int64, hash string, ttl time.Duration) error

CreateLoginToken stores a one-time login token hash.

func (*Store) CreateMR

func (s *Store) CreateMR(repoID, authorID, sourceRepoID int64, sourceRef, targetRef, title, body, headSHA string) (int64, error)

func (*Store) CreateMilestone added in v0.2.0

func (s *Store) CreateMilestone(repoID int64, title, description, due string) (int64, error)

func (*Store) CreateOrg

func (s *Store) CreateOrg(name string, creatorID int64) (int64, error)

CreateOrg makes an organization with the creator as its first admin.

func (*Store) CreateRegisteredUser

func (s *Store) CreateRegisteredUser(username string, pending bool) (int64, error)

CreateRegisteredUser makes a self-registered account, pending until its email is verified.

func (*Store) CreateRelease added in v0.2.0

func (s *Store) CreateRelease(repoID int64, tag, title, notes string, authorID int64) (int64, error)

func (*Store) CreateRepo

func (s *Store) CreateRepo(ownerKind string, ownerID int64, name, visibility string) (int64, error)

func (*Store) CreateTeam added in v0.3.0

func (s *Store) CreateTeam(orgID int64, name string) (int64, error)

func (*Store) CreateUser

func (s *Store) CreateUser(username string, isAdmin bool) (int64, error)

func (*Store) CreateWebSession

func (s *Store) CreateWebSession(hash string, userID int64, ttl time.Duration) error

func (*Store) DashboardIssues added in v0.2.0

func (s *Store) DashboardIssues(userID int64) ([]DashboardItem, error)

DashboardIssues is the issue counterpart of DashboardMRs.

func (*Store) DashboardMRs added in v0.2.0

func (s *Store) DashboardMRs(userID int64) ([]DashboardItem, error)

DashboardMRs returns open merge requests involving the user: on their repositories (owned, granted, org) or authored by them anywhere.

func (*Store) DeleteOrg

func (s *Store) DeleteOrg(orgID int64) error

DeleteOrg removes an empty organization; orgs still owning repositories are refused.

func (*Store) DeleteRelease added in v0.2.0

func (s *Store) DeleteRelease(id int64) error

func (*Store) DeleteRepo

func (s *Store) DeleteRepo(repoID int64) error

func (*Store) DeleteTeam added in v0.3.0

func (s *Store) DeleteTeam(teamID int64) error

func (*Store) DeleteUser added in v0.3.0

func (s *Store) DeleteUser(id int64) error

DeleteUser removes an account whose removal orphans nothing: no owned repositories, no authored issues, MRs, comments, or reviews, and not the only admin of an org. Everything else (keys, emails, sessions, tokens, pins, memberships, activity) cascades. Blockers come back as an error naming what stands in the way, so the operator can transfer, delete, or disable instead.

func (*Store) DeleteWebSession

func (s *Store) DeleteWebSession(hash string) error

func (*Store) DiffCommentAuthor added in v0.2.0

func (s *Store) DiffCommentAuthor(mrID, id int64) (int64, error)

DiffCommentAuthor returns the author id of one comment.

func (*Store) DueDeliveries

func (s *Store) DueDeliveries(limit int) ([]Delivery, error)

DueDeliveries returns pending deliveries whose time has come, with the event and hook context needed to send them.

func (*Store) DueMail added in v0.2.0

func (s *Store) DueMail(limit int) ([]QueuedMail, error)

func (*Store) DueMirrors added in v0.2.0

func (s *Store) DueMirrors(intervalSeconds int) ([]Mirror, error)

DueMirrors returns mirrors needing a sync: anything dirty, plus pull mirrors whose last sync is older than intervalSeconds.

func (*Store) DueSchedules added in v0.3.0

func (s *Store) DueSchedules(nowISO string) ([]Schedule, error)

DueSchedules returns entries whose next_run is at or before now.

func (*Store) EmailInUse added in v0.2.0

func (s *Store) EmailInUse(address string) (bool, error)

EmailInUse reports whether an address is attached to any account.

func (*Store) EnqueueMail added in v0.2.0

func (s *Store) EnqueueMail(recipient, subject, body string) error

func (*Store) FinishBuild added in v0.3.0

func (s *Store) FinishBuild(id int64, status string) error

FinishBuild records the outcome of a running build.

func (*Store) GrantAccess

func (s *Store) GrantAccess(repoID, userID int64, role string) error

func (*Store) GrantTeamRepo added in v0.3.0

func (s *Store) GrantTeamRepo(teamID, repoID int64, role string) error

GrantTeamRepo attaches (or updates) a team's role on a repo.

func (*Store) ImportMarker added in v0.2.0

func (s *Store) ImportMarker(repoID int64, key string) (string, bool, error)

ImportMarker returns the stored value for an import progress key, and whether it exists. Markers make history imports resumable: items and comments already imported are skipped on re-run.

func (*Store) InstanceCounts added in v0.2.0

func (s *Store) InstanceCounts() (Counts, error)

func (*Store) IsPinned added in v0.2.0

func (s *Store) IsPinned(userID, repoID int64) bool

func (*Store) IssueByNumber

func (s *Store) IssueByNumber(repoID, number int64) (Issue, error)

func (*Store) IssueParticipants added in v0.2.0

func (s *Store) IssueParticipants(issueID int64) ([]int64, error)

IssueParticipants returns distinct user ids involved in an issue: the author and every commenter.

func (*Store) KeyEpoch

func (s *Store) KeyEpoch() (int64, error)

func (*Store) LFSSecret added in v0.4.0

func (s *Store) LFSSecret(gen func() string) (string, error)

LFSSecret returns the instance's LFS token-signing secret, minting and persisting one on first use. gen supplies the new value so this package stays free of crypto choices.

func (*Store) LabelColors added in v0.2.0

func (s *Store) LabelColors(repoID int64) (map[string]string, error)

LabelColors returns the repo's label colors keyed by label name. Labels with no stored color map to "".

func (*Store) LatestBuild added in v0.5.0

func (s *Store) LatestBuild(repoID int64, job string) (Build, error)

LatestBuild returns the newest build for a repo, optionally narrowed to one job. It is what a status badge reports.

func (*Store) ListAPITokens

func (s *Store) ListAPITokens(userID int64) ([]APIToken, error)

func (*Store) ListAccess

func (s *Store) ListAccess(repoID int64) ([]AccessEntry, error)

func (*Store) ListAllRepos added in v0.2.0

func (s *Store) ListAllRepos() ([]Repo, error)

ListAllRepos returns every repository, for host-local admin tooling.

func (*Store) ListBuildSecretNames added in v0.3.0

func (s *Store) ListBuildSecretNames(repoID int64) ([]string, error)

ListBuildSecretNames returns names only; values are for builds.

func (*Store) ListBuilds added in v0.3.0

func (s *Store) ListBuilds(repoID int64, limit int) ([]Build, error)

func (*Store) ListCommitStatuses added in v0.2.0

func (s *Store) ListCommitStatuses(repoID int64, sha string) ([]CommitStatus, error)

ListCommitStatuses returns the latest status per context for a commit.

func (*Store) ListDeliveries

func (s *Store) ListDeliveries(repoID int64, limit int) ([]DeliveryStatus, error)

func (*Store) ListDeployKeys added in v0.2.0

func (s *Store) ListDeployKeys(repoID int64) ([]SSHKey, error)

ListDeployKeys returns the deploy keys bound to a repository.

func (*Store) ListDiffComments added in v0.2.0

func (s *Store) ListDiffComments(mrID int64) ([]DiffComment, error)

ListDiffComments returns every diff comment on an MR, roots and replies, oldest first.

func (*Store) ListEmails added in v1.0.0

func (s *Store) ListEmails(userID int64) ([]Email, error)

ListEmails returns every address on the account with its state.

func (*Store) ListIssueComments

func (s *Store) ListIssueComments(issueID int64) ([]IssueComment, error)

func (*Store) ListIssueLabels added in v0.2.0

func (s *Store) ListIssueLabels(repoID int64) (map[int64][]string, error)

ListIssueLabels returns the label names attached to each issue of a repo, keyed by issue id. Used by the web issue listing; ListIssues itself stays label-free for the CLI's lean list output.

func (*Store) ListIssues

func (s *Store) ListIssues(repoID int64, state string) ([]Issue, error)

ListIssues returns issues for a repo; state is "open", "closed", or "all".

func (*Store) ListMRComments

func (s *Store) ListMRComments(mrID int64) ([]IssueComment, error)

func (*Store) ListMRReviews

func (s *Store) ListMRReviews(mrID int64) ([]MRReview, error)

func (*Store) ListMRs

func (s *Store) ListMRs(repoID int64, state string) ([]MR, error)

func (*Store) ListMilestones added in v0.2.0

func (s *Store) ListMilestones(repoID int64, state string) ([]Milestone, error)

func (*Store) ListMirrors added in v0.2.0

func (s *Store) ListMirrors(repoID int64) ([]Mirror, error)

func (*Store) ListOrgsForUser

func (s *Store) ListOrgsForUser(userID int64) ([]OrgMember, error)

ListOrgsForUser returns the orgs the user belongs to, with their role.

func (*Store) ListPGPKeys

func (s *Store) ListPGPKeys(userID int64) ([]PGPKey, error)

func (*Store) ListPageDomains added in v0.3.0

func (s *Store) ListPageDomains(repoID int64) ([]PageDomain, error)

func (*Store) ListPublicRepos

func (s *Store) ListPublicRepos() ([]Repo, error)

ListPublicRepos returns all public repositories, for the anonymous index.

func (*Store) ListReleases added in v0.2.0

func (s *Store) ListReleases(repoID int64) ([]Release, error)

ListReleases returns releases newest-first, assets included.

func (*Store) ListReposForOwner

func (s *Store) ListReposForOwner(ownerKind string, ownerID int64) ([]Repo, error)

ListReposForOwner returns every repo owned by one user or org; the caller filters by viewer visibility.

func (*Store) ListReposForUser

func (s *Store) ListReposForUser(userID int64) ([]Repo, error)

ListReposForUser returns repos the user owns, reaches through an org (unless the org scopes members to 'none'), has an explicit grant on, or reaches through a team.

func (*Store) ListSSHKeys

func (s *Store) ListSSHKeys(userID int64) ([]SSHKey, error)

func (*Store) ListTeams added in v0.3.0

func (s *Store) ListTeams(orgID int64) ([]Team, error)

func (*Store) ListTopics added in v0.2.0

func (s *Store) ListTopics(repoID int64) ([]string, error)

func (*Store) ListWebhooks

func (s *Store) ListWebhooks(repoID int64) ([]Webhook, error)

func (*Store) MRByNumber

func (s *Store) MRByNumber(repoID, number int64) (MR, error)

func (*Store) MRParticipants added in v0.2.0

func (s *Store) MRParticipants(mrID int64) ([]int64, error)

MRParticipants returns distinct user ids involved in an MR: author, commenters, reviewers.

func (*Store) MarkAttemptFailed

func (s *Store) MarkAttemptFailed(id int64, status int, errMsg string, nextAt *time.Time) error

MarkAttemptFailed records a failed attempt; nextAt nil dead-letters it.

func (*Store) MarkDelivered

func (s *Store) MarkDelivered(id int64, status int) error

func (*Store) MarkMailFailed added in v0.2.0

func (s *Store) MarkMailFailed(id int64, errMsg string, nextAt *time.Time) error

func (*Store) MarkMailSent added in v0.2.0

func (s *Store) MarkMailSent(id int64) error

func (*Store) MarkMerged

func (s *Store) MarkMerged(mrID int64, baseSHA string) error

MarkMerged records the merge along with the target tip it landed on, so the MR's diff stays reconstructable after fast-forwards.

func (*Store) MarkMirrorsDirty added in v0.2.0

func (s *Store) MarkMirrorsDirty(repoID int64, direction string) error

MarkMirrorsDirty schedules a sync. An empty direction marks both.

func (*Store) MarkSourceGoneForRepo

func (s *Store) MarkSourceGoneForRepo(sourceRepoID int64) error

MarkSourceGoneForRepo flags every open MR sourced from the repo; called when a fork is deleted. Head refs in the target repos are retained.

func (*Store) MigrateCommitRefComments added in v0.3.0

func (s *Store) MigrateCommitRefComments() (int, error)

MigrateCommitRefComments converts legacy commit-reference comments into system messages with a linked sha, matching what new references produce. It is idempotent: only kind='comment' rows are considered, and converted rows become kind='system'. Returns the number converted.

func (*Store) MigrateTo

func (s *Store) MigrateTo(target int) error

MigrateTo migrates up or down to the given version. 0 empties the schema.

func (*Store) MigrateUp

func (s *Store) MigrateUp() error

MigrateUp applies all pending migrations.

func (*Store) MilestoneByTitle added in v0.2.0

func (s *Store) MilestoneByTitle(repoID int64, title string) (Milestone, error)

func (*Store) OpenCounts added in v0.5.0

func (s *Store) OpenCounts(repoID int64) (issues, mrs int)

OpenCounts returns the repo's open issue and open merge request counts, for the repo tab badges.

func (*Store) OpenMRsBySource

func (s *Store) OpenMRsBySource(sourceRepoID int64, sourceRef string) ([]MR, error)

OpenMRsBySource returns open (and source_gone) MRs fed by the given source repo branch — the cross-repo hook effect consults this.

func (*Store) OrgActivityByDay added in v0.3.0

func (s *Store) OrgActivityByDay(orgID int64, sinceDay string) (map[string]int, error)

OrgActivityByDay aggregates activity across an org's repositories.

func (*Store) OrgByName

func (s *Store) OrgByName(name string) (Org, error)

func (*Store) OrgMembers

func (s *Store) OrgMembers(orgID int64) ([]OrgMember, error)

func (*Store) OrgRole

func (s *Store) OrgRole(orgID, userID int64) (string, error)

OrgRole returns the user's role in the org ("" for non-members).

func (*Store) OwnerExists added in v0.3.0

func (s *Store) OwnerExists(name string) bool

OwnerExists reports whether a user or org owns the name — the ACME host policy check for pages subdomains.

func (*Store) OwnerProfile

func (s *Store) OwnerProfile(kind string, id int64) (Profile, error)

OwnerProfile reads the profile for kind "user" or "org".

func (*Store) PageDomainClaim added in v0.3.0

func (s *Store) PageDomainClaim(domain string, repoID int64) (PageDomain, error)

PageDomainClaim returns a repo's claim on a domain, verified or pending.

func (*Store) PageDomainExpired added in v0.3.0

func (s *Store) PageDomainExpired(d PageDomain, ttlSeconds int) bool

PageDomainExpired reports whether a pending claim has outlived the TTL.

func (*Store) PageDomainRepo added in v0.3.0

func (s *Store) PageDomainRepo(domain string) (Repo, error)

PageDomainRepo resolves a request host to the repo serving it. Only verified claims serve.

func (*Store) PinRepo added in v0.2.0

func (s *Store) PinRepo(userID, repoID int64) error

func (*Store) PinnedRepos added in v0.2.0

func (s *Store) PinnedRepos(userID int64) ([]Repo, error)

PinnedRepos returns the user's pinned repositories in pin order. The caller applies visibility checks before rendering.

func (*Store) PrimaryVerifiedEmail

func (s *Store) PrimaryVerifiedEmail(userID int64) (string, error)

PrimaryVerifiedEmail returns the user's primary email if verified, else "".

func (*Store) PullMirrored added in v0.2.0

func (s *Store) PullMirrored(repoID int64) (bool, error)

PullMirrored reports whether the repo has a pull mirror, which makes it read-only locally: its refs belong to the upstream.

func (*Store) RecentEvents added in v0.5.0

func (s *Store) RecentEvents(userID int64, limit int) ([]FeedEvent, error)

RecentEvents returns activity on repositories the user can reach. Push events are excluded: they repeat what the commit lists already show.

func (*Store) RecordCommitActivity added in v0.3.0

func (s *Store) RecordCommitActivity(repoID int64, sha string, userID int64, day string) bool

RecordCommitActivity is idempotent per (repo, sha); it reports whether this call recorded a new row.

func (*Store) RecordEvent

func (s *Store) RecordEvent(repoID, actorID int64, kind, dataJSON string) error

RecordEvent appends to the event log and enqueues a delivery for every active webhook on the repo whose event filter matches.

func (*Store) RedeemInvite added in v0.2.0

func (s *Store) RedeemInvite(codeHash, username, keyFP, keyAlgo string, keyBlob []byte) (string, error)

RedeemInvite performs the whole invite registration in one transaction: consume the code, create the user, attach the invite's email as verified, register the key. Any failure rolls everything back — the invite stays redeemable and no partial account exists.

func (*Store) Redeliver

func (s *Store) Redeliver(repoID, deliveryID int64) error

Redeliver resets a delivery for an immediate retry.

func (*Store) RegisterOpen added in v0.2.0

func (s *Store) RegisterOpen(username, email, keyFP, keyAlgo string, keyBlob []byte) (int64, error)

RegisterOpen performs open registration in one transaction: pending user, unverified email, key. Failure leaves nothing behind.

func (*Store) ReleaseByTag added in v0.2.0

func (s *Store) ReleaseByTag(repoID int64, tag string) (Release, error)

func (*Store) RemoveBuildSecret added in v0.3.0

func (s *Store) RemoveBuildSecret(repoID int64, name string) error

func (*Store) RemoveDeployKey added in v0.2.0

func (s *Store) RemoveDeployKey(repoID int64, fingerprint string) error

RemoveDeployKey removes a deploy key from a repository by fingerprint; any repo admin may remove it regardless of who added it.

func (*Store) RemoveMirror added in v0.2.0

func (s *Store) RemoveMirror(repoID, id int64) error

func (*Store) RemoveOrgMember

func (s *Store) RemoveOrgMember(orgID, userID int64) error

RemoveOrgMember drops a member, refusing to remove the last admin.

func (*Store) RemovePGPKey

func (s *Store) RemovePGPKey(userID int64, fingerprint string) error

func (*Store) RemovePageDomain added in v0.3.0

func (s *Store) RemovePageDomain(domain string, repoID int64) error

func (*Store) RemoveReleaseAsset added in v0.2.0

func (s *Store) RemoveReleaseAsset(releaseID int64, name string) error

func (*Store) RemoveSSHKey

func (s *Store) RemoveSSHKey(userID int64, fingerprint string) error

RemoveSSHKey removes a key owned by userID and bumps the key epoch.

func (*Store) RemoveSchedule added in v0.3.0

func (s *Store) RemoveSchedule(repoID int64, job string) error

func (*Store) RemoveTeamMember added in v0.3.0

func (s *Store) RemoveTeamMember(teamID, userID int64) error

func (*Store) RemoveTopic added in v0.2.0

func (s *Store) RemoveTopic(repoID int64, topic string) error

func (*Store) RemoveWebhook

func (s *Store) RemoveWebhook(repoID, hookID int64) error

func (*Store) RenameOrg

func (s *Store) RenameOrg(orgID int64, newName string) error

RenameOrg changes an org's name, holding the shared owner-namespace invariant. The caller moves the on-disk repos directory afterward.

func (*Store) RepoByID

func (s *Store) RepoByID(id int64) (Repo, error)

func (*Store) RepoByPath

func (s *Store) RepoByPath(path string) (Repo, error)

RepoByPath resolves "owner/name"; the owner may be a user or an org.

func (*Store) RepoNotifyTargets added in v0.2.0

func (s *Store) RepoNotifyTargets(repo Repo) ([]int64, error)

RepoNotifyTargets returns who should hear about new activity on a repo: the owning user, or every admin of the owning org.

func (*Store) ReviewQueue added in v0.5.0

func (s *Store) ReviewQueue(userID int64) ([]DashboardItem, error)

ReviewQueue returns open merge requests the user is involved in, has not authored, and has not reviewed at the current head — what the rail shows as waiting on them. Ordered most recently touched first.

func (*Store) RevokeAPIToken

func (s *Store) RevokeAPIToken(userID int64, name string) error

func (*Store) RevokeAccess

func (s *Store) RevokeAccess(repoID, userID int64) error

func (*Store) RevokeTeamRepo added in v0.3.0

func (s *Store) RevokeTeamRepo(teamID, repoID int64) error

func (*Store) SSHKeyByFingerprint

func (s *Store) SSHKeyByFingerprint(fingerprint string) (SSHKey, error)

func (*Store) SSHKeyByID

func (s *Store) SSHKeyByID(id int64) (SSHKey, error)

func (*Store) SetBuildSecret added in v0.3.0

func (s *Store) SetBuildSecret(repoID int64, name, value string) error

SetBuildSecret stores or replaces one secret. The value never leaves the server except inside a claimed build's environment.

func (*Store) SetCommitStatus added in v0.2.0

func (s *Store) SetCommitStatus(repoID int64, sha, context, state, description, targetURL string, creatorID int64) error

SetCommitStatus upserts the latest state for one context on one commit. A zero creatorID records no creator (system actions like the scheduler).

func (*Store) SetForkOf

func (s *Store) SetForkOf(repoID, parentID int64) error

func (*Store) SetImportMarker added in v0.2.0

func (s *Store) SetImportMarker(repoID int64, key, value string) error

func (*Store) SetIssueAssignee

func (s *Store) SetIssueAssignee(issueID, userID int64, add bool) error

SetIssueAssignee adds or removes an assignee by user id.

func (*Store) SetIssueLabel

func (s *Store) SetIssueLabel(repoID, issueID int64, name string, add bool) error

SetIssueLabel attaches (add) or detaches a label, creating the repo label on first use.

func (*Store) SetIssueMilestone added in v0.2.0

func (s *Store) SetIssueMilestone(issueID, milestoneID int64) error

SetIssueMilestone attaches (or with milestoneID 0 clears) a milestone.

func (*Store) SetIssueState

func (s *Store) SetIssueState(issueID int64, state string) error

func (*Store) SetMRMilestone added in v0.2.0

func (s *Store) SetMRMilestone(mrID, milestoneID int64) error

func (*Store) SetMRState

func (s *Store) SetMRState(mrID int64, state string) error

func (*Store) SetMilestoneState added in v0.2.0

func (s *Store) SetMilestoneState(id int64, state string) error

func (*Store) SetMirrorResult added in v0.2.0

func (s *Store) SetMirrorResult(id int64, syncErr string) error

SetMirrorResult records a sync outcome and clears the dirty flag.

func (*Store) SetOrgMember

func (s *Store) SetOrgMember(orgID, userID int64, role string) error

SetOrgMember adds a member or updates their role. Demoting the last admin is refused: an org must always have one.

func (*Store) SetOrgMembersRole added in v0.3.0

func (s *Store) SetOrgMembersRole(orgID int64, role string) error

func (*Store) SetOwnerProfile

func (s *Store) SetOwnerProfile(kind string, id int64, p Profile) error

SetOwnerProfile updates the profile for kind "user" or "org".

func (*Store) SetRepoSettings

func (s *Store) SetRepoSettings(repoID int64, settings RepoSettings) error

func (*Store) SetRepoVisibility added in v0.5.0

func (s *Store) SetRepoVisibility(repoID int64, visibility string) error

SetRepoVisibility switches a repository between public and private.

func (*Store) SetScheduleNext added in v0.3.0

func (s *Store) SetScheduleNext(repoID int64, job, nextRun string) error

SetScheduleNext advances one entry's next firing time.

func (*Store) SetThreadResolved added in v0.2.0

func (s *Store) SetThreadResolved(mrID, rootID, byUser int64, resolved bool) error

SetThreadResolved resolves or unresolves a thread root.

func (*Store) SetUserDisabled added in v0.2.0

func (s *Store) SetUserDisabled(userID int64, disabled bool) error

SetUserDisabled suspends or restores an account. Disabling also drops the user's web sessions; their keys and tokens stay registered but are refused at every entry point until re-enabled.

func (*Store) StoreSignature

func (s *Store) StoreSignature(repoID int64, sha string, r sig.Result, epoch int64) error

func (*Store) SyncSchedules added in v0.3.0

func (s *Store) SyncSchedules(repoID int64, entries []Schedule) error

SyncSchedules replaces a repo's schedule set with the given entries, preserving next_run for entries whose cron is unchanged.

func (*Store) TeamByName added in v0.3.0

func (s *Store) TeamByName(orgID int64, name string) (Team, error)

func (*Store) TeamGrants added in v0.3.0

func (s *Store) TeamGrants(teamID int64) ([]TeamGrant, error)

func (*Store) TeamMembers added in v0.3.0

func (s *Store) TeamMembers(teamID int64) ([]string, error)

func (*Store) TouchSSHKey

func (s *Store) TouchSSHKey(id int64) error

TouchSSHKey records key use; best-effort, callers ignore the error.

func (*Store) TransferRepo

func (s *Store) TransferRepo(repoID int64, newKind string, newOwnerID int64) error

TransferRepo moves a repository to a new owner. The unique index on (owner_kind, owner_id, name) refuses collisions in the target namespace.

func (*Store) TryRecordCommitRef added in v0.2.0

func (s *Store) TryRecordCommitRef(issueID int64, sha string) (bool, error)

TryRecordCommitRef marks a commit as having referenced an issue. It reports whether this pair was new — false means the reference was already processed and must not act again.

func (*Store) UnpinRepo added in v0.2.0

func (s *Store) UnpinRepo(userID, repoID int64) error

func (*Store) UnresolvedThreadCount added in v0.2.0

func (s *Store) UnresolvedThreadCount(mrID int64) (int, error)

UnresolvedThreadCount counts unresolved thread roots on an MR.

func (*Store) UpdateDefaultBranch

func (s *Store) UpdateDefaultBranch(repoID int64, branch string) error

func (*Store) UpdateIssueText added in v0.2.0

func (s *Store) UpdateIssueText(issueID int64, title, body *string) error

UpdateIssueText edits title and/or body; nil leaves a field unchanged.

func (*Store) UpdateMRHead

func (s *Store) UpdateMRHead(mrID int64, headSHA string) error

UpdateMRHead records a new head and marks every review at another head stale, in one transaction.

func (*Store) UpdateMRText added in v0.2.0

func (s *Store) UpdateMRText(mrID int64, title, body *string) error

UpdateMRText edits title and/or body; nil leaves a field unchanged.

func (*Store) UpdateRelease added in v0.4.0

func (s *Store) UpdateRelease(repoID int64, tag, title, notes string) error

UpdateRelease replaces a release's title and notes.

func (*Store) UserByID

func (s *Store) UserByID(id int64) (User, error)

func (*Store) UserByUsername

func (s *Store) UserByUsername(name string) (User, error)

func (*Store) UserEmailAddresses added in v0.2.0

func (s *Store) UserEmailAddresses(userID int64) ([]string, error)

UserEmailAddresses returns every address on the account, verified or not.

func (*Store) UserIDByVerifiedEmail added in v0.3.0

func (s *Store) UserIDByVerifiedEmail(address string) (int64, bool)

UserIDByVerifiedEmail resolves a commit author email to an account, only through addresses the account has verified — the same trust rule as signature attribution.

func (*Store) UsernameByVerifiedEmail added in v0.5.0

func (s *Store) UsernameByVerifiedEmail(address string) (string, bool)

UsernameByVerifiedEmail resolves a commit author address to the account that has proven it, so the forge can show its own name for a person rather than whatever git config happened to be set.

func (*Store) VerifyEmail

func (s *Store) VerifyEmail(userID int64, address, by string) error

VerifyEmail marks an address verified and bumps the key epoch (email verification is a trust input for signature states).

func (*Store) VerifyPageDomain added in v0.3.0

func (s *Store) VerifyPageDomain(domain string, repoID int64) error

VerifyPageDomain activates a pending claim.

func (*Store) Version

func (s *Store) Version() (int, error)

Version returns the current schema version (0 = empty database).

func (*Store) WebSessionUser

func (s *Store) WebSessionUser(hash string) (User, error)

WebSessionUser resolves a session cookie hash to its user.

type Team added in v0.3.0

type Team struct {
	ID    int64
	OrgID int64
	Name  string
}

type TeamGrant added in v0.3.0

type TeamGrant struct {
	RepoPath string `json:"repo"`
	Role     string `json:"role"`
}

type User

type User struct {
	ID       int64
	Username string
	IsAdmin  bool
	Pending  bool // self-registered, email not yet verified
	Disabled bool // administratively suspended
}

type Webhook

type Webhook struct {
	ID        int64
	URL       string
	Secret    string
	Events    string // "*" or comma-separated kinds
	Active    bool
	CreatedAt string
}

Source Files

  • activity.go
  • audit.go
  • builds.go
  • cisecrets.go
  • commentmigrate.go
  • commitrefs.go
  • dashboard.go
  • diffcomments.go
  • importmarkers.go
  • issues.go
  • lfs.go
  • milestones.go
  • mirrors.go
  • mrs.go
  • notify.go
  • orgs.go
  • pagedomains.go
  • registration.go
  • releases.go
  • repos.go
  • sessions.go
  • signatures.go
  • stats.go
  • statuses.go
  • store.go
  • teams.go
  • tokens.go
  • topics.go
  • users.go
  • webhooks.go

Jump to

Keyboard shortcuts

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