This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdeploymentstatus.go
67 lines (56 loc) · 1.84 KB
/
deploymentstatus.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
package store
import (
"context"
"fmt"
"github.com/gitploy-io/gitploy/model/ent"
"github.com/gitploy-io/gitploy/model/ent/deploymentstatus"
"github.com/gitploy-io/gitploy/pkg/e"
)
func (s *Store) ListDeploymentStatuses(ctx context.Context, d *ent.Deployment) ([]*ent.DeploymentStatus, error) {
dss, err := s.c.DeploymentStatus.
Query().
Where(deploymentstatus.DeploymentIDEQ(d.ID)).
All(ctx)
if err != nil {
return nil, e.NewErrorWithMessage(e.ErrorCodeInternalError, "Failed to list deployment statuses.", err)
}
return dss, nil
}
func (s *Store) FindDeploymentStatusByID(ctx context.Context, id int) (*ent.DeploymentStatus, error) {
ds, err := s.c.DeploymentStatus.Query().
Where(deploymentstatus.IDEQ(id)).
WithDeployment().
WithRepo().
Only(ctx)
if ent.IsNotFound(err) {
return nil, e.NewError(e.ErrorCodeEntityNotFound, err)
} else if err != nil {
return nil, e.NewErrorWithMessage(e.ErrorCodeInternalError, "Failed to find deployment status.", err)
}
return ds, nil
}
func (s *Store) CreateEntDeploymentStatus(ctx context.Context, ds *ent.DeploymentStatus) (*ent.DeploymentStatus, error) {
// Build the query creating a deployment status.
qry := s.c.DeploymentStatus.Create().
SetStatus(ds.Status).
SetDescription(ds.Description).
SetLogURL(ds.LogURL).
SetDeploymentID(ds.DeploymentID).
SetRepoID(ds.RepoID)
if !ds.CreatedAt.IsZero() {
qry.SetCreatedAt(ds.CreatedAt.UTC())
}
if !ds.UpdatedAt.IsZero() {
qry.SetUpdatedAt(ds.UpdatedAt.UTC())
}
ret, err := qry.Save(ctx)
if ent.IsConstraintError(err) {
return nil, e.NewErrorWithMessage(
e.ErrorCodeEntityUnprocessable,
fmt.Sprintf("Failed to create a deployment status. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name),
err)
} else if err != nil {
return nil, e.NewError(e.ErrorCodeInternalError, err)
}
return ret, nil
}