forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_factory.go
72 lines (57 loc) · 1.4 KB
/
build_factory.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
package db
import (
"database/sql"
"github.com/lib/pq"
)
func newBuildFactory(conn Conn, bus *notificationsBus) *buildFactory {
return &buildFactory{
conn: conn,
bus: bus,
}
}
type buildFactory struct {
conn Conn
bus *notificationsBus
}
func (f *buildFactory) ScanBuild(row scannable) (Build, bool, error) {
var id int
var name string
var jobID, pipelineID, teamID sql.NullInt64
var status string
var scheduled bool
var engine, engineMetadata, jobName, pipelineName sql.NullString
var startTime pq.NullTime
var endTime pq.NullTime
var reapTime pq.NullTime
var teamName string
err := row.Scan(&id, &name, &jobID, &teamID, &status, &scheduled, &engine, &engineMetadata, &startTime, &endTime, &reapTime, &jobName, &pipelineID, &pipelineName, &teamName)
if err != nil {
if err == sql.ErrNoRows {
return nil, false, nil
}
return nil, false, err
}
build := &build{
conn: f.conn,
bus: f.bus,
id: id,
name: name,
status: Status(status),
scheduled: scheduled,
engine: engine.String,
engineMetadata: engineMetadata.String,
startTime: startTime.Time,
endTime: endTime.Time,
reapTime: reapTime.Time,
teamName: teamName,
}
if jobID.Valid {
build.jobName = jobName.String
build.pipelineName = pipelineName.String
build.pipelineID = int(pipelineID.Int64)
}
if teamID.Valid {
build.teamID = int(teamID.Int64)
}
return build, true, nil
}