diff --git a/docs/concepts/metrics.md b/docs/concepts/metrics.md
index 2e713b0c..0e8a2a49 100644
--- a/docs/concepts/metrics.md
+++ b/docs/concepts/metrics.md
@@ -28,10 +28,14 @@ scrape_configs:
## Gitploy Metrics
-Gitploy provides the following Gitploy metrics:
+Gitploy provides the following Gitploy metrics. *Note that Some metrics are provided only for the production environment* (i.e. `production_environment: true` in the configuration file).
* **gitploy_requests_total**
How many HTTP requests processed, partitioned by status code and HTTP method.
* **gitploy_request_duration_seconds**
The HTTP request latencies in seconds.
-* **gitploy_deployment_count**
The total count of success deployment for each environment, respectively.
+* **gitploy_deployment_count**
The count of success deployment of the production environment.
+* **gitploy_rollback_count**
The count of rollback of the production environment.
+* **gitploy_line_additions**
The count of added lines from the latest deployment of the production environment.
+* **gitploy_line_deletions**
The count of deleted lines from the latest deployment of the production environment.
+* **gitploy_line_changes**
The count of changed lines from the latest deployment of the production environment.
* **gitploy_member_count**
The total count of members.
-* **gitploy_member_limit**
The limit count of members.
\ No newline at end of file
+* **gitploy_member_limit**
The limit count of members.
diff --git a/ent/client.go b/ent/client.go
index 67418bd5..ad4a6c81 100644
--- a/ent/client.go
+++ b/ent/client.go
@@ -804,6 +804,22 @@ func (c *DeploymentStatisticsClient) GetX(ctx context.Context, id int) *Deployme
return obj
}
+// QueryRepo queries the repo edge of a DeploymentStatistics.
+func (c *DeploymentStatisticsClient) QueryRepo(ds *DeploymentStatistics) *RepoQuery {
+ query := &RepoQuery{config: c.config}
+ query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
+ id := ds.ID
+ step := sqlgraph.NewStep(
+ sqlgraph.From(deploymentstatistics.Table, deploymentstatistics.FieldID, id),
+ sqlgraph.To(repo.Table, repo.FieldID),
+ sqlgraph.Edge(sqlgraph.M2O, true, deploymentstatistics.RepoTable, deploymentstatistics.RepoColumn),
+ )
+ fromV = sqlgraph.Neighbors(ds.driver.Dialect(), step)
+ return fromV, nil
+ }
+ return query
+}
+
// Hooks returns the client hooks.
func (c *DeploymentStatisticsClient) Hooks() []Hook {
return c.hooks.DeploymentStatistics
@@ -1552,6 +1568,22 @@ func (c *RepoClient) QueryLocks(r *Repo) *LockQuery {
return query
}
+// QueryDeploymentStatistics queries the deployment_statistics edge of a Repo.
+func (c *RepoClient) QueryDeploymentStatistics(r *Repo) *DeploymentStatisticsQuery {
+ query := &DeploymentStatisticsQuery{config: c.config}
+ query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
+ id := r.ID
+ step := sqlgraph.NewStep(
+ sqlgraph.From(repo.Table, repo.FieldID, id),
+ sqlgraph.To(deploymentstatistics.Table, deploymentstatistics.FieldID),
+ sqlgraph.Edge(sqlgraph.O2M, false, repo.DeploymentStatisticsTable, repo.DeploymentStatisticsColumn),
+ )
+ fromV = sqlgraph.Neighbors(r.driver.Dialect(), step)
+ return fromV, nil
+ }
+ return query
+}
+
// Hooks returns the client hooks.
func (c *RepoClient) Hooks() []Hook {
return c.hooks.Repo
diff --git a/ent/deployment.go b/ent/deployment.go
index cbdf6f1f..c736f41c 100644
--- a/ent/deployment.go
+++ b/ent/deployment.go
@@ -34,6 +34,8 @@ type Deployment struct {
Sha string `json:"sha,omitemtpy"`
// HTMLURL holds the value of the "html_url" field.
HTMLURL string `json:"html_url,omitemtpy"`
+ // ProductionEnvironment holds the value of the "production_environment" field.
+ ProductionEnvironment bool `json:"production_environment"`
// IsRollback holds the value of the "is_rollback" field.
IsRollback bool `json:"is_rollback"`
// IsApprovalEnabled holds the value of the "is_approval_enabled" field.
@@ -130,7 +132,7 @@ func (*Deployment) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
- case deployment.FieldIsRollback, deployment.FieldIsApprovalEnabled:
+ case deployment.FieldProductionEnvironment, deployment.FieldIsRollback, deployment.FieldIsApprovalEnabled:
values[i] = new(sql.NullBool)
case deployment.FieldID, deployment.FieldNumber, deployment.FieldUID, deployment.FieldRequiredApprovalCount, deployment.FieldUserID, deployment.FieldRepoID:
values[i] = new(sql.NullInt64)
@@ -207,6 +209,12 @@ func (d *Deployment) assignValues(columns []string, values []interface{}) error
} else if value.Valid {
d.HTMLURL = value.String
}
+ case deployment.FieldProductionEnvironment:
+ if value, ok := values[i].(*sql.NullBool); !ok {
+ return fmt.Errorf("unexpected type %T for field production_environment", values[i])
+ } else if value.Valid {
+ d.ProductionEnvironment = value.Bool
+ }
case deployment.FieldIsRollback:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_rollback", values[i])
@@ -318,6 +326,8 @@ func (d *Deployment) String() string {
builder.WriteString(d.Sha)
builder.WriteString(", html_url=")
builder.WriteString(d.HTMLURL)
+ builder.WriteString(", production_environment=")
+ builder.WriteString(fmt.Sprintf("%v", d.ProductionEnvironment))
builder.WriteString(", is_rollback=")
builder.WriteString(fmt.Sprintf("%v", d.IsRollback))
builder.WriteString(", is_approval_enabled=")
diff --git a/ent/deployment/deployment.go b/ent/deployment/deployment.go
index 6ae273d1..1a694c35 100644
--- a/ent/deployment/deployment.go
+++ b/ent/deployment/deployment.go
@@ -28,6 +28,8 @@ const (
FieldSha = "sha"
// FieldHTMLURL holds the string denoting the html_url field in the database.
FieldHTMLURL = "html_url"
+ // FieldProductionEnvironment holds the string denoting the production_environment field in the database.
+ FieldProductionEnvironment = "production_environment"
// FieldIsRollback holds the string denoting the is_rollback field in the database.
FieldIsRollback = "is_rollback"
// FieldIsApprovalEnabled holds the string denoting the is_approval_enabled field in the database.
@@ -102,6 +104,7 @@ var Columns = []string{
FieldUID,
FieldSha,
FieldHTMLURL,
+ FieldProductionEnvironment,
FieldIsRollback,
FieldIsApprovalEnabled,
FieldRequiredApprovalCount,
@@ -124,6 +127,8 @@ func ValidColumn(column string) bool {
var (
// HTMLURLValidator is a validator for the "html_url" field. It is called by the builders before save.
HTMLURLValidator func(string) error
+ // DefaultProductionEnvironment holds the default value on creation for the "production_environment" field.
+ DefaultProductionEnvironment bool
// DefaultIsRollback holds the default value on creation for the "is_rollback" field.
DefaultIsRollback bool
// DefaultIsApprovalEnabled holds the default value on creation for the "is_approval_enabled" field.
diff --git a/ent/deployment/where.go b/ent/deployment/where.go
index 18458ac9..46554dd1 100644
--- a/ent/deployment/where.go
+++ b/ent/deployment/where.go
@@ -135,6 +135,13 @@ func HTMLURL(v string) predicate.Deployment {
})
}
+// ProductionEnvironment applies equality check predicate on the "production_environment" field. It's identical to ProductionEnvironmentEQ.
+func ProductionEnvironment(v bool) predicate.Deployment {
+ return predicate.Deployment(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldProductionEnvironment), v))
+ })
+}
+
// IsRollback applies equality check predicate on the "is_rollback" field. It's identical to IsRollbackEQ.
func IsRollback(v bool) predicate.Deployment {
return predicate.Deployment(func(s *sql.Selector) {
@@ -918,6 +925,20 @@ func HTMLURLContainsFold(v string) predicate.Deployment {
})
}
+// ProductionEnvironmentEQ applies the EQ predicate on the "production_environment" field.
+func ProductionEnvironmentEQ(v bool) predicate.Deployment {
+ return predicate.Deployment(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldProductionEnvironment), v))
+ })
+}
+
+// ProductionEnvironmentNEQ applies the NEQ predicate on the "production_environment" field.
+func ProductionEnvironmentNEQ(v bool) predicate.Deployment {
+ return predicate.Deployment(func(s *sql.Selector) {
+ s.Where(sql.NEQ(s.C(FieldProductionEnvironment), v))
+ })
+}
+
// IsRollbackEQ applies the EQ predicate on the "is_rollback" field.
func IsRollbackEQ(v bool) predicate.Deployment {
return predicate.Deployment(func(s *sql.Selector) {
diff --git a/ent/deployment_create.go b/ent/deployment_create.go
index 0b51ee17..2ea27bfe 100644
--- a/ent/deployment_create.go
+++ b/ent/deployment_create.go
@@ -113,6 +113,20 @@ func (dc *DeploymentCreate) SetNillableHTMLURL(s *string) *DeploymentCreate {
return dc
}
+// SetProductionEnvironment sets the "production_environment" field.
+func (dc *DeploymentCreate) SetProductionEnvironment(b bool) *DeploymentCreate {
+ dc.mutation.SetProductionEnvironment(b)
+ return dc
+}
+
+// SetNillableProductionEnvironment sets the "production_environment" field if the given value is not nil.
+func (dc *DeploymentCreate) SetNillableProductionEnvironment(b *bool) *DeploymentCreate {
+ if b != nil {
+ dc.SetProductionEnvironment(*b)
+ }
+ return dc
+}
+
// SetIsRollback sets the "is_rollback" field.
func (dc *DeploymentCreate) SetIsRollback(b bool) *DeploymentCreate {
dc.mutation.SetIsRollback(b)
@@ -329,6 +343,10 @@ func (dc *DeploymentCreate) defaults() {
v := deployment.DefaultStatus
dc.mutation.SetStatus(v)
}
+ if _, ok := dc.mutation.ProductionEnvironment(); !ok {
+ v := deployment.DefaultProductionEnvironment
+ dc.mutation.SetProductionEnvironment(v)
+ }
if _, ok := dc.mutation.IsRollback(); !ok {
v := deployment.DefaultIsRollback
dc.mutation.SetIsRollback(v)
@@ -383,6 +401,9 @@ func (dc *DeploymentCreate) check() error {
return &ValidationError{Name: "html_url", err: fmt.Errorf(`ent: validator failed for field "html_url": %w`, err)}
}
}
+ if _, ok := dc.mutation.ProductionEnvironment(); !ok {
+ return &ValidationError{Name: "production_environment", err: errors.New(`ent: missing required field "production_environment"`)}
+ }
if _, ok := dc.mutation.IsRollback(); !ok {
return &ValidationError{Name: "is_rollback", err: errors.New(`ent: missing required field "is_rollback"`)}
}
@@ -501,6 +522,14 @@ func (dc *DeploymentCreate) createSpec() (*Deployment, *sqlgraph.CreateSpec) {
})
_node.HTMLURL = value
}
+ if value, ok := dc.mutation.ProductionEnvironment(); ok {
+ _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
+ Type: field.TypeBool,
+ Value: value,
+ Column: deployment.FieldProductionEnvironment,
+ })
+ _node.ProductionEnvironment = value
+ }
if value, ok := dc.mutation.IsRollback(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeBool,
diff --git a/ent/deployment_update.go b/ent/deployment_update.go
index 859cd4a8..756e0621 100644
--- a/ent/deployment_update.go
+++ b/ent/deployment_update.go
@@ -153,6 +153,20 @@ func (du *DeploymentUpdate) ClearHTMLURL() *DeploymentUpdate {
return du
}
+// SetProductionEnvironment sets the "production_environment" field.
+func (du *DeploymentUpdate) SetProductionEnvironment(b bool) *DeploymentUpdate {
+ du.mutation.SetProductionEnvironment(b)
+ return du
+}
+
+// SetNillableProductionEnvironment sets the "production_environment" field if the given value is not nil.
+func (du *DeploymentUpdate) SetNillableProductionEnvironment(b *bool) *DeploymentUpdate {
+ if b != nil {
+ du.SetProductionEnvironment(*b)
+ }
+ return du
+}
+
// SetIsRollback sets the "is_rollback" field.
func (du *DeploymentUpdate) SetIsRollback(b bool) *DeploymentUpdate {
du.mutation.SetIsRollback(b)
@@ -570,6 +584,13 @@ func (du *DeploymentUpdate) sqlSave(ctx context.Context) (n int, err error) {
Column: deployment.FieldHTMLURL,
})
}
+ if value, ok := du.mutation.ProductionEnvironment(); ok {
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
+ Type: field.TypeBool,
+ Value: value,
+ Column: deployment.FieldProductionEnvironment,
+ })
+ }
if value, ok := du.mutation.IsRollback(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeBool,
@@ -983,6 +1004,20 @@ func (duo *DeploymentUpdateOne) ClearHTMLURL() *DeploymentUpdateOne {
return duo
}
+// SetProductionEnvironment sets the "production_environment" field.
+func (duo *DeploymentUpdateOne) SetProductionEnvironment(b bool) *DeploymentUpdateOne {
+ duo.mutation.SetProductionEnvironment(b)
+ return duo
+}
+
+// SetNillableProductionEnvironment sets the "production_environment" field if the given value is not nil.
+func (duo *DeploymentUpdateOne) SetNillableProductionEnvironment(b *bool) *DeploymentUpdateOne {
+ if b != nil {
+ duo.SetProductionEnvironment(*b)
+ }
+ return duo
+}
+
// SetIsRollback sets the "is_rollback" field.
func (duo *DeploymentUpdateOne) SetIsRollback(b bool) *DeploymentUpdateOne {
duo.mutation.SetIsRollback(b)
@@ -1424,6 +1459,13 @@ func (duo *DeploymentUpdateOne) sqlSave(ctx context.Context) (_node *Deployment,
Column: deployment.FieldHTMLURL,
})
}
+ if value, ok := duo.mutation.ProductionEnvironment(); ok {
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
+ Type: field.TypeBool,
+ Value: value,
+ Column: deployment.FieldProductionEnvironment,
+ })
+ }
if value, ok := duo.mutation.IsRollback(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeBool,
diff --git a/ent/deploymentstatistics.go b/ent/deploymentstatistics.go
index 17f656b0..441631ba 100644
--- a/ent/deploymentstatistics.go
+++ b/ent/deploymentstatistics.go
@@ -9,6 +9,7 @@ import (
"entgo.io/ent/dialect/sql"
"github.com/gitploy-io/gitploy/ent/deploymentstatistics"
+ "github.com/gitploy-io/gitploy/ent/repo"
)
// DeploymentStatistics is the model entity for the DeploymentStatistics schema.
@@ -16,18 +17,50 @@ type DeploymentStatistics struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
- // Namespace holds the value of the "namespace" field.
- Namespace string `json:"namespace"`
- // Name holds the value of the "name" field.
- Name string `json:"name"`
// Env holds the value of the "env" field.
Env string `json:"env"`
// Count holds the value of the "count" field.
Count int `json:"count"`
+ // RollbackCount holds the value of the "rollback_count" field.
+ RollbackCount int `json:"rollback_count"`
+ // Additions holds the value of the "additions" field.
+ Additions int `json:"additions"`
+ // Deletions holds the value of the "deletions" field.
+ Deletions int `json:"deletions"`
+ // Changes holds the value of the "changes" field.
+ Changes int `json:"changes"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at"`
+ // RepoID holds the value of the "repo_id" field.
+ RepoID int64 `json:"repo_id"`
+ // Edges holds the relations/edges for other nodes in the graph.
+ // The values are being populated by the DeploymentStatisticsQuery when eager-loading is set.
+ Edges DeploymentStatisticsEdges `json:"edges"`
+}
+
+// DeploymentStatisticsEdges holds the relations/edges for other nodes in the graph.
+type DeploymentStatisticsEdges struct {
+ // Repo holds the value of the repo edge.
+ Repo *Repo `json:"repo,omitempty"`
+ // loadedTypes holds the information for reporting if a
+ // type was loaded (or requested) in eager-loading or not.
+ loadedTypes [1]bool
+}
+
+// RepoOrErr returns the Repo value or an error if the edge
+// was not loaded in eager-loading, or loaded but was not found.
+func (e DeploymentStatisticsEdges) RepoOrErr() (*Repo, error) {
+ if e.loadedTypes[0] {
+ if e.Repo == nil {
+ // The edge repo was loaded in eager-loading,
+ // but was not found.
+ return nil, &NotFoundError{label: repo.Label}
+ }
+ return e.Repo, nil
+ }
+ return nil, &NotLoadedError{edge: "repo"}
}
// scanValues returns the types for scanning values from sql.Rows.
@@ -35,9 +68,9 @@ func (*DeploymentStatistics) scanValues(columns []string) ([]interface{}, error)
values := make([]interface{}, len(columns))
for i := range columns {
switch columns[i] {
- case deploymentstatistics.FieldID, deploymentstatistics.FieldCount:
+ case deploymentstatistics.FieldID, deploymentstatistics.FieldCount, deploymentstatistics.FieldRollbackCount, deploymentstatistics.FieldAdditions, deploymentstatistics.FieldDeletions, deploymentstatistics.FieldChanges, deploymentstatistics.FieldRepoID:
values[i] = new(sql.NullInt64)
- case deploymentstatistics.FieldNamespace, deploymentstatistics.FieldName, deploymentstatistics.FieldEnv:
+ case deploymentstatistics.FieldEnv:
values[i] = new(sql.NullString)
case deploymentstatistics.FieldCreatedAt, deploymentstatistics.FieldUpdatedAt:
values[i] = new(sql.NullTime)
@@ -62,18 +95,6 @@ func (ds *DeploymentStatistics) assignValues(columns []string, values []interfac
return fmt.Errorf("unexpected type %T for field id", value)
}
ds.ID = int(value.Int64)
- case deploymentstatistics.FieldNamespace:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field namespace", values[i])
- } else if value.Valid {
- ds.Namespace = value.String
- }
- case deploymentstatistics.FieldName:
- if value, ok := values[i].(*sql.NullString); !ok {
- return fmt.Errorf("unexpected type %T for field name", values[i])
- } else if value.Valid {
- ds.Name = value.String
- }
case deploymentstatistics.FieldEnv:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field env", values[i])
@@ -86,6 +107,30 @@ func (ds *DeploymentStatistics) assignValues(columns []string, values []interfac
} else if value.Valid {
ds.Count = int(value.Int64)
}
+ case deploymentstatistics.FieldRollbackCount:
+ if value, ok := values[i].(*sql.NullInt64); !ok {
+ return fmt.Errorf("unexpected type %T for field rollback_count", values[i])
+ } else if value.Valid {
+ ds.RollbackCount = int(value.Int64)
+ }
+ case deploymentstatistics.FieldAdditions:
+ if value, ok := values[i].(*sql.NullInt64); !ok {
+ return fmt.Errorf("unexpected type %T for field additions", values[i])
+ } else if value.Valid {
+ ds.Additions = int(value.Int64)
+ }
+ case deploymentstatistics.FieldDeletions:
+ if value, ok := values[i].(*sql.NullInt64); !ok {
+ return fmt.Errorf("unexpected type %T for field deletions", values[i])
+ } else if value.Valid {
+ ds.Deletions = int(value.Int64)
+ }
+ case deploymentstatistics.FieldChanges:
+ if value, ok := values[i].(*sql.NullInt64); !ok {
+ return fmt.Errorf("unexpected type %T for field changes", values[i])
+ } else if value.Valid {
+ ds.Changes = int(value.Int64)
+ }
case deploymentstatistics.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
@@ -98,11 +143,22 @@ func (ds *DeploymentStatistics) assignValues(columns []string, values []interfac
} else if value.Valid {
ds.UpdatedAt = value.Time
}
+ case deploymentstatistics.FieldRepoID:
+ if value, ok := values[i].(*sql.NullInt64); !ok {
+ return fmt.Errorf("unexpected type %T for field repo_id", values[i])
+ } else if value.Valid {
+ ds.RepoID = value.Int64
+ }
}
}
return nil
}
+// QueryRepo queries the "repo" edge of the DeploymentStatistics entity.
+func (ds *DeploymentStatistics) QueryRepo() *RepoQuery {
+ return (&DeploymentStatisticsClient{config: ds.config}).QueryRepo(ds)
+}
+
// Update returns a builder for updating this DeploymentStatistics.
// Note that you need to call DeploymentStatistics.Unwrap() before calling this method if this DeploymentStatistics
// was returned from a transaction, and the transaction was committed or rolled back.
@@ -126,18 +182,24 @@ func (ds *DeploymentStatistics) String() string {
var builder strings.Builder
builder.WriteString("DeploymentStatistics(")
builder.WriteString(fmt.Sprintf("id=%v", ds.ID))
- builder.WriteString(", namespace=")
- builder.WriteString(ds.Namespace)
- builder.WriteString(", name=")
- builder.WriteString(ds.Name)
builder.WriteString(", env=")
builder.WriteString(ds.Env)
builder.WriteString(", count=")
builder.WriteString(fmt.Sprintf("%v", ds.Count))
+ builder.WriteString(", rollback_count=")
+ builder.WriteString(fmt.Sprintf("%v", ds.RollbackCount))
+ builder.WriteString(", additions=")
+ builder.WriteString(fmt.Sprintf("%v", ds.Additions))
+ builder.WriteString(", deletions=")
+ builder.WriteString(fmt.Sprintf("%v", ds.Deletions))
+ builder.WriteString(", changes=")
+ builder.WriteString(fmt.Sprintf("%v", ds.Changes))
builder.WriteString(", created_at=")
builder.WriteString(ds.CreatedAt.Format(time.ANSIC))
builder.WriteString(", updated_at=")
builder.WriteString(ds.UpdatedAt.Format(time.ANSIC))
+ builder.WriteString(", repo_id=")
+ builder.WriteString(fmt.Sprintf("%v", ds.RepoID))
builder.WriteByte(')')
return builder.String()
}
diff --git a/ent/deploymentstatistics/deploymentstatistics.go b/ent/deploymentstatistics/deploymentstatistics.go
index 2f24a4b1..74992a8d 100644
--- a/ent/deploymentstatistics/deploymentstatistics.go
+++ b/ent/deploymentstatistics/deploymentstatistics.go
@@ -11,31 +11,49 @@ const (
Label = "deployment_statistics"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
- // FieldNamespace holds the string denoting the namespace field in the database.
- FieldNamespace = "namespace"
- // FieldName holds the string denoting the name field in the database.
- FieldName = "name"
// FieldEnv holds the string denoting the env field in the database.
FieldEnv = "env"
// FieldCount holds the string denoting the count field in the database.
FieldCount = "count"
+ // FieldRollbackCount holds the string denoting the rollback_count field in the database.
+ FieldRollbackCount = "rollback_count"
+ // FieldAdditions holds the string denoting the additions field in the database.
+ FieldAdditions = "additions"
+ // FieldDeletions holds the string denoting the deletions field in the database.
+ FieldDeletions = "deletions"
+ // FieldChanges holds the string denoting the changes field in the database.
+ FieldChanges = "changes"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
+ // FieldRepoID holds the string denoting the repo_id field in the database.
+ FieldRepoID = "repo_id"
+ // EdgeRepo holds the string denoting the repo edge name in mutations.
+ EdgeRepo = "repo"
// Table holds the table name of the deploymentstatistics in the database.
Table = "deployment_statistics"
+ // RepoTable is the table that holds the repo relation/edge.
+ RepoTable = "deployment_statistics"
+ // RepoInverseTable is the table name for the Repo entity.
+ // It exists in this package in order to avoid circular dependency with the "repo" package.
+ RepoInverseTable = "repos"
+ // RepoColumn is the table column denoting the repo relation/edge.
+ RepoColumn = "repo_id"
)
// Columns holds all SQL columns for deploymentstatistics fields.
var Columns = []string{
FieldID,
- FieldNamespace,
- FieldName,
FieldEnv,
FieldCount,
+ FieldRollbackCount,
+ FieldAdditions,
+ FieldDeletions,
+ FieldChanges,
FieldCreatedAt,
FieldUpdatedAt,
+ FieldRepoID,
}
// ValidColumn reports if the column name is valid (part of the table columns).
@@ -51,6 +69,14 @@ func ValidColumn(column string) bool {
var (
// DefaultCount holds the default value on creation for the "count" field.
DefaultCount int
+ // DefaultRollbackCount holds the default value on creation for the "rollback_count" field.
+ DefaultRollbackCount int
+ // DefaultAdditions holds the default value on creation for the "additions" field.
+ DefaultAdditions int
+ // DefaultDeletions holds the default value on creation for the "deletions" field.
+ DefaultDeletions int
+ // DefaultChanges holds the default value on creation for the "changes" field.
+ DefaultChanges int
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
diff --git a/ent/deploymentstatistics/where.go b/ent/deploymentstatistics/where.go
index ff610a09..901a5eb1 100644
--- a/ent/deploymentstatistics/where.go
+++ b/ent/deploymentstatistics/where.go
@@ -6,6 +6,7 @@ import (
"time"
"entgo.io/ent/dialect/sql"
+ "entgo.io/ent/dialect/sql/sqlgraph"
"github.com/gitploy-io/gitploy/ent/predicate"
)
@@ -92,31 +93,45 @@ func IDLTE(id int) predicate.DeploymentStatistics {
})
}
-// Namespace applies equality check predicate on the "namespace" field. It's identical to NamespaceEQ.
-func Namespace(v string) predicate.DeploymentStatistics {
+// Env applies equality check predicate on the "env" field. It's identical to EnvEQ.
+func Env(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldNamespace), v))
+ s.Where(sql.EQ(s.C(FieldEnv), v))
})
}
-// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
-func Name(v string) predicate.DeploymentStatistics {
+// Count applies equality check predicate on the "count" field. It's identical to CountEQ.
+func Count(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldName), v))
+ s.Where(sql.EQ(s.C(FieldCount), v))
})
}
-// Env applies equality check predicate on the "env" field. It's identical to EnvEQ.
-func Env(v string) predicate.DeploymentStatistics {
+// RollbackCount applies equality check predicate on the "rollback_count" field. It's identical to RollbackCountEQ.
+func RollbackCount(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldEnv), v))
+ s.Where(sql.EQ(s.C(FieldRollbackCount), v))
})
}
-// Count applies equality check predicate on the "count" field. It's identical to CountEQ.
-func Count(v int) predicate.DeploymentStatistics {
+// Additions applies equality check predicate on the "additions" field. It's identical to AdditionsEQ.
+func Additions(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldCount), v))
+ s.Where(sql.EQ(s.C(FieldAdditions), v))
+ })
+}
+
+// Deletions applies equality check predicate on the "deletions" field. It's identical to DeletionsEQ.
+func Deletions(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldDeletions), v))
+ })
+}
+
+// Changes applies equality check predicate on the "changes" field. It's identical to ChangesEQ.
+func Changes(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldChanges), v))
})
}
@@ -134,22 +149,29 @@ func UpdatedAt(v time.Time) predicate.DeploymentStatistics {
})
}
-// NamespaceEQ applies the EQ predicate on the "namespace" field.
-func NamespaceEQ(v string) predicate.DeploymentStatistics {
+// RepoID applies equality check predicate on the "repo_id" field. It's identical to RepoIDEQ.
+func RepoID(v int64) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldRepoID), v))
+ })
+}
+
+// EnvEQ applies the EQ predicate on the "env" field.
+func EnvEQ(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldNamespace), v))
+ s.Where(sql.EQ(s.C(FieldEnv), v))
})
}
-// NamespaceNEQ applies the NEQ predicate on the "namespace" field.
-func NamespaceNEQ(v string) predicate.DeploymentStatistics {
+// EnvNEQ applies the NEQ predicate on the "env" field.
+func EnvNEQ(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.NEQ(s.C(FieldNamespace), v))
+ s.Where(sql.NEQ(s.C(FieldEnv), v))
})
}
-// NamespaceIn applies the In predicate on the "namespace" field.
-func NamespaceIn(vs ...string) predicate.DeploymentStatistics {
+// EnvIn applies the In predicate on the "env" field.
+func EnvIn(vs ...string) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -161,12 +183,12 @@ func NamespaceIn(vs ...string) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.In(s.C(FieldNamespace), v...))
+ s.Where(sql.In(s.C(FieldEnv), v...))
})
}
-// NamespaceNotIn applies the NotIn predicate on the "namespace" field.
-func NamespaceNotIn(vs ...string) predicate.DeploymentStatistics {
+// EnvNotIn applies the NotIn predicate on the "env" field.
+func EnvNotIn(vs ...string) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -178,89 +200,89 @@ func NamespaceNotIn(vs ...string) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.NotIn(s.C(FieldNamespace), v...))
+ s.Where(sql.NotIn(s.C(FieldEnv), v...))
})
}
-// NamespaceGT applies the GT predicate on the "namespace" field.
-func NamespaceGT(v string) predicate.DeploymentStatistics {
+// EnvGT applies the GT predicate on the "env" field.
+func EnvGT(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GT(s.C(FieldNamespace), v))
+ s.Where(sql.GT(s.C(FieldEnv), v))
})
}
-// NamespaceGTE applies the GTE predicate on the "namespace" field.
-func NamespaceGTE(v string) predicate.DeploymentStatistics {
+// EnvGTE applies the GTE predicate on the "env" field.
+func EnvGTE(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GTE(s.C(FieldNamespace), v))
+ s.Where(sql.GTE(s.C(FieldEnv), v))
})
}
-// NamespaceLT applies the LT predicate on the "namespace" field.
-func NamespaceLT(v string) predicate.DeploymentStatistics {
+// EnvLT applies the LT predicate on the "env" field.
+func EnvLT(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LT(s.C(FieldNamespace), v))
+ s.Where(sql.LT(s.C(FieldEnv), v))
})
}
-// NamespaceLTE applies the LTE predicate on the "namespace" field.
-func NamespaceLTE(v string) predicate.DeploymentStatistics {
+// EnvLTE applies the LTE predicate on the "env" field.
+func EnvLTE(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LTE(s.C(FieldNamespace), v))
+ s.Where(sql.LTE(s.C(FieldEnv), v))
})
}
-// NamespaceContains applies the Contains predicate on the "namespace" field.
-func NamespaceContains(v string) predicate.DeploymentStatistics {
+// EnvContains applies the Contains predicate on the "env" field.
+func EnvContains(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.Contains(s.C(FieldNamespace), v))
+ s.Where(sql.Contains(s.C(FieldEnv), v))
})
}
-// NamespaceHasPrefix applies the HasPrefix predicate on the "namespace" field.
-func NamespaceHasPrefix(v string) predicate.DeploymentStatistics {
+// EnvHasPrefix applies the HasPrefix predicate on the "env" field.
+func EnvHasPrefix(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.HasPrefix(s.C(FieldNamespace), v))
+ s.Where(sql.HasPrefix(s.C(FieldEnv), v))
})
}
-// NamespaceHasSuffix applies the HasSuffix predicate on the "namespace" field.
-func NamespaceHasSuffix(v string) predicate.DeploymentStatistics {
+// EnvHasSuffix applies the HasSuffix predicate on the "env" field.
+func EnvHasSuffix(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.HasSuffix(s.C(FieldNamespace), v))
+ s.Where(sql.HasSuffix(s.C(FieldEnv), v))
})
}
-// NamespaceEqualFold applies the EqualFold predicate on the "namespace" field.
-func NamespaceEqualFold(v string) predicate.DeploymentStatistics {
+// EnvEqualFold applies the EqualFold predicate on the "env" field.
+func EnvEqualFold(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EqualFold(s.C(FieldNamespace), v))
+ s.Where(sql.EqualFold(s.C(FieldEnv), v))
})
}
-// NamespaceContainsFold applies the ContainsFold predicate on the "namespace" field.
-func NamespaceContainsFold(v string) predicate.DeploymentStatistics {
+// EnvContainsFold applies the ContainsFold predicate on the "env" field.
+func EnvContainsFold(v string) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.ContainsFold(s.C(FieldNamespace), v))
+ s.Where(sql.ContainsFold(s.C(FieldEnv), v))
})
}
-// NameEQ applies the EQ predicate on the "name" field.
-func NameEQ(v string) predicate.DeploymentStatistics {
+// CountEQ applies the EQ predicate on the "count" field.
+func CountEQ(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldName), v))
+ s.Where(sql.EQ(s.C(FieldCount), v))
})
}
-// NameNEQ applies the NEQ predicate on the "name" field.
-func NameNEQ(v string) predicate.DeploymentStatistics {
+// CountNEQ applies the NEQ predicate on the "count" field.
+func CountNEQ(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.NEQ(s.C(FieldName), v))
+ s.Where(sql.NEQ(s.C(FieldCount), v))
})
}
-// NameIn applies the In predicate on the "name" field.
-func NameIn(vs ...string) predicate.DeploymentStatistics {
+// CountIn applies the In predicate on the "count" field.
+func CountIn(vs ...int) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -272,12 +294,12 @@ func NameIn(vs ...string) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.In(s.C(FieldName), v...))
+ s.Where(sql.In(s.C(FieldCount), v...))
})
}
-// NameNotIn applies the NotIn predicate on the "name" field.
-func NameNotIn(vs ...string) predicate.DeploymentStatistics {
+// CountNotIn applies the NotIn predicate on the "count" field.
+func CountNotIn(vs ...int) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -289,89 +311,130 @@ func NameNotIn(vs ...string) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.NotIn(s.C(FieldName), v...))
+ s.Where(sql.NotIn(s.C(FieldCount), v...))
})
}
-// NameGT applies the GT predicate on the "name" field.
-func NameGT(v string) predicate.DeploymentStatistics {
+// CountGT applies the GT predicate on the "count" field.
+func CountGT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GT(s.C(FieldName), v))
+ s.Where(sql.GT(s.C(FieldCount), v))
})
}
-// NameGTE applies the GTE predicate on the "name" field.
-func NameGTE(v string) predicate.DeploymentStatistics {
+// CountGTE applies the GTE predicate on the "count" field.
+func CountGTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GTE(s.C(FieldName), v))
+ s.Where(sql.GTE(s.C(FieldCount), v))
})
}
-// NameLT applies the LT predicate on the "name" field.
-func NameLT(v string) predicate.DeploymentStatistics {
+// CountLT applies the LT predicate on the "count" field.
+func CountLT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LT(s.C(FieldName), v))
+ s.Where(sql.LT(s.C(FieldCount), v))
})
}
-// NameLTE applies the LTE predicate on the "name" field.
-func NameLTE(v string) predicate.DeploymentStatistics {
+// CountLTE applies the LTE predicate on the "count" field.
+func CountLTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LTE(s.C(FieldName), v))
+ s.Where(sql.LTE(s.C(FieldCount), v))
})
}
-// NameContains applies the Contains predicate on the "name" field.
-func NameContains(v string) predicate.DeploymentStatistics {
+// RollbackCountEQ applies the EQ predicate on the "rollback_count" field.
+func RollbackCountEQ(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.Contains(s.C(FieldName), v))
+ s.Where(sql.EQ(s.C(FieldRollbackCount), v))
})
}
-// NameHasPrefix applies the HasPrefix predicate on the "name" field.
-func NameHasPrefix(v string) predicate.DeploymentStatistics {
+// RollbackCountNEQ applies the NEQ predicate on the "rollback_count" field.
+func RollbackCountNEQ(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.HasPrefix(s.C(FieldName), v))
+ s.Where(sql.NEQ(s.C(FieldRollbackCount), v))
})
}
-// NameHasSuffix applies the HasSuffix predicate on the "name" field.
-func NameHasSuffix(v string) predicate.DeploymentStatistics {
+// RollbackCountIn applies the In predicate on the "rollback_count" field.
+func RollbackCountIn(vs ...int) predicate.DeploymentStatistics {
+ v := make([]interface{}, len(vs))
+ for i := range v {
+ v[i] = vs[i]
+ }
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.HasSuffix(s.C(FieldName), v))
+ // if not arguments were provided, append the FALSE constants,
+ // since we can't apply "IN ()". This will make this predicate falsy.
+ if len(v) == 0 {
+ s.Where(sql.False())
+ return
+ }
+ s.Where(sql.In(s.C(FieldRollbackCount), v...))
})
}
-// NameEqualFold applies the EqualFold predicate on the "name" field.
-func NameEqualFold(v string) predicate.DeploymentStatistics {
+// RollbackCountNotIn applies the NotIn predicate on the "rollback_count" field.
+func RollbackCountNotIn(vs ...int) predicate.DeploymentStatistics {
+ v := make([]interface{}, len(vs))
+ for i := range v {
+ v[i] = vs[i]
+ }
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EqualFold(s.C(FieldName), v))
+ // if not arguments were provided, append the FALSE constants,
+ // since we can't apply "IN ()". This will make this predicate falsy.
+ if len(v) == 0 {
+ s.Where(sql.False())
+ return
+ }
+ s.Where(sql.NotIn(s.C(FieldRollbackCount), v...))
})
}
-// NameContainsFold applies the ContainsFold predicate on the "name" field.
-func NameContainsFold(v string) predicate.DeploymentStatistics {
+// RollbackCountGT applies the GT predicate on the "rollback_count" field.
+func RollbackCountGT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.ContainsFold(s.C(FieldName), v))
+ s.Where(sql.GT(s.C(FieldRollbackCount), v))
})
}
-// EnvEQ applies the EQ predicate on the "env" field.
-func EnvEQ(v string) predicate.DeploymentStatistics {
+// RollbackCountGTE applies the GTE predicate on the "rollback_count" field.
+func RollbackCountGTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldEnv), v))
+ s.Where(sql.GTE(s.C(FieldRollbackCount), v))
})
}
-// EnvNEQ applies the NEQ predicate on the "env" field.
-func EnvNEQ(v string) predicate.DeploymentStatistics {
+// RollbackCountLT applies the LT predicate on the "rollback_count" field.
+func RollbackCountLT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.NEQ(s.C(FieldEnv), v))
+ s.Where(sql.LT(s.C(FieldRollbackCount), v))
})
}
-// EnvIn applies the In predicate on the "env" field.
-func EnvIn(vs ...string) predicate.DeploymentStatistics {
+// RollbackCountLTE applies the LTE predicate on the "rollback_count" field.
+func RollbackCountLTE(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.LTE(s.C(FieldRollbackCount), v))
+ })
+}
+
+// AdditionsEQ applies the EQ predicate on the "additions" field.
+func AdditionsEQ(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldAdditions), v))
+ })
+}
+
+// AdditionsNEQ applies the NEQ predicate on the "additions" field.
+func AdditionsNEQ(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.NEQ(s.C(FieldAdditions), v))
+ })
+}
+
+// AdditionsIn applies the In predicate on the "additions" field.
+func AdditionsIn(vs ...int) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -383,12 +446,12 @@ func EnvIn(vs ...string) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.In(s.C(FieldEnv), v...))
+ s.Where(sql.In(s.C(FieldAdditions), v...))
})
}
-// EnvNotIn applies the NotIn predicate on the "env" field.
-func EnvNotIn(vs ...string) predicate.DeploymentStatistics {
+// AdditionsNotIn applies the NotIn predicate on the "additions" field.
+func AdditionsNotIn(vs ...int) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -400,89 +463,130 @@ func EnvNotIn(vs ...string) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.NotIn(s.C(FieldEnv), v...))
+ s.Where(sql.NotIn(s.C(FieldAdditions), v...))
})
}
-// EnvGT applies the GT predicate on the "env" field.
-func EnvGT(v string) predicate.DeploymentStatistics {
+// AdditionsGT applies the GT predicate on the "additions" field.
+func AdditionsGT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GT(s.C(FieldEnv), v))
+ s.Where(sql.GT(s.C(FieldAdditions), v))
})
}
-// EnvGTE applies the GTE predicate on the "env" field.
-func EnvGTE(v string) predicate.DeploymentStatistics {
+// AdditionsGTE applies the GTE predicate on the "additions" field.
+func AdditionsGTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GTE(s.C(FieldEnv), v))
+ s.Where(sql.GTE(s.C(FieldAdditions), v))
})
}
-// EnvLT applies the LT predicate on the "env" field.
-func EnvLT(v string) predicate.DeploymentStatistics {
+// AdditionsLT applies the LT predicate on the "additions" field.
+func AdditionsLT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LT(s.C(FieldEnv), v))
+ s.Where(sql.LT(s.C(FieldAdditions), v))
})
}
-// EnvLTE applies the LTE predicate on the "env" field.
-func EnvLTE(v string) predicate.DeploymentStatistics {
+// AdditionsLTE applies the LTE predicate on the "additions" field.
+func AdditionsLTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LTE(s.C(FieldEnv), v))
+ s.Where(sql.LTE(s.C(FieldAdditions), v))
})
}
-// EnvContains applies the Contains predicate on the "env" field.
-func EnvContains(v string) predicate.DeploymentStatistics {
+// DeletionsEQ applies the EQ predicate on the "deletions" field.
+func DeletionsEQ(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.Contains(s.C(FieldEnv), v))
+ s.Where(sql.EQ(s.C(FieldDeletions), v))
})
}
-// EnvHasPrefix applies the HasPrefix predicate on the "env" field.
-func EnvHasPrefix(v string) predicate.DeploymentStatistics {
+// DeletionsNEQ applies the NEQ predicate on the "deletions" field.
+func DeletionsNEQ(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.HasPrefix(s.C(FieldEnv), v))
+ s.Where(sql.NEQ(s.C(FieldDeletions), v))
})
}
-// EnvHasSuffix applies the HasSuffix predicate on the "env" field.
-func EnvHasSuffix(v string) predicate.DeploymentStatistics {
+// DeletionsIn applies the In predicate on the "deletions" field.
+func DeletionsIn(vs ...int) predicate.DeploymentStatistics {
+ v := make([]interface{}, len(vs))
+ for i := range v {
+ v[i] = vs[i]
+ }
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.HasSuffix(s.C(FieldEnv), v))
+ // if not arguments were provided, append the FALSE constants,
+ // since we can't apply "IN ()". This will make this predicate falsy.
+ if len(v) == 0 {
+ s.Where(sql.False())
+ return
+ }
+ s.Where(sql.In(s.C(FieldDeletions), v...))
})
}
-// EnvEqualFold applies the EqualFold predicate on the "env" field.
-func EnvEqualFold(v string) predicate.DeploymentStatistics {
+// DeletionsNotIn applies the NotIn predicate on the "deletions" field.
+func DeletionsNotIn(vs ...int) predicate.DeploymentStatistics {
+ v := make([]interface{}, len(vs))
+ for i := range v {
+ v[i] = vs[i]
+ }
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EqualFold(s.C(FieldEnv), v))
+ // if not arguments were provided, append the FALSE constants,
+ // since we can't apply "IN ()". This will make this predicate falsy.
+ if len(v) == 0 {
+ s.Where(sql.False())
+ return
+ }
+ s.Where(sql.NotIn(s.C(FieldDeletions), v...))
})
}
-// EnvContainsFold applies the ContainsFold predicate on the "env" field.
-func EnvContainsFold(v string) predicate.DeploymentStatistics {
+// DeletionsGT applies the GT predicate on the "deletions" field.
+func DeletionsGT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.ContainsFold(s.C(FieldEnv), v))
+ s.Where(sql.GT(s.C(FieldDeletions), v))
})
}
-// CountEQ applies the EQ predicate on the "count" field.
-func CountEQ(v int) predicate.DeploymentStatistics {
+// DeletionsGTE applies the GTE predicate on the "deletions" field.
+func DeletionsGTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.EQ(s.C(FieldCount), v))
+ s.Where(sql.GTE(s.C(FieldDeletions), v))
})
}
-// CountNEQ applies the NEQ predicate on the "count" field.
-func CountNEQ(v int) predicate.DeploymentStatistics {
+// DeletionsLT applies the LT predicate on the "deletions" field.
+func DeletionsLT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.NEQ(s.C(FieldCount), v))
+ s.Where(sql.LT(s.C(FieldDeletions), v))
})
}
-// CountIn applies the In predicate on the "count" field.
-func CountIn(vs ...int) predicate.DeploymentStatistics {
+// DeletionsLTE applies the LTE predicate on the "deletions" field.
+func DeletionsLTE(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.LTE(s.C(FieldDeletions), v))
+ })
+}
+
+// ChangesEQ applies the EQ predicate on the "changes" field.
+func ChangesEQ(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldChanges), v))
+ })
+}
+
+// ChangesNEQ applies the NEQ predicate on the "changes" field.
+func ChangesNEQ(v int) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.NEQ(s.C(FieldChanges), v))
+ })
+}
+
+// ChangesIn applies the In predicate on the "changes" field.
+func ChangesIn(vs ...int) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -494,12 +598,12 @@ func CountIn(vs ...int) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.In(s.C(FieldCount), v...))
+ s.Where(sql.In(s.C(FieldChanges), v...))
})
}
-// CountNotIn applies the NotIn predicate on the "count" field.
-func CountNotIn(vs ...int) predicate.DeploymentStatistics {
+// ChangesNotIn applies the NotIn predicate on the "changes" field.
+func ChangesNotIn(vs ...int) predicate.DeploymentStatistics {
v := make([]interface{}, len(vs))
for i := range v {
v[i] = vs[i]
@@ -511,35 +615,35 @@ func CountNotIn(vs ...int) predicate.DeploymentStatistics {
s.Where(sql.False())
return
}
- s.Where(sql.NotIn(s.C(FieldCount), v...))
+ s.Where(sql.NotIn(s.C(FieldChanges), v...))
})
}
-// CountGT applies the GT predicate on the "count" field.
-func CountGT(v int) predicate.DeploymentStatistics {
+// ChangesGT applies the GT predicate on the "changes" field.
+func ChangesGT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GT(s.C(FieldCount), v))
+ s.Where(sql.GT(s.C(FieldChanges), v))
})
}
-// CountGTE applies the GTE predicate on the "count" field.
-func CountGTE(v int) predicate.DeploymentStatistics {
+// ChangesGTE applies the GTE predicate on the "changes" field.
+func ChangesGTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.GTE(s.C(FieldCount), v))
+ s.Where(sql.GTE(s.C(FieldChanges), v))
})
}
-// CountLT applies the LT predicate on the "count" field.
-func CountLT(v int) predicate.DeploymentStatistics {
+// ChangesLT applies the LT predicate on the "changes" field.
+func ChangesLT(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LT(s.C(FieldCount), v))
+ s.Where(sql.LT(s.C(FieldChanges), v))
})
}
-// CountLTE applies the LTE predicate on the "count" field.
-func CountLTE(v int) predicate.DeploymentStatistics {
+// ChangesLTE applies the LTE predicate on the "changes" field.
+func ChangesLTE(v int) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
- s.Where(sql.LTE(s.C(FieldCount), v))
+ s.Where(sql.LTE(s.C(FieldChanges), v))
})
}
@@ -695,6 +799,82 @@ func UpdatedAtLTE(v time.Time) predicate.DeploymentStatistics {
})
}
+// RepoIDEQ applies the EQ predicate on the "repo_id" field.
+func RepoIDEQ(v int64) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.EQ(s.C(FieldRepoID), v))
+ })
+}
+
+// RepoIDNEQ applies the NEQ predicate on the "repo_id" field.
+func RepoIDNEQ(v int64) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.NEQ(s.C(FieldRepoID), v))
+ })
+}
+
+// RepoIDIn applies the In predicate on the "repo_id" field.
+func RepoIDIn(vs ...int64) predicate.DeploymentStatistics {
+ v := make([]interface{}, len(vs))
+ for i := range v {
+ v[i] = vs[i]
+ }
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ // if not arguments were provided, append the FALSE constants,
+ // since we can't apply "IN ()". This will make this predicate falsy.
+ if len(v) == 0 {
+ s.Where(sql.False())
+ return
+ }
+ s.Where(sql.In(s.C(FieldRepoID), v...))
+ })
+}
+
+// RepoIDNotIn applies the NotIn predicate on the "repo_id" field.
+func RepoIDNotIn(vs ...int64) predicate.DeploymentStatistics {
+ v := make([]interface{}, len(vs))
+ for i := range v {
+ v[i] = vs[i]
+ }
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ // if not arguments were provided, append the FALSE constants,
+ // since we can't apply "IN ()". This will make this predicate falsy.
+ if len(v) == 0 {
+ s.Where(sql.False())
+ return
+ }
+ s.Where(sql.NotIn(s.C(FieldRepoID), v...))
+ })
+}
+
+// HasRepo applies the HasEdge predicate on the "repo" edge.
+func HasRepo() predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ step := sqlgraph.NewStep(
+ sqlgraph.From(Table, FieldID),
+ sqlgraph.To(RepoTable, FieldID),
+ sqlgraph.Edge(sqlgraph.M2O, true, RepoTable, RepoColumn),
+ )
+ sqlgraph.HasNeighbors(s, step)
+ })
+}
+
+// HasRepoWith applies the HasEdge predicate on the "repo" edge with a given conditions (other predicates).
+func HasRepoWith(preds ...predicate.Repo) predicate.DeploymentStatistics {
+ return predicate.DeploymentStatistics(func(s *sql.Selector) {
+ step := sqlgraph.NewStep(
+ sqlgraph.From(Table, FieldID),
+ sqlgraph.To(RepoInverseTable, FieldID),
+ sqlgraph.Edge(sqlgraph.M2O, true, RepoTable, RepoColumn),
+ )
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
+ for _, p := range preds {
+ p(s)
+ }
+ })
+ })
+}
+
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.DeploymentStatistics) predicate.DeploymentStatistics {
return predicate.DeploymentStatistics(func(s *sql.Selector) {
diff --git a/ent/deploymentstatistics_create.go b/ent/deploymentstatistics_create.go
index 33195fdb..1a24b272 100644
--- a/ent/deploymentstatistics_create.go
+++ b/ent/deploymentstatistics_create.go
@@ -11,6 +11,7 @@ import (
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/gitploy-io/gitploy/ent/deploymentstatistics"
+ "github.com/gitploy-io/gitploy/ent/repo"
)
// DeploymentStatisticsCreate is the builder for creating a DeploymentStatistics entity.
@@ -20,18 +21,6 @@ type DeploymentStatisticsCreate struct {
hooks []Hook
}
-// SetNamespace sets the "namespace" field.
-func (dsc *DeploymentStatisticsCreate) SetNamespace(s string) *DeploymentStatisticsCreate {
- dsc.mutation.SetNamespace(s)
- return dsc
-}
-
-// SetName sets the "name" field.
-func (dsc *DeploymentStatisticsCreate) SetName(s string) *DeploymentStatisticsCreate {
- dsc.mutation.SetName(s)
- return dsc
-}
-
// SetEnv sets the "env" field.
func (dsc *DeploymentStatisticsCreate) SetEnv(s string) *DeploymentStatisticsCreate {
dsc.mutation.SetEnv(s)
@@ -52,6 +41,62 @@ func (dsc *DeploymentStatisticsCreate) SetNillableCount(i *int) *DeploymentStati
return dsc
}
+// SetRollbackCount sets the "rollback_count" field.
+func (dsc *DeploymentStatisticsCreate) SetRollbackCount(i int) *DeploymentStatisticsCreate {
+ dsc.mutation.SetRollbackCount(i)
+ return dsc
+}
+
+// SetNillableRollbackCount sets the "rollback_count" field if the given value is not nil.
+func (dsc *DeploymentStatisticsCreate) SetNillableRollbackCount(i *int) *DeploymentStatisticsCreate {
+ if i != nil {
+ dsc.SetRollbackCount(*i)
+ }
+ return dsc
+}
+
+// SetAdditions sets the "additions" field.
+func (dsc *DeploymentStatisticsCreate) SetAdditions(i int) *DeploymentStatisticsCreate {
+ dsc.mutation.SetAdditions(i)
+ return dsc
+}
+
+// SetNillableAdditions sets the "additions" field if the given value is not nil.
+func (dsc *DeploymentStatisticsCreate) SetNillableAdditions(i *int) *DeploymentStatisticsCreate {
+ if i != nil {
+ dsc.SetAdditions(*i)
+ }
+ return dsc
+}
+
+// SetDeletions sets the "deletions" field.
+func (dsc *DeploymentStatisticsCreate) SetDeletions(i int) *DeploymentStatisticsCreate {
+ dsc.mutation.SetDeletions(i)
+ return dsc
+}
+
+// SetNillableDeletions sets the "deletions" field if the given value is not nil.
+func (dsc *DeploymentStatisticsCreate) SetNillableDeletions(i *int) *DeploymentStatisticsCreate {
+ if i != nil {
+ dsc.SetDeletions(*i)
+ }
+ return dsc
+}
+
+// SetChanges sets the "changes" field.
+func (dsc *DeploymentStatisticsCreate) SetChanges(i int) *DeploymentStatisticsCreate {
+ dsc.mutation.SetChanges(i)
+ return dsc
+}
+
+// SetNillableChanges sets the "changes" field if the given value is not nil.
+func (dsc *DeploymentStatisticsCreate) SetNillableChanges(i *int) *DeploymentStatisticsCreate {
+ if i != nil {
+ dsc.SetChanges(*i)
+ }
+ return dsc
+}
+
// SetCreatedAt sets the "created_at" field.
func (dsc *DeploymentStatisticsCreate) SetCreatedAt(t time.Time) *DeploymentStatisticsCreate {
dsc.mutation.SetCreatedAt(t)
@@ -80,6 +125,17 @@ func (dsc *DeploymentStatisticsCreate) SetNillableUpdatedAt(t *time.Time) *Deplo
return dsc
}
+// SetRepoID sets the "repo_id" field.
+func (dsc *DeploymentStatisticsCreate) SetRepoID(i int64) *DeploymentStatisticsCreate {
+ dsc.mutation.SetRepoID(i)
+ return dsc
+}
+
+// SetRepo sets the "repo" edge to the Repo entity.
+func (dsc *DeploymentStatisticsCreate) SetRepo(r *Repo) *DeploymentStatisticsCreate {
+ return dsc.SetRepoID(r.ID)
+}
+
// Mutation returns the DeploymentStatisticsMutation object of the builder.
func (dsc *DeploymentStatisticsCreate) Mutation() *DeploymentStatisticsMutation {
return dsc.mutation
@@ -155,6 +211,22 @@ func (dsc *DeploymentStatisticsCreate) defaults() {
v := deploymentstatistics.DefaultCount
dsc.mutation.SetCount(v)
}
+ if _, ok := dsc.mutation.RollbackCount(); !ok {
+ v := deploymentstatistics.DefaultRollbackCount
+ dsc.mutation.SetRollbackCount(v)
+ }
+ if _, ok := dsc.mutation.Additions(); !ok {
+ v := deploymentstatistics.DefaultAdditions
+ dsc.mutation.SetAdditions(v)
+ }
+ if _, ok := dsc.mutation.Deletions(); !ok {
+ v := deploymentstatistics.DefaultDeletions
+ dsc.mutation.SetDeletions(v)
+ }
+ if _, ok := dsc.mutation.Changes(); !ok {
+ v := deploymentstatistics.DefaultChanges
+ dsc.mutation.SetChanges(v)
+ }
if _, ok := dsc.mutation.CreatedAt(); !ok {
v := deploymentstatistics.DefaultCreatedAt()
dsc.mutation.SetCreatedAt(v)
@@ -167,24 +239,36 @@ func (dsc *DeploymentStatisticsCreate) defaults() {
// check runs all checks and user-defined validators on the builder.
func (dsc *DeploymentStatisticsCreate) check() error {
- if _, ok := dsc.mutation.Namespace(); !ok {
- return &ValidationError{Name: "namespace", err: errors.New(`ent: missing required field "namespace"`)}
- }
- if _, ok := dsc.mutation.Name(); !ok {
- return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "name"`)}
- }
if _, ok := dsc.mutation.Env(); !ok {
return &ValidationError{Name: "env", err: errors.New(`ent: missing required field "env"`)}
}
if _, ok := dsc.mutation.Count(); !ok {
return &ValidationError{Name: "count", err: errors.New(`ent: missing required field "count"`)}
}
+ if _, ok := dsc.mutation.RollbackCount(); !ok {
+ return &ValidationError{Name: "rollback_count", err: errors.New(`ent: missing required field "rollback_count"`)}
+ }
+ if _, ok := dsc.mutation.Additions(); !ok {
+ return &ValidationError{Name: "additions", err: errors.New(`ent: missing required field "additions"`)}
+ }
+ if _, ok := dsc.mutation.Deletions(); !ok {
+ return &ValidationError{Name: "deletions", err: errors.New(`ent: missing required field "deletions"`)}
+ }
+ if _, ok := dsc.mutation.Changes(); !ok {
+ return &ValidationError{Name: "changes", err: errors.New(`ent: missing required field "changes"`)}
+ }
if _, ok := dsc.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "created_at"`)}
}
if _, ok := dsc.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "updated_at"`)}
}
+ if _, ok := dsc.mutation.RepoID(); !ok {
+ return &ValidationError{Name: "repo_id", err: errors.New(`ent: missing required field "repo_id"`)}
+ }
+ if _, ok := dsc.mutation.RepoID(); !ok {
+ return &ValidationError{Name: "repo", err: errors.New("ent: missing required edge \"repo\"")}
+ }
return nil
}
@@ -212,37 +296,53 @@ func (dsc *DeploymentStatisticsCreate) createSpec() (*DeploymentStatistics, *sql
},
}
)
- if value, ok := dsc.mutation.Namespace(); ok {
+ if value, ok := dsc.mutation.Env(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
- Column: deploymentstatistics.FieldNamespace,
+ Column: deploymentstatistics.FieldEnv,
})
- _node.Namespace = value
+ _node.Env = value
}
- if value, ok := dsc.mutation.Name(); ok {
+ if value, ok := dsc.mutation.Count(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
- Type: field.TypeString,
+ Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldName,
+ Column: deploymentstatistics.FieldCount,
})
- _node.Name = value
+ _node.Count = value
}
- if value, ok := dsc.mutation.Env(); ok {
+ if value, ok := dsc.mutation.RollbackCount(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
- Type: field.TypeString,
+ Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldEnv,
+ Column: deploymentstatistics.FieldRollbackCount,
})
- _node.Env = value
+ _node.RollbackCount = value
}
- if value, ok := dsc.mutation.Count(); ok {
+ if value, ok := dsc.mutation.Additions(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldCount,
+ Column: deploymentstatistics.FieldAdditions,
})
- _node.Count = value
+ _node.Additions = value
+ }
+ if value, ok := dsc.mutation.Deletions(); ok {
+ _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldDeletions,
+ })
+ _node.Deletions = value
+ }
+ if value, ok := dsc.mutation.Changes(); ok {
+ _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldChanges,
+ })
+ _node.Changes = value
}
if value, ok := dsc.mutation.CreatedAt(); ok {
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
@@ -260,6 +360,26 @@ func (dsc *DeploymentStatisticsCreate) createSpec() (*DeploymentStatistics, *sql
})
_node.UpdatedAt = value
}
+ if nodes := dsc.mutation.RepoIDs(); len(nodes) > 0 {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.M2O,
+ Inverse: true,
+ Table: deploymentstatistics.RepoTable,
+ Columns: []string{deploymentstatistics.RepoColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt64,
+ Column: repo.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _node.RepoID = nodes[0]
+ _spec.Edges = append(_spec.Edges, edge)
+ }
return _node, _spec
}
diff --git a/ent/deploymentstatistics_query.go b/ent/deploymentstatistics_query.go
index 5c389d14..926d6d10 100644
--- a/ent/deploymentstatistics_query.go
+++ b/ent/deploymentstatistics_query.go
@@ -14,6 +14,7 @@ import (
"entgo.io/ent/schema/field"
"github.com/gitploy-io/gitploy/ent/deploymentstatistics"
"github.com/gitploy-io/gitploy/ent/predicate"
+ "github.com/gitploy-io/gitploy/ent/repo"
)
// DeploymentStatisticsQuery is the builder for querying DeploymentStatistics entities.
@@ -25,7 +26,9 @@ type DeploymentStatisticsQuery struct {
order []OrderFunc
fields []string
predicates []predicate.DeploymentStatistics
- modifiers []func(s *sql.Selector)
+ // eager-loading edges.
+ withRepo *RepoQuery
+ modifiers []func(s *sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
@@ -62,6 +65,28 @@ func (dsq *DeploymentStatisticsQuery) Order(o ...OrderFunc) *DeploymentStatistic
return dsq
}
+// QueryRepo chains the current query on the "repo" edge.
+func (dsq *DeploymentStatisticsQuery) QueryRepo() *RepoQuery {
+ query := &RepoQuery{config: dsq.config}
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
+ if err := dsq.prepareQuery(ctx); err != nil {
+ return nil, err
+ }
+ selector := dsq.sqlQuery(ctx)
+ if err := selector.Err(); err != nil {
+ return nil, err
+ }
+ step := sqlgraph.NewStep(
+ sqlgraph.From(deploymentstatistics.Table, deploymentstatistics.FieldID, selector),
+ sqlgraph.To(repo.Table, repo.FieldID),
+ sqlgraph.Edge(sqlgraph.M2O, true, deploymentstatistics.RepoTable, deploymentstatistics.RepoColumn),
+ )
+ fromU = sqlgraph.SetNeighbors(dsq.driver.Dialect(), step)
+ return fromU, nil
+ }
+ return query
+}
+
// First returns the first DeploymentStatistics entity from the query.
// Returns a *NotFoundError when no DeploymentStatistics was found.
func (dsq *DeploymentStatisticsQuery) First(ctx context.Context) (*DeploymentStatistics, error) {
@@ -243,24 +268,36 @@ func (dsq *DeploymentStatisticsQuery) Clone() *DeploymentStatisticsQuery {
offset: dsq.offset,
order: append([]OrderFunc{}, dsq.order...),
predicates: append([]predicate.DeploymentStatistics{}, dsq.predicates...),
+ withRepo: dsq.withRepo.Clone(),
// clone intermediate query.
sql: dsq.sql.Clone(),
path: dsq.path,
}
}
+// WithRepo tells the query-builder to eager-load the nodes that are connected to
+// the "repo" edge. The optional arguments are used to configure the query builder of the edge.
+func (dsq *DeploymentStatisticsQuery) WithRepo(opts ...func(*RepoQuery)) *DeploymentStatisticsQuery {
+ query := &RepoQuery{config: dsq.config}
+ for _, opt := range opts {
+ opt(query)
+ }
+ dsq.withRepo = query
+ return dsq
+}
+
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
-// Namespace string `json:"namespace"`
+// Env string `json:"env"`
// Count int `json:"count,omitempty"`
// }
//
// client.DeploymentStatistics.Query().
-// GroupBy(deploymentstatistics.FieldNamespace).
+// GroupBy(deploymentstatistics.FieldEnv).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
//
@@ -282,11 +319,11 @@ func (dsq *DeploymentStatisticsQuery) GroupBy(field string, fields ...string) *D
// Example:
//
// var v []struct {
-// Namespace string `json:"namespace"`
+// Env string `json:"env"`
// }
//
// client.DeploymentStatistics.Query().
-// Select(deploymentstatistics.FieldNamespace).
+// Select(deploymentstatistics.FieldEnv).
// Scan(ctx, &v)
//
func (dsq *DeploymentStatisticsQuery) Select(fields ...string) *DeploymentStatisticsSelect {
@@ -312,8 +349,11 @@ func (dsq *DeploymentStatisticsQuery) prepareQuery(ctx context.Context) error {
func (dsq *DeploymentStatisticsQuery) sqlAll(ctx context.Context) ([]*DeploymentStatistics, error) {
var (
- nodes = []*DeploymentStatistics{}
- _spec = dsq.querySpec()
+ nodes = []*DeploymentStatistics{}
+ _spec = dsq.querySpec()
+ loadedTypes = [1]bool{
+ dsq.withRepo != nil,
+ }
)
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
node := &DeploymentStatistics{config: dsq.config}
@@ -325,6 +365,7 @@ func (dsq *DeploymentStatisticsQuery) sqlAll(ctx context.Context) ([]*Deployment
return fmt.Errorf("ent: Assign called without calling ScanValues")
}
node := nodes[len(nodes)-1]
+ node.Edges.loadedTypes = loadedTypes
return node.assignValues(columns, values)
}
if len(dsq.modifiers) > 0 {
@@ -336,6 +377,33 @@ func (dsq *DeploymentStatisticsQuery) sqlAll(ctx context.Context) ([]*Deployment
if len(nodes) == 0 {
return nodes, nil
}
+
+ if query := dsq.withRepo; query != nil {
+ ids := make([]int64, 0, len(nodes))
+ nodeids := make(map[int64][]*DeploymentStatistics)
+ for i := range nodes {
+ fk := nodes[i].RepoID
+ if _, ok := nodeids[fk]; !ok {
+ ids = append(ids, fk)
+ }
+ nodeids[fk] = append(nodeids[fk], nodes[i])
+ }
+ query.Where(repo.IDIn(ids...))
+ neighbors, err := query.All(ctx)
+ if err != nil {
+ return nil, err
+ }
+ for _, n := range neighbors {
+ nodes, ok := nodeids[n.ID]
+ if !ok {
+ return nil, fmt.Errorf(`unexpected foreign-key "repo_id" returned %v`, n.ID)
+ }
+ for i := range nodes {
+ nodes[i].Edges.Repo = n
+ }
+ }
+ }
+
return nodes, nil
}
diff --git a/ent/deploymentstatistics_update.go b/ent/deploymentstatistics_update.go
index 3c7262e6..db5aa014 100644
--- a/ent/deploymentstatistics_update.go
+++ b/ent/deploymentstatistics_update.go
@@ -4,6 +4,7 @@ package ent
import (
"context"
+ "errors"
"fmt"
"time"
@@ -12,6 +13,7 @@ import (
"entgo.io/ent/schema/field"
"github.com/gitploy-io/gitploy/ent/deploymentstatistics"
"github.com/gitploy-io/gitploy/ent/predicate"
+ "github.com/gitploy-io/gitploy/ent/repo"
)
// DeploymentStatisticsUpdate is the builder for updating DeploymentStatistics entities.
@@ -27,18 +29,6 @@ func (dsu *DeploymentStatisticsUpdate) Where(ps ...predicate.DeploymentStatistic
return dsu
}
-// SetNamespace sets the "namespace" field.
-func (dsu *DeploymentStatisticsUpdate) SetNamespace(s string) *DeploymentStatisticsUpdate {
- dsu.mutation.SetNamespace(s)
- return dsu
-}
-
-// SetName sets the "name" field.
-func (dsu *DeploymentStatisticsUpdate) SetName(s string) *DeploymentStatisticsUpdate {
- dsu.mutation.SetName(s)
- return dsu
-}
-
// SetEnv sets the "env" field.
func (dsu *DeploymentStatisticsUpdate) SetEnv(s string) *DeploymentStatisticsUpdate {
dsu.mutation.SetEnv(s)
@@ -66,6 +56,90 @@ func (dsu *DeploymentStatisticsUpdate) AddCount(i int) *DeploymentStatisticsUpda
return dsu
}
+// SetRollbackCount sets the "rollback_count" field.
+func (dsu *DeploymentStatisticsUpdate) SetRollbackCount(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.ResetRollbackCount()
+ dsu.mutation.SetRollbackCount(i)
+ return dsu
+}
+
+// SetNillableRollbackCount sets the "rollback_count" field if the given value is not nil.
+func (dsu *DeploymentStatisticsUpdate) SetNillableRollbackCount(i *int) *DeploymentStatisticsUpdate {
+ if i != nil {
+ dsu.SetRollbackCount(*i)
+ }
+ return dsu
+}
+
+// AddRollbackCount adds i to the "rollback_count" field.
+func (dsu *DeploymentStatisticsUpdate) AddRollbackCount(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.AddRollbackCount(i)
+ return dsu
+}
+
+// SetAdditions sets the "additions" field.
+func (dsu *DeploymentStatisticsUpdate) SetAdditions(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.ResetAdditions()
+ dsu.mutation.SetAdditions(i)
+ return dsu
+}
+
+// SetNillableAdditions sets the "additions" field if the given value is not nil.
+func (dsu *DeploymentStatisticsUpdate) SetNillableAdditions(i *int) *DeploymentStatisticsUpdate {
+ if i != nil {
+ dsu.SetAdditions(*i)
+ }
+ return dsu
+}
+
+// AddAdditions adds i to the "additions" field.
+func (dsu *DeploymentStatisticsUpdate) AddAdditions(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.AddAdditions(i)
+ return dsu
+}
+
+// SetDeletions sets the "deletions" field.
+func (dsu *DeploymentStatisticsUpdate) SetDeletions(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.ResetDeletions()
+ dsu.mutation.SetDeletions(i)
+ return dsu
+}
+
+// SetNillableDeletions sets the "deletions" field if the given value is not nil.
+func (dsu *DeploymentStatisticsUpdate) SetNillableDeletions(i *int) *DeploymentStatisticsUpdate {
+ if i != nil {
+ dsu.SetDeletions(*i)
+ }
+ return dsu
+}
+
+// AddDeletions adds i to the "deletions" field.
+func (dsu *DeploymentStatisticsUpdate) AddDeletions(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.AddDeletions(i)
+ return dsu
+}
+
+// SetChanges sets the "changes" field.
+func (dsu *DeploymentStatisticsUpdate) SetChanges(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.ResetChanges()
+ dsu.mutation.SetChanges(i)
+ return dsu
+}
+
+// SetNillableChanges sets the "changes" field if the given value is not nil.
+func (dsu *DeploymentStatisticsUpdate) SetNillableChanges(i *int) *DeploymentStatisticsUpdate {
+ if i != nil {
+ dsu.SetChanges(*i)
+ }
+ return dsu
+}
+
+// AddChanges adds i to the "changes" field.
+func (dsu *DeploymentStatisticsUpdate) AddChanges(i int) *DeploymentStatisticsUpdate {
+ dsu.mutation.AddChanges(i)
+ return dsu
+}
+
// SetCreatedAt sets the "created_at" field.
func (dsu *DeploymentStatisticsUpdate) SetCreatedAt(t time.Time) *DeploymentStatisticsUpdate {
dsu.mutation.SetCreatedAt(t)
@@ -86,11 +160,28 @@ func (dsu *DeploymentStatisticsUpdate) SetUpdatedAt(t time.Time) *DeploymentStat
return dsu
}
+// SetRepoID sets the "repo_id" field.
+func (dsu *DeploymentStatisticsUpdate) SetRepoID(i int64) *DeploymentStatisticsUpdate {
+ dsu.mutation.SetRepoID(i)
+ return dsu
+}
+
+// SetRepo sets the "repo" edge to the Repo entity.
+func (dsu *DeploymentStatisticsUpdate) SetRepo(r *Repo) *DeploymentStatisticsUpdate {
+ return dsu.SetRepoID(r.ID)
+}
+
// Mutation returns the DeploymentStatisticsMutation object of the builder.
func (dsu *DeploymentStatisticsUpdate) Mutation() *DeploymentStatisticsMutation {
return dsu.mutation
}
+// ClearRepo clears the "repo" edge to the Repo entity.
+func (dsu *DeploymentStatisticsUpdate) ClearRepo() *DeploymentStatisticsUpdate {
+ dsu.mutation.ClearRepo()
+ return dsu
+}
+
// Save executes the query and returns the number of nodes affected by the update operation.
func (dsu *DeploymentStatisticsUpdate) Save(ctx context.Context) (int, error) {
var (
@@ -99,6 +190,9 @@ func (dsu *DeploymentStatisticsUpdate) Save(ctx context.Context) (int, error) {
)
dsu.defaults()
if len(dsu.hooks) == 0 {
+ if err = dsu.check(); err != nil {
+ return 0, err
+ }
affected, err = dsu.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
@@ -106,6 +200,9 @@ func (dsu *DeploymentStatisticsUpdate) Save(ctx context.Context) (int, error) {
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
+ if err = dsu.check(); err != nil {
+ return 0, err
+ }
dsu.mutation = mutation
affected, err = dsu.sqlSave(ctx)
mutation.done = true
@@ -154,6 +251,14 @@ func (dsu *DeploymentStatisticsUpdate) defaults() {
}
}
+// check runs all checks and user-defined validators on the builder.
+func (dsu *DeploymentStatisticsUpdate) check() error {
+ if _, ok := dsu.mutation.RepoID(); dsu.mutation.RepoCleared() && !ok {
+ return errors.New("ent: clearing a required unique edge \"repo\"")
+ }
+ return nil
+}
+
func (dsu *DeploymentStatisticsUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
@@ -172,39 +277,81 @@ func (dsu *DeploymentStatisticsUpdate) sqlSave(ctx context.Context) (n int, err
}
}
}
- if value, ok := dsu.mutation.Namespace(); ok {
+ if value, ok := dsu.mutation.Env(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
- Column: deploymentstatistics.FieldNamespace,
+ Column: deploymentstatistics.FieldEnv,
})
}
- if value, ok := dsu.mutation.Name(); ok {
+ if value, ok := dsu.mutation.Count(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
+ Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldName,
+ Column: deploymentstatistics.FieldCount,
})
}
- if value, ok := dsu.mutation.Env(); ok {
+ if value, ok := dsu.mutation.AddedCount(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldCount,
+ })
+ }
+ if value, ok := dsu.mutation.RollbackCount(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
+ Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldEnv,
+ Column: deploymentstatistics.FieldRollbackCount,
})
}
- if value, ok := dsu.mutation.Count(); ok {
+ if value, ok := dsu.mutation.AddedRollbackCount(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldRollbackCount,
+ })
+ }
+ if value, ok := dsu.mutation.Additions(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldCount,
+ Column: deploymentstatistics.FieldAdditions,
})
}
- if value, ok := dsu.mutation.AddedCount(); ok {
+ if value, ok := dsu.mutation.AddedAdditions(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldCount,
+ Column: deploymentstatistics.FieldAdditions,
+ })
+ }
+ if value, ok := dsu.mutation.Deletions(); ok {
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldDeletions,
+ })
+ }
+ if value, ok := dsu.mutation.AddedDeletions(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldDeletions,
+ })
+ }
+ if value, ok := dsu.mutation.Changes(); ok {
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldChanges,
+ })
+ }
+ if value, ok := dsu.mutation.AddedChanges(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldChanges,
})
}
if value, ok := dsu.mutation.CreatedAt(); ok {
@@ -221,6 +368,41 @@ func (dsu *DeploymentStatisticsUpdate) sqlSave(ctx context.Context) (n int, err
Column: deploymentstatistics.FieldUpdatedAt,
})
}
+ if dsu.mutation.RepoCleared() {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.M2O,
+ Inverse: true,
+ Table: deploymentstatistics.RepoTable,
+ Columns: []string{deploymentstatistics.RepoColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt64,
+ Column: repo.FieldID,
+ },
+ },
+ }
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+ }
+ if nodes := dsu.mutation.RepoIDs(); len(nodes) > 0 {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.M2O,
+ Inverse: true,
+ Table: deploymentstatistics.RepoTable,
+ Columns: []string{deploymentstatistics.RepoColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt64,
+ Column: repo.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
+ }
if n, err = sqlgraph.UpdateNodes(ctx, dsu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{deploymentstatistics.Label}
@@ -240,18 +422,6 @@ type DeploymentStatisticsUpdateOne struct {
mutation *DeploymentStatisticsMutation
}
-// SetNamespace sets the "namespace" field.
-func (dsuo *DeploymentStatisticsUpdateOne) SetNamespace(s string) *DeploymentStatisticsUpdateOne {
- dsuo.mutation.SetNamespace(s)
- return dsuo
-}
-
-// SetName sets the "name" field.
-func (dsuo *DeploymentStatisticsUpdateOne) SetName(s string) *DeploymentStatisticsUpdateOne {
- dsuo.mutation.SetName(s)
- return dsuo
-}
-
// SetEnv sets the "env" field.
func (dsuo *DeploymentStatisticsUpdateOne) SetEnv(s string) *DeploymentStatisticsUpdateOne {
dsuo.mutation.SetEnv(s)
@@ -279,6 +449,90 @@ func (dsuo *DeploymentStatisticsUpdateOne) AddCount(i int) *DeploymentStatistics
return dsuo
}
+// SetRollbackCount sets the "rollback_count" field.
+func (dsuo *DeploymentStatisticsUpdateOne) SetRollbackCount(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.ResetRollbackCount()
+ dsuo.mutation.SetRollbackCount(i)
+ return dsuo
+}
+
+// SetNillableRollbackCount sets the "rollback_count" field if the given value is not nil.
+func (dsuo *DeploymentStatisticsUpdateOne) SetNillableRollbackCount(i *int) *DeploymentStatisticsUpdateOne {
+ if i != nil {
+ dsuo.SetRollbackCount(*i)
+ }
+ return dsuo
+}
+
+// AddRollbackCount adds i to the "rollback_count" field.
+func (dsuo *DeploymentStatisticsUpdateOne) AddRollbackCount(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.AddRollbackCount(i)
+ return dsuo
+}
+
+// SetAdditions sets the "additions" field.
+func (dsuo *DeploymentStatisticsUpdateOne) SetAdditions(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.ResetAdditions()
+ dsuo.mutation.SetAdditions(i)
+ return dsuo
+}
+
+// SetNillableAdditions sets the "additions" field if the given value is not nil.
+func (dsuo *DeploymentStatisticsUpdateOne) SetNillableAdditions(i *int) *DeploymentStatisticsUpdateOne {
+ if i != nil {
+ dsuo.SetAdditions(*i)
+ }
+ return dsuo
+}
+
+// AddAdditions adds i to the "additions" field.
+func (dsuo *DeploymentStatisticsUpdateOne) AddAdditions(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.AddAdditions(i)
+ return dsuo
+}
+
+// SetDeletions sets the "deletions" field.
+func (dsuo *DeploymentStatisticsUpdateOne) SetDeletions(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.ResetDeletions()
+ dsuo.mutation.SetDeletions(i)
+ return dsuo
+}
+
+// SetNillableDeletions sets the "deletions" field if the given value is not nil.
+func (dsuo *DeploymentStatisticsUpdateOne) SetNillableDeletions(i *int) *DeploymentStatisticsUpdateOne {
+ if i != nil {
+ dsuo.SetDeletions(*i)
+ }
+ return dsuo
+}
+
+// AddDeletions adds i to the "deletions" field.
+func (dsuo *DeploymentStatisticsUpdateOne) AddDeletions(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.AddDeletions(i)
+ return dsuo
+}
+
+// SetChanges sets the "changes" field.
+func (dsuo *DeploymentStatisticsUpdateOne) SetChanges(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.ResetChanges()
+ dsuo.mutation.SetChanges(i)
+ return dsuo
+}
+
+// SetNillableChanges sets the "changes" field if the given value is not nil.
+func (dsuo *DeploymentStatisticsUpdateOne) SetNillableChanges(i *int) *DeploymentStatisticsUpdateOne {
+ if i != nil {
+ dsuo.SetChanges(*i)
+ }
+ return dsuo
+}
+
+// AddChanges adds i to the "changes" field.
+func (dsuo *DeploymentStatisticsUpdateOne) AddChanges(i int) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.AddChanges(i)
+ return dsuo
+}
+
// SetCreatedAt sets the "created_at" field.
func (dsuo *DeploymentStatisticsUpdateOne) SetCreatedAt(t time.Time) *DeploymentStatisticsUpdateOne {
dsuo.mutation.SetCreatedAt(t)
@@ -299,11 +553,28 @@ func (dsuo *DeploymentStatisticsUpdateOne) SetUpdatedAt(t time.Time) *Deployment
return dsuo
}
+// SetRepoID sets the "repo_id" field.
+func (dsuo *DeploymentStatisticsUpdateOne) SetRepoID(i int64) *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.SetRepoID(i)
+ return dsuo
+}
+
+// SetRepo sets the "repo" edge to the Repo entity.
+func (dsuo *DeploymentStatisticsUpdateOne) SetRepo(r *Repo) *DeploymentStatisticsUpdateOne {
+ return dsuo.SetRepoID(r.ID)
+}
+
// Mutation returns the DeploymentStatisticsMutation object of the builder.
func (dsuo *DeploymentStatisticsUpdateOne) Mutation() *DeploymentStatisticsMutation {
return dsuo.mutation
}
+// ClearRepo clears the "repo" edge to the Repo entity.
+func (dsuo *DeploymentStatisticsUpdateOne) ClearRepo() *DeploymentStatisticsUpdateOne {
+ dsuo.mutation.ClearRepo()
+ return dsuo
+}
+
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (dsuo *DeploymentStatisticsUpdateOne) Select(field string, fields ...string) *DeploymentStatisticsUpdateOne {
@@ -319,6 +590,9 @@ func (dsuo *DeploymentStatisticsUpdateOne) Save(ctx context.Context) (*Deploymen
)
dsuo.defaults()
if len(dsuo.hooks) == 0 {
+ if err = dsuo.check(); err != nil {
+ return nil, err
+ }
node, err = dsuo.sqlSave(ctx)
} else {
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
@@ -326,6 +600,9 @@ func (dsuo *DeploymentStatisticsUpdateOne) Save(ctx context.Context) (*Deploymen
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
+ if err = dsuo.check(); err != nil {
+ return nil, err
+ }
dsuo.mutation = mutation
node, err = dsuo.sqlSave(ctx)
mutation.done = true
@@ -374,6 +651,14 @@ func (dsuo *DeploymentStatisticsUpdateOne) defaults() {
}
}
+// check runs all checks and user-defined validators on the builder.
+func (dsuo *DeploymentStatisticsUpdateOne) check() error {
+ if _, ok := dsuo.mutation.RepoID(); dsuo.mutation.RepoCleared() && !ok {
+ return errors.New("ent: clearing a required unique edge \"repo\"")
+ }
+ return nil
+}
+
func (dsuo *DeploymentStatisticsUpdateOne) sqlSave(ctx context.Context) (_node *DeploymentStatistics, err error) {
_spec := &sqlgraph.UpdateSpec{
Node: &sqlgraph.NodeSpec{
@@ -409,39 +694,81 @@ func (dsuo *DeploymentStatisticsUpdateOne) sqlSave(ctx context.Context) (_node *
}
}
}
- if value, ok := dsuo.mutation.Namespace(); ok {
+ if value, ok := dsuo.mutation.Env(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeString,
Value: value,
- Column: deploymentstatistics.FieldNamespace,
+ Column: deploymentstatistics.FieldEnv,
})
}
- if value, ok := dsuo.mutation.Name(); ok {
+ if value, ok := dsuo.mutation.Count(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
+ Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldName,
+ Column: deploymentstatistics.FieldCount,
})
}
- if value, ok := dsuo.mutation.Env(); ok {
+ if value, ok := dsuo.mutation.AddedCount(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldCount,
+ })
+ }
+ if value, ok := dsuo.mutation.RollbackCount(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
- Type: field.TypeString,
+ Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldEnv,
+ Column: deploymentstatistics.FieldRollbackCount,
})
}
- if value, ok := dsuo.mutation.Count(); ok {
+ if value, ok := dsuo.mutation.AddedRollbackCount(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldRollbackCount,
+ })
+ }
+ if value, ok := dsuo.mutation.Additions(); ok {
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldCount,
+ Column: deploymentstatistics.FieldAdditions,
})
}
- if value, ok := dsuo.mutation.AddedCount(); ok {
+ if value, ok := dsuo.mutation.AddedAdditions(); ok {
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
Type: field.TypeInt,
Value: value,
- Column: deploymentstatistics.FieldCount,
+ Column: deploymentstatistics.FieldAdditions,
+ })
+ }
+ if value, ok := dsuo.mutation.Deletions(); ok {
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldDeletions,
+ })
+ }
+ if value, ok := dsuo.mutation.AddedDeletions(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldDeletions,
+ })
+ }
+ if value, ok := dsuo.mutation.Changes(); ok {
+ _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldChanges,
+ })
+ }
+ if value, ok := dsuo.mutation.AddedChanges(); ok {
+ _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Value: value,
+ Column: deploymentstatistics.FieldChanges,
})
}
if value, ok := dsuo.mutation.CreatedAt(); ok {
@@ -458,6 +785,41 @@ func (dsuo *DeploymentStatisticsUpdateOne) sqlSave(ctx context.Context) (_node *
Column: deploymentstatistics.FieldUpdatedAt,
})
}
+ if dsuo.mutation.RepoCleared() {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.M2O,
+ Inverse: true,
+ Table: deploymentstatistics.RepoTable,
+ Columns: []string{deploymentstatistics.RepoColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt64,
+ Column: repo.FieldID,
+ },
+ },
+ }
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+ }
+ if nodes := dsuo.mutation.RepoIDs(); len(nodes) > 0 {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.M2O,
+ Inverse: true,
+ Table: deploymentstatistics.RepoTable,
+ Columns: []string{deploymentstatistics.RepoColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt64,
+ Column: repo.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
+ }
_node = &DeploymentStatistics{config: dsuo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go
index 20e23e85..27bc2da5 100644
--- a/ent/migrate/schema.go
+++ b/ent/migrate/schema.go
@@ -96,6 +96,7 @@ var (
{Name: "uid", Type: field.TypeInt64, Nullable: true},
{Name: "sha", Type: field.TypeString, Nullable: true},
{Name: "html_url", Type: field.TypeString, Nullable: true, Size: 2000},
+ {Name: "production_environment", Type: field.TypeBool, Default: false},
{Name: "is_rollback", Type: field.TypeBool, Default: false},
{Name: "is_approval_enabled", Type: field.TypeBool, Default: false},
{Name: "required_approval_count", Type: field.TypeInt, Default: 0},
@@ -112,13 +113,13 @@ var (
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "deployments_repos_deployments",
- Columns: []*schema.Column{DeploymentsColumns[14]},
+ Columns: []*schema.Column{DeploymentsColumns[15]},
RefColumns: []*schema.Column{ReposColumns[0]},
OnDelete: schema.Cascade,
},
{
Symbol: "deployments_users_deployments",
- Columns: []*schema.Column{DeploymentsColumns[15]},
+ Columns: []*schema.Column{DeploymentsColumns[16]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.SetNull,
},
@@ -127,22 +128,22 @@ var (
{
Name: "deployment_repo_id_env_status_updated_at",
Unique: false,
- Columns: []*schema.Column{DeploymentsColumns[14], DeploymentsColumns[3], DeploymentsColumns[5], DeploymentsColumns[13]},
+ Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[3], DeploymentsColumns[5], DeploymentsColumns[14]},
},
{
Name: "deployment_repo_id_env_created_at",
Unique: false,
- Columns: []*schema.Column{DeploymentsColumns[14], DeploymentsColumns[3], DeploymentsColumns[12]},
+ Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[3], DeploymentsColumns[13]},
},
{
Name: "deployment_repo_id_created_at",
Unique: false,
- Columns: []*schema.Column{DeploymentsColumns[14], DeploymentsColumns[12]},
+ Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[13]},
},
{
Name: "deployment_number_repo_id",
Unique: true,
- Columns: []*schema.Column{DeploymentsColumns[1], DeploymentsColumns[14]},
+ Columns: []*schema.Column{DeploymentsColumns[1], DeploymentsColumns[15]},
},
{
Name: "deployment_uid",
@@ -152,35 +153,46 @@ var (
{
Name: "deployment_status_created_at",
Unique: false,
- Columns: []*schema.Column{DeploymentsColumns[5], DeploymentsColumns[12]},
+ Columns: []*schema.Column{DeploymentsColumns[5], DeploymentsColumns[13]},
},
},
}
// DeploymentStatisticsColumns holds the columns for the "deployment_statistics" table.
DeploymentStatisticsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
- {Name: "namespace", Type: field.TypeString},
- {Name: "name", Type: field.TypeString},
{Name: "env", Type: field.TypeString},
- {Name: "count", Type: field.TypeInt, Default: 1},
+ {Name: "count", Type: field.TypeInt, Default: 0},
+ {Name: "rollback_count", Type: field.TypeInt, Default: 0},
+ {Name: "additions", Type: field.TypeInt, Default: 0},
+ {Name: "deletions", Type: field.TypeInt, Default: 0},
+ {Name: "changes", Type: field.TypeInt, Default: 0},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
+ {Name: "repo_id", Type: field.TypeInt64, Nullable: true},
}
// DeploymentStatisticsTable holds the schema information for the "deployment_statistics" table.
DeploymentStatisticsTable = &schema.Table{
Name: "deployment_statistics",
Columns: DeploymentStatisticsColumns,
PrimaryKey: []*schema.Column{DeploymentStatisticsColumns[0]},
+ ForeignKeys: []*schema.ForeignKey{
+ {
+ Symbol: "deployment_statistics_repos_deployment_statistics",
+ Columns: []*schema.Column{DeploymentStatisticsColumns[9]},
+ RefColumns: []*schema.Column{ReposColumns[0]},
+ OnDelete: schema.Cascade,
+ },
+ },
Indexes: []*schema.Index{
{
- Name: "deploymentstatistics_namespace_name_env",
+ Name: "deploymentstatistics_repo_id_env",
Unique: true,
- Columns: []*schema.Column{DeploymentStatisticsColumns[1], DeploymentStatisticsColumns[2], DeploymentStatisticsColumns[3]},
+ Columns: []*schema.Column{DeploymentStatisticsColumns[9], DeploymentStatisticsColumns[1]},
},
{
Name: "deploymentstatistics_updated_at",
Unique: false,
- Columns: []*schema.Column{DeploymentStatisticsColumns[6]},
+ Columns: []*schema.Column{DeploymentStatisticsColumns[8]},
},
},
}
@@ -415,6 +427,7 @@ func init() {
ChatUsersTable.ForeignKeys[0].RefTable = UsersTable
DeploymentsTable.ForeignKeys[0].RefTable = ReposTable
DeploymentsTable.ForeignKeys[1].RefTable = UsersTable
+ DeploymentStatisticsTable.ForeignKeys[0].RefTable = ReposTable
DeploymentStatusTable.ForeignKeys[0].RefTable = DeploymentsTable
EventsTable.ForeignKeys[0].RefTable = ApprovalsTable
EventsTable.ForeignKeys[1].RefTable = DeploymentsTable
diff --git a/ent/mutation.go b/ent/mutation.go
index 03c21b27..88379fc2 100644
--- a/ent/mutation.go
+++ b/ent/mutation.go
@@ -2004,6 +2004,7 @@ type DeploymentMutation struct {
adduid *int64
sha *string
html_url *string
+ production_environment *bool
is_rollback *bool
is_approval_enabled *bool
required_approval_count *int
@@ -2476,6 +2477,42 @@ func (m *DeploymentMutation) ResetHTMLURL() {
delete(m.clearedFields, deployment.FieldHTMLURL)
}
+// SetProductionEnvironment sets the "production_environment" field.
+func (m *DeploymentMutation) SetProductionEnvironment(b bool) {
+ m.production_environment = &b
+}
+
+// ProductionEnvironment returns the value of the "production_environment" field in the mutation.
+func (m *DeploymentMutation) ProductionEnvironment() (r bool, exists bool) {
+ v := m.production_environment
+ if v == nil {
+ return
+ }
+ return *v, true
+}
+
+// OldProductionEnvironment returns the old "production_environment" field's value of the Deployment entity.
+// If the Deployment object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *DeploymentMutation) OldProductionEnvironment(ctx context.Context) (v bool, err error) {
+ if !m.op.Is(OpUpdateOne) {
+ return v, fmt.Errorf("OldProductionEnvironment is only allowed on UpdateOne operations")
+ }
+ if m.id == nil || m.oldValue == nil {
+ return v, fmt.Errorf("OldProductionEnvironment requires an ID field in the mutation")
+ }
+ oldValue, err := m.oldValue(ctx)
+ if err != nil {
+ return v, fmt.Errorf("querying old value for OldProductionEnvironment: %w", err)
+ }
+ return oldValue.ProductionEnvironment, nil
+}
+
+// ResetProductionEnvironment resets all changes to the "production_environment" field.
+func (m *DeploymentMutation) ResetProductionEnvironment() {
+ m.production_environment = nil
+}
+
// SetIsRollback sets the "is_rollback" field.
func (m *DeploymentMutation) SetIsRollback(b bool) {
m.is_rollback = &b
@@ -2981,7 +3018,7 @@ func (m *DeploymentMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *DeploymentMutation) Fields() []string {
- fields := make([]string, 0, 15)
+ fields := make([]string, 0, 16)
if m.number != nil {
fields = append(fields, deployment.FieldNumber)
}
@@ -3006,6 +3043,9 @@ func (m *DeploymentMutation) Fields() []string {
if m.html_url != nil {
fields = append(fields, deployment.FieldHTMLURL)
}
+ if m.production_environment != nil {
+ fields = append(fields, deployment.FieldProductionEnvironment)
+ }
if m.is_rollback != nil {
fields = append(fields, deployment.FieldIsRollback)
}
@@ -3051,6 +3091,8 @@ func (m *DeploymentMutation) Field(name string) (ent.Value, bool) {
return m.Sha()
case deployment.FieldHTMLURL:
return m.HTMLURL()
+ case deployment.FieldProductionEnvironment:
+ return m.ProductionEnvironment()
case deployment.FieldIsRollback:
return m.IsRollback()
case deployment.FieldIsApprovalEnabled:
@@ -3090,6 +3132,8 @@ func (m *DeploymentMutation) OldField(ctx context.Context, name string) (ent.Val
return m.OldSha(ctx)
case deployment.FieldHTMLURL:
return m.OldHTMLURL(ctx)
+ case deployment.FieldProductionEnvironment:
+ return m.OldProductionEnvironment(ctx)
case deployment.FieldIsRollback:
return m.OldIsRollback(ctx)
case deployment.FieldIsApprovalEnabled:
@@ -3169,6 +3213,13 @@ func (m *DeploymentMutation) SetField(name string, value ent.Value) error {
}
m.SetHTMLURL(v)
return nil
+ case deployment.FieldProductionEnvironment:
+ v, ok := value.(bool)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.SetProductionEnvironment(v)
+ return nil
case deployment.FieldIsRollback:
v, ok := value.(bool)
if !ok {
@@ -3351,6 +3402,9 @@ func (m *DeploymentMutation) ResetField(name string) error {
case deployment.FieldHTMLURL:
m.ResetHTMLURL()
return nil
+ case deployment.FieldProductionEnvironment:
+ m.ResetProductionEnvironment()
+ return nil
case deployment.FieldIsRollback:
m.ResetIsRollback()
return nil
@@ -3551,20 +3605,28 @@ func (m *DeploymentMutation) ResetEdge(name string) error {
// DeploymentStatisticsMutation represents an operation that mutates the DeploymentStatistics nodes in the graph.
type DeploymentStatisticsMutation struct {
config
- op Op
- typ string
- id *int
- namespace *string
- name *string
- env *string
- count *int
- addcount *int
- created_at *time.Time
- updated_at *time.Time
- clearedFields map[string]struct{}
- done bool
- oldValue func(context.Context) (*DeploymentStatistics, error)
- predicates []predicate.DeploymentStatistics
+ op Op
+ typ string
+ id *int
+ env *string
+ count *int
+ addcount *int
+ rollback_count *int
+ addrollback_count *int
+ additions *int
+ addadditions *int
+ deletions *int
+ adddeletions *int
+ changes *int
+ addchanges *int
+ created_at *time.Time
+ updated_at *time.Time
+ clearedFields map[string]struct{}
+ repo *int64
+ clearedrepo bool
+ done bool
+ oldValue func(context.Context) (*DeploymentStatistics, error)
+ predicates []predicate.DeploymentStatistics
}
var _ ent.Mutation = (*DeploymentStatisticsMutation)(nil)
@@ -3646,168 +3708,320 @@ func (m *DeploymentStatisticsMutation) ID() (id int, exists bool) {
return *m.id, true
}
-// SetNamespace sets the "namespace" field.
-func (m *DeploymentStatisticsMutation) SetNamespace(s string) {
- m.namespace = &s
+// SetEnv sets the "env" field.
+func (m *DeploymentStatisticsMutation) SetEnv(s string) {
+ m.env = &s
}
-// Namespace returns the value of the "namespace" field in the mutation.
-func (m *DeploymentStatisticsMutation) Namespace() (r string, exists bool) {
- v := m.namespace
+// Env returns the value of the "env" field in the mutation.
+func (m *DeploymentStatisticsMutation) Env() (r string, exists bool) {
+ v := m.env
if v == nil {
return
}
return *v, true
}
-// OldNamespace returns the old "namespace" field's value of the DeploymentStatistics entity.
+// OldEnv returns the old "env" field's value of the DeploymentStatistics entity.
// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
-func (m *DeploymentStatisticsMutation) OldNamespace(ctx context.Context) (v string, err error) {
+func (m *DeploymentStatisticsMutation) OldEnv(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
- return v, fmt.Errorf("OldNamespace is only allowed on UpdateOne operations")
+ return v, fmt.Errorf("OldEnv is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
- return v, fmt.Errorf("OldNamespace requires an ID field in the mutation")
+ return v, fmt.Errorf("OldEnv requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
- return v, fmt.Errorf("querying old value for OldNamespace: %w", err)
+ return v, fmt.Errorf("querying old value for OldEnv: %w", err)
}
- return oldValue.Namespace, nil
+ return oldValue.Env, nil
}
-// ResetNamespace resets all changes to the "namespace" field.
-func (m *DeploymentStatisticsMutation) ResetNamespace() {
- m.namespace = nil
+// ResetEnv resets all changes to the "env" field.
+func (m *DeploymentStatisticsMutation) ResetEnv() {
+ m.env = nil
}
-// SetName sets the "name" field.
-func (m *DeploymentStatisticsMutation) SetName(s string) {
- m.name = &s
+// SetCount sets the "count" field.
+func (m *DeploymentStatisticsMutation) SetCount(i int) {
+ m.count = &i
+ m.addcount = nil
}
-// Name returns the value of the "name" field in the mutation.
-func (m *DeploymentStatisticsMutation) Name() (r string, exists bool) {
- v := m.name
+// Count returns the value of the "count" field in the mutation.
+func (m *DeploymentStatisticsMutation) Count() (r int, exists bool) {
+ v := m.count
if v == nil {
return
}
return *v, true
}
-// OldName returns the old "name" field's value of the DeploymentStatistics entity.
+// OldCount returns the old "count" field's value of the DeploymentStatistics entity.
// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
-func (m *DeploymentStatisticsMutation) OldName(ctx context.Context) (v string, err error) {
+func (m *DeploymentStatisticsMutation) OldCount(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
- return v, fmt.Errorf("OldName is only allowed on UpdateOne operations")
+ return v, fmt.Errorf("OldCount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
- return v, fmt.Errorf("OldName requires an ID field in the mutation")
+ return v, fmt.Errorf("OldCount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
- return v, fmt.Errorf("querying old value for OldName: %w", err)
+ return v, fmt.Errorf("querying old value for OldCount: %w", err)
}
- return oldValue.Name, nil
+ return oldValue.Count, nil
}
-// ResetName resets all changes to the "name" field.
-func (m *DeploymentStatisticsMutation) ResetName() {
- m.name = nil
+// AddCount adds i to the "count" field.
+func (m *DeploymentStatisticsMutation) AddCount(i int) {
+ if m.addcount != nil {
+ *m.addcount += i
+ } else {
+ m.addcount = &i
+ }
}
-// SetEnv sets the "env" field.
-func (m *DeploymentStatisticsMutation) SetEnv(s string) {
- m.env = &s
+// AddedCount returns the value that was added to the "count" field in this mutation.
+func (m *DeploymentStatisticsMutation) AddedCount() (r int, exists bool) {
+ v := m.addcount
+ if v == nil {
+ return
+ }
+ return *v, true
}
-// Env returns the value of the "env" field in the mutation.
-func (m *DeploymentStatisticsMutation) Env() (r string, exists bool) {
- v := m.env
+// ResetCount resets all changes to the "count" field.
+func (m *DeploymentStatisticsMutation) ResetCount() {
+ m.count = nil
+ m.addcount = nil
+}
+
+// SetRollbackCount sets the "rollback_count" field.
+func (m *DeploymentStatisticsMutation) SetRollbackCount(i int) {
+ m.rollback_count = &i
+ m.addrollback_count = nil
+}
+
+// RollbackCount returns the value of the "rollback_count" field in the mutation.
+func (m *DeploymentStatisticsMutation) RollbackCount() (r int, exists bool) {
+ v := m.rollback_count
if v == nil {
return
}
return *v, true
}
-// OldEnv returns the old "env" field's value of the DeploymentStatistics entity.
+// OldRollbackCount returns the old "rollback_count" field's value of the DeploymentStatistics entity.
// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
-func (m *DeploymentStatisticsMutation) OldEnv(ctx context.Context) (v string, err error) {
+func (m *DeploymentStatisticsMutation) OldRollbackCount(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
- return v, fmt.Errorf("OldEnv is only allowed on UpdateOne operations")
+ return v, fmt.Errorf("OldRollbackCount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
- return v, fmt.Errorf("OldEnv requires an ID field in the mutation")
+ return v, fmt.Errorf("OldRollbackCount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
- return v, fmt.Errorf("querying old value for OldEnv: %w", err)
+ return v, fmt.Errorf("querying old value for OldRollbackCount: %w", err)
}
- return oldValue.Env, nil
+ return oldValue.RollbackCount, nil
}
-// ResetEnv resets all changes to the "env" field.
-func (m *DeploymentStatisticsMutation) ResetEnv() {
- m.env = nil
+// AddRollbackCount adds i to the "rollback_count" field.
+func (m *DeploymentStatisticsMutation) AddRollbackCount(i int) {
+ if m.addrollback_count != nil {
+ *m.addrollback_count += i
+ } else {
+ m.addrollback_count = &i
+ }
}
-// SetCount sets the "count" field.
-func (m *DeploymentStatisticsMutation) SetCount(i int) {
- m.count = &i
- m.addcount = nil
+// AddedRollbackCount returns the value that was added to the "rollback_count" field in this mutation.
+func (m *DeploymentStatisticsMutation) AddedRollbackCount() (r int, exists bool) {
+ v := m.addrollback_count
+ if v == nil {
+ return
+ }
+ return *v, true
}
-// Count returns the value of the "count" field in the mutation.
-func (m *DeploymentStatisticsMutation) Count() (r int, exists bool) {
- v := m.count
+// ResetRollbackCount resets all changes to the "rollback_count" field.
+func (m *DeploymentStatisticsMutation) ResetRollbackCount() {
+ m.rollback_count = nil
+ m.addrollback_count = nil
+}
+
+// SetAdditions sets the "additions" field.
+func (m *DeploymentStatisticsMutation) SetAdditions(i int) {
+ m.additions = &i
+ m.addadditions = nil
+}
+
+// Additions returns the value of the "additions" field in the mutation.
+func (m *DeploymentStatisticsMutation) Additions() (r int, exists bool) {
+ v := m.additions
if v == nil {
return
}
return *v, true
}
-// OldCount returns the old "count" field's value of the DeploymentStatistics entity.
+// OldAdditions returns the old "additions" field's value of the DeploymentStatistics entity.
// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
-func (m *DeploymentStatisticsMutation) OldCount(ctx context.Context) (v int, err error) {
+func (m *DeploymentStatisticsMutation) OldAdditions(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
- return v, fmt.Errorf("OldCount is only allowed on UpdateOne operations")
+ return v, fmt.Errorf("OldAdditions is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
- return v, fmt.Errorf("OldCount requires an ID field in the mutation")
+ return v, fmt.Errorf("OldAdditions requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
- return v, fmt.Errorf("querying old value for OldCount: %w", err)
+ return v, fmt.Errorf("querying old value for OldAdditions: %w", err)
}
- return oldValue.Count, nil
+ return oldValue.Additions, nil
}
-// AddCount adds i to the "count" field.
-func (m *DeploymentStatisticsMutation) AddCount(i int) {
- if m.addcount != nil {
- *m.addcount += i
+// AddAdditions adds i to the "additions" field.
+func (m *DeploymentStatisticsMutation) AddAdditions(i int) {
+ if m.addadditions != nil {
+ *m.addadditions += i
} else {
- m.addcount = &i
+ m.addadditions = &i
}
}
-// AddedCount returns the value that was added to the "count" field in this mutation.
-func (m *DeploymentStatisticsMutation) AddedCount() (r int, exists bool) {
- v := m.addcount
+// AddedAdditions returns the value that was added to the "additions" field in this mutation.
+func (m *DeploymentStatisticsMutation) AddedAdditions() (r int, exists bool) {
+ v := m.addadditions
if v == nil {
return
}
return *v, true
}
-// ResetCount resets all changes to the "count" field.
-func (m *DeploymentStatisticsMutation) ResetCount() {
- m.count = nil
- m.addcount = nil
+// ResetAdditions resets all changes to the "additions" field.
+func (m *DeploymentStatisticsMutation) ResetAdditions() {
+ m.additions = nil
+ m.addadditions = nil
+}
+
+// SetDeletions sets the "deletions" field.
+func (m *DeploymentStatisticsMutation) SetDeletions(i int) {
+ m.deletions = &i
+ m.adddeletions = nil
+}
+
+// Deletions returns the value of the "deletions" field in the mutation.
+func (m *DeploymentStatisticsMutation) Deletions() (r int, exists bool) {
+ v := m.deletions
+ if v == nil {
+ return
+ }
+ return *v, true
+}
+
+// OldDeletions returns the old "deletions" field's value of the DeploymentStatistics entity.
+// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *DeploymentStatisticsMutation) OldDeletions(ctx context.Context) (v int, err error) {
+ if !m.op.Is(OpUpdateOne) {
+ return v, fmt.Errorf("OldDeletions is only allowed on UpdateOne operations")
+ }
+ if m.id == nil || m.oldValue == nil {
+ return v, fmt.Errorf("OldDeletions requires an ID field in the mutation")
+ }
+ oldValue, err := m.oldValue(ctx)
+ if err != nil {
+ return v, fmt.Errorf("querying old value for OldDeletions: %w", err)
+ }
+ return oldValue.Deletions, nil
+}
+
+// AddDeletions adds i to the "deletions" field.
+func (m *DeploymentStatisticsMutation) AddDeletions(i int) {
+ if m.adddeletions != nil {
+ *m.adddeletions += i
+ } else {
+ m.adddeletions = &i
+ }
+}
+
+// AddedDeletions returns the value that was added to the "deletions" field in this mutation.
+func (m *DeploymentStatisticsMutation) AddedDeletions() (r int, exists bool) {
+ v := m.adddeletions
+ if v == nil {
+ return
+ }
+ return *v, true
+}
+
+// ResetDeletions resets all changes to the "deletions" field.
+func (m *DeploymentStatisticsMutation) ResetDeletions() {
+ m.deletions = nil
+ m.adddeletions = nil
+}
+
+// SetChanges sets the "changes" field.
+func (m *DeploymentStatisticsMutation) SetChanges(i int) {
+ m.changes = &i
+ m.addchanges = nil
+}
+
+// Changes returns the value of the "changes" field in the mutation.
+func (m *DeploymentStatisticsMutation) Changes() (r int, exists bool) {
+ v := m.changes
+ if v == nil {
+ return
+ }
+ return *v, true
+}
+
+// OldChanges returns the old "changes" field's value of the DeploymentStatistics entity.
+// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *DeploymentStatisticsMutation) OldChanges(ctx context.Context) (v int, err error) {
+ if !m.op.Is(OpUpdateOne) {
+ return v, fmt.Errorf("OldChanges is only allowed on UpdateOne operations")
+ }
+ if m.id == nil || m.oldValue == nil {
+ return v, fmt.Errorf("OldChanges requires an ID field in the mutation")
+ }
+ oldValue, err := m.oldValue(ctx)
+ if err != nil {
+ return v, fmt.Errorf("querying old value for OldChanges: %w", err)
+ }
+ return oldValue.Changes, nil
+}
+
+// AddChanges adds i to the "changes" field.
+func (m *DeploymentStatisticsMutation) AddChanges(i int) {
+ if m.addchanges != nil {
+ *m.addchanges += i
+ } else {
+ m.addchanges = &i
+ }
+}
+
+// AddedChanges returns the value that was added to the "changes" field in this mutation.
+func (m *DeploymentStatisticsMutation) AddedChanges() (r int, exists bool) {
+ v := m.addchanges
+ if v == nil {
+ return
+ }
+ return *v, true
+}
+
+// ResetChanges resets all changes to the "changes" field.
+func (m *DeploymentStatisticsMutation) ResetChanges() {
+ m.changes = nil
+ m.addchanges = nil
}
// SetCreatedAt sets the "created_at" field.
@@ -3882,6 +4096,68 @@ func (m *DeploymentStatisticsMutation) ResetUpdatedAt() {
m.updated_at = nil
}
+// SetRepoID sets the "repo_id" field.
+func (m *DeploymentStatisticsMutation) SetRepoID(i int64) {
+ m.repo = &i
+}
+
+// RepoID returns the value of the "repo_id" field in the mutation.
+func (m *DeploymentStatisticsMutation) RepoID() (r int64, exists bool) {
+ v := m.repo
+ if v == nil {
+ return
+ }
+ return *v, true
+}
+
+// OldRepoID returns the old "repo_id" field's value of the DeploymentStatistics entity.
+// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *DeploymentStatisticsMutation) OldRepoID(ctx context.Context) (v int64, err error) {
+ if !m.op.Is(OpUpdateOne) {
+ return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations")
+ }
+ if m.id == nil || m.oldValue == nil {
+ return v, fmt.Errorf("OldRepoID requires an ID field in the mutation")
+ }
+ oldValue, err := m.oldValue(ctx)
+ if err != nil {
+ return v, fmt.Errorf("querying old value for OldRepoID: %w", err)
+ }
+ return oldValue.RepoID, nil
+}
+
+// ResetRepoID resets all changes to the "repo_id" field.
+func (m *DeploymentStatisticsMutation) ResetRepoID() {
+ m.repo = nil
+}
+
+// ClearRepo clears the "repo" edge to the Repo entity.
+func (m *DeploymentStatisticsMutation) ClearRepo() {
+ m.clearedrepo = true
+}
+
+// RepoCleared reports if the "repo" edge to the Repo entity was cleared.
+func (m *DeploymentStatisticsMutation) RepoCleared() bool {
+ return m.clearedrepo
+}
+
+// RepoIDs returns the "repo" edge IDs in the mutation.
+// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
+// RepoID instead. It exists only for internal usage by the builders.
+func (m *DeploymentStatisticsMutation) RepoIDs() (ids []int64) {
+ if id := m.repo; id != nil {
+ ids = append(ids, *id)
+ }
+ return
+}
+
+// ResetRepo resets all changes to the "repo" edge.
+func (m *DeploymentStatisticsMutation) ResetRepo() {
+ m.repo = nil
+ m.clearedrepo = false
+}
+
// Where appends a list predicates to the DeploymentStatisticsMutation builder.
func (m *DeploymentStatisticsMutation) Where(ps ...predicate.DeploymentStatistics) {
m.predicates = append(m.predicates, ps...)
@@ -3901,25 +4177,34 @@ func (m *DeploymentStatisticsMutation) Type() string {
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *DeploymentStatisticsMutation) Fields() []string {
- fields := make([]string, 0, 6)
- if m.namespace != nil {
- fields = append(fields, deploymentstatistics.FieldNamespace)
- }
- if m.name != nil {
- fields = append(fields, deploymentstatistics.FieldName)
- }
+ fields := make([]string, 0, 9)
if m.env != nil {
fields = append(fields, deploymentstatistics.FieldEnv)
}
if m.count != nil {
fields = append(fields, deploymentstatistics.FieldCount)
}
+ if m.rollback_count != nil {
+ fields = append(fields, deploymentstatistics.FieldRollbackCount)
+ }
+ if m.additions != nil {
+ fields = append(fields, deploymentstatistics.FieldAdditions)
+ }
+ if m.deletions != nil {
+ fields = append(fields, deploymentstatistics.FieldDeletions)
+ }
+ if m.changes != nil {
+ fields = append(fields, deploymentstatistics.FieldChanges)
+ }
if m.created_at != nil {
fields = append(fields, deploymentstatistics.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, deploymentstatistics.FieldUpdatedAt)
}
+ if m.repo != nil {
+ fields = append(fields, deploymentstatistics.FieldRepoID)
+ }
return fields
}
@@ -3928,18 +4213,24 @@ func (m *DeploymentStatisticsMutation) Fields() []string {
// schema.
func (m *DeploymentStatisticsMutation) Field(name string) (ent.Value, bool) {
switch name {
- case deploymentstatistics.FieldNamespace:
- return m.Namespace()
- case deploymentstatistics.FieldName:
- return m.Name()
case deploymentstatistics.FieldEnv:
return m.Env()
case deploymentstatistics.FieldCount:
return m.Count()
+ case deploymentstatistics.FieldRollbackCount:
+ return m.RollbackCount()
+ case deploymentstatistics.FieldAdditions:
+ return m.Additions()
+ case deploymentstatistics.FieldDeletions:
+ return m.Deletions()
+ case deploymentstatistics.FieldChanges:
+ return m.Changes()
case deploymentstatistics.FieldCreatedAt:
return m.CreatedAt()
case deploymentstatistics.FieldUpdatedAt:
return m.UpdatedAt()
+ case deploymentstatistics.FieldRepoID:
+ return m.RepoID()
}
return nil, false
}
@@ -3949,18 +4240,24 @@ func (m *DeploymentStatisticsMutation) Field(name string) (ent.Value, bool) {
// database failed.
func (m *DeploymentStatisticsMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
- case deploymentstatistics.FieldNamespace:
- return m.OldNamespace(ctx)
- case deploymentstatistics.FieldName:
- return m.OldName(ctx)
case deploymentstatistics.FieldEnv:
return m.OldEnv(ctx)
case deploymentstatistics.FieldCount:
return m.OldCount(ctx)
+ case deploymentstatistics.FieldRollbackCount:
+ return m.OldRollbackCount(ctx)
+ case deploymentstatistics.FieldAdditions:
+ return m.OldAdditions(ctx)
+ case deploymentstatistics.FieldDeletions:
+ return m.OldDeletions(ctx)
+ case deploymentstatistics.FieldChanges:
+ return m.OldChanges(ctx)
case deploymentstatistics.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case deploymentstatistics.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
+ case deploymentstatistics.FieldRepoID:
+ return m.OldRepoID(ctx)
}
return nil, fmt.Errorf("unknown DeploymentStatistics field %s", name)
}
@@ -3970,33 +4267,47 @@ func (m *DeploymentStatisticsMutation) OldField(ctx context.Context, name string
// type.
func (m *DeploymentStatisticsMutation) SetField(name string, value ent.Value) error {
switch name {
- case deploymentstatistics.FieldNamespace:
+ case deploymentstatistics.FieldEnv:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
- m.SetNamespace(v)
+ m.SetEnv(v)
return nil
- case deploymentstatistics.FieldName:
- v, ok := value.(string)
+ case deploymentstatistics.FieldCount:
+ v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
- m.SetName(v)
+ m.SetCount(v)
return nil
- case deploymentstatistics.FieldEnv:
- v, ok := value.(string)
+ case deploymentstatistics.FieldRollbackCount:
+ v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
- m.SetEnv(v)
+ m.SetRollbackCount(v)
return nil
- case deploymentstatistics.FieldCount:
+ case deploymentstatistics.FieldAdditions:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
- m.SetCount(v)
+ m.SetAdditions(v)
+ return nil
+ case deploymentstatistics.FieldDeletions:
+ v, ok := value.(int)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.SetDeletions(v)
+ return nil
+ case deploymentstatistics.FieldChanges:
+ v, ok := value.(int)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.SetChanges(v)
return nil
case deploymentstatistics.FieldCreatedAt:
v, ok := value.(time.Time)
@@ -4012,6 +4323,13 @@ func (m *DeploymentStatisticsMutation) SetField(name string, value ent.Value) er
}
m.SetUpdatedAt(v)
return nil
+ case deploymentstatistics.FieldRepoID:
+ v, ok := value.(int64)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.SetRepoID(v)
+ return nil
}
return fmt.Errorf("unknown DeploymentStatistics field %s", name)
}
@@ -4023,6 +4341,18 @@ func (m *DeploymentStatisticsMutation) AddedFields() []string {
if m.addcount != nil {
fields = append(fields, deploymentstatistics.FieldCount)
}
+ if m.addrollback_count != nil {
+ fields = append(fields, deploymentstatistics.FieldRollbackCount)
+ }
+ if m.addadditions != nil {
+ fields = append(fields, deploymentstatistics.FieldAdditions)
+ }
+ if m.adddeletions != nil {
+ fields = append(fields, deploymentstatistics.FieldDeletions)
+ }
+ if m.addchanges != nil {
+ fields = append(fields, deploymentstatistics.FieldChanges)
+ }
return fields
}
@@ -4033,6 +4363,14 @@ func (m *DeploymentStatisticsMutation) AddedField(name string) (ent.Value, bool)
switch name {
case deploymentstatistics.FieldCount:
return m.AddedCount()
+ case deploymentstatistics.FieldRollbackCount:
+ return m.AddedRollbackCount()
+ case deploymentstatistics.FieldAdditions:
+ return m.AddedAdditions()
+ case deploymentstatistics.FieldDeletions:
+ return m.AddedDeletions()
+ case deploymentstatistics.FieldChanges:
+ return m.AddedChanges()
}
return nil, false
}
@@ -4049,6 +4387,34 @@ func (m *DeploymentStatisticsMutation) AddField(name string, value ent.Value) er
}
m.AddCount(v)
return nil
+ case deploymentstatistics.FieldRollbackCount:
+ v, ok := value.(int)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.AddRollbackCount(v)
+ return nil
+ case deploymentstatistics.FieldAdditions:
+ v, ok := value.(int)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.AddAdditions(v)
+ return nil
+ case deploymentstatistics.FieldDeletions:
+ v, ok := value.(int)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.AddDeletions(v)
+ return nil
+ case deploymentstatistics.FieldChanges:
+ v, ok := value.(int)
+ if !ok {
+ return fmt.Errorf("unexpected type %T for field %s", value, name)
+ }
+ m.AddChanges(v)
+ return nil
}
return fmt.Errorf("unknown DeploymentStatistics numeric field %s", name)
}
@@ -4076,73 +4442,110 @@ func (m *DeploymentStatisticsMutation) ClearField(name string) error {
// It returns an error if the field is not defined in the schema.
func (m *DeploymentStatisticsMutation) ResetField(name string) error {
switch name {
- case deploymentstatistics.FieldNamespace:
- m.ResetNamespace()
- return nil
- case deploymentstatistics.FieldName:
- m.ResetName()
- return nil
case deploymentstatistics.FieldEnv:
m.ResetEnv()
return nil
case deploymentstatistics.FieldCount:
m.ResetCount()
return nil
+ case deploymentstatistics.FieldRollbackCount:
+ m.ResetRollbackCount()
+ return nil
+ case deploymentstatistics.FieldAdditions:
+ m.ResetAdditions()
+ return nil
+ case deploymentstatistics.FieldDeletions:
+ m.ResetDeletions()
+ return nil
+ case deploymentstatistics.FieldChanges:
+ m.ResetChanges()
+ return nil
case deploymentstatistics.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case deploymentstatistics.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
+ case deploymentstatistics.FieldRepoID:
+ m.ResetRepoID()
+ return nil
}
return fmt.Errorf("unknown DeploymentStatistics field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *DeploymentStatisticsMutation) AddedEdges() []string {
- edges := make([]string, 0, 0)
+ edges := make([]string, 0, 1)
+ if m.repo != nil {
+ edges = append(edges, deploymentstatistics.EdgeRepo)
+ }
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *DeploymentStatisticsMutation) AddedIDs(name string) []ent.Value {
+ switch name {
+ case deploymentstatistics.EdgeRepo:
+ if id := m.repo; id != nil {
+ return []ent.Value{*id}
+ }
+ }
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *DeploymentStatisticsMutation) RemovedEdges() []string {
- edges := make([]string, 0, 0)
+ edges := make([]string, 0, 1)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *DeploymentStatisticsMutation) RemovedIDs(name string) []ent.Value {
+ switch name {
+ }
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *DeploymentStatisticsMutation) ClearedEdges() []string {
- edges := make([]string, 0, 0)
+ edges := make([]string, 0, 1)
+ if m.clearedrepo {
+ edges = append(edges, deploymentstatistics.EdgeRepo)
+ }
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *DeploymentStatisticsMutation) EdgeCleared(name string) bool {
+ switch name {
+ case deploymentstatistics.EdgeRepo:
+ return m.clearedrepo
+ }
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *DeploymentStatisticsMutation) ClearEdge(name string) error {
+ switch name {
+ case deploymentstatistics.EdgeRepo:
+ m.ClearRepo()
+ return nil
+ }
return fmt.Errorf("unknown DeploymentStatistics unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *DeploymentStatisticsMutation) ResetEdge(name string) error {
+ switch name {
+ case deploymentstatistics.EdgeRepo:
+ m.ResetRepo()
+ return nil
+ }
return fmt.Errorf("unknown DeploymentStatistics edge %s", name)
}
@@ -7222,35 +7625,38 @@ func (m *PermMutation) ResetEdge(name string) error {
// RepoMutation represents an operation that mutates the Repo nodes in the graph.
type RepoMutation struct {
config
- op Op
- typ string
- id *int64
- namespace *string
- name *string
- description *string
- config_path *string
- active *bool
- webhook_id *int64
- addwebhook_id *int64
- created_at *time.Time
- updated_at *time.Time
- latest_deployed_at *time.Time
- clearedFields map[string]struct{}
- perms map[int]struct{}
- removedperms map[int]struct{}
- clearedperms bool
- deployments map[int]struct{}
- removeddeployments map[int]struct{}
- cleareddeployments bool
- callback map[int]struct{}
- removedcallback map[int]struct{}
- clearedcallback bool
- locks map[int]struct{}
- removedlocks map[int]struct{}
- clearedlocks bool
- done bool
- oldValue func(context.Context) (*Repo, error)
- predicates []predicate.Repo
+ op Op
+ typ string
+ id *int64
+ namespace *string
+ name *string
+ description *string
+ config_path *string
+ active *bool
+ webhook_id *int64
+ addwebhook_id *int64
+ created_at *time.Time
+ updated_at *time.Time
+ latest_deployed_at *time.Time
+ clearedFields map[string]struct{}
+ perms map[int]struct{}
+ removedperms map[int]struct{}
+ clearedperms bool
+ deployments map[int]struct{}
+ removeddeployments map[int]struct{}
+ cleareddeployments bool
+ callback map[int]struct{}
+ removedcallback map[int]struct{}
+ clearedcallback bool
+ locks map[int]struct{}
+ removedlocks map[int]struct{}
+ clearedlocks bool
+ deployment_statistics map[int]struct{}
+ removeddeployment_statistics map[int]struct{}
+ cleareddeployment_statistics bool
+ done bool
+ oldValue func(context.Context) (*Repo, error)
+ predicates []predicate.Repo
}
var _ ent.Mutation = (*RepoMutation)(nil)
@@ -7925,6 +8331,60 @@ func (m *RepoMutation) ResetLocks() {
m.removedlocks = nil
}
+// AddDeploymentStatisticIDs adds the "deployment_statistics" edge to the DeploymentStatistics entity by ids.
+func (m *RepoMutation) AddDeploymentStatisticIDs(ids ...int) {
+ if m.deployment_statistics == nil {
+ m.deployment_statistics = make(map[int]struct{})
+ }
+ for i := range ids {
+ m.deployment_statistics[ids[i]] = struct{}{}
+ }
+}
+
+// ClearDeploymentStatistics clears the "deployment_statistics" edge to the DeploymentStatistics entity.
+func (m *RepoMutation) ClearDeploymentStatistics() {
+ m.cleareddeployment_statistics = true
+}
+
+// DeploymentStatisticsCleared reports if the "deployment_statistics" edge to the DeploymentStatistics entity was cleared.
+func (m *RepoMutation) DeploymentStatisticsCleared() bool {
+ return m.cleareddeployment_statistics
+}
+
+// RemoveDeploymentStatisticIDs removes the "deployment_statistics" edge to the DeploymentStatistics entity by IDs.
+func (m *RepoMutation) RemoveDeploymentStatisticIDs(ids ...int) {
+ if m.removeddeployment_statistics == nil {
+ m.removeddeployment_statistics = make(map[int]struct{})
+ }
+ for i := range ids {
+ delete(m.deployment_statistics, ids[i])
+ m.removeddeployment_statistics[ids[i]] = struct{}{}
+ }
+}
+
+// RemovedDeploymentStatistics returns the removed IDs of the "deployment_statistics" edge to the DeploymentStatistics entity.
+func (m *RepoMutation) RemovedDeploymentStatisticsIDs() (ids []int) {
+ for id := range m.removeddeployment_statistics {
+ ids = append(ids, id)
+ }
+ return
+}
+
+// DeploymentStatisticsIDs returns the "deployment_statistics" edge IDs in the mutation.
+func (m *RepoMutation) DeploymentStatisticsIDs() (ids []int) {
+ for id := range m.deployment_statistics {
+ ids = append(ids, id)
+ }
+ return
+}
+
+// ResetDeploymentStatistics resets all changes to the "deployment_statistics" edge.
+func (m *RepoMutation) ResetDeploymentStatistics() {
+ m.deployment_statistics = nil
+ m.cleareddeployment_statistics = false
+ m.removeddeployment_statistics = nil
+}
+
// Where appends a list predicates to the RepoMutation builder.
func (m *RepoMutation) Where(ps ...predicate.Repo) {
m.predicates = append(m.predicates, ps...)
@@ -8209,7 +8669,7 @@ func (m *RepoMutation) ResetField(name string) error {
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *RepoMutation) AddedEdges() []string {
- edges := make([]string, 0, 4)
+ edges := make([]string, 0, 5)
if m.perms != nil {
edges = append(edges, repo.EdgePerms)
}
@@ -8222,6 +8682,9 @@ func (m *RepoMutation) AddedEdges() []string {
if m.locks != nil {
edges = append(edges, repo.EdgeLocks)
}
+ if m.deployment_statistics != nil {
+ edges = append(edges, repo.EdgeDeploymentStatistics)
+ }
return edges
}
@@ -8253,13 +8716,19 @@ func (m *RepoMutation) AddedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
+ case repo.EdgeDeploymentStatistics:
+ ids := make([]ent.Value, 0, len(m.deployment_statistics))
+ for id := range m.deployment_statistics {
+ ids = append(ids, id)
+ }
+ return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *RepoMutation) RemovedEdges() []string {
- edges := make([]string, 0, 4)
+ edges := make([]string, 0, 5)
if m.removedperms != nil {
edges = append(edges, repo.EdgePerms)
}
@@ -8272,6 +8741,9 @@ func (m *RepoMutation) RemovedEdges() []string {
if m.removedlocks != nil {
edges = append(edges, repo.EdgeLocks)
}
+ if m.removeddeployment_statistics != nil {
+ edges = append(edges, repo.EdgeDeploymentStatistics)
+ }
return edges
}
@@ -8303,13 +8775,19 @@ func (m *RepoMutation) RemovedIDs(name string) []ent.Value {
ids = append(ids, id)
}
return ids
+ case repo.EdgeDeploymentStatistics:
+ ids := make([]ent.Value, 0, len(m.removeddeployment_statistics))
+ for id := range m.removeddeployment_statistics {
+ ids = append(ids, id)
+ }
+ return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *RepoMutation) ClearedEdges() []string {
- edges := make([]string, 0, 4)
+ edges := make([]string, 0, 5)
if m.clearedperms {
edges = append(edges, repo.EdgePerms)
}
@@ -8322,6 +8800,9 @@ func (m *RepoMutation) ClearedEdges() []string {
if m.clearedlocks {
edges = append(edges, repo.EdgeLocks)
}
+ if m.cleareddeployment_statistics {
+ edges = append(edges, repo.EdgeDeploymentStatistics)
+ }
return edges
}
@@ -8337,6 +8818,8 @@ func (m *RepoMutation) EdgeCleared(name string) bool {
return m.clearedcallback
case repo.EdgeLocks:
return m.clearedlocks
+ case repo.EdgeDeploymentStatistics:
+ return m.cleareddeployment_statistics
}
return false
}
@@ -8365,6 +8848,9 @@ func (m *RepoMutation) ResetEdge(name string) error {
case repo.EdgeLocks:
m.ResetLocks()
return nil
+ case repo.EdgeDeploymentStatistics:
+ m.ResetDeploymentStatistics()
+ return nil
}
return fmt.Errorf("unknown Repo edge %s", name)
}
diff --git a/ent/repo.go b/ent/repo.go
index b61b3568..ecd06395 100644
--- a/ent/repo.go
+++ b/ent/repo.go
@@ -49,9 +49,11 @@ type RepoEdges struct {
Callback []*Callback `json:"callback,omitempty"`
// Locks holds the value of the locks edge.
Locks []*Lock `json:"locks,omitempty"`
+ // DeploymentStatistics holds the value of the deployment_statistics edge.
+ DeploymentStatistics []*DeploymentStatistics `json:"deployment_statistics,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
- loadedTypes [4]bool
+ loadedTypes [5]bool
}
// PermsOrErr returns the Perms value or an error if the edge
@@ -90,6 +92,15 @@ func (e RepoEdges) LocksOrErr() ([]*Lock, error) {
return nil, &NotLoadedError{edge: "locks"}
}
+// DeploymentStatisticsOrErr returns the DeploymentStatistics value or an error if the edge
+// was not loaded in eager-loading.
+func (e RepoEdges) DeploymentStatisticsOrErr() ([]*DeploymentStatistics, error) {
+ if e.loadedTypes[4] {
+ return e.DeploymentStatistics, nil
+ }
+ return nil, &NotLoadedError{edge: "deployment_statistics"}
+}
+
// scanValues returns the types for scanning values from sql.Rows.
func (*Repo) scanValues(columns []string) ([]interface{}, error) {
values := make([]interface{}, len(columns))
@@ -203,6 +214,11 @@ func (r *Repo) QueryLocks() *LockQuery {
return (&RepoClient{config: r.config}).QueryLocks(r)
}
+// QueryDeploymentStatistics queries the "deployment_statistics" edge of the Repo entity.
+func (r *Repo) QueryDeploymentStatistics() *DeploymentStatisticsQuery {
+ return (&RepoClient{config: r.config}).QueryDeploymentStatistics(r)
+}
+
// Update returns a builder for updating this Repo.
// Note that you need to call Repo.Unwrap() before calling this method if this Repo
// was returned from a transaction, and the transaction was committed or rolled back.
diff --git a/ent/repo/repo.go b/ent/repo/repo.go
index e52a36e5..9d44cbf3 100644
--- a/ent/repo/repo.go
+++ b/ent/repo/repo.go
@@ -37,6 +37,8 @@ const (
EdgeCallback = "callback"
// EdgeLocks holds the string denoting the locks edge name in mutations.
EdgeLocks = "locks"
+ // EdgeDeploymentStatistics holds the string denoting the deployment_statistics edge name in mutations.
+ EdgeDeploymentStatistics = "deployment_statistics"
// Table holds the table name of the repo in the database.
Table = "repos"
// PermsTable is the table that holds the perms relation/edge.
@@ -67,6 +69,13 @@ const (
LocksInverseTable = "locks"
// LocksColumn is the table column denoting the locks relation/edge.
LocksColumn = "repo_id"
+ // DeploymentStatisticsTable is the table that holds the deployment_statistics relation/edge.
+ DeploymentStatisticsTable = "deployment_statistics"
+ // DeploymentStatisticsInverseTable is the table name for the DeploymentStatistics entity.
+ // It exists in this package in order to avoid circular dependency with the "deploymentstatistics" package.
+ DeploymentStatisticsInverseTable = "deployment_statistics"
+ // DeploymentStatisticsColumn is the table column denoting the deployment_statistics relation/edge.
+ DeploymentStatisticsColumn = "repo_id"
)
// Columns holds all SQL columns for repo fields.
diff --git a/ent/repo/where.go b/ent/repo/where.go
index c492fd50..d65cce62 100644
--- a/ent/repo/where.go
+++ b/ent/repo/where.go
@@ -1058,6 +1058,34 @@ func HasLocksWith(preds ...predicate.Lock) predicate.Repo {
})
}
+// HasDeploymentStatistics applies the HasEdge predicate on the "deployment_statistics" edge.
+func HasDeploymentStatistics() predicate.Repo {
+ return predicate.Repo(func(s *sql.Selector) {
+ step := sqlgraph.NewStep(
+ sqlgraph.From(Table, FieldID),
+ sqlgraph.To(DeploymentStatisticsTable, FieldID),
+ sqlgraph.Edge(sqlgraph.O2M, false, DeploymentStatisticsTable, DeploymentStatisticsColumn),
+ )
+ sqlgraph.HasNeighbors(s, step)
+ })
+}
+
+// HasDeploymentStatisticsWith applies the HasEdge predicate on the "deployment_statistics" edge with a given conditions (other predicates).
+func HasDeploymentStatisticsWith(preds ...predicate.DeploymentStatistics) predicate.Repo {
+ return predicate.Repo(func(s *sql.Selector) {
+ step := sqlgraph.NewStep(
+ sqlgraph.From(Table, FieldID),
+ sqlgraph.To(DeploymentStatisticsInverseTable, FieldID),
+ sqlgraph.Edge(sqlgraph.O2M, false, DeploymentStatisticsTable, DeploymentStatisticsColumn),
+ )
+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
+ for _, p := range preds {
+ p(s)
+ }
+ })
+ })
+}
+
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Repo) predicate.Repo {
return predicate.Repo(func(s *sql.Selector) {
diff --git a/ent/repo_create.go b/ent/repo_create.go
index 5fbaac68..14e0ef51 100644
--- a/ent/repo_create.go
+++ b/ent/repo_create.go
@@ -12,6 +12,7 @@ import (
"entgo.io/ent/schema/field"
"github.com/gitploy-io/gitploy/ent/callback"
"github.com/gitploy-io/gitploy/ent/deployment"
+ "github.com/gitploy-io/gitploy/ent/deploymentstatistics"
"github.com/gitploy-io/gitploy/ent/lock"
"github.com/gitploy-io/gitploy/ent/perm"
"github.com/gitploy-io/gitploy/ent/repo"
@@ -192,6 +193,21 @@ func (rc *RepoCreate) AddLocks(l ...*Lock) *RepoCreate {
return rc.AddLockIDs(ids...)
}
+// AddDeploymentStatisticIDs adds the "deployment_statistics" edge to the DeploymentStatistics entity by IDs.
+func (rc *RepoCreate) AddDeploymentStatisticIDs(ids ...int) *RepoCreate {
+ rc.mutation.AddDeploymentStatisticIDs(ids...)
+ return rc
+}
+
+// AddDeploymentStatistics adds the "deployment_statistics" edges to the DeploymentStatistics entity.
+func (rc *RepoCreate) AddDeploymentStatistics(d ...*DeploymentStatistics) *RepoCreate {
+ ids := make([]int, len(d))
+ for i := range d {
+ ids[i] = d[i].ID
+ }
+ return rc.AddDeploymentStatisticIDs(ids...)
+}
+
// Mutation returns the RepoMutation object of the builder.
func (rc *RepoCreate) Mutation() *RepoMutation {
return rc.mutation
@@ -485,6 +501,25 @@ func (rc *RepoCreate) createSpec() (*Repo, *sqlgraph.CreateSpec) {
}
_spec.Edges = append(_spec.Edges, edge)
}
+ if nodes := rc.mutation.DeploymentStatisticsIDs(); len(nodes) > 0 {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.O2M,
+ Inverse: false,
+ Table: repo.DeploymentStatisticsTable,
+ Columns: []string{repo.DeploymentStatisticsColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Column: deploymentstatistics.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _spec.Edges = append(_spec.Edges, edge)
+ }
return _node, _spec
}
diff --git a/ent/repo_query.go b/ent/repo_query.go
index 4828176b..31d918de 100644
--- a/ent/repo_query.go
+++ b/ent/repo_query.go
@@ -15,6 +15,7 @@ import (
"entgo.io/ent/schema/field"
"github.com/gitploy-io/gitploy/ent/callback"
"github.com/gitploy-io/gitploy/ent/deployment"
+ "github.com/gitploy-io/gitploy/ent/deploymentstatistics"
"github.com/gitploy-io/gitploy/ent/lock"
"github.com/gitploy-io/gitploy/ent/perm"
"github.com/gitploy-io/gitploy/ent/predicate"
@@ -31,11 +32,12 @@ type RepoQuery struct {
fields []string
predicates []predicate.Repo
// eager-loading edges.
- withPerms *PermQuery
- withDeployments *DeploymentQuery
- withCallback *CallbackQuery
- withLocks *LockQuery
- modifiers []func(s *sql.Selector)
+ withPerms *PermQuery
+ withDeployments *DeploymentQuery
+ withCallback *CallbackQuery
+ withLocks *LockQuery
+ withDeploymentStatistics *DeploymentStatisticsQuery
+ modifiers []func(s *sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
@@ -160,6 +162,28 @@ func (rq *RepoQuery) QueryLocks() *LockQuery {
return query
}
+// QueryDeploymentStatistics chains the current query on the "deployment_statistics" edge.
+func (rq *RepoQuery) QueryDeploymentStatistics() *DeploymentStatisticsQuery {
+ query := &DeploymentStatisticsQuery{config: rq.config}
+ query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
+ if err := rq.prepareQuery(ctx); err != nil {
+ return nil, err
+ }
+ selector := rq.sqlQuery(ctx)
+ if err := selector.Err(); err != nil {
+ return nil, err
+ }
+ step := sqlgraph.NewStep(
+ sqlgraph.From(repo.Table, repo.FieldID, selector),
+ sqlgraph.To(deploymentstatistics.Table, deploymentstatistics.FieldID),
+ sqlgraph.Edge(sqlgraph.O2M, false, repo.DeploymentStatisticsTable, repo.DeploymentStatisticsColumn),
+ )
+ fromU = sqlgraph.SetNeighbors(rq.driver.Dialect(), step)
+ return fromU, nil
+ }
+ return query
+}
+
// First returns the first Repo entity from the query.
// Returns a *NotFoundError when no Repo was found.
func (rq *RepoQuery) First(ctx context.Context) (*Repo, error) {
@@ -336,15 +360,16 @@ func (rq *RepoQuery) Clone() *RepoQuery {
return nil
}
return &RepoQuery{
- config: rq.config,
- limit: rq.limit,
- offset: rq.offset,
- order: append([]OrderFunc{}, rq.order...),
- predicates: append([]predicate.Repo{}, rq.predicates...),
- withPerms: rq.withPerms.Clone(),
- withDeployments: rq.withDeployments.Clone(),
- withCallback: rq.withCallback.Clone(),
- withLocks: rq.withLocks.Clone(),
+ config: rq.config,
+ limit: rq.limit,
+ offset: rq.offset,
+ order: append([]OrderFunc{}, rq.order...),
+ predicates: append([]predicate.Repo{}, rq.predicates...),
+ withPerms: rq.withPerms.Clone(),
+ withDeployments: rq.withDeployments.Clone(),
+ withCallback: rq.withCallback.Clone(),
+ withLocks: rq.withLocks.Clone(),
+ withDeploymentStatistics: rq.withDeploymentStatistics.Clone(),
// clone intermediate query.
sql: rq.sql.Clone(),
path: rq.path,
@@ -395,6 +420,17 @@ func (rq *RepoQuery) WithLocks(opts ...func(*LockQuery)) *RepoQuery {
return rq
}
+// WithDeploymentStatistics tells the query-builder to eager-load the nodes that are connected to
+// the "deployment_statistics" edge. The optional arguments are used to configure the query builder of the edge.
+func (rq *RepoQuery) WithDeploymentStatistics(opts ...func(*DeploymentStatisticsQuery)) *RepoQuery {
+ query := &DeploymentStatisticsQuery{config: rq.config}
+ for _, opt := range opts {
+ opt(query)
+ }
+ rq.withDeploymentStatistics = query
+ return rq
+}
+
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
@@ -460,11 +496,12 @@ func (rq *RepoQuery) sqlAll(ctx context.Context) ([]*Repo, error) {
var (
nodes = []*Repo{}
_spec = rq.querySpec()
- loadedTypes = [4]bool{
+ loadedTypes = [5]bool{
rq.withPerms != nil,
rq.withDeployments != nil,
rq.withCallback != nil,
rq.withLocks != nil,
+ rq.withDeploymentStatistics != nil,
}
)
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
@@ -590,6 +627,31 @@ func (rq *RepoQuery) sqlAll(ctx context.Context) ([]*Repo, error) {
}
}
+ if query := rq.withDeploymentStatistics; query != nil {
+ fks := make([]driver.Value, 0, len(nodes))
+ nodeids := make(map[int64]*Repo)
+ for i := range nodes {
+ fks = append(fks, nodes[i].ID)
+ nodeids[nodes[i].ID] = nodes[i]
+ nodes[i].Edges.DeploymentStatistics = []*DeploymentStatistics{}
+ }
+ query.Where(predicate.DeploymentStatistics(func(s *sql.Selector) {
+ s.Where(sql.InValues(repo.DeploymentStatisticsColumn, fks...))
+ }))
+ neighbors, err := query.All(ctx)
+ if err != nil {
+ return nil, err
+ }
+ for _, n := range neighbors {
+ fk := n.RepoID
+ node, ok := nodeids[fk]
+ if !ok {
+ return nil, fmt.Errorf(`unexpected foreign-key "repo_id" returned %v for node %v`, fk, n.ID)
+ }
+ node.Edges.DeploymentStatistics = append(node.Edges.DeploymentStatistics, n)
+ }
+ }
+
return nodes, nil
}
diff --git a/ent/repo_update.go b/ent/repo_update.go
index 0cd075ca..b18632f0 100644
--- a/ent/repo_update.go
+++ b/ent/repo_update.go
@@ -12,6 +12,7 @@ import (
"entgo.io/ent/schema/field"
"github.com/gitploy-io/gitploy/ent/callback"
"github.com/gitploy-io/gitploy/ent/deployment"
+ "github.com/gitploy-io/gitploy/ent/deploymentstatistics"
"github.com/gitploy-io/gitploy/ent/lock"
"github.com/gitploy-io/gitploy/ent/perm"
"github.com/gitploy-io/gitploy/ent/predicate"
@@ -204,6 +205,21 @@ func (ru *RepoUpdate) AddLocks(l ...*Lock) *RepoUpdate {
return ru.AddLockIDs(ids...)
}
+// AddDeploymentStatisticIDs adds the "deployment_statistics" edge to the DeploymentStatistics entity by IDs.
+func (ru *RepoUpdate) AddDeploymentStatisticIDs(ids ...int) *RepoUpdate {
+ ru.mutation.AddDeploymentStatisticIDs(ids...)
+ return ru
+}
+
+// AddDeploymentStatistics adds the "deployment_statistics" edges to the DeploymentStatistics entity.
+func (ru *RepoUpdate) AddDeploymentStatistics(d ...*DeploymentStatistics) *RepoUpdate {
+ ids := make([]int, len(d))
+ for i := range d {
+ ids[i] = d[i].ID
+ }
+ return ru.AddDeploymentStatisticIDs(ids...)
+}
+
// Mutation returns the RepoMutation object of the builder.
func (ru *RepoUpdate) Mutation() *RepoMutation {
return ru.mutation
@@ -293,6 +309,27 @@ func (ru *RepoUpdate) RemoveLocks(l ...*Lock) *RepoUpdate {
return ru.RemoveLockIDs(ids...)
}
+// ClearDeploymentStatistics clears all "deployment_statistics" edges to the DeploymentStatistics entity.
+func (ru *RepoUpdate) ClearDeploymentStatistics() *RepoUpdate {
+ ru.mutation.ClearDeploymentStatistics()
+ return ru
+}
+
+// RemoveDeploymentStatisticIDs removes the "deployment_statistics" edge to DeploymentStatistics entities by IDs.
+func (ru *RepoUpdate) RemoveDeploymentStatisticIDs(ids ...int) *RepoUpdate {
+ ru.mutation.RemoveDeploymentStatisticIDs(ids...)
+ return ru
+}
+
+// RemoveDeploymentStatistics removes "deployment_statistics" edges to DeploymentStatistics entities.
+func (ru *RepoUpdate) RemoveDeploymentStatistics(d ...*DeploymentStatistics) *RepoUpdate {
+ ids := make([]int, len(d))
+ for i := range d {
+ ids[i] = d[i].ID
+ }
+ return ru.RemoveDeploymentStatisticIDs(ids...)
+}
+
// Save executes the query and returns the number of nodes affected by the update operation.
func (ru *RepoUpdate) Save(ctx context.Context) (int, error) {
var (
@@ -672,6 +709,60 @@ func (ru *RepoUpdate) sqlSave(ctx context.Context) (n int, err error) {
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
+ if ru.mutation.DeploymentStatisticsCleared() {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.O2M,
+ Inverse: false,
+ Table: repo.DeploymentStatisticsTable,
+ Columns: []string{repo.DeploymentStatisticsColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Column: deploymentstatistics.FieldID,
+ },
+ },
+ }
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+ }
+ if nodes := ru.mutation.RemovedDeploymentStatisticsIDs(); len(nodes) > 0 && !ru.mutation.DeploymentStatisticsCleared() {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.O2M,
+ Inverse: false,
+ Table: repo.DeploymentStatisticsTable,
+ Columns: []string{repo.DeploymentStatisticsColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Column: deploymentstatistics.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+ }
+ if nodes := ru.mutation.DeploymentStatisticsIDs(); len(nodes) > 0 {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.O2M,
+ Inverse: false,
+ Table: repo.DeploymentStatisticsTable,
+ Columns: []string{repo.DeploymentStatisticsColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Column: deploymentstatistics.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
+ }
if n, err = sqlgraph.UpdateNodes(ctx, ru.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{repo.Label}
@@ -864,6 +955,21 @@ func (ruo *RepoUpdateOne) AddLocks(l ...*Lock) *RepoUpdateOne {
return ruo.AddLockIDs(ids...)
}
+// AddDeploymentStatisticIDs adds the "deployment_statistics" edge to the DeploymentStatistics entity by IDs.
+func (ruo *RepoUpdateOne) AddDeploymentStatisticIDs(ids ...int) *RepoUpdateOne {
+ ruo.mutation.AddDeploymentStatisticIDs(ids...)
+ return ruo
+}
+
+// AddDeploymentStatistics adds the "deployment_statistics" edges to the DeploymentStatistics entity.
+func (ruo *RepoUpdateOne) AddDeploymentStatistics(d ...*DeploymentStatistics) *RepoUpdateOne {
+ ids := make([]int, len(d))
+ for i := range d {
+ ids[i] = d[i].ID
+ }
+ return ruo.AddDeploymentStatisticIDs(ids...)
+}
+
// Mutation returns the RepoMutation object of the builder.
func (ruo *RepoUpdateOne) Mutation() *RepoMutation {
return ruo.mutation
@@ -953,6 +1059,27 @@ func (ruo *RepoUpdateOne) RemoveLocks(l ...*Lock) *RepoUpdateOne {
return ruo.RemoveLockIDs(ids...)
}
+// ClearDeploymentStatistics clears all "deployment_statistics" edges to the DeploymentStatistics entity.
+func (ruo *RepoUpdateOne) ClearDeploymentStatistics() *RepoUpdateOne {
+ ruo.mutation.ClearDeploymentStatistics()
+ return ruo
+}
+
+// RemoveDeploymentStatisticIDs removes the "deployment_statistics" edge to DeploymentStatistics entities by IDs.
+func (ruo *RepoUpdateOne) RemoveDeploymentStatisticIDs(ids ...int) *RepoUpdateOne {
+ ruo.mutation.RemoveDeploymentStatisticIDs(ids...)
+ return ruo
+}
+
+// RemoveDeploymentStatistics removes "deployment_statistics" edges to DeploymentStatistics entities.
+func (ruo *RepoUpdateOne) RemoveDeploymentStatistics(d ...*DeploymentStatistics) *RepoUpdateOne {
+ ids := make([]int, len(d))
+ for i := range d {
+ ids[i] = d[i].ID
+ }
+ return ruo.RemoveDeploymentStatisticIDs(ids...)
+}
+
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (ruo *RepoUpdateOne) Select(field string, fields ...string) *RepoUpdateOne {
@@ -1356,6 +1483,60 @@ func (ruo *RepoUpdateOne) sqlSave(ctx context.Context) (_node *Repo, err error)
}
_spec.Edges.Add = append(_spec.Edges.Add, edge)
}
+ if ruo.mutation.DeploymentStatisticsCleared() {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.O2M,
+ Inverse: false,
+ Table: repo.DeploymentStatisticsTable,
+ Columns: []string{repo.DeploymentStatisticsColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Column: deploymentstatistics.FieldID,
+ },
+ },
+ }
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+ }
+ if nodes := ruo.mutation.RemovedDeploymentStatisticsIDs(); len(nodes) > 0 && !ruo.mutation.DeploymentStatisticsCleared() {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.O2M,
+ Inverse: false,
+ Table: repo.DeploymentStatisticsTable,
+ Columns: []string{repo.DeploymentStatisticsColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Column: deploymentstatistics.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
+ }
+ if nodes := ruo.mutation.DeploymentStatisticsIDs(); len(nodes) > 0 {
+ edge := &sqlgraph.EdgeSpec{
+ Rel: sqlgraph.O2M,
+ Inverse: false,
+ Table: repo.DeploymentStatisticsTable,
+ Columns: []string{repo.DeploymentStatisticsColumn},
+ Bidi: false,
+ Target: &sqlgraph.EdgeTarget{
+ IDSpec: &sqlgraph.FieldSpec{
+ Type: field.TypeInt,
+ Column: deploymentstatistics.FieldID,
+ },
+ },
+ }
+ for _, k := range nodes {
+ edge.Target.Nodes = append(edge.Target.Nodes, k)
+ }
+ _spec.Edges.Add = append(_spec.Edges.Add, edge)
+ }
_node = &Repo{config: ruo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
diff --git a/ent/runtime.go b/ent/runtime.go
index 7d71b0b0..b12e3bcb 100644
--- a/ent/runtime.go
+++ b/ent/runtime.go
@@ -69,24 +69,28 @@ func init() {
deploymentDescHTMLURL := deploymentFields[7].Descriptor()
// deployment.HTMLURLValidator is a validator for the "html_url" field. It is called by the builders before save.
deployment.HTMLURLValidator = deploymentDescHTMLURL.Validators[0].(func(string) error)
+ // deploymentDescProductionEnvironment is the schema descriptor for production_environment field.
+ deploymentDescProductionEnvironment := deploymentFields[8].Descriptor()
+ // deployment.DefaultProductionEnvironment holds the default value on creation for the production_environment field.
+ deployment.DefaultProductionEnvironment = deploymentDescProductionEnvironment.Default.(bool)
// deploymentDescIsRollback is the schema descriptor for is_rollback field.
- deploymentDescIsRollback := deploymentFields[8].Descriptor()
+ deploymentDescIsRollback := deploymentFields[9].Descriptor()
// deployment.DefaultIsRollback holds the default value on creation for the is_rollback field.
deployment.DefaultIsRollback = deploymentDescIsRollback.Default.(bool)
// deploymentDescIsApprovalEnabled is the schema descriptor for is_approval_enabled field.
- deploymentDescIsApprovalEnabled := deploymentFields[9].Descriptor()
+ deploymentDescIsApprovalEnabled := deploymentFields[10].Descriptor()
// deployment.DefaultIsApprovalEnabled holds the default value on creation for the is_approval_enabled field.
deployment.DefaultIsApprovalEnabled = deploymentDescIsApprovalEnabled.Default.(bool)
// deploymentDescRequiredApprovalCount is the schema descriptor for required_approval_count field.
- deploymentDescRequiredApprovalCount := deploymentFields[10].Descriptor()
+ deploymentDescRequiredApprovalCount := deploymentFields[11].Descriptor()
// deployment.DefaultRequiredApprovalCount holds the default value on creation for the required_approval_count field.
deployment.DefaultRequiredApprovalCount = deploymentDescRequiredApprovalCount.Default.(int)
// deploymentDescCreatedAt is the schema descriptor for created_at field.
- deploymentDescCreatedAt := deploymentFields[11].Descriptor()
+ deploymentDescCreatedAt := deploymentFields[12].Descriptor()
// deployment.DefaultCreatedAt holds the default value on creation for the created_at field.
deployment.DefaultCreatedAt = deploymentDescCreatedAt.Default.(func() time.Time)
// deploymentDescUpdatedAt is the schema descriptor for updated_at field.
- deploymentDescUpdatedAt := deploymentFields[12].Descriptor()
+ deploymentDescUpdatedAt := deploymentFields[13].Descriptor()
// deployment.DefaultUpdatedAt holds the default value on creation for the updated_at field.
deployment.DefaultUpdatedAt = deploymentDescUpdatedAt.Default.(func() time.Time)
// deployment.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
@@ -94,15 +98,31 @@ func init() {
deploymentstatisticsFields := schema.DeploymentStatistics{}.Fields()
_ = deploymentstatisticsFields
// deploymentstatisticsDescCount is the schema descriptor for count field.
- deploymentstatisticsDescCount := deploymentstatisticsFields[3].Descriptor()
+ deploymentstatisticsDescCount := deploymentstatisticsFields[1].Descriptor()
// deploymentstatistics.DefaultCount holds the default value on creation for the count field.
deploymentstatistics.DefaultCount = deploymentstatisticsDescCount.Default.(int)
+ // deploymentstatisticsDescRollbackCount is the schema descriptor for rollback_count field.
+ deploymentstatisticsDescRollbackCount := deploymentstatisticsFields[2].Descriptor()
+ // deploymentstatistics.DefaultRollbackCount holds the default value on creation for the rollback_count field.
+ deploymentstatistics.DefaultRollbackCount = deploymentstatisticsDescRollbackCount.Default.(int)
+ // deploymentstatisticsDescAdditions is the schema descriptor for additions field.
+ deploymentstatisticsDescAdditions := deploymentstatisticsFields[3].Descriptor()
+ // deploymentstatistics.DefaultAdditions holds the default value on creation for the additions field.
+ deploymentstatistics.DefaultAdditions = deploymentstatisticsDescAdditions.Default.(int)
+ // deploymentstatisticsDescDeletions is the schema descriptor for deletions field.
+ deploymentstatisticsDescDeletions := deploymentstatisticsFields[4].Descriptor()
+ // deploymentstatistics.DefaultDeletions holds the default value on creation for the deletions field.
+ deploymentstatistics.DefaultDeletions = deploymentstatisticsDescDeletions.Default.(int)
+ // deploymentstatisticsDescChanges is the schema descriptor for changes field.
+ deploymentstatisticsDescChanges := deploymentstatisticsFields[5].Descriptor()
+ // deploymentstatistics.DefaultChanges holds the default value on creation for the changes field.
+ deploymentstatistics.DefaultChanges = deploymentstatisticsDescChanges.Default.(int)
// deploymentstatisticsDescCreatedAt is the schema descriptor for created_at field.
- deploymentstatisticsDescCreatedAt := deploymentstatisticsFields[4].Descriptor()
+ deploymentstatisticsDescCreatedAt := deploymentstatisticsFields[6].Descriptor()
// deploymentstatistics.DefaultCreatedAt holds the default value on creation for the created_at field.
deploymentstatistics.DefaultCreatedAt = deploymentstatisticsDescCreatedAt.Default.(func() time.Time)
// deploymentstatisticsDescUpdatedAt is the schema descriptor for updated_at field.
- deploymentstatisticsDescUpdatedAt := deploymentstatisticsFields[5].Descriptor()
+ deploymentstatisticsDescUpdatedAt := deploymentstatisticsFields[7].Descriptor()
// deploymentstatistics.DefaultUpdatedAt holds the default value on creation for the updated_at field.
deploymentstatistics.DefaultUpdatedAt = deploymentstatisticsDescUpdatedAt.Default.(func() time.Time)
// deploymentstatistics.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
diff --git a/ent/schema/deployment.go b/ent/schema/deployment.go
index cd845213..48e9ea2e 100644
--- a/ent/schema/deployment.go
+++ b/ent/schema/deployment.go
@@ -47,6 +47,8 @@ func (Deployment) Fields() []ent.Field {
field.String("html_url").
MaxLen(2000).
Optional(),
+ field.Bool("production_environment").
+ Default(false),
field.Bool("is_rollback").
Default(false),
field.Bool("is_approval_enabled").
diff --git a/ent/schema/deploymentstatistics.go b/ent/schema/deploymentstatistics.go
index be16d5e2..709daee5 100644
--- a/ent/schema/deploymentstatistics.go
+++ b/ent/schema/deploymentstatistics.go
@@ -4,6 +4,7 @@ import (
"time"
"entgo.io/ent"
+ "entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
@@ -16,27 +17,40 @@ type DeploymentStatistics struct {
// Fields of the DeploymentStatistics.
func (DeploymentStatistics) Fields() []ent.Field {
return []ent.Field{
- field.String("namespace"),
- field.String("name"),
field.String("env"),
field.Int("count").
- Default(1),
+ Default(0),
+ field.Int("rollback_count").
+ Default(0),
+ field.Int("additions").
+ Default(0),
+ field.Int("deletions").
+ Default(0),
+ field.Int("changes").
+ Default(0),
field.Time("created_at").
Default(time.Now),
field.Time("updated_at").
Default(time.Now).
UpdateDefault(time.Now),
+ field.Int64("repo_id"),
}
}
// Edges of the DeploymentStatistics.
func (DeploymentStatistics) Edges() []ent.Edge {
- return nil
+ return []ent.Edge{
+ edge.From("repo", Repo.Type).
+ Ref("deployment_statistics").
+ Field("repo_id").
+ Unique().
+ Required(),
+ }
}
func (DeploymentStatistics) Indexes() []ent.Index {
return []ent.Index{
- index.Fields("namespace", "name", "env").
+ index.Fields("repo_id", "env").
Unique(),
// The collector searches updated records only.
index.Fields("updated_at"),
diff --git a/ent/schema/repo.go b/ent/schema/repo.go
index af72c54e..9780f162 100644
--- a/ent/schema/repo.go
+++ b/ent/schema/repo.go
@@ -59,6 +59,10 @@ func (Repo) Edges() []ent.Edge {
Annotations(entsql.Annotation{
OnDelete: entsql.Cascade,
}),
+ edge.To("deployment_statistics", DeploymentStatistics.Type).
+ Annotations(entsql.Annotation{
+ OnDelete: entsql.Cascade,
+ }),
}
}
diff --git a/internal/interactor/deployment.go b/internal/interactor/deployment.go
index b1f533ad..5da36cd9 100644
--- a/internal/interactor/deployment.go
+++ b/internal/interactor/deployment.go
@@ -14,6 +14,7 @@ import (
)
func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, e *vo.Env) (*ent.Deployment, error) {
+ d.ProductionEnvironment = e.IsProductionEnvironment()
d.UserID = u.ID
d.RepoID = r.ID
diff --git a/internal/interactor/deploymentstatistics.go b/internal/interactor/deploymentstatistics.go
index 49721f78..b12e2a97 100644
--- a/internal/interactor/deploymentstatistics.go
+++ b/internal/interactor/deploymentstatistics.go
@@ -2,6 +2,7 @@ package interactor
import (
"context"
+ "fmt"
"github.com/gitploy-io/gitploy/ent"
)
@@ -10,15 +11,59 @@ func (i *Interactor) ProduceDeploymentStatisticsOfRepo(ctx context.Context, r *e
s, err := i.Store.FindDeploymentStatisticsOfRepoByEnv(ctx, r, d.Env)
if ent.IsNotFound(err) {
- return i.Store.CreateDeploymentStatistics(ctx, &ent.DeploymentStatistics{
- Namespace: r.Namespace,
- Name: r.Name,
- Env: d.Env,
- Count: 1,
- })
+ if s, err = i.Store.CreateDeploymentStatistics(ctx, &ent.DeploymentStatistics{
+ Env: d.Env,
+ RepoID: r.ID,
+ }); err != nil {
+ return nil, err
+ }
}
- s.Count = s.Count + 1
+ if s, err = i.produceDeploymentStatisticsOfRepo(ctx, r, d, s); err != nil {
+ return nil, err
+ }
return i.Store.UpdateDeploymentStatistics(ctx, s)
}
+
+func (i *Interactor) produceDeploymentStatisticsOfRepo(ctx context.Context, r *ent.Repo, d *ent.Deployment, s *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) {
+ // Increase the count of deployment.
+ {
+ if d.IsRollback {
+ s.RollbackCount = s.RollbackCount + 1
+ } else {
+ s.Count = s.Count + 1
+ }
+ }
+
+ // Calculate changes from the lastest deployment.
+ {
+ ld, err := i.Store.FindPrevSuccessDeployment(ctx, d)
+ if ent.IsNotFound(err) {
+ return s, nil
+ } else if err != nil {
+ return nil, err
+ }
+
+ if d.Edges.User == nil {
+ if d, err = i.Store.FindDeploymentByID(ctx, d.ID); err != nil {
+ return nil, err
+ } else if d.Edges.User == nil {
+ return nil, fmt.Errorf("The deployer is not found.")
+ }
+ }
+
+ _, fs, err := i.SCM.CompareCommits(ctx, d.Edges.User, r, ld.Sha, d.Sha, 1, 100)
+ if err != nil {
+ return nil, err
+ }
+
+ for _, f := range fs {
+ s.Additions = s.Additions + f.Additions
+ s.Deletions = s.Deletions + f.Deletions
+ s.Changes = s.Changes + f.Changes
+ }
+ }
+
+ return s, nil
+}
diff --git a/internal/interactor/deploymentstatistics_test.go b/internal/interactor/deploymentstatistics_test.go
index 2b6c4f0c..4644bd4e 100644
--- a/internal/interactor/deploymentstatistics_test.go
+++ b/internal/interactor/deploymentstatistics_test.go
@@ -6,6 +6,7 @@ import (
"github.com/gitploy-io/gitploy/ent"
"github.com/gitploy-io/gitploy/internal/interactor/mock"
+ "github.com/gitploy-io/gitploy/vo"
"github.com/golang/mock/gomock"
)
@@ -40,6 +41,78 @@ func TestInteractor_ProduceDeploymentStatisticsOfRepo(t *testing.T) {
CreateDeploymentStatistics(gomock.Any(), gomock.AssignableToTypeOf(&ent.DeploymentStatistics{})).
Return(&ent.DeploymentStatistics{ID: 1}, nil)
+ t.Log("MOCK - The prev deployment is not found.")
+ store.
+ EXPECT().
+ FindPrevSuccessDeployment(gomock.Any(), gomock.AssignableToTypeOf(&ent.Deployment{})).
+ Return(nil, &ent.NotFoundError{})
+
+ t.Log("MOCK - Update the statistics.")
+ store.
+ EXPECT().
+ UpdateDeploymentStatistics(gomock.Any(), gomock.Eq(&ent.DeploymentStatistics{ID: 1, Count: 1})).
+ DoAndReturn(func(ctx context.Context, s *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) {
+ return s, nil
+ })
+
+ i := newMockInteractor(store, scm)
+
+ _, err := i.ProduceDeploymentStatisticsOfRepo(context.Background(), input.repo, input.d)
+ if err != nil {
+ t.Fatalf("ProduceDeploymentStatisticsOfRepo returns an error: %s", err)
+ }
+ })
+
+ t.Run("Calculate changes from the lastest deployment.", func(t *testing.T) {
+ input := struct {
+ repo *ent.Repo
+ d *ent.Deployment
+ }{
+ repo: &ent.Repo{
+ Namespace: "octocat",
+ Name: "HelloWorld",
+ },
+ d: &ent.Deployment{
+ ID: 2,
+ Env: "production",
+ Edges: ent.DeploymentEdges{
+ User: &ent.User{},
+ },
+ },
+ }
+
+ ctrl := gomock.NewController(t)
+ store := mock.NewMockStore(ctrl)
+ scm := mock.NewMockSCM(ctrl)
+
+ t.Log("MOCK - Find the deployment_statistics by the environment.")
+ store.
+ EXPECT().
+ FindDeploymentStatisticsOfRepoByEnv(gomock.Any(), gomock.Eq(input.repo), gomock.Eq(input.d.Env)).
+ Return(&ent.DeploymentStatistics{ID: 1, Count: 1}, nil)
+
+ t.Log("MOCK - Find the latest deployment.")
+ store.
+ EXPECT().
+ FindPrevSuccessDeployment(gomock.Any(), gomock.Eq(input.d)).
+ Return(&ent.Deployment{ID: 2}, nil)
+
+ t.Log("MOCK - Get changed commits from the SCM.")
+ scm.
+ EXPECT().
+ CompareCommits(gomock.Any(), gomock.AssignableToTypeOf(&ent.User{}), gomock.AssignableToTypeOf(&ent.Repo{}), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
+ Return([]*vo.Commit{}, []*vo.CommitFile{
+ {Additions: 1, Deletions: 1, Changes: 2},
+ }, nil)
+
+ t.Log("MOCK - Update the statistics.")
+ store.
+ EXPECT().
+ UpdateDeploymentStatistics(gomock.Any(), gomock.Eq(&ent.DeploymentStatistics{ID: 1, Count: 2, Additions: 1, Deletions: 1, Changes: 2})).
+ DoAndReturn(func(ctx context.Context, s *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) {
+ return s, nil
+ })
+
i := newMockInteractor(store, scm)
_, err := i.ProduceDeploymentStatisticsOfRepo(context.Background(), input.repo, input.d)
@@ -47,4 +120,5 @@ func TestInteractor_ProduceDeploymentStatisticsOfRepo(t *testing.T) {
t.Fatalf("ProduceDeploymentStatisticsOfRepo returns an error: %s", err)
}
})
+
}
diff --git a/internal/interactor/interface.go b/internal/interactor/interface.go
index 06a7a4e7..48c0c999 100644
--- a/internal/interactor/interface.go
+++ b/internal/interactor/interface.go
@@ -101,7 +101,7 @@ type (
DeleteWebhook(ctx context.Context, u *ent.User, r *ent.Repo, id int64) error
ListCommits(ctx context.Context, u *ent.User, r *ent.Repo, branch string, page, perPage int) ([]*vo.Commit, error)
- CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, error)
+ CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, []*vo.CommitFile, error)
GetCommit(ctx context.Context, u *ent.User, r *ent.Repo, sha string) (*vo.Commit, error)
ListCommitStatuses(ctx context.Context, u *ent.User, r *ent.Repo, sha string) ([]*vo.Status, error)
diff --git a/internal/interactor/mock/pkg.go b/internal/interactor/mock/pkg.go
index a9894f30..dd3188e3 100644
--- a/internal/interactor/mock/pkg.go
+++ b/internal/interactor/mock/pkg.go
@@ -957,12 +957,13 @@ func (mr *MockSCMMockRecorder) CancelDeployment(ctx, u, r, d, s interface{}) *go
}
// CompareCommits mocks base method.
-func (m *MockSCM) CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, error) {
+func (m *MockSCM) CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, []*vo.CommitFile, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "CompareCommits", ctx, u, r, base, head, page, perPage)
ret0, _ := ret[0].([]*vo.Commit)
- ret1, _ := ret[1].(error)
- return ret0, ret1
+ ret1, _ := ret[1].([]*vo.CommitFile)
+ ret2, _ := ret[2].(error)
+ return ret0, ret1, ret2
}
// CompareCommits indicates an expected call of CompareCommits.
diff --git a/internal/pkg/github/mapper.go b/internal/pkg/github/mapper.go
index 46b8c9b9..343d7b5f 100644
--- a/internal/pkg/github/mapper.go
+++ b/internal/pkg/github/mapper.go
@@ -73,6 +73,15 @@ func mapGithubCommitToCommit(cm *github.RepositoryCommit) *vo.Commit {
}
}
+func mapGithubCommitFileToCommitFile(cf *github.CommitFile) *vo.CommitFile {
+ return &vo.CommitFile{
+ FileName: *cf.Filename,
+ Additions: *cf.Additions,
+ Deletions: *cf.Deletions,
+ Changes: *cf.Changes,
+ }
+}
+
func mapGithubStatusToStatus(s *github.RepoStatus) *vo.Status {
var (
state vo.StatusState
diff --git a/internal/pkg/github/repos.go b/internal/pkg/github/repos.go
index ee23410e..4216bbf0 100644
--- a/internal/pkg/github/repos.go
+++ b/internal/pkg/github/repos.go
@@ -44,21 +44,26 @@ func (g *Github) ListCommits(ctx context.Context, u *ent.User, r *ent.Repo, bran
return ret, nil
}
-func (g *Github) CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, error) {
- // TODO: support pagination.
+func (g *Github) CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, []*vo.CommitFile, error) {
+ // TODO: Support pagination.
res, _, err := g.Client(ctx, u.Token).
Repositories.
CompareCommits(ctx, r.Namespace, r.Name, base, head)
if err != nil {
- return nil, err
+ return nil, nil, err
}
- ret := make([]*vo.Commit, 0)
+ cms := make([]*vo.Commit, 0)
for _, cm := range res.Commits {
- ret = append(ret, mapGithubCommitToCommit(cm))
+ cms = append(cms, mapGithubCommitToCommit(cm))
}
- return ret, nil
+ cfs := make([]*vo.CommitFile, 0)
+ for _, cf := range res.Files {
+ cfs = append(cfs, mapGithubCommitFileToCommitFile(cf))
+ }
+
+ return cms, cfs, nil
}
func (g *Github) GetCommit(ctx context.Context, u *ent.User, r *ent.Repo, sha string) (*vo.Commit, error) {
diff --git a/internal/pkg/store/deployment.go b/internal/pkg/store/deployment.go
index 4d296732..d57eca42 100644
--- a/internal/pkg/store/deployment.go
+++ b/internal/pkg/store/deployment.go
@@ -200,6 +200,7 @@ func (s *Store) CreateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D
SetUID(d.UID).
SetSha(d.Sha).
SetHTMLURL(d.HTMLURL).
+ SetProductionEnvironment(d.ProductionEnvironment).
SetIsRollback(d.IsRollback).
SetIsApprovalEnabled(d.IsApprovalEnabled).
SetRequiredApprovalCount(d.RequiredApprovalCount).
diff --git a/internal/pkg/store/deploymentstatistics.go b/internal/pkg/store/deploymentstatistics.go
index 324a92ab..b28b8866 100644
--- a/internal/pkg/store/deploymentstatistics.go
+++ b/internal/pkg/store/deploymentstatistics.go
@@ -9,8 +9,10 @@ import (
)
func (s *Store) ListAllDeploymentStatistics(ctx context.Context) ([]*ent.DeploymentStatistics, error) {
+ // TODO: List only active repositories.
return s.c.DeploymentStatistics.
Query().
+ WithRepo().
All(ctx)
}
@@ -20,6 +22,7 @@ func (s *Store) ListDeploymentStatisticsGreaterThanTime(ctx context.Context, upd
Where(
deploymentstatistics.UpdatedAtGT(updated),
).
+ WithRepo().
All(ctx)
}
@@ -27,20 +30,23 @@ func (s *Store) FindDeploymentStatisticsOfRepoByEnv(ctx context.Context, r *ent.
return s.c.DeploymentStatistics.
Query().
Where(
- deploymentstatistics.NamespaceEQ(r.Namespace),
- deploymentstatistics.NameEQ(r.Name),
+ deploymentstatistics.RepoIDEQ(r.ID),
deploymentstatistics.EnvEQ(env),
).
+ WithRepo().
Only(ctx)
}
func (s *Store) CreateDeploymentStatistics(ctx context.Context, ds *ent.DeploymentStatistics) (*ent.DeploymentStatistics, error) {
return s.c.DeploymentStatistics.
Create().
- SetNamespace(ds.Namespace).
- SetName(ds.Name).
SetEnv(ds.Env).
SetCount(ds.Count).
+ SetRollbackCount(ds.RollbackCount).
+ SetAdditions(ds.Additions).
+ SetDeletions(ds.Deletions).
+ SetChanges(ds.Changes).
+ SetRepoID(ds.RepoID).
Save(ctx)
}
@@ -48,5 +54,9 @@ func (s *Store) UpdateDeploymentStatistics(ctx context.Context, ds *ent.Deployme
return s.c.DeploymentStatistics.
UpdateOne(ds).
SetCount(ds.Count).
+ SetRollbackCount(ds.RollbackCount).
+ SetAdditions(ds.Additions).
+ SetDeletions(ds.Deletions).
+ SetChanges(ds.Changes).
Save(ctx)
}
diff --git a/internal/pkg/store/deploymentstatistics_test.go b/internal/pkg/store/deploymentstatistics_test.go
index 618177b5..0d01aad9 100644
--- a/internal/pkg/store/deploymentstatistics_test.go
+++ b/internal/pkg/store/deploymentstatistics_test.go
@@ -21,16 +21,14 @@ func TestStore_ListDeploymentStatisticsGreaterThanTime(t *testing.T) {
client.DeploymentStatistics.
Create().
- SetNamespace("octocat").
- SetName("Hello").
+ SetRepoID(1).
SetEnv("dev").
SetUpdatedAt(tm.Add(-time.Hour)).
SaveX(ctx)
client.DeploymentStatistics.
Create().
- SetNamespace("octocat").
- SetName("Hello").
+ SetRepoID(1).
SetEnv("prod").
SetUpdatedAt(tm.Add(time.Hour)).
SaveX(ctx)
diff --git a/internal/server/api/v1/repos/deployment.go b/internal/server/api/v1/repos/deployment.go
index 6d484ecd..d981cd94 100644
--- a/internal/server/api/v1/repos/deployment.go
+++ b/internal/server/api/v1/repos/deployment.go
@@ -412,7 +412,7 @@ func (r *Repo) ListDeploymentChanges(c *gin.Context) {
}
}
- commits, err := r.i.CompareCommits(ctx, u, re, ld.Sha, sha, atoi(page), atoi(perPage))
+ commits, _, err := r.i.CompareCommits(ctx, u, re, ld.Sha, sha, atoi(page), atoi(perPage))
if err != nil {
r.log.Error("It has failed to compare two commits.", zap.Error(err))
gb.ErrorResponse(c, http.StatusInternalServerError, "It has failed to compare two commits.")
diff --git a/internal/server/api/v1/repos/deployment_test.go b/internal/server/api/v1/repos/deployment_test.go
index 4f12e56c..eca7110f 100644
--- a/internal/server/api/v1/repos/deployment_test.go
+++ b/internal/server/api/v1/repos/deployment_test.go
@@ -69,7 +69,7 @@ func TestRepo_ListDeploymentChanges(t *testing.T) {
{
SHA: head,
},
- }, nil)
+ }, []*vo.CommitFile{}, nil)
// Ready the router to handle it.
gin.SetMode(gin.ReleaseMode)
diff --git a/internal/server/api/v1/repos/interface.go b/internal/server/api/v1/repos/interface.go
index 3eb3d5ea..4aa1a36d 100644
--- a/internal/server/api/v1/repos/interface.go
+++ b/internal/server/api/v1/repos/interface.go
@@ -49,7 +49,7 @@ type (
CreateEvent(ctx context.Context, e *ent.Event) (*ent.Event, error)
ListCommits(ctx context.Context, u *ent.User, r *ent.Repo, branch string, page, perPage int) ([]*vo.Commit, error)
- CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, error)
+ CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, []*vo.CommitFile, error)
GetCommit(ctx context.Context, u *ent.User, r *ent.Repo, sha string) (*vo.Commit, error)
ListCommitStatuses(ctx context.Context, u *ent.User, r *ent.Repo, sha string) ([]*vo.Status, error)
diff --git a/internal/server/api/v1/repos/mock/interactor.go b/internal/server/api/v1/repos/mock/interactor.go
index 55701512..4b41c6c4 100644
--- a/internal/server/api/v1/repos/mock/interactor.go
+++ b/internal/server/api/v1/repos/mock/interactor.go
@@ -52,12 +52,13 @@ func (mr *MockInteractorMockRecorder) ActivateRepo(ctx, u, r, c interface{}) *go
}
// CompareCommits mocks base method.
-func (m *MockInteractor) CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, error) {
+func (m *MockInteractor) CompareCommits(ctx context.Context, u *ent.User, r *ent.Repo, base, head string, page, perPage int) ([]*vo.Commit, []*vo.CommitFile, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "CompareCommits", ctx, u, r, base, head, page, perPage)
ret0, _ := ret[0].([]*vo.Commit)
- ret1, _ := ret[1].(error)
- return ret0, ret1
+ ret1, _ := ret[1].([]*vo.CommitFile)
+ ret2, _ := ret[2].(error)
+ return ret0, ret1, ret2
}
// CompareCommits indicates an expected call of CompareCommits.
diff --git a/internal/server/hooks/hook.go b/internal/server/hooks/hook.go
index 915a87f6..9d4ca315 100644
--- a/internal/server/hooks/hook.go
+++ b/internal/server/hooks/hook.go
@@ -119,8 +119,10 @@ func (h *Hooks) handleGithubHook(c *gin.Context) {
h.log.Error("It has failed to create the event.", zap.Error(err))
}
- // Produce statistics when the deployment is success.
- if d.Status == deployment.StatusSuccess && d.Edges.Repo != nil {
+ // Produce statistics when the deployment is success, and production environment.
+ if d.Status == deployment.StatusSuccess &&
+ d.ProductionEnvironment &&
+ d.Edges.Repo != nil {
if _, err := h.i.ProduceDeploymentStatisticsOfRepo(ctx, d.Edges.Repo, d); err != nil {
h.log.Error("It has failed to produce the statistics of deployment.", zap.Error(err))
}
diff --git a/internal/server/metrics/metrics.go b/internal/server/metrics/metrics.go
index bdf2fbd9..5cc5c874 100644
--- a/internal/server/metrics/metrics.go
+++ b/internal/server/metrics/metrics.go
@@ -109,6 +109,10 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
}
for _, dc := range c.cache {
+ if dc.Edges.Repo == nil {
+ continue
+ }
+
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(
@@ -116,13 +120,77 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
"",
"deployment_count",
),
- "The count of success deployment for each environment, respectively.",
+ "The count of success deployment of the production environment.",
[]string{"namespace", "name", "env"},
nil,
),
prometheus.GaugeValue,
float64(dc.Count),
- dc.Namespace, dc.Name, dc.Env,
+ dc.Edges.Repo.Namespace, dc.Edges.Repo.Name, dc.Env,
+ )
+
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc(
+ prometheus.BuildFQName(
+ namespace,
+ "",
+ "rollback_count",
+ ),
+ "The count of rollback of the production environment.",
+ []string{"namespace", "name", "env"},
+ nil,
+ ),
+ prometheus.GaugeValue,
+ float64(dc.RollbackCount),
+ dc.Edges.Repo.Namespace, dc.Edges.Repo.Name, dc.Env,
+ )
+
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc(
+ prometheus.BuildFQName(
+ namespace,
+ "",
+ "line_additions",
+ ),
+ "The count of added lines from the latest deployment of the production environment.",
+ []string{"namespace", "name", "env"},
+ nil,
+ ),
+ prometheus.GaugeValue,
+ float64(dc.Additions),
+ dc.Edges.Repo.Namespace, dc.Edges.Repo.Name, dc.Env,
+ )
+
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc(
+ prometheus.BuildFQName(
+ namespace,
+ "",
+ "line_deletions",
+ ),
+ "The count of deleted lines from the latest deployment of the production environment.",
+ []string{"namespace", "name", "env"},
+ nil,
+ ),
+ prometheus.GaugeValue,
+ float64(dc.Deletions),
+ dc.Edges.Repo.Namespace, dc.Edges.Repo.Name, dc.Env,
+ )
+
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc(
+ prometheus.BuildFQName(
+ namespace,
+ "",
+ "line_changes",
+ ),
+ "The count of changed lines from the latest deployment of the production environment.",
+ []string{"namespace", "name", "env"},
+ nil,
+ ),
+ prometheus.GaugeValue,
+ float64(dc.Changes),
+ dc.Edges.Repo.Namespace, dc.Edges.Repo.Name, dc.Env,
)
}
diff --git a/openapi.yml b/openapi.yml
index d054cfd0..f6906dcd 100644
--- a/openapi.yml
+++ b/openapi.yml
@@ -1746,6 +1746,8 @@ components:
type: string
html_url:
type: string
+ production_environment:
+ type: boolean
is_rollback:
type: boolean
is_approval_enabled:
@@ -1773,6 +1775,7 @@ components:
- ref
- env
- status
+ - production_environment
- is_rollback
- is_approval_enabled
- required_approval_count
diff --git a/vo/commit.go b/vo/commit.go
index c4e88820..d9e72a71 100644
--- a/vo/commit.go
+++ b/vo/commit.go
@@ -25,6 +25,13 @@ type (
TargetURL string `json:"target_url"`
State StatusState `json:"state"`
}
+
+ CommitFile struct {
+ FileName string `json:"filename"`
+ Additions int `json:"addtitions"`
+ Deletions int `json:"deletions"`
+ Changes int `json:"changes"`
+ }
)
const (
diff --git a/vo/config.go b/vo/config.go
index 6f06c02f..44b7fffb 100644
--- a/vo/config.go
+++ b/vo/config.go
@@ -79,6 +79,10 @@ func (c *Config) GetEnv(name string) *Env {
return nil
}
+func (e *Env) IsProductionEnvironment() bool {
+ return e.ProductionEnvironment != nil && *e.ProductionEnvironment
+}
+
func (e *Env) IsApprovalEabled() bool {
if e.Approval == nil {
return false
diff --git a/vo/config_test.go b/vo/config_test.go
index 4b4b179a..a657463d 100644
--- a/vo/config_test.go
+++ b/vo/config_test.go
@@ -90,6 +90,28 @@ envs:
})
}
+func TestEnv_IsProductionEnvironment(t *testing.T) {
+ t.Run("Reutrn false when the production environment is nil", func(t *testing.T) {
+ e := &Env{}
+
+ expected := false
+ if e.IsProductionEnvironment() != expected {
+ t.Errorf("IsProductionEnvironment = %v, wanted %v", e.IsProductionEnvironment(), expected)
+ }
+ })
+
+ t.Run("Reutrn true when the production environment is true", func(t *testing.T) {
+ e := &Env{
+ ProductionEnvironment: pointer.ToBool(true),
+ }
+
+ expected := true
+ if e.IsProductionEnvironment() != expected {
+ t.Errorf("IsProductionEnvironment = %v, wanted %v", e.IsProductionEnvironment(), expected)
+ }
+ })
+}
+
func TestEnv_Eval(t *testing.T) {
t.Run("eval the task.", func(t *testing.T) {
cs := []struct {