repos / git-pr

a self-hosted git collaboration server
git clone https://github.com/picosh/git-pr.git

Eric Bower  ·  2024-11-12

models.go

 1package git
 2
 3import (
 4	"database/sql"
 5	"time"
 6
 7	"github.com/bluekeyes/go-gitdiff/gitdiff"
 8)
 9
10// User is a db model for users.
11type User struct {
12	ID        int64     `db:"id"`
13	Pubkey    string    `db:"pubkey"`
14	Name      string    `db:"name"`
15	CreatedAt time.Time `db:"created_at"`
16	UpdatedAt time.Time `db:"updated_at"`
17}
18
19// Acl is a db model for access control.
20type Acl struct {
21	ID         int64          `db:"id"`
22	Pubkey     sql.NullString `db:"pubkey"`
23	IpAddress  sql.NullString `db:"ip_address"`
24	Permission string         `db:"permission"`
25	CreatedAt  time.Time      `db:"created_at"`
26}
27
28// Repo is a container for patch requests.
29type Repo struct {
30	ID        int64     `db:"id"`
31	Name      string    `db:"name"`
32	UserID    int64     `db:"user_id"`
33	CreatedAt time.Time `db:"created_at"`
34	UpdatedAt time.Time `db:"updated_at"`
35}
36
37// PatchRequest is a database model for patches submitted to a Repo.
38type PatchRequest struct {
39	ID        int64     `db:"id"`
40	UserID    int64     `db:"user_id"`
41	RepoID    int64     `db:"repo_id"`
42	Name      string    `db:"name"`
43	Text      string    `db:"text"`
44	Status    string    `db:"status"`
45	CreatedAt time.Time `db:"created_at"`
46	UpdatedAt time.Time `db:"updated_at"`
47	// only used for aggregate queries
48	LastUpdated string `db:"last_updated"`
49}
50
51type Patchset struct {
52	ID             int64     `db:"id"`
53	UserID         int64     `db:"user_id"`
54	PatchRequestID int64     `db:"patch_request_id"`
55	Review         bool      `db:"review"`
56	CreatedAt      time.Time `db:"created_at"`
57}
58
59// Patch is a database model for a single entry in a patchset.
60// This usually corresponds to a git commit.
61type Patch struct {
62	ID            int64          `db:"id"`
63	UserID        int64          `db:"user_id"`
64	PatchsetID    int64          `db:"patchset_id"`
65	AuthorName    string         `db:"author_name"`
66	AuthorEmail   string         `db:"author_email"`
67	AuthorDate    time.Time      `db:"author_date"`
68	Title         string         `db:"title"`
69	Body          string         `db:"body"`
70	BodyAppendix  string         `db:"body_appendix"`
71	CommitSha     string         `db:"commit_sha"`
72	ContentSha    string         `db:"content_sha"`
73	BaseCommitSha sql.NullString `db:"base_commit_sha"`
74	RawText       string         `db:"raw_text"`
75	CreatedAt     time.Time      `db:"created_at"`
76	Files         []*gitdiff.File
77}
78
79func (p *Patch) CalcDiff() string {
80	return p.RawText
81}
82
83// EventLog is a event log for RSS or other notification systems.
84type EventLog struct {
85	ID             int64         `db:"id"`
86	UserID         int64         `db:"user_id"`
87	RepoID         sql.NullInt64 `db:"repo_id"`
88	PatchRequestID sql.NullInt64 `db:"patch_request_id"`
89	PatchsetID     sql.NullInt64 `db:"patchset_id"`
90	Event          string        `db:"event"`
91	Data           string        `db:"data"`
92	CreatedAt      time.Time     `db:"created_at"`
93}