-
Notifications
You must be signed in to change notification settings - Fork 4
/
repository.go
242 lines (224 loc) · 8.15 KB
/
repository.go
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/go-faster/bot/internal/ent/organization"
"github.com/go-faster/bot/internal/ent/repository"
)
// Repository is the model entity for the Repository schema.
type Repository struct {
config `json:"-"`
// ID of the ent.
// GitHub repository ID.
ID int64 `json:"id,omitempty"`
// GitHub repository name.
Name string `json:"name,omitempty"`
// GitHub repository full name.
FullName string `json:"full_name,omitempty"`
// GitHub repository URL.
HTMLURL string `json:"html_url,omitempty"`
// GitHub repository description.
Description string `json:"description,omitempty"`
// LastPushedAt holds the value of the "last_pushed_at" field.
LastPushedAt time.Time `json:"last_pushed_at,omitempty"`
// LastEventAt holds the value of the "last_event_at" field.
LastEventAt time.Time `json:"last_event_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the RepositoryQuery when eager-loading is set.
Edges RepositoryEdges `json:"edges"`
organization_repositories *int64
selectValues sql.SelectValues
}
// RepositoryEdges holds the relations/edges for other nodes in the graph.
type RepositoryEdges struct {
// GitHub organization.
Organization *Organization `json:"organization,omitempty"`
// Commits.
Commits []*GitCommit `json:"commits,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [2]bool
namedCommits map[string][]*GitCommit
}
// OrganizationOrErr returns the Organization value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e RepositoryEdges) OrganizationOrErr() (*Organization, error) {
if e.Organization != nil {
return e.Organization, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: organization.Label}
}
return nil, &NotLoadedError{edge: "organization"}
}
// CommitsOrErr returns the Commits value or an error if the edge
// was not loaded in eager-loading.
func (e RepositoryEdges) CommitsOrErr() ([]*GitCommit, error) {
if e.loadedTypes[1] {
return e.Commits, nil
}
return nil, &NotLoadedError{edge: "commits"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Repository) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case repository.FieldID:
values[i] = new(sql.NullInt64)
case repository.FieldName, repository.FieldFullName, repository.FieldHTMLURL, repository.FieldDescription:
values[i] = new(sql.NullString)
case repository.FieldLastPushedAt, repository.FieldLastEventAt:
values[i] = new(sql.NullTime)
case repository.ForeignKeys[0]: // organization_repositories
values[i] = new(sql.NullInt64)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Repository fields.
func (r *Repository) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case repository.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
r.ID = int64(value.Int64)
case repository.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
r.Name = value.String
}
case repository.FieldFullName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field full_name", values[i])
} else if value.Valid {
r.FullName = value.String
}
case repository.FieldHTMLURL:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field html_url", values[i])
} else if value.Valid {
r.HTMLURL = value.String
}
case repository.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
r.Description = value.String
}
case repository.FieldLastPushedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field last_pushed_at", values[i])
} else if value.Valid {
r.LastPushedAt = value.Time
}
case repository.FieldLastEventAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field last_event_at", values[i])
} else if value.Valid {
r.LastEventAt = value.Time
}
case repository.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field organization_repositories", value)
} else if value.Valid {
r.organization_repositories = new(int64)
*r.organization_repositories = int64(value.Int64)
}
default:
r.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Repository.
// This includes values selected through modifiers, order, etc.
func (r *Repository) Value(name string) (ent.Value, error) {
return r.selectValues.Get(name)
}
// QueryOrganization queries the "organization" edge of the Repository entity.
func (r *Repository) QueryOrganization() *OrganizationQuery {
return NewRepositoryClient(r.config).QueryOrganization(r)
}
// QueryCommits queries the "commits" edge of the Repository entity.
func (r *Repository) QueryCommits() *GitCommitQuery {
return NewRepositoryClient(r.config).QueryCommits(r)
}
// Update returns a builder for updating this Repository.
// Note that you need to call Repository.Unwrap() before calling this method if this Repository
// was returned from a transaction, and the transaction was committed or rolled back.
func (r *Repository) Update() *RepositoryUpdateOne {
return NewRepositoryClient(r.config).UpdateOne(r)
}
// Unwrap unwraps the Repository entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (r *Repository) Unwrap() *Repository {
_tx, ok := r.config.driver.(*txDriver)
if !ok {
panic("ent: Repository is not a transactional entity")
}
r.config.driver = _tx.drv
return r
}
// String implements the fmt.Stringer.
func (r *Repository) String() string {
var builder strings.Builder
builder.WriteString("Repository(")
builder.WriteString(fmt.Sprintf("id=%v, ", r.ID))
builder.WriteString("name=")
builder.WriteString(r.Name)
builder.WriteString(", ")
builder.WriteString("full_name=")
builder.WriteString(r.FullName)
builder.WriteString(", ")
builder.WriteString("html_url=")
builder.WriteString(r.HTMLURL)
builder.WriteString(", ")
builder.WriteString("description=")
builder.WriteString(r.Description)
builder.WriteString(", ")
builder.WriteString("last_pushed_at=")
builder.WriteString(r.LastPushedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("last_event_at=")
builder.WriteString(r.LastEventAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// NamedCommits returns the Commits named value or an error if the edge was not
// loaded in eager-loading with this name.
func (r *Repository) NamedCommits(name string) ([]*GitCommit, error) {
if r.Edges.namedCommits == nil {
return nil, &NotLoadedError{edge: name}
}
nodes, ok := r.Edges.namedCommits[name]
if !ok {
return nil, &NotLoadedError{edge: name}
}
return nodes, nil
}
func (r *Repository) appendNamedCommits(name string, edges ...*GitCommit) {
if r.Edges.namedCommits == nil {
r.Edges.namedCommits = make(map[string][]*GitCommit)
}
if len(edges) == 0 {
r.Edges.namedCommits[name] = []*GitCommit{}
} else {
r.Edges.namedCommits[name] = append(r.Edges.namedCommits[name], edges...)
}
}
// Repositories is a parsable slice of Repository.
type Repositories []*Repository