-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathmodels.go
More file actions
119 lines (101 loc) · 2.9 KB
/
models.go
File metadata and controls
119 lines (101 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package models
//go:generate kallax gen
import (
"time"
"github.com/gogo/protobuf/types"
"github.com/src-d/lookout"
"gopkg.in/src-d/go-kallax.v1"
)
// ReviewEvent is a persisted model for review event
type ReviewEvent struct {
kallax.Model `pk:"id"`
ID kallax.ULID
Status EventStatus
InternalID string
// those fields can change with each push
IsMergeable bool
Source lookout.ReferencePointer
Configuration types.Struct
Base lookout.ReferencePointer
Head lookout.ReferencePointer
CreatedAt time.Time
UpdatedAt time.Time
// static part of review
ReviewTarget *ReviewTarget `fk:",inverse"`
}
func newReviewEvent(e *lookout.ReviewEvent) *ReviewEvent {
return &ReviewEvent{
ID: kallax.NewULID(),
Status: EventStatusNew,
InternalID: e.ID().String(),
IsMergeable: e.IsMergeable,
Source: e.Source,
Configuration: e.Configuration,
Base: e.Base,
Head: e.Head,
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
}
}
// ReviewTarget is a persisted model for a pull request
type ReviewTarget struct {
kallax.Model `pk:"id"`
ID kallax.ULID
kallax.Timestamps
Provider string
InternalID string
RepositoryID uint32
Number uint32
}
func newReviewTarget(e *lookout.ReviewEvent) *ReviewTarget {
return &ReviewTarget{
ID: kallax.NewULID(),
Provider: e.Provider,
InternalID: e.InternalID,
RepositoryID: e.RepositoryID,
Number: e.Number,
}
}
// PushEvent is a persisted model for review event
type PushEvent struct {
kallax.Model `pk:"id"`
ID kallax.ULID
Status EventStatus
// can't be pointer or kallax panics
lookout.PushEvent `kallax:",inline"`
}
func newPushEvent(e *lookout.PushEvent) *PushEvent {
return &PushEvent{ID: kallax.NewULID(), Status: EventStatusNew, PushEvent: *e}
}
// Comment is a persisted model for comment
type Comment struct {
kallax.Model `pk:"id"`
kallax.Timestamps
ID kallax.ULID
ReviewEvent *ReviewEvent `fk:",inverse"`
lookout.Comment `kallax:",inline"`
Analyzer string
}
func newComment(r *ReviewEvent, c *lookout.Comment) *Comment {
return &Comment{ID: kallax.NewULID(), ReviewEvent: r, Comment: *c}
}
// Organization is a persisted model for an Organization (e.g. a GitHub App
// installation). It contains settings for a group of repositories.
// The primary key should be (Provider,InternalID), but kallax does not support
// composite or string keys. It also does not support setting uniqueness on
// multiple columns.
type Organization struct {
kallax.Model `pk:"id"`
ID kallax.ULID
Provider string
InternalID string
Config string
}
func newOrganization(provider string, internalID string, config string) *Organization {
return &Organization{
ID: kallax.NewULID(),
Provider: provider,
InternalID: internalID,
Config: config,
}
}