diff --git a/deploy.yml b/deploy.yml index 41ba7da8..29443cf0 100644 --- a/deploy.yml +++ b/deploy.yml @@ -22,6 +22,8 @@ envs: - "react-test" - "publish-image" production_environment: true - approval: + review: enabled: true - required_count: 0 + reviewers: + - hanjunlee + - noah-qa diff --git a/ent/approval_delete.go b/ent/approval_delete.go deleted file mode 100644 index 0c45df82..00000000 --- a/ent/approval_delete.go +++ /dev/null @@ -1,111 +0,0 @@ -// Code generated by entc, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" - "github.com/gitploy-io/gitploy/ent/predicate" -) - -// ApprovalDelete is the builder for deleting a Approval entity. -type ApprovalDelete struct { - config - hooks []Hook - mutation *ApprovalMutation -} - -// Where appends a list predicates to the ApprovalDelete builder. -func (ad *ApprovalDelete) Where(ps ...predicate.Approval) *ApprovalDelete { - ad.mutation.Where(ps...) - return ad -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (ad *ApprovalDelete) Exec(ctx context.Context) (int, error) { - var ( - err error - affected int - ) - if len(ad.hooks) == 0 { - affected, err = ad.sqlExec(ctx) - } else { - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ApprovalMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - ad.mutation = mutation - affected, err = ad.sqlExec(ctx) - mutation.done = true - return affected, err - }) - for i := len(ad.hooks) - 1; i >= 0; i-- { - if ad.hooks[i] == nil { - return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = ad.hooks[i](mut) - } - if _, err := mut.Mutate(ctx, ad.mutation); err != nil { - return 0, err - } - } - return affected, err -} - -// ExecX is like Exec, but panics if an error occurs. -func (ad *ApprovalDelete) ExecX(ctx context.Context) int { - n, err := ad.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (ad *ApprovalDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: approval.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: approval.FieldID, - }, - }, - } - if ps := ad.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return sqlgraph.DeleteNodes(ctx, ad.driver, _spec) -} - -// ApprovalDeleteOne is the builder for deleting a single Approval entity. -type ApprovalDeleteOne struct { - ad *ApprovalDelete -} - -// Exec executes the deletion query. -func (ado *ApprovalDeleteOne) Exec(ctx context.Context) error { - n, err := ado.ad.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{approval.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (ado *ApprovalDeleteOne) ExecX(ctx context.Context) { - ado.ad.ExecX(ctx) -} diff --git a/ent/client.go b/ent/client.go index ad4a6c81..136a4380 100644 --- a/ent/client.go +++ b/ent/client.go @@ -9,7 +9,6 @@ import ( "github.com/gitploy-io/gitploy/ent/migrate" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/callback" "github.com/gitploy-io/gitploy/ent/chatuser" "github.com/gitploy-io/gitploy/ent/deployment" @@ -20,6 +19,7 @@ import ( "github.com/gitploy-io/gitploy/ent/notificationrecord" "github.com/gitploy-io/gitploy/ent/perm" "github.com/gitploy-io/gitploy/ent/repo" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" "entgo.io/ent/dialect" @@ -32,8 +32,6 @@ type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema - // Approval is the client for interacting with the Approval builders. - Approval *ApprovalClient // Callback is the client for interacting with the Callback builders. Callback *CallbackClient // ChatUser is the client for interacting with the ChatUser builders. @@ -54,6 +52,8 @@ type Client struct { Perm *PermClient // Repo is the client for interacting with the Repo builders. Repo *RepoClient + // Review is the client for interacting with the Review builders. + Review *ReviewClient // User is the client for interacting with the User builders. User *UserClient } @@ -69,7 +69,6 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) - c.Approval = NewApprovalClient(c.config) c.Callback = NewCallbackClient(c.config) c.ChatUser = NewChatUserClient(c.config) c.Deployment = NewDeploymentClient(c.config) @@ -80,6 +79,7 @@ func (c *Client) init() { c.NotificationRecord = NewNotificationRecordClient(c.config) c.Perm = NewPermClient(c.config) c.Repo = NewRepoClient(c.config) + c.Review = NewReviewClient(c.config) c.User = NewUserClient(c.config) } @@ -114,7 +114,6 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { return &Tx{ ctx: ctx, config: cfg, - Approval: NewApprovalClient(cfg), Callback: NewCallbackClient(cfg), ChatUser: NewChatUserClient(cfg), Deployment: NewDeploymentClient(cfg), @@ -125,6 +124,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { NotificationRecord: NewNotificationRecordClient(cfg), Perm: NewPermClient(cfg), Repo: NewRepoClient(cfg), + Review: NewReviewClient(cfg), User: NewUserClient(cfg), }, nil } @@ -144,7 +144,6 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ config: cfg, - Approval: NewApprovalClient(cfg), Callback: NewCallbackClient(cfg), ChatUser: NewChatUserClient(cfg), Deployment: NewDeploymentClient(cfg), @@ -155,6 +154,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) NotificationRecord: NewNotificationRecordClient(cfg), Perm: NewPermClient(cfg), Repo: NewRepoClient(cfg), + Review: NewReviewClient(cfg), User: NewUserClient(cfg), }, nil } @@ -162,7 +162,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). -// Approval. +// Callback. // Query(). // Count(ctx) // @@ -185,7 +185,6 @@ func (c *Client) Close() error { // Use adds the mutation hooks to all the entity clients. // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { - c.Approval.Use(hooks...) c.Callback.Use(hooks...) c.ChatUser.Use(hooks...) c.Deployment.Use(hooks...) @@ -196,147 +195,10 @@ func (c *Client) Use(hooks ...Hook) { c.NotificationRecord.Use(hooks...) c.Perm.Use(hooks...) c.Repo.Use(hooks...) + c.Review.Use(hooks...) c.User.Use(hooks...) } -// ApprovalClient is a client for the Approval schema. -type ApprovalClient struct { - config -} - -// NewApprovalClient returns a client for the Approval from the given config. -func NewApprovalClient(c config) *ApprovalClient { - return &ApprovalClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `approval.Hooks(f(g(h())))`. -func (c *ApprovalClient) Use(hooks ...Hook) { - c.hooks.Approval = append(c.hooks.Approval, hooks...) -} - -// Create returns a create builder for Approval. -func (c *ApprovalClient) Create() *ApprovalCreate { - mutation := newApprovalMutation(c.config, OpCreate) - return &ApprovalCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Approval entities. -func (c *ApprovalClient) CreateBulk(builders ...*ApprovalCreate) *ApprovalCreateBulk { - return &ApprovalCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Approval. -func (c *ApprovalClient) Update() *ApprovalUpdate { - mutation := newApprovalMutation(c.config, OpUpdate) - return &ApprovalUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *ApprovalClient) UpdateOne(a *Approval) *ApprovalUpdateOne { - mutation := newApprovalMutation(c.config, OpUpdateOne, withApproval(a)) - return &ApprovalUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *ApprovalClient) UpdateOneID(id int) *ApprovalUpdateOne { - mutation := newApprovalMutation(c.config, OpUpdateOne, withApprovalID(id)) - return &ApprovalUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Approval. -func (c *ApprovalClient) Delete() *ApprovalDelete { - mutation := newApprovalMutation(c.config, OpDelete) - return &ApprovalDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a delete builder for the given entity. -func (c *ApprovalClient) DeleteOne(a *Approval) *ApprovalDeleteOne { - return c.DeleteOneID(a.ID) -} - -// DeleteOneID returns a delete builder for the given id. -func (c *ApprovalClient) DeleteOneID(id int) *ApprovalDeleteOne { - builder := c.Delete().Where(approval.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &ApprovalDeleteOne{builder} -} - -// Query returns a query builder for Approval. -func (c *ApprovalClient) Query() *ApprovalQuery { - return &ApprovalQuery{ - config: c.config, - } -} - -// Get returns a Approval entity by its id. -func (c *ApprovalClient) Get(ctx context.Context, id int) (*Approval, error) { - return c.Query().Where(approval.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *ApprovalClient) GetX(ctx context.Context, id int) *Approval { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryUser queries the user edge of a Approval. -func (c *ApprovalClient) QueryUser(a *Approval) *UserQuery { - query := &UserQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := a.ID - step := sqlgraph.NewStep( - sqlgraph.From(approval.Table, approval.FieldID, id), - sqlgraph.To(user.Table, user.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, approval.UserTable, approval.UserColumn), - ) - fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// QueryDeployment queries the deployment edge of a Approval. -func (c *ApprovalClient) QueryDeployment(a *Approval) *DeploymentQuery { - query := &DeploymentQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := a.ID - step := sqlgraph.NewStep( - sqlgraph.From(approval.Table, approval.FieldID, id), - sqlgraph.To(deployment.Table, deployment.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, approval.DeploymentTable, approval.DeploymentColumn), - ) - fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// QueryEvent queries the event edge of a Approval. -func (c *ApprovalClient) QueryEvent(a *Approval) *EventQuery { - query := &EventQuery{config: c.config} - query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { - id := a.ID - step := sqlgraph.NewStep( - sqlgraph.From(approval.Table, approval.FieldID, id), - sqlgraph.To(event.Table, event.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, approval.EventTable, approval.EventColumn), - ) - fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *ApprovalClient) Hooks() []Hook { - return c.hooks.Approval -} - // CallbackClient is a client for the Callback schema. type CallbackClient struct { config @@ -666,15 +528,15 @@ func (c *DeploymentClient) QueryRepo(d *Deployment) *RepoQuery { return query } -// QueryApprovals queries the approvals edge of a Deployment. -func (c *DeploymentClient) QueryApprovals(d *Deployment) *ApprovalQuery { - query := &ApprovalQuery{config: c.config} +// QueryReviews queries the reviews edge of a Deployment. +func (c *DeploymentClient) QueryReviews(d *Deployment) *ReviewQuery { + query := &ReviewQuery{config: c.config} query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { id := d.ID step := sqlgraph.NewStep( sqlgraph.From(deployment.Table, deployment.FieldID, id), - sqlgraph.To(approval.Table, approval.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, deployment.ApprovalsTable, deployment.ApprovalsColumn), + sqlgraph.To(review.Table, review.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, deployment.ReviewsTable, deployment.ReviewsColumn), ) fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) return fromV, nil @@ -1032,15 +894,15 @@ func (c *EventClient) QueryDeployment(e *Event) *DeploymentQuery { return query } -// QueryApproval queries the approval edge of a Event. -func (c *EventClient) QueryApproval(e *Event) *ApprovalQuery { - query := &ApprovalQuery{config: c.config} +// QueryReview queries the review edge of a Event. +func (c *EventClient) QueryReview(e *Event) *ReviewQuery { + query := &ReviewQuery{config: c.config} query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { id := e.ID step := sqlgraph.NewStep( sqlgraph.From(event.Table, event.FieldID, id), - sqlgraph.To(approval.Table, approval.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, event.ApprovalTable, event.ApprovalColumn), + sqlgraph.To(review.Table, review.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, event.ReviewTable, event.ReviewColumn), ) fromV = sqlgraph.Neighbors(e.driver.Dialect(), step) return fromV, nil @@ -1589,6 +1451,144 @@ func (c *RepoClient) Hooks() []Hook { return c.hooks.Repo } +// ReviewClient is a client for the Review schema. +type ReviewClient struct { + config +} + +// NewReviewClient returns a client for the Review from the given config. +func NewReviewClient(c config) *ReviewClient { + return &ReviewClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `review.Hooks(f(g(h())))`. +func (c *ReviewClient) Use(hooks ...Hook) { + c.hooks.Review = append(c.hooks.Review, hooks...) +} + +// Create returns a create builder for Review. +func (c *ReviewClient) Create() *ReviewCreate { + mutation := newReviewMutation(c.config, OpCreate) + return &ReviewCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Review entities. +func (c *ReviewClient) CreateBulk(builders ...*ReviewCreate) *ReviewCreateBulk { + return &ReviewCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Review. +func (c *ReviewClient) Update() *ReviewUpdate { + mutation := newReviewMutation(c.config, OpUpdate) + return &ReviewUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ReviewClient) UpdateOne(r *Review) *ReviewUpdateOne { + mutation := newReviewMutation(c.config, OpUpdateOne, withReview(r)) + return &ReviewUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ReviewClient) UpdateOneID(id int) *ReviewUpdateOne { + mutation := newReviewMutation(c.config, OpUpdateOne, withReviewID(id)) + return &ReviewUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Review. +func (c *ReviewClient) Delete() *ReviewDelete { + mutation := newReviewMutation(c.config, OpDelete) + return &ReviewDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *ReviewClient) DeleteOne(r *Review) *ReviewDeleteOne { + return c.DeleteOneID(r.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *ReviewClient) DeleteOneID(id int) *ReviewDeleteOne { + builder := c.Delete().Where(review.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ReviewDeleteOne{builder} +} + +// Query returns a query builder for Review. +func (c *ReviewClient) Query() *ReviewQuery { + return &ReviewQuery{ + config: c.config, + } +} + +// Get returns a Review entity by its id. +func (c *ReviewClient) Get(ctx context.Context, id int) (*Review, error) { + return c.Query().Where(review.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ReviewClient) GetX(ctx context.Context, id int) *Review { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryUser queries the user edge of a Review. +func (c *ReviewClient) QueryUser(r *Review) *UserQuery { + query := &UserQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := r.ID + step := sqlgraph.NewStep( + sqlgraph.From(review.Table, review.FieldID, id), + sqlgraph.To(user.Table, user.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, review.UserTable, review.UserColumn), + ) + fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryDeployment queries the deployment edge of a Review. +func (c *ReviewClient) QueryDeployment(r *Review) *DeploymentQuery { + query := &DeploymentQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := r.ID + step := sqlgraph.NewStep( + sqlgraph.From(review.Table, review.FieldID, id), + sqlgraph.To(deployment.Table, deployment.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, review.DeploymentTable, review.DeploymentColumn), + ) + fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryEvent queries the event edge of a Review. +func (c *ReviewClient) QueryEvent(r *Review) *EventQuery { + query := &EventQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := r.ID + step := sqlgraph.NewStep( + sqlgraph.From(review.Table, review.FieldID, id), + sqlgraph.To(event.Table, event.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, review.EventTable, review.EventColumn), + ) + fromV = sqlgraph.Neighbors(r.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *ReviewClient) Hooks() []Hook { + return c.hooks.Review +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -1722,15 +1722,15 @@ func (c *UserClient) QueryDeployments(u *User) *DeploymentQuery { return query } -// QueryApprovals queries the approvals edge of a User. -func (c *UserClient) QueryApprovals(u *User) *ApprovalQuery { - query := &ApprovalQuery{config: c.config} +// QueryReviews queries the reviews edge of a User. +func (c *UserClient) QueryReviews(u *User) *ReviewQuery { + query := &ReviewQuery{config: c.config} query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { id := u.ID step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, id), - sqlgraph.To(approval.Table, approval.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, user.ApprovalsTable, user.ApprovalsColumn), + sqlgraph.To(review.Table, review.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.ReviewsTable, user.ReviewsColumn), ) fromV = sqlgraph.Neighbors(u.driver.Dialect(), step) return fromV, nil diff --git a/ent/config.go b/ent/config.go index c37af045..29f56d1a 100644 --- a/ent/config.go +++ b/ent/config.go @@ -24,7 +24,6 @@ type config struct { // hooks per client, for fast access. type hooks struct { - Approval []ent.Hook Callback []ent.Hook ChatUser []ent.Hook Deployment []ent.Hook @@ -35,6 +34,7 @@ type hooks struct { NotificationRecord []ent.Hook Perm []ent.Hook Repo []ent.Hook + Review []ent.Hook User []ent.Hook } diff --git a/ent/deployment.go b/ent/deployment.go index c736f41c..7c11ca8a 100644 --- a/ent/deployment.go +++ b/ent/deployment.go @@ -38,10 +38,6 @@ type Deployment struct { 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. - IsApprovalEnabled bool `json:"is_approval_enabled"` - // RequiredApprovalCount holds the value of the "required_approval_count" field. - RequiredApprovalCount int `json:"required_approval_count"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at"` // UpdatedAt holds the value of the "updated_at" field. @@ -50,6 +46,10 @@ type Deployment struct { UserID int64 `json:"user_id"` // RepoID holds the value of the "repo_id" field. RepoID int64 `json:"repo_id"` + // IsApprovalEnabled holds the value of the "is_approval_enabled" field. + IsApprovalEnabled *bool `json:"is_approval_enabled,omitemtpy"` + // RequiredApprovalCount holds the value of the "required_approval_count" field. + RequiredApprovalCount *int `json:"required_approval_count,omitemtpy"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the DeploymentQuery when eager-loading is set. Edges DeploymentEdges `json:"edges"` @@ -61,8 +61,8 @@ type DeploymentEdges struct { User *User `json:"user,omitempty"` // Repo holds the value of the repo edge. Repo *Repo `json:"repo,omitempty"` - // Approvals holds the value of the approvals edge. - Approvals []*Approval `json:"approvals,omitempty"` + // Reviews holds the value of the reviews edge. + Reviews []*Review `json:"reviews,omitempty"` // DeploymentStatuses holds the value of the deployment_statuses edge. DeploymentStatuses []*DeploymentStatus `json:"deployment_statuses,omitempty"` // Event holds the value of the event edge. @@ -100,13 +100,13 @@ func (e DeploymentEdges) RepoOrErr() (*Repo, error) { return nil, &NotLoadedError{edge: "repo"} } -// ApprovalsOrErr returns the Approvals value or an error if the edge +// ReviewsOrErr returns the Reviews value or an error if the edge // was not loaded in eager-loading. -func (e DeploymentEdges) ApprovalsOrErr() ([]*Approval, error) { +func (e DeploymentEdges) ReviewsOrErr() ([]*Review, error) { if e.loadedTypes[2] { - return e.Approvals, nil + return e.Reviews, nil } - return nil, &NotLoadedError{edge: "approvals"} + return nil, &NotLoadedError{edge: "reviews"} } // DeploymentStatusesOrErr returns the DeploymentStatuses value or an error if the edge @@ -134,7 +134,7 @@ func (*Deployment) scanValues(columns []string) ([]interface{}, error) { switch columns[i] { 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: + case deployment.FieldID, deployment.FieldNumber, deployment.FieldUID, deployment.FieldUserID, deployment.FieldRepoID, deployment.FieldRequiredApprovalCount: values[i] = new(sql.NullInt64) case deployment.FieldType, deployment.FieldEnv, deployment.FieldRef, deployment.FieldStatus, deployment.FieldSha, deployment.FieldHTMLURL: values[i] = new(sql.NullString) @@ -221,18 +221,6 @@ func (d *Deployment) assignValues(columns []string, values []interface{}) error } else if value.Valid { d.IsRollback = value.Bool } - case deployment.FieldIsApprovalEnabled: - if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field is_approval_enabled", values[i]) - } else if value.Valid { - d.IsApprovalEnabled = value.Bool - } - case deployment.FieldRequiredApprovalCount: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field required_approval_count", values[i]) - } else if value.Valid { - d.RequiredApprovalCount = int(value.Int64) - } case deployment.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) @@ -257,6 +245,20 @@ func (d *Deployment) assignValues(columns []string, values []interface{}) error } else if value.Valid { d.RepoID = value.Int64 } + case deployment.FieldIsApprovalEnabled: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field is_approval_enabled", values[i]) + } else if value.Valid { + d.IsApprovalEnabled = new(bool) + *d.IsApprovalEnabled = value.Bool + } + case deployment.FieldRequiredApprovalCount: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field required_approval_count", values[i]) + } else if value.Valid { + d.RequiredApprovalCount = new(int) + *d.RequiredApprovalCount = int(value.Int64) + } } } return nil @@ -272,9 +274,9 @@ func (d *Deployment) QueryRepo() *RepoQuery { return (&DeploymentClient{config: d.config}).QueryRepo(d) } -// QueryApprovals queries the "approvals" edge of the Deployment entity. -func (d *Deployment) QueryApprovals() *ApprovalQuery { - return (&DeploymentClient{config: d.config}).QueryApprovals(d) +// QueryReviews queries the "reviews" edge of the Deployment entity. +func (d *Deployment) QueryReviews() *ReviewQuery { + return (&DeploymentClient{config: d.config}).QueryReviews(d) } // QueryDeploymentStatuses queries the "deployment_statuses" edge of the Deployment entity. @@ -330,10 +332,6 @@ func (d *Deployment) String() string { builder.WriteString(fmt.Sprintf("%v", d.ProductionEnvironment)) builder.WriteString(", is_rollback=") builder.WriteString(fmt.Sprintf("%v", d.IsRollback)) - builder.WriteString(", is_approval_enabled=") - builder.WriteString(fmt.Sprintf("%v", d.IsApprovalEnabled)) - builder.WriteString(", required_approval_count=") - builder.WriteString(fmt.Sprintf("%v", d.RequiredApprovalCount)) builder.WriteString(", created_at=") builder.WriteString(d.CreatedAt.Format(time.ANSIC)) builder.WriteString(", updated_at=") @@ -342,6 +340,14 @@ func (d *Deployment) String() string { builder.WriteString(fmt.Sprintf("%v", d.UserID)) builder.WriteString(", repo_id=") builder.WriteString(fmt.Sprintf("%v", d.RepoID)) + if v := d.IsApprovalEnabled; v != nil { + builder.WriteString(", is_approval_enabled=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + if v := d.RequiredApprovalCount; v != nil { + builder.WriteString(", required_approval_count=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } builder.WriteByte(')') return builder.String() } diff --git a/ent/deployment/deployment.go b/ent/deployment/deployment.go index 1a694c35..6770d658 100644 --- a/ent/deployment/deployment.go +++ b/ent/deployment/deployment.go @@ -32,10 +32,6 @@ const ( 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. - FieldIsApprovalEnabled = "is_approval_enabled" - // FieldRequiredApprovalCount holds the string denoting the required_approval_count field in the database. - FieldRequiredApprovalCount = "required_approval_count" // 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. @@ -44,12 +40,16 @@ const ( FieldUserID = "user_id" // FieldRepoID holds the string denoting the repo_id field in the database. FieldRepoID = "repo_id" + // FieldIsApprovalEnabled holds the string denoting the is_approval_enabled field in the database. + FieldIsApprovalEnabled = "is_approval_enabled" + // FieldRequiredApprovalCount holds the string denoting the required_approval_count field in the database. + FieldRequiredApprovalCount = "required_approval_count" // EdgeUser holds the string denoting the user edge name in mutations. EdgeUser = "user" // EdgeRepo holds the string denoting the repo edge name in mutations. EdgeRepo = "repo" - // EdgeApprovals holds the string denoting the approvals edge name in mutations. - EdgeApprovals = "approvals" + // EdgeReviews holds the string denoting the reviews edge name in mutations. + EdgeReviews = "reviews" // EdgeDeploymentStatuses holds the string denoting the deployment_statuses edge name in mutations. EdgeDeploymentStatuses = "deployment_statuses" // EdgeEvent holds the string denoting the event edge name in mutations. @@ -70,13 +70,13 @@ const ( RepoInverseTable = "repos" // RepoColumn is the table column denoting the repo relation/edge. RepoColumn = "repo_id" - // ApprovalsTable is the table that holds the approvals relation/edge. - ApprovalsTable = "approvals" - // ApprovalsInverseTable is the table name for the Approval entity. - // It exists in this package in order to avoid circular dependency with the "approval" package. - ApprovalsInverseTable = "approvals" - // ApprovalsColumn is the table column denoting the approvals relation/edge. - ApprovalsColumn = "deployment_id" + // ReviewsTable is the table that holds the reviews relation/edge. + ReviewsTable = "reviews" + // ReviewsInverseTable is the table name for the Review entity. + // It exists in this package in order to avoid circular dependency with the "review" package. + ReviewsInverseTable = "reviews" + // ReviewsColumn is the table column denoting the reviews relation/edge. + ReviewsColumn = "deployment_id" // DeploymentStatusesTable is the table that holds the deployment_statuses relation/edge. DeploymentStatusesTable = "deployment_status" // DeploymentStatusesInverseTable is the table name for the DeploymentStatus entity. @@ -106,12 +106,12 @@ var Columns = []string{ FieldHTMLURL, FieldProductionEnvironment, FieldIsRollback, - FieldIsApprovalEnabled, - FieldRequiredApprovalCount, FieldCreatedAt, FieldUpdatedAt, FieldUserID, FieldRepoID, + FieldIsApprovalEnabled, + FieldRequiredApprovalCount, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -131,10 +131,6 @@ var ( 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. - DefaultIsApprovalEnabled bool - // DefaultRequiredApprovalCount holds the default value on creation for the "required_approval_count" field. - DefaultRequiredApprovalCount 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/deployment/where.go b/ent/deployment/where.go index 46554dd1..758c61d5 100644 --- a/ent/deployment/where.go +++ b/ent/deployment/where.go @@ -149,20 +149,6 @@ func IsRollback(v bool) predicate.Deployment { }) } -// IsApprovalEnabled applies equality check predicate on the "is_approval_enabled" field. It's identical to IsApprovalEnabledEQ. -func IsApprovalEnabled(v bool) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsApprovalEnabled), v)) - }) -} - -// RequiredApprovalCount applies equality check predicate on the "required_approval_count" field. It's identical to RequiredApprovalCountEQ. -func RequiredApprovalCount(v int) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRequiredApprovalCount), v)) - }) -} - // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. func CreatedAt(v time.Time) predicate.Deployment { return predicate.Deployment(func(s *sql.Selector) { @@ -191,6 +177,20 @@ func RepoID(v int64) predicate.Deployment { }) } +// IsApprovalEnabled applies equality check predicate on the "is_approval_enabled" field. It's identical to IsApprovalEnabledEQ. +func IsApprovalEnabled(v bool) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldIsApprovalEnabled), v)) + }) +} + +// RequiredApprovalCount applies equality check predicate on the "required_approval_count" field. It's identical to RequiredApprovalCountEQ. +func RequiredApprovalCount(v int) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldRequiredApprovalCount), v)) + }) +} + // NumberEQ applies the EQ predicate on the "number" field. func NumberEQ(v int) predicate.Deployment { return predicate.Deployment(func(s *sql.Selector) { @@ -953,96 +953,6 @@ func IsRollbackNEQ(v bool) predicate.Deployment { }) } -// IsApprovalEnabledEQ applies the EQ predicate on the "is_approval_enabled" field. -func IsApprovalEnabledEQ(v bool) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldIsApprovalEnabled), v)) - }) -} - -// IsApprovalEnabledNEQ applies the NEQ predicate on the "is_approval_enabled" field. -func IsApprovalEnabledNEQ(v bool) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldIsApprovalEnabled), v)) - }) -} - -// RequiredApprovalCountEQ applies the EQ predicate on the "required_approval_count" field. -func RequiredApprovalCountEQ(v int) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldRequiredApprovalCount), v)) - }) -} - -// RequiredApprovalCountNEQ applies the NEQ predicate on the "required_approval_count" field. -func RequiredApprovalCountNEQ(v int) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldRequiredApprovalCount), v)) - }) -} - -// RequiredApprovalCountIn applies the In predicate on the "required_approval_count" field. -func RequiredApprovalCountIn(vs ...int) predicate.Deployment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Deployment(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(FieldRequiredApprovalCount), v...)) - }) -} - -// RequiredApprovalCountNotIn applies the NotIn predicate on the "required_approval_count" field. -func RequiredApprovalCountNotIn(vs ...int) predicate.Deployment { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Deployment(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(FieldRequiredApprovalCount), v...)) - }) -} - -// RequiredApprovalCountGT applies the GT predicate on the "required_approval_count" field. -func RequiredApprovalCountGT(v int) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldRequiredApprovalCount), v)) - }) -} - -// RequiredApprovalCountGTE applies the GTE predicate on the "required_approval_count" field. -func RequiredApprovalCountGTE(v int) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldRequiredApprovalCount), v)) - }) -} - -// RequiredApprovalCountLT applies the LT predicate on the "required_approval_count" field. -func RequiredApprovalCountLT(v int) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldRequiredApprovalCount), v)) - }) -} - -// RequiredApprovalCountLTE applies the LTE predicate on the "required_approval_count" field. -func RequiredApprovalCountLTE(v int) predicate.Deployment { - return predicate.Deployment(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldRequiredApprovalCount), v)) - }) -} - // CreatedAtEQ applies the EQ predicate on the "created_at" field. func CreatedAtEQ(v time.Time) predicate.Deployment { return predicate.Deployment(func(s *sql.Selector) { @@ -1291,6 +1201,124 @@ func RepoIDNotIn(vs ...int64) predicate.Deployment { }) } +// IsApprovalEnabledEQ applies the EQ predicate on the "is_approval_enabled" field. +func IsApprovalEnabledEQ(v bool) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldIsApprovalEnabled), v)) + }) +} + +// IsApprovalEnabledNEQ applies the NEQ predicate on the "is_approval_enabled" field. +func IsApprovalEnabledNEQ(v bool) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldIsApprovalEnabled), v)) + }) +} + +// IsApprovalEnabledIsNil applies the IsNil predicate on the "is_approval_enabled" field. +func IsApprovalEnabledIsNil() predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldIsApprovalEnabled))) + }) +} + +// IsApprovalEnabledNotNil applies the NotNil predicate on the "is_approval_enabled" field. +func IsApprovalEnabledNotNil() predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldIsApprovalEnabled))) + }) +} + +// RequiredApprovalCountEQ applies the EQ predicate on the "required_approval_count" field. +func RequiredApprovalCountEQ(v int) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldRequiredApprovalCount), v)) + }) +} + +// RequiredApprovalCountNEQ applies the NEQ predicate on the "required_approval_count" field. +func RequiredApprovalCountNEQ(v int) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldRequiredApprovalCount), v)) + }) +} + +// RequiredApprovalCountIn applies the In predicate on the "required_approval_count" field. +func RequiredApprovalCountIn(vs ...int) predicate.Deployment { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Deployment(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(FieldRequiredApprovalCount), v...)) + }) +} + +// RequiredApprovalCountNotIn applies the NotIn predicate on the "required_approval_count" field. +func RequiredApprovalCountNotIn(vs ...int) predicate.Deployment { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Deployment(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(FieldRequiredApprovalCount), v...)) + }) +} + +// RequiredApprovalCountGT applies the GT predicate on the "required_approval_count" field. +func RequiredApprovalCountGT(v int) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldRequiredApprovalCount), v)) + }) +} + +// RequiredApprovalCountGTE applies the GTE predicate on the "required_approval_count" field. +func RequiredApprovalCountGTE(v int) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldRequiredApprovalCount), v)) + }) +} + +// RequiredApprovalCountLT applies the LT predicate on the "required_approval_count" field. +func RequiredApprovalCountLT(v int) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldRequiredApprovalCount), v)) + }) +} + +// RequiredApprovalCountLTE applies the LTE predicate on the "required_approval_count" field. +func RequiredApprovalCountLTE(v int) predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldRequiredApprovalCount), v)) + }) +} + +// RequiredApprovalCountIsNil applies the IsNil predicate on the "required_approval_count" field. +func RequiredApprovalCountIsNil() predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldRequiredApprovalCount))) + }) +} + +// RequiredApprovalCountNotNil applies the NotNil predicate on the "required_approval_count" field. +func RequiredApprovalCountNotNil() predicate.Deployment { + return predicate.Deployment(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldRequiredApprovalCount))) + }) +} + // HasUser applies the HasEdge predicate on the "user" edge. func HasUser() predicate.Deployment { return predicate.Deployment(func(s *sql.Selector) { @@ -1347,25 +1375,25 @@ func HasRepoWith(preds ...predicate.Repo) predicate.Deployment { }) } -// HasApprovals applies the HasEdge predicate on the "approvals" edge. -func HasApprovals() predicate.Deployment { +// HasReviews applies the HasEdge predicate on the "reviews" edge. +func HasReviews() predicate.Deployment { return predicate.Deployment(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ApprovalsTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, ApprovalsTable, ApprovalsColumn), + sqlgraph.To(ReviewsTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ReviewsTable, ReviewsColumn), ) sqlgraph.HasNeighbors(s, step) }) } -// HasApprovalsWith applies the HasEdge predicate on the "approvals" edge with a given conditions (other predicates). -func HasApprovalsWith(preds ...predicate.Approval) predicate.Deployment { +// HasReviewsWith applies the HasEdge predicate on the "reviews" edge with a given conditions (other predicates). +func HasReviewsWith(preds ...predicate.Review) predicate.Deployment { return predicate.Deployment(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ApprovalsInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, ApprovalsTable, ApprovalsColumn), + sqlgraph.To(ReviewsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ReviewsTable, ReviewsColumn), ) sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { diff --git a/ent/deployment_create.go b/ent/deployment_create.go index 2ea27bfe..4138ac2b 100644 --- a/ent/deployment_create.go +++ b/ent/deployment_create.go @@ -10,11 +10,11 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/deploymentstatus" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/repo" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) @@ -141,34 +141,6 @@ func (dc *DeploymentCreate) SetNillableIsRollback(b *bool) *DeploymentCreate { return dc } -// SetIsApprovalEnabled sets the "is_approval_enabled" field. -func (dc *DeploymentCreate) SetIsApprovalEnabled(b bool) *DeploymentCreate { - dc.mutation.SetIsApprovalEnabled(b) - return dc -} - -// SetNillableIsApprovalEnabled sets the "is_approval_enabled" field if the given value is not nil. -func (dc *DeploymentCreate) SetNillableIsApprovalEnabled(b *bool) *DeploymentCreate { - if b != nil { - dc.SetIsApprovalEnabled(*b) - } - return dc -} - -// SetRequiredApprovalCount sets the "required_approval_count" field. -func (dc *DeploymentCreate) SetRequiredApprovalCount(i int) *DeploymentCreate { - dc.mutation.SetRequiredApprovalCount(i) - return dc -} - -// SetNillableRequiredApprovalCount sets the "required_approval_count" field if the given value is not nil. -func (dc *DeploymentCreate) SetNillableRequiredApprovalCount(i *int) *DeploymentCreate { - if i != nil { - dc.SetRequiredApprovalCount(*i) - } - return dc -} - // SetCreatedAt sets the "created_at" field. func (dc *DeploymentCreate) SetCreatedAt(t time.Time) *DeploymentCreate { dc.mutation.SetCreatedAt(t) @@ -209,6 +181,34 @@ func (dc *DeploymentCreate) SetRepoID(i int64) *DeploymentCreate { return dc } +// SetIsApprovalEnabled sets the "is_approval_enabled" field. +func (dc *DeploymentCreate) SetIsApprovalEnabled(b bool) *DeploymentCreate { + dc.mutation.SetIsApprovalEnabled(b) + return dc +} + +// SetNillableIsApprovalEnabled sets the "is_approval_enabled" field if the given value is not nil. +func (dc *DeploymentCreate) SetNillableIsApprovalEnabled(b *bool) *DeploymentCreate { + if b != nil { + dc.SetIsApprovalEnabled(*b) + } + return dc +} + +// SetRequiredApprovalCount sets the "required_approval_count" field. +func (dc *DeploymentCreate) SetRequiredApprovalCount(i int) *DeploymentCreate { + dc.mutation.SetRequiredApprovalCount(i) + return dc +} + +// SetNillableRequiredApprovalCount sets the "required_approval_count" field if the given value is not nil. +func (dc *DeploymentCreate) SetNillableRequiredApprovalCount(i *int) *DeploymentCreate { + if i != nil { + dc.SetRequiredApprovalCount(*i) + } + return dc +} + // SetUser sets the "user" edge to the User entity. func (dc *DeploymentCreate) SetUser(u *User) *DeploymentCreate { return dc.SetUserID(u.ID) @@ -219,19 +219,19 @@ func (dc *DeploymentCreate) SetRepo(r *Repo) *DeploymentCreate { return dc.SetRepoID(r.ID) } -// AddApprovalIDs adds the "approvals" edge to the Approval entity by IDs. -func (dc *DeploymentCreate) AddApprovalIDs(ids ...int) *DeploymentCreate { - dc.mutation.AddApprovalIDs(ids...) +// AddReviewIDs adds the "reviews" edge to the Review entity by IDs. +func (dc *DeploymentCreate) AddReviewIDs(ids ...int) *DeploymentCreate { + dc.mutation.AddReviewIDs(ids...) return dc } -// AddApprovals adds the "approvals" edges to the Approval entity. -func (dc *DeploymentCreate) AddApprovals(a ...*Approval) *DeploymentCreate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// AddReviews adds the "reviews" edges to the Review entity. +func (dc *DeploymentCreate) AddReviews(r ...*Review) *DeploymentCreate { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return dc.AddApprovalIDs(ids...) + return dc.AddReviewIDs(ids...) } // AddDeploymentStatusIDs adds the "deployment_statuses" edge to the DeploymentStatus entity by IDs. @@ -351,14 +351,6 @@ func (dc *DeploymentCreate) defaults() { v := deployment.DefaultIsRollback dc.mutation.SetIsRollback(v) } - if _, ok := dc.mutation.IsApprovalEnabled(); !ok { - v := deployment.DefaultIsApprovalEnabled - dc.mutation.SetIsApprovalEnabled(v) - } - if _, ok := dc.mutation.RequiredApprovalCount(); !ok { - v := deployment.DefaultRequiredApprovalCount - dc.mutation.SetRequiredApprovalCount(v) - } if _, ok := dc.mutation.CreatedAt(); !ok { v := deployment.DefaultCreatedAt() dc.mutation.SetCreatedAt(v) @@ -407,12 +399,6 @@ func (dc *DeploymentCreate) check() error { if _, ok := dc.mutation.IsRollback(); !ok { return &ValidationError{Name: "is_rollback", err: errors.New(`ent: missing required field "is_rollback"`)} } - if _, ok := dc.mutation.IsApprovalEnabled(); !ok { - return &ValidationError{Name: "is_approval_enabled", err: errors.New(`ent: missing required field "is_approval_enabled"`)} - } - if _, ok := dc.mutation.RequiredApprovalCount(); !ok { - return &ValidationError{Name: "required_approval_count", err: errors.New(`ent: missing required field "required_approval_count"`)} - } if _, ok := dc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "created_at"`)} } @@ -538,22 +524,6 @@ func (dc *DeploymentCreate) createSpec() (*Deployment, *sqlgraph.CreateSpec) { }) _node.IsRollback = value } - if value, ok := dc.mutation.IsApprovalEnabled(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeBool, - Value: value, - Column: deployment.FieldIsApprovalEnabled, - }) - _node.IsApprovalEnabled = value - } - if value, ok := dc.mutation.RequiredApprovalCount(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Value: value, - Column: deployment.FieldRequiredApprovalCount, - }) - _node.RequiredApprovalCount = value - } if value, ok := dc.mutation.CreatedAt(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeTime, @@ -570,6 +540,22 @@ func (dc *DeploymentCreate) createSpec() (*Deployment, *sqlgraph.CreateSpec) { }) _node.UpdatedAt = value } + if value, ok := dc.mutation.IsApprovalEnabled(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: deployment.FieldIsApprovalEnabled, + }) + _node.IsApprovalEnabled = &value + } + if value, ok := dc.mutation.RequiredApprovalCount(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Value: value, + Column: deployment.FieldRequiredApprovalCount, + }) + _node.RequiredApprovalCount = &value + } if nodes := dc.mutation.UserIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -610,17 +596,17 @@ func (dc *DeploymentCreate) createSpec() (*Deployment, *sqlgraph.CreateSpec) { _node.RepoID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } - if nodes := dc.mutation.ApprovalsIDs(); len(nodes) > 0 { + if nodes := dc.mutation.ReviewsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: deployment.ApprovalsTable, - Columns: []string{deployment.ApprovalsColumn}, + Table: deployment.ReviewsTable, + Columns: []string{deployment.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } diff --git a/ent/deployment_query.go b/ent/deployment_query.go index 1665e162..c300fb2f 100644 --- a/ent/deployment_query.go +++ b/ent/deployment_query.go @@ -13,12 +13,12 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/deploymentstatus" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/predicate" "github.com/gitploy-io/gitploy/ent/repo" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) @@ -34,7 +34,7 @@ type DeploymentQuery struct { // eager-loading edges. withUser *UserQuery withRepo *RepoQuery - withApprovals *ApprovalQuery + withReviews *ReviewQuery withDeploymentStatuses *DeploymentStatusQuery withEvent *EventQuery modifiers []func(s *sql.Selector) @@ -118,9 +118,9 @@ func (dq *DeploymentQuery) QueryRepo() *RepoQuery { return query } -// QueryApprovals chains the current query on the "approvals" edge. -func (dq *DeploymentQuery) QueryApprovals() *ApprovalQuery { - query := &ApprovalQuery{config: dq.config} +// QueryReviews chains the current query on the "reviews" edge. +func (dq *DeploymentQuery) QueryReviews() *ReviewQuery { + query := &ReviewQuery{config: dq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := dq.prepareQuery(ctx); err != nil { return nil, err @@ -131,8 +131,8 @@ func (dq *DeploymentQuery) QueryApprovals() *ApprovalQuery { } step := sqlgraph.NewStep( sqlgraph.From(deployment.Table, deployment.FieldID, selector), - sqlgraph.To(approval.Table, approval.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, deployment.ApprovalsTable, deployment.ApprovalsColumn), + sqlgraph.To(review.Table, review.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, deployment.ReviewsTable, deployment.ReviewsColumn), ) fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step) return fromU, nil @@ -367,7 +367,7 @@ func (dq *DeploymentQuery) Clone() *DeploymentQuery { predicates: append([]predicate.Deployment{}, dq.predicates...), withUser: dq.withUser.Clone(), withRepo: dq.withRepo.Clone(), - withApprovals: dq.withApprovals.Clone(), + withReviews: dq.withReviews.Clone(), withDeploymentStatuses: dq.withDeploymentStatuses.Clone(), withEvent: dq.withEvent.Clone(), // clone intermediate query. @@ -398,14 +398,14 @@ func (dq *DeploymentQuery) WithRepo(opts ...func(*RepoQuery)) *DeploymentQuery { return dq } -// WithApprovals tells the query-builder to eager-load the nodes that are connected to -// the "approvals" edge. The optional arguments are used to configure the query builder of the edge. -func (dq *DeploymentQuery) WithApprovals(opts ...func(*ApprovalQuery)) *DeploymentQuery { - query := &ApprovalQuery{config: dq.config} +// WithReviews tells the query-builder to eager-load the nodes that are connected to +// the "reviews" edge. The optional arguments are used to configure the query builder of the edge. +func (dq *DeploymentQuery) WithReviews(opts ...func(*ReviewQuery)) *DeploymentQuery { + query := &ReviewQuery{config: dq.config} for _, opt := range opts { opt(query) } - dq.withApprovals = query + dq.withReviews = query return dq } @@ -499,7 +499,7 @@ func (dq *DeploymentQuery) sqlAll(ctx context.Context) ([]*Deployment, error) { loadedTypes = [5]bool{ dq.withUser != nil, dq.withRepo != nil, - dq.withApprovals != nil, + dq.withReviews != nil, dq.withDeploymentStatuses != nil, dq.withEvent != nil, } @@ -579,16 +579,16 @@ func (dq *DeploymentQuery) sqlAll(ctx context.Context) ([]*Deployment, error) { } } - if query := dq.withApprovals; query != nil { + if query := dq.withReviews; query != nil { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[int]*Deployment) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Approvals = []*Approval{} + nodes[i].Edges.Reviews = []*Review{} } - query.Where(predicate.Approval(func(s *sql.Selector) { - s.Where(sql.InValues(deployment.ApprovalsColumn, fks...)) + query.Where(predicate.Review(func(s *sql.Selector) { + s.Where(sql.InValues(deployment.ReviewsColumn, fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -600,7 +600,7 @@ func (dq *DeploymentQuery) sqlAll(ctx context.Context) ([]*Deployment, error) { if !ok { return nil, fmt.Errorf(`unexpected foreign-key "deployment_id" returned %v for node %v`, fk, n.ID) } - node.Edges.Approvals = append(node.Edges.Approvals, n) + node.Edges.Reviews = append(node.Edges.Reviews, n) } } diff --git a/ent/deployment_update.go b/ent/deployment_update.go index 756e0621..619b5825 100644 --- a/ent/deployment_update.go +++ b/ent/deployment_update.go @@ -11,12 +11,12 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/deploymentstatus" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/predicate" "github.com/gitploy-io/gitploy/ent/repo" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) @@ -181,6 +181,38 @@ func (du *DeploymentUpdate) SetNillableIsRollback(b *bool) *DeploymentUpdate { return du } +// SetCreatedAt sets the "created_at" field. +func (du *DeploymentUpdate) SetCreatedAt(t time.Time) *DeploymentUpdate { + du.mutation.SetCreatedAt(t) + return du +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (du *DeploymentUpdate) SetNillableCreatedAt(t *time.Time) *DeploymentUpdate { + if t != nil { + du.SetCreatedAt(*t) + } + return du +} + +// SetUpdatedAt sets the "updated_at" field. +func (du *DeploymentUpdate) SetUpdatedAt(t time.Time) *DeploymentUpdate { + du.mutation.SetUpdatedAt(t) + return du +} + +// SetUserID sets the "user_id" field. +func (du *DeploymentUpdate) SetUserID(i int64) *DeploymentUpdate { + du.mutation.SetUserID(i) + return du +} + +// SetRepoID sets the "repo_id" field. +func (du *DeploymentUpdate) SetRepoID(i int64) *DeploymentUpdate { + du.mutation.SetRepoID(i) + return du +} + // SetIsApprovalEnabled sets the "is_approval_enabled" field. func (du *DeploymentUpdate) SetIsApprovalEnabled(b bool) *DeploymentUpdate { du.mutation.SetIsApprovalEnabled(b) @@ -195,6 +227,12 @@ func (du *DeploymentUpdate) SetNillableIsApprovalEnabled(b *bool) *DeploymentUpd return du } +// ClearIsApprovalEnabled clears the value of the "is_approval_enabled" field. +func (du *DeploymentUpdate) ClearIsApprovalEnabled() *DeploymentUpdate { + du.mutation.ClearIsApprovalEnabled() + return du +} + // SetRequiredApprovalCount sets the "required_approval_count" field. func (du *DeploymentUpdate) SetRequiredApprovalCount(i int) *DeploymentUpdate { du.mutation.ResetRequiredApprovalCount() @@ -216,35 +254,9 @@ func (du *DeploymentUpdate) AddRequiredApprovalCount(i int) *DeploymentUpdate { return du } -// SetCreatedAt sets the "created_at" field. -func (du *DeploymentUpdate) SetCreatedAt(t time.Time) *DeploymentUpdate { - du.mutation.SetCreatedAt(t) - return du -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (du *DeploymentUpdate) SetNillableCreatedAt(t *time.Time) *DeploymentUpdate { - if t != nil { - du.SetCreatedAt(*t) - } - return du -} - -// SetUpdatedAt sets the "updated_at" field. -func (du *DeploymentUpdate) SetUpdatedAt(t time.Time) *DeploymentUpdate { - du.mutation.SetUpdatedAt(t) - return du -} - -// SetUserID sets the "user_id" field. -func (du *DeploymentUpdate) SetUserID(i int64) *DeploymentUpdate { - du.mutation.SetUserID(i) - return du -} - -// SetRepoID sets the "repo_id" field. -func (du *DeploymentUpdate) SetRepoID(i int64) *DeploymentUpdate { - du.mutation.SetRepoID(i) +// ClearRequiredApprovalCount clears the value of the "required_approval_count" field. +func (du *DeploymentUpdate) ClearRequiredApprovalCount() *DeploymentUpdate { + du.mutation.ClearRequiredApprovalCount() return du } @@ -258,19 +270,19 @@ func (du *DeploymentUpdate) SetRepo(r *Repo) *DeploymentUpdate { return du.SetRepoID(r.ID) } -// AddApprovalIDs adds the "approvals" edge to the Approval entity by IDs. -func (du *DeploymentUpdate) AddApprovalIDs(ids ...int) *DeploymentUpdate { - du.mutation.AddApprovalIDs(ids...) +// AddReviewIDs adds the "reviews" edge to the Review entity by IDs. +func (du *DeploymentUpdate) AddReviewIDs(ids ...int) *DeploymentUpdate { + du.mutation.AddReviewIDs(ids...) return du } -// AddApprovals adds the "approvals" edges to the Approval entity. -func (du *DeploymentUpdate) AddApprovals(a ...*Approval) *DeploymentUpdate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// AddReviews adds the "reviews" edges to the Review entity. +func (du *DeploymentUpdate) AddReviews(r ...*Review) *DeploymentUpdate { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return du.AddApprovalIDs(ids...) + return du.AddReviewIDs(ids...) } // AddDeploymentStatusIDs adds the "deployment_statuses" edge to the DeploymentStatus entity by IDs. @@ -320,25 +332,25 @@ func (du *DeploymentUpdate) ClearRepo() *DeploymentUpdate { return du } -// ClearApprovals clears all "approvals" edges to the Approval entity. -func (du *DeploymentUpdate) ClearApprovals() *DeploymentUpdate { - du.mutation.ClearApprovals() +// ClearReviews clears all "reviews" edges to the Review entity. +func (du *DeploymentUpdate) ClearReviews() *DeploymentUpdate { + du.mutation.ClearReviews() return du } -// RemoveApprovalIDs removes the "approvals" edge to Approval entities by IDs. -func (du *DeploymentUpdate) RemoveApprovalIDs(ids ...int) *DeploymentUpdate { - du.mutation.RemoveApprovalIDs(ids...) +// RemoveReviewIDs removes the "reviews" edge to Review entities by IDs. +func (du *DeploymentUpdate) RemoveReviewIDs(ids ...int) *DeploymentUpdate { + du.mutation.RemoveReviewIDs(ids...) return du } -// RemoveApprovals removes "approvals" edges to Approval entities. -func (du *DeploymentUpdate) RemoveApprovals(a ...*Approval) *DeploymentUpdate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// RemoveReviews removes "reviews" edges to Review entities. +func (du *DeploymentUpdate) RemoveReviews(r ...*Review) *DeploymentUpdate { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return du.RemoveApprovalIDs(ids...) + return du.RemoveReviewIDs(ids...) } // ClearDeploymentStatuses clears all "deployment_statuses" edges to the DeploymentStatus entity. @@ -598,6 +610,20 @@ func (du *DeploymentUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: deployment.FieldIsRollback, }) } + if value, ok := du.mutation.CreatedAt(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: deployment.FieldCreatedAt, + }) + } + if value, ok := du.mutation.UpdatedAt(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: deployment.FieldUpdatedAt, + }) + } if value, ok := du.mutation.IsApprovalEnabled(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, @@ -605,6 +631,12 @@ func (du *DeploymentUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: deployment.FieldIsApprovalEnabled, }) } + if du.mutation.IsApprovalEnabledCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Column: deployment.FieldIsApprovalEnabled, + }) + } if value, ok := du.mutation.RequiredApprovalCount(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, @@ -619,18 +651,10 @@ func (du *DeploymentUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: deployment.FieldRequiredApprovalCount, }) } - if value, ok := du.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: deployment.FieldCreatedAt, - }) - } - if value, ok := du.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: deployment.FieldUpdatedAt, + if du.mutation.RequiredApprovalCountCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: deployment.FieldRequiredApprovalCount, }) } if du.mutation.UserCleared() { @@ -703,33 +727,33 @@ func (du *DeploymentUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if du.mutation.ApprovalsCleared() { + if du.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: deployment.ApprovalsTable, - Columns: []string{deployment.ApprovalsColumn}, + Table: deployment.ReviewsTable, + Columns: []string{deployment.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := du.mutation.RemovedApprovalsIDs(); len(nodes) > 0 && !du.mutation.ApprovalsCleared() { + if nodes := du.mutation.RemovedReviewsIDs(); len(nodes) > 0 && !du.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: deployment.ApprovalsTable, - Columns: []string{deployment.ApprovalsColumn}, + Table: deployment.ReviewsTable, + Columns: []string{deployment.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } @@ -738,17 +762,17 @@ func (du *DeploymentUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := du.mutation.ApprovalsIDs(); len(nodes) > 0 { + if nodes := du.mutation.ReviewsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: deployment.ApprovalsTable, - Columns: []string{deployment.ApprovalsColumn}, + Table: deployment.ReviewsTable, + Columns: []string{deployment.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } @@ -1032,6 +1056,38 @@ func (duo *DeploymentUpdateOne) SetNillableIsRollback(b *bool) *DeploymentUpdate return duo } +// SetCreatedAt sets the "created_at" field. +func (duo *DeploymentUpdateOne) SetCreatedAt(t time.Time) *DeploymentUpdateOne { + duo.mutation.SetCreatedAt(t) + return duo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (duo *DeploymentUpdateOne) SetNillableCreatedAt(t *time.Time) *DeploymentUpdateOne { + if t != nil { + duo.SetCreatedAt(*t) + } + return duo +} + +// SetUpdatedAt sets the "updated_at" field. +func (duo *DeploymentUpdateOne) SetUpdatedAt(t time.Time) *DeploymentUpdateOne { + duo.mutation.SetUpdatedAt(t) + return duo +} + +// SetUserID sets the "user_id" field. +func (duo *DeploymentUpdateOne) SetUserID(i int64) *DeploymentUpdateOne { + duo.mutation.SetUserID(i) + return duo +} + +// SetRepoID sets the "repo_id" field. +func (duo *DeploymentUpdateOne) SetRepoID(i int64) *DeploymentUpdateOne { + duo.mutation.SetRepoID(i) + return duo +} + // SetIsApprovalEnabled sets the "is_approval_enabled" field. func (duo *DeploymentUpdateOne) SetIsApprovalEnabled(b bool) *DeploymentUpdateOne { duo.mutation.SetIsApprovalEnabled(b) @@ -1046,6 +1102,12 @@ func (duo *DeploymentUpdateOne) SetNillableIsApprovalEnabled(b *bool) *Deploymen return duo } +// ClearIsApprovalEnabled clears the value of the "is_approval_enabled" field. +func (duo *DeploymentUpdateOne) ClearIsApprovalEnabled() *DeploymentUpdateOne { + duo.mutation.ClearIsApprovalEnabled() + return duo +} + // SetRequiredApprovalCount sets the "required_approval_count" field. func (duo *DeploymentUpdateOne) SetRequiredApprovalCount(i int) *DeploymentUpdateOne { duo.mutation.ResetRequiredApprovalCount() @@ -1067,35 +1129,9 @@ func (duo *DeploymentUpdateOne) AddRequiredApprovalCount(i int) *DeploymentUpdat return duo } -// SetCreatedAt sets the "created_at" field. -func (duo *DeploymentUpdateOne) SetCreatedAt(t time.Time) *DeploymentUpdateOne { - duo.mutation.SetCreatedAt(t) - return duo -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (duo *DeploymentUpdateOne) SetNillableCreatedAt(t *time.Time) *DeploymentUpdateOne { - if t != nil { - duo.SetCreatedAt(*t) - } - return duo -} - -// SetUpdatedAt sets the "updated_at" field. -func (duo *DeploymentUpdateOne) SetUpdatedAt(t time.Time) *DeploymentUpdateOne { - duo.mutation.SetUpdatedAt(t) - return duo -} - -// SetUserID sets the "user_id" field. -func (duo *DeploymentUpdateOne) SetUserID(i int64) *DeploymentUpdateOne { - duo.mutation.SetUserID(i) - return duo -} - -// SetRepoID sets the "repo_id" field. -func (duo *DeploymentUpdateOne) SetRepoID(i int64) *DeploymentUpdateOne { - duo.mutation.SetRepoID(i) +// ClearRequiredApprovalCount clears the value of the "required_approval_count" field. +func (duo *DeploymentUpdateOne) ClearRequiredApprovalCount() *DeploymentUpdateOne { + duo.mutation.ClearRequiredApprovalCount() return duo } @@ -1109,19 +1145,19 @@ func (duo *DeploymentUpdateOne) SetRepo(r *Repo) *DeploymentUpdateOne { return duo.SetRepoID(r.ID) } -// AddApprovalIDs adds the "approvals" edge to the Approval entity by IDs. -func (duo *DeploymentUpdateOne) AddApprovalIDs(ids ...int) *DeploymentUpdateOne { - duo.mutation.AddApprovalIDs(ids...) +// AddReviewIDs adds the "reviews" edge to the Review entity by IDs. +func (duo *DeploymentUpdateOne) AddReviewIDs(ids ...int) *DeploymentUpdateOne { + duo.mutation.AddReviewIDs(ids...) return duo } -// AddApprovals adds the "approvals" edges to the Approval entity. -func (duo *DeploymentUpdateOne) AddApprovals(a ...*Approval) *DeploymentUpdateOne { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// AddReviews adds the "reviews" edges to the Review entity. +func (duo *DeploymentUpdateOne) AddReviews(r ...*Review) *DeploymentUpdateOne { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return duo.AddApprovalIDs(ids...) + return duo.AddReviewIDs(ids...) } // AddDeploymentStatusIDs adds the "deployment_statuses" edge to the DeploymentStatus entity by IDs. @@ -1171,25 +1207,25 @@ func (duo *DeploymentUpdateOne) ClearRepo() *DeploymentUpdateOne { return duo } -// ClearApprovals clears all "approvals" edges to the Approval entity. -func (duo *DeploymentUpdateOne) ClearApprovals() *DeploymentUpdateOne { - duo.mutation.ClearApprovals() +// ClearReviews clears all "reviews" edges to the Review entity. +func (duo *DeploymentUpdateOne) ClearReviews() *DeploymentUpdateOne { + duo.mutation.ClearReviews() return duo } -// RemoveApprovalIDs removes the "approvals" edge to Approval entities by IDs. -func (duo *DeploymentUpdateOne) RemoveApprovalIDs(ids ...int) *DeploymentUpdateOne { - duo.mutation.RemoveApprovalIDs(ids...) +// RemoveReviewIDs removes the "reviews" edge to Review entities by IDs. +func (duo *DeploymentUpdateOne) RemoveReviewIDs(ids ...int) *DeploymentUpdateOne { + duo.mutation.RemoveReviewIDs(ids...) return duo } -// RemoveApprovals removes "approvals" edges to Approval entities. -func (duo *DeploymentUpdateOne) RemoveApprovals(a ...*Approval) *DeploymentUpdateOne { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// RemoveReviews removes "reviews" edges to Review entities. +func (duo *DeploymentUpdateOne) RemoveReviews(r ...*Review) *DeploymentUpdateOne { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return duo.RemoveApprovalIDs(ids...) + return duo.RemoveReviewIDs(ids...) } // ClearDeploymentStatuses clears all "deployment_statuses" edges to the DeploymentStatus entity. @@ -1473,6 +1509,20 @@ func (duo *DeploymentUpdateOne) sqlSave(ctx context.Context) (_node *Deployment, Column: deployment.FieldIsRollback, }) } + if value, ok := duo.mutation.CreatedAt(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: deployment.FieldCreatedAt, + }) + } + if value, ok := duo.mutation.UpdatedAt(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: deployment.FieldUpdatedAt, + }) + } if value, ok := duo.mutation.IsApprovalEnabled(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeBool, @@ -1480,6 +1530,12 @@ func (duo *DeploymentUpdateOne) sqlSave(ctx context.Context) (_node *Deployment, Column: deployment.FieldIsApprovalEnabled, }) } + if duo.mutation.IsApprovalEnabledCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Column: deployment.FieldIsApprovalEnabled, + }) + } if value, ok := duo.mutation.RequiredApprovalCount(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, @@ -1494,18 +1550,10 @@ func (duo *DeploymentUpdateOne) sqlSave(ctx context.Context) (_node *Deployment, Column: deployment.FieldRequiredApprovalCount, }) } - if value, ok := duo.mutation.CreatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: deployment.FieldCreatedAt, - }) - } - if value, ok := duo.mutation.UpdatedAt(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeTime, - Value: value, - Column: deployment.FieldUpdatedAt, + if duo.mutation.RequiredApprovalCountCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: deployment.FieldRequiredApprovalCount, }) } if duo.mutation.UserCleared() { @@ -1578,33 +1626,33 @@ func (duo *DeploymentUpdateOne) sqlSave(ctx context.Context) (_node *Deployment, } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if duo.mutation.ApprovalsCleared() { + if duo.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: deployment.ApprovalsTable, - Columns: []string{deployment.ApprovalsColumn}, + Table: deployment.ReviewsTable, + Columns: []string{deployment.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := duo.mutation.RemovedApprovalsIDs(); len(nodes) > 0 && !duo.mutation.ApprovalsCleared() { + if nodes := duo.mutation.RemovedReviewsIDs(); len(nodes) > 0 && !duo.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: deployment.ApprovalsTable, - Columns: []string{deployment.ApprovalsColumn}, + Table: deployment.ReviewsTable, + Columns: []string{deployment.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } @@ -1613,17 +1661,17 @@ func (duo *DeploymentUpdateOne) sqlSave(ctx context.Context) (_node *Deployment, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := duo.mutation.ApprovalsIDs(); len(nodes) > 0 { + if nodes := duo.mutation.ReviewsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: deployment.ApprovalsTable, - Columns: []string{deployment.ApprovalsColumn}, + Table: deployment.ReviewsTable, + Columns: []string{deployment.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } diff --git a/ent/ent.go b/ent/ent.go index 6f6e854d..0c01e1c7 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -8,7 +8,6 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/callback" "github.com/gitploy-io/gitploy/ent/chatuser" "github.com/gitploy-io/gitploy/ent/deployment" @@ -19,6 +18,7 @@ import ( "github.com/gitploy-io/gitploy/ent/notificationrecord" "github.com/gitploy-io/gitploy/ent/perm" "github.com/gitploy-io/gitploy/ent/repo" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) @@ -40,7 +40,6 @@ type OrderFunc func(*sql.Selector) // columnChecker returns a function indicates if the column exists in the given column. func columnChecker(table string) func(string) error { checks := map[string]func(string) bool{ - approval.Table: approval.ValidColumn, callback.Table: callback.ValidColumn, chatuser.Table: chatuser.ValidColumn, deployment.Table: deployment.ValidColumn, @@ -51,6 +50,7 @@ func columnChecker(table string) func(string) error { notificationrecord.Table: notificationrecord.ValidColumn, perm.Table: perm.ValidColumn, repo.Table: repo.ValidColumn, + review.Table: review.ValidColumn, user.Table: user.ValidColumn, } check, ok := checks[table] diff --git a/ent/event.go b/ent/event.go index 93e217a7..b5504647 100644 --- a/ent/event.go +++ b/ent/event.go @@ -8,10 +8,10 @@ import ( "time" "entgo.io/ent/dialect/sql" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/notificationrecord" + "github.com/gitploy-io/gitploy/ent/review" ) // Event is the model entity for the Event schema. @@ -29,6 +29,8 @@ type Event struct { DeploymentID int `json:"deployment_id,omitemtpy"` // ApprovalID holds the value of the "approval_id" field. ApprovalID int `json:"approval_id,omitemtpy"` + // ReviewID holds the value of the "review_id" field. + ReviewID int `json:"review_id,omitemtpy"` // DeletedID holds the value of the "deleted_id" field. DeletedID int `json:"deleted_id,omitemtpy"` // Edges holds the relations/edges for other nodes in the graph. @@ -40,8 +42,8 @@ type Event struct { type EventEdges struct { // Deployment holds the value of the deployment edge. Deployment *Deployment `json:"deployment,omitempty"` - // Approval holds the value of the approval edge. - Approval *Approval `json:"approval,omitempty"` + // Review holds the value of the review edge. + Review *Review `json:"review,omitempty"` // NotificationRecord holds the value of the notification_record edge. NotificationRecord *NotificationRecord `json:"notification_record,omitempty"` // loadedTypes holds the information for reporting if a @@ -63,18 +65,18 @@ func (e EventEdges) DeploymentOrErr() (*Deployment, error) { return nil, &NotLoadedError{edge: "deployment"} } -// ApprovalOrErr returns the Approval value or an error if the edge +// ReviewOrErr returns the Review value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. -func (e EventEdges) ApprovalOrErr() (*Approval, error) { +func (e EventEdges) ReviewOrErr() (*Review, error) { if e.loadedTypes[1] { - if e.Approval == nil { - // The edge approval was loaded in eager-loading, + if e.Review == nil { + // The edge review was loaded in eager-loading, // but was not found. - return nil, &NotFoundError{label: approval.Label} + return nil, &NotFoundError{label: review.Label} } - return e.Approval, nil + return e.Review, nil } - return nil, &NotLoadedError{edge: "approval"} + return nil, &NotLoadedError{edge: "review"} } // NotificationRecordOrErr returns the NotificationRecord value or an error if the edge @@ -96,7 +98,7 @@ func (*Event) scanValues(columns []string) ([]interface{}, error) { values := make([]interface{}, len(columns)) for i := range columns { switch columns[i] { - case event.FieldID, event.FieldDeploymentID, event.FieldApprovalID, event.FieldDeletedID: + case event.FieldID, event.FieldDeploymentID, event.FieldApprovalID, event.FieldReviewID, event.FieldDeletedID: values[i] = new(sql.NullInt64) case event.FieldKind, event.FieldType: values[i] = new(sql.NullString) @@ -153,6 +155,12 @@ func (e *Event) assignValues(columns []string, values []interface{}) error { } else if value.Valid { e.ApprovalID = int(value.Int64) } + case event.FieldReviewID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field review_id", values[i]) + } else if value.Valid { + e.ReviewID = int(value.Int64) + } case event.FieldDeletedID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field deleted_id", values[i]) @@ -169,9 +177,9 @@ func (e *Event) QueryDeployment() *DeploymentQuery { return (&EventClient{config: e.config}).QueryDeployment(e) } -// QueryApproval queries the "approval" edge of the Event entity. -func (e *Event) QueryApproval() *ApprovalQuery { - return (&EventClient{config: e.config}).QueryApproval(e) +// QueryReview queries the "review" edge of the Event entity. +func (e *Event) QueryReview() *ReviewQuery { + return (&EventClient{config: e.config}).QueryReview(e) } // QueryNotificationRecord queries the "notification_record" edge of the Event entity. @@ -212,6 +220,8 @@ func (e *Event) String() string { builder.WriteString(fmt.Sprintf("%v", e.DeploymentID)) builder.WriteString(", approval_id=") builder.WriteString(fmt.Sprintf("%v", e.ApprovalID)) + builder.WriteString(", review_id=") + builder.WriteString(fmt.Sprintf("%v", e.ReviewID)) builder.WriteString(", deleted_id=") builder.WriteString(fmt.Sprintf("%v", e.DeletedID)) builder.WriteByte(')') diff --git a/ent/event/event.go b/ent/event/event.go index 069788ee..ba49f5b4 100644 --- a/ent/event/event.go +++ b/ent/event/event.go @@ -22,12 +22,14 @@ const ( FieldDeploymentID = "deployment_id" // FieldApprovalID holds the string denoting the approval_id field in the database. FieldApprovalID = "approval_id" + // FieldReviewID holds the string denoting the review_id field in the database. + FieldReviewID = "review_id" // FieldDeletedID holds the string denoting the deleted_id field in the database. FieldDeletedID = "deleted_id" // EdgeDeployment holds the string denoting the deployment edge name in mutations. EdgeDeployment = "deployment" - // EdgeApproval holds the string denoting the approval edge name in mutations. - EdgeApproval = "approval" + // EdgeReview holds the string denoting the review edge name in mutations. + EdgeReview = "review" // EdgeNotificationRecord holds the string denoting the notification_record edge name in mutations. EdgeNotificationRecord = "notification_record" // Table holds the table name of the event in the database. @@ -39,13 +41,13 @@ const ( DeploymentInverseTable = "deployments" // DeploymentColumn is the table column denoting the deployment relation/edge. DeploymentColumn = "deployment_id" - // ApprovalTable is the table that holds the approval relation/edge. - ApprovalTable = "events" - // ApprovalInverseTable is the table name for the Approval entity. - // It exists in this package in order to avoid circular dependency with the "approval" package. - ApprovalInverseTable = "approvals" - // ApprovalColumn is the table column denoting the approval relation/edge. - ApprovalColumn = "approval_id" + // ReviewTable is the table that holds the review relation/edge. + ReviewTable = "events" + // ReviewInverseTable is the table name for the Review entity. + // It exists in this package in order to avoid circular dependency with the "review" package. + ReviewInverseTable = "reviews" + // ReviewColumn is the table column denoting the review relation/edge. + ReviewColumn = "review_id" // NotificationRecordTable is the table that holds the notification_record relation/edge. NotificationRecordTable = "notification_records" // NotificationRecordInverseTable is the table name for the NotificationRecord entity. @@ -63,6 +65,7 @@ var Columns = []string{ FieldCreatedAt, FieldDeploymentID, FieldApprovalID, + FieldReviewID, FieldDeletedID, } @@ -88,6 +91,7 @@ type Kind string const ( KindDeployment Kind = "deployment" KindApproval Kind = "approval" + KindReview Kind = "review" ) func (k Kind) String() string { @@ -97,7 +101,7 @@ func (k Kind) String() string { // KindValidator is a validator for the "kind" field enum values. It is called by the builders before save. func KindValidator(k Kind) error { switch k { - case KindDeployment, KindApproval: + case KindDeployment, KindApproval, KindReview: return nil default: return fmt.Errorf("event: invalid enum value for kind field: %q", k) diff --git a/ent/event/where.go b/ent/event/where.go index e383720a..d3335a26 100644 --- a/ent/event/where.go +++ b/ent/event/where.go @@ -114,6 +114,13 @@ func ApprovalID(v int) predicate.Event { }) } +// ReviewID applies equality check predicate on the "review_id" field. It's identical to ReviewIDEQ. +func ReviewID(v int) predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldReviewID), v)) + }) +} + // DeletedID applies equality check predicate on the "deleted_id" field. It's identical to DeletedIDEQ. func DeletedID(v int) predicate.Event { return predicate.Event(func(s *sql.Selector) { @@ -403,6 +410,34 @@ func ApprovalIDNotIn(vs ...int) predicate.Event { }) } +// ApprovalIDGT applies the GT predicate on the "approval_id" field. +func ApprovalIDGT(v int) predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldApprovalID), v)) + }) +} + +// ApprovalIDGTE applies the GTE predicate on the "approval_id" field. +func ApprovalIDGTE(v int) predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldApprovalID), v)) + }) +} + +// ApprovalIDLT applies the LT predicate on the "approval_id" field. +func ApprovalIDLT(v int) predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldApprovalID), v)) + }) +} + +// ApprovalIDLTE applies the LTE predicate on the "approval_id" field. +func ApprovalIDLTE(v int) predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldApprovalID), v)) + }) +} + // ApprovalIDIsNil applies the IsNil predicate on the "approval_id" field. func ApprovalIDIsNil() predicate.Event { return predicate.Event(func(s *sql.Selector) { @@ -417,6 +452,68 @@ func ApprovalIDNotNil() predicate.Event { }) } +// ReviewIDEQ applies the EQ predicate on the "review_id" field. +func ReviewIDEQ(v int) predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldReviewID), v)) + }) +} + +// ReviewIDNEQ applies the NEQ predicate on the "review_id" field. +func ReviewIDNEQ(v int) predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldReviewID), v)) + }) +} + +// ReviewIDIn applies the In predicate on the "review_id" field. +func ReviewIDIn(vs ...int) predicate.Event { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Event(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(FieldReviewID), v...)) + }) +} + +// ReviewIDNotIn applies the NotIn predicate on the "review_id" field. +func ReviewIDNotIn(vs ...int) predicate.Event { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Event(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(FieldReviewID), v...)) + }) +} + +// ReviewIDIsNil applies the IsNil predicate on the "review_id" field. +func ReviewIDIsNil() predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldReviewID))) + }) +} + +// ReviewIDNotNil applies the NotNil predicate on the "review_id" field. +func ReviewIDNotNil() predicate.Event { + return predicate.Event(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldReviewID))) + }) +} + // DeletedIDEQ applies the EQ predicate on the "deleted_id" field. func DeletedIDEQ(v int) predicate.Event { return predicate.Event(func(s *sql.Selector) { @@ -535,25 +632,25 @@ func HasDeploymentWith(preds ...predicate.Deployment) predicate.Event { }) } -// HasApproval applies the HasEdge predicate on the "approval" edge. -func HasApproval() predicate.Event { +// HasReview applies the HasEdge predicate on the "review" edge. +func HasReview() predicate.Event { return predicate.Event(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ApprovalTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, ApprovalTable, ApprovalColumn), + sqlgraph.To(ReviewTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ReviewTable, ReviewColumn), ) sqlgraph.HasNeighbors(s, step) }) } -// HasApprovalWith applies the HasEdge predicate on the "approval" edge with a given conditions (other predicates). -func HasApprovalWith(preds ...predicate.Approval) predicate.Event { +// HasReviewWith applies the HasEdge predicate on the "review" edge with a given conditions (other predicates). +func HasReviewWith(preds ...predicate.Review) predicate.Event { return predicate.Event(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ApprovalInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, ApprovalTable, ApprovalColumn), + sqlgraph.To(ReviewInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, ReviewTable, ReviewColumn), ) sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { diff --git a/ent/event_create.go b/ent/event_create.go index b29f82a3..7e64a1ff 100644 --- a/ent/event_create.go +++ b/ent/event_create.go @@ -10,10 +10,10 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/notificationrecord" + "github.com/gitploy-io/gitploy/ent/review" ) // EventCreate is the builder for creating a Event entity. @@ -77,6 +77,20 @@ func (ec *EventCreate) SetNillableApprovalID(i *int) *EventCreate { return ec } +// SetReviewID sets the "review_id" field. +func (ec *EventCreate) SetReviewID(i int) *EventCreate { + ec.mutation.SetReviewID(i) + return ec +} + +// SetNillableReviewID sets the "review_id" field if the given value is not nil. +func (ec *EventCreate) SetNillableReviewID(i *int) *EventCreate { + if i != nil { + ec.SetReviewID(*i) + } + return ec +} + // SetDeletedID sets the "deleted_id" field. func (ec *EventCreate) SetDeletedID(i int) *EventCreate { ec.mutation.SetDeletedID(i) @@ -96,9 +110,9 @@ func (ec *EventCreate) SetDeployment(d *Deployment) *EventCreate { return ec.SetDeploymentID(d.ID) } -// SetApproval sets the "approval" edge to the Approval entity. -func (ec *EventCreate) SetApproval(a *Approval) *EventCreate { - return ec.SetApprovalID(a.ID) +// SetReview sets the "review" edge to the Review entity. +func (ec *EventCreate) SetReview(r *Review) *EventCreate { + return ec.SetReviewID(r.ID) } // SetNotificationRecordID sets the "notification_record" edge to the NotificationRecord entity by ID. @@ -269,6 +283,14 @@ func (ec *EventCreate) createSpec() (*Event, *sqlgraph.CreateSpec) { }) _node.CreatedAt = value } + if value, ok := ec.mutation.ApprovalID(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Value: value, + Column: event.FieldApprovalID, + }) + _node.ApprovalID = value + } if value, ok := ec.mutation.DeletedID(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeInt, @@ -297,24 +319,24 @@ func (ec *EventCreate) createSpec() (*Event, *sqlgraph.CreateSpec) { _node.DeploymentID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } - if nodes := ec.mutation.ApprovalIDs(); len(nodes) > 0 { + if nodes := ec.mutation.ReviewIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: event.ApprovalTable, - Columns: []string{event.ApprovalColumn}, + Table: event.ReviewTable, + Columns: []string{event.ReviewColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } - _node.ApprovalID = nodes[0] + _node.ReviewID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := ec.mutation.NotificationRecordIDs(); len(nodes) > 0 { diff --git a/ent/event_query.go b/ent/event_query.go index 7f7758e4..6553e290 100644 --- a/ent/event_query.go +++ b/ent/event_query.go @@ -13,11 +13,11 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/notificationrecord" "github.com/gitploy-io/gitploy/ent/predicate" + "github.com/gitploy-io/gitploy/ent/review" ) // EventQuery is the builder for querying Event entities. @@ -31,7 +31,7 @@ type EventQuery struct { predicates []predicate.Event // eager-loading edges. withDeployment *DeploymentQuery - withApproval *ApprovalQuery + withReview *ReviewQuery withNotificationRecord *NotificationRecordQuery modifiers []func(s *sql.Selector) // intermediate query (i.e. traversal path). @@ -92,9 +92,9 @@ func (eq *EventQuery) QueryDeployment() *DeploymentQuery { return query } -// QueryApproval chains the current query on the "approval" edge. -func (eq *EventQuery) QueryApproval() *ApprovalQuery { - query := &ApprovalQuery{config: eq.config} +// QueryReview chains the current query on the "review" edge. +func (eq *EventQuery) QueryReview() *ReviewQuery { + query := &ReviewQuery{config: eq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := eq.prepareQuery(ctx); err != nil { return nil, err @@ -105,8 +105,8 @@ func (eq *EventQuery) QueryApproval() *ApprovalQuery { } step := sqlgraph.NewStep( sqlgraph.From(event.Table, event.FieldID, selector), - sqlgraph.To(approval.Table, approval.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, event.ApprovalTable, event.ApprovalColumn), + sqlgraph.To(review.Table, review.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, event.ReviewTable, event.ReviewColumn), ) fromU = sqlgraph.SetNeighbors(eq.driver.Dialect(), step) return fromU, nil @@ -318,7 +318,7 @@ func (eq *EventQuery) Clone() *EventQuery { order: append([]OrderFunc{}, eq.order...), predicates: append([]predicate.Event{}, eq.predicates...), withDeployment: eq.withDeployment.Clone(), - withApproval: eq.withApproval.Clone(), + withReview: eq.withReview.Clone(), withNotificationRecord: eq.withNotificationRecord.Clone(), // clone intermediate query. sql: eq.sql.Clone(), @@ -337,14 +337,14 @@ func (eq *EventQuery) WithDeployment(opts ...func(*DeploymentQuery)) *EventQuery return eq } -// WithApproval tells the query-builder to eager-load the nodes that are connected to -// the "approval" edge. The optional arguments are used to configure the query builder of the edge. -func (eq *EventQuery) WithApproval(opts ...func(*ApprovalQuery)) *EventQuery { - query := &ApprovalQuery{config: eq.config} +// WithReview tells the query-builder to eager-load the nodes that are connected to +// the "review" edge. The optional arguments are used to configure the query builder of the edge. +func (eq *EventQuery) WithReview(opts ...func(*ReviewQuery)) *EventQuery { + query := &ReviewQuery{config: eq.config} for _, opt := range opts { opt(query) } - eq.withApproval = query + eq.withReview = query return eq } @@ -426,7 +426,7 @@ func (eq *EventQuery) sqlAll(ctx context.Context) ([]*Event, error) { _spec = eq.querySpec() loadedTypes = [3]bool{ eq.withDeployment != nil, - eq.withApproval != nil, + eq.withReview != nil, eq.withNotificationRecord != nil, } ) @@ -479,17 +479,17 @@ func (eq *EventQuery) sqlAll(ctx context.Context) ([]*Event, error) { } } - if query := eq.withApproval; query != nil { + if query := eq.withReview; query != nil { ids := make([]int, 0, len(nodes)) nodeids := make(map[int][]*Event) for i := range nodes { - fk := nodes[i].ApprovalID + fk := nodes[i].ReviewID if _, ok := nodeids[fk]; !ok { ids = append(ids, fk) } nodeids[fk] = append(nodeids[fk], nodes[i]) } - query.Where(approval.IDIn(ids...)) + query.Where(review.IDIn(ids...)) neighbors, err := query.All(ctx) if err != nil { return nil, err @@ -497,10 +497,10 @@ func (eq *EventQuery) sqlAll(ctx context.Context) ([]*Event, error) { for _, n := range neighbors { nodes, ok := nodeids[n.ID] if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "approval_id" returned %v`, n.ID) + return nil, fmt.Errorf(`unexpected foreign-key "review_id" returned %v`, n.ID) } for i := range nodes { - nodes[i].Edges.Approval = n + nodes[i].Edges.Review = n } } } diff --git a/ent/event_update.go b/ent/event_update.go index d7b50bce..fbd57d9b 100644 --- a/ent/event_update.go +++ b/ent/event_update.go @@ -10,11 +10,11 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/notificationrecord" "github.com/gitploy-io/gitploy/ent/predicate" + "github.com/gitploy-io/gitploy/ent/review" ) // EventUpdate is the builder for updating Event entities. @@ -78,6 +78,7 @@ func (eu *EventUpdate) ClearDeploymentID() *EventUpdate { // SetApprovalID sets the "approval_id" field. func (eu *EventUpdate) SetApprovalID(i int) *EventUpdate { + eu.mutation.ResetApprovalID() eu.mutation.SetApprovalID(i) return eu } @@ -90,12 +91,38 @@ func (eu *EventUpdate) SetNillableApprovalID(i *int) *EventUpdate { return eu } +// AddApprovalID adds i to the "approval_id" field. +func (eu *EventUpdate) AddApprovalID(i int) *EventUpdate { + eu.mutation.AddApprovalID(i) + return eu +} + // ClearApprovalID clears the value of the "approval_id" field. func (eu *EventUpdate) ClearApprovalID() *EventUpdate { eu.mutation.ClearApprovalID() return eu } +// SetReviewID sets the "review_id" field. +func (eu *EventUpdate) SetReviewID(i int) *EventUpdate { + eu.mutation.SetReviewID(i) + return eu +} + +// SetNillableReviewID sets the "review_id" field if the given value is not nil. +func (eu *EventUpdate) SetNillableReviewID(i *int) *EventUpdate { + if i != nil { + eu.SetReviewID(*i) + } + return eu +} + +// ClearReviewID clears the value of the "review_id" field. +func (eu *EventUpdate) ClearReviewID() *EventUpdate { + eu.mutation.ClearReviewID() + return eu +} + // SetDeletedID sets the "deleted_id" field. func (eu *EventUpdate) SetDeletedID(i int) *EventUpdate { eu.mutation.ResetDeletedID() @@ -128,9 +155,9 @@ func (eu *EventUpdate) SetDeployment(d *Deployment) *EventUpdate { return eu.SetDeploymentID(d.ID) } -// SetApproval sets the "approval" edge to the Approval entity. -func (eu *EventUpdate) SetApproval(a *Approval) *EventUpdate { - return eu.SetApprovalID(a.ID) +// SetReview sets the "review" edge to the Review entity. +func (eu *EventUpdate) SetReview(r *Review) *EventUpdate { + return eu.SetReviewID(r.ID) } // SetNotificationRecordID sets the "notification_record" edge to the NotificationRecord entity by ID. @@ -163,9 +190,9 @@ func (eu *EventUpdate) ClearDeployment() *EventUpdate { return eu } -// ClearApproval clears the "approval" edge to the Approval entity. -func (eu *EventUpdate) ClearApproval() *EventUpdate { - eu.mutation.ClearApproval() +// ClearReview clears the "review" edge to the Review entity. +func (eu *EventUpdate) ClearReview() *EventUpdate { + eu.mutation.ClearReview() return eu } @@ -289,6 +316,26 @@ func (eu *EventUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: event.FieldCreatedAt, }) } + if value, ok := eu.mutation.ApprovalID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Value: value, + Column: event.FieldApprovalID, + }) + } + if value, ok := eu.mutation.AddedApprovalID(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Value: value, + Column: event.FieldApprovalID, + }) + } + if eu.mutation.ApprovalIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: event.FieldApprovalID, + }) + } if value, ok := eu.mutation.DeletedID(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, @@ -344,33 +391,33 @@ func (eu *EventUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if eu.mutation.ApprovalCleared() { + if eu.mutation.ReviewCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: event.ApprovalTable, - Columns: []string{event.ApprovalColumn}, + Table: event.ReviewTable, + Columns: []string{event.ReviewColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := eu.mutation.ApprovalIDs(); len(nodes) > 0 { + if nodes := eu.mutation.ReviewIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: event.ApprovalTable, - Columns: []string{event.ApprovalColumn}, + Table: event.ReviewTable, + Columns: []string{event.ReviewColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } @@ -481,6 +528,7 @@ func (euo *EventUpdateOne) ClearDeploymentID() *EventUpdateOne { // SetApprovalID sets the "approval_id" field. func (euo *EventUpdateOne) SetApprovalID(i int) *EventUpdateOne { + euo.mutation.ResetApprovalID() euo.mutation.SetApprovalID(i) return euo } @@ -493,12 +541,38 @@ func (euo *EventUpdateOne) SetNillableApprovalID(i *int) *EventUpdateOne { return euo } +// AddApprovalID adds i to the "approval_id" field. +func (euo *EventUpdateOne) AddApprovalID(i int) *EventUpdateOne { + euo.mutation.AddApprovalID(i) + return euo +} + // ClearApprovalID clears the value of the "approval_id" field. func (euo *EventUpdateOne) ClearApprovalID() *EventUpdateOne { euo.mutation.ClearApprovalID() return euo } +// SetReviewID sets the "review_id" field. +func (euo *EventUpdateOne) SetReviewID(i int) *EventUpdateOne { + euo.mutation.SetReviewID(i) + return euo +} + +// SetNillableReviewID sets the "review_id" field if the given value is not nil. +func (euo *EventUpdateOne) SetNillableReviewID(i *int) *EventUpdateOne { + if i != nil { + euo.SetReviewID(*i) + } + return euo +} + +// ClearReviewID clears the value of the "review_id" field. +func (euo *EventUpdateOne) ClearReviewID() *EventUpdateOne { + euo.mutation.ClearReviewID() + return euo +} + // SetDeletedID sets the "deleted_id" field. func (euo *EventUpdateOne) SetDeletedID(i int) *EventUpdateOne { euo.mutation.ResetDeletedID() @@ -531,9 +605,9 @@ func (euo *EventUpdateOne) SetDeployment(d *Deployment) *EventUpdateOne { return euo.SetDeploymentID(d.ID) } -// SetApproval sets the "approval" edge to the Approval entity. -func (euo *EventUpdateOne) SetApproval(a *Approval) *EventUpdateOne { - return euo.SetApprovalID(a.ID) +// SetReview sets the "review" edge to the Review entity. +func (euo *EventUpdateOne) SetReview(r *Review) *EventUpdateOne { + return euo.SetReviewID(r.ID) } // SetNotificationRecordID sets the "notification_record" edge to the NotificationRecord entity by ID. @@ -566,9 +640,9 @@ func (euo *EventUpdateOne) ClearDeployment() *EventUpdateOne { return euo } -// ClearApproval clears the "approval" edge to the Approval entity. -func (euo *EventUpdateOne) ClearApproval() *EventUpdateOne { - euo.mutation.ClearApproval() +// ClearReview clears the "review" edge to the Review entity. +func (euo *EventUpdateOne) ClearReview() *EventUpdateOne { + euo.mutation.ClearReview() return euo } @@ -716,6 +790,26 @@ func (euo *EventUpdateOne) sqlSave(ctx context.Context) (_node *Event, err error Column: event.FieldCreatedAt, }) } + if value, ok := euo.mutation.ApprovalID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Value: value, + Column: event.FieldApprovalID, + }) + } + if value, ok := euo.mutation.AddedApprovalID(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Value: value, + Column: event.FieldApprovalID, + }) + } + if euo.mutation.ApprovalIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: event.FieldApprovalID, + }) + } if value, ok := euo.mutation.DeletedID(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeInt, @@ -771,33 +865,33 @@ func (euo *EventUpdateOne) sqlSave(ctx context.Context) (_node *Event, err error } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if euo.mutation.ApprovalCleared() { + if euo.mutation.ReviewCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: event.ApprovalTable, - Columns: []string{event.ApprovalColumn}, + Table: event.ReviewTable, + Columns: []string{event.ReviewColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := euo.mutation.ApprovalIDs(); len(nodes) > 0 { + if nodes := euo.mutation.ReviewIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: event.ApprovalTable, - Columns: []string{event.ApprovalColumn}, + Table: event.ReviewTable, + Columns: []string{event.ReviewColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } diff --git a/ent/hook/hook.go b/ent/hook/hook.go index 76577f9f..89d4beb2 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -9,19 +9,6 @@ import ( "github.com/gitploy-io/gitploy/ent" ) -// The ApprovalFunc type is an adapter to allow the use of ordinary -// function as Approval mutator. -type ApprovalFunc func(context.Context, *ent.ApprovalMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f ApprovalFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - mv, ok := m.(*ent.ApprovalMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ApprovalMutation", m) - } - return f(ctx, mv) -} - // The CallbackFunc type is an adapter to allow the use of ordinary // function as Callback mutator. type CallbackFunc func(context.Context, *ent.CallbackMutation) (ent.Value, error) @@ -152,6 +139,19 @@ func (f RepoFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) return f(ctx, mv) } +// The ReviewFunc type is an adapter to allow the use of ordinary +// function as Review mutator. +type ReviewFunc func(context.Context, *ent.ReviewMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f ReviewFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.ReviewMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ReviewMutation", m) + } + return f(ctx, mv) +} + // The UserFunc type is an adapter to allow the use of ordinary // function as User mutator. type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index fa9ba499..4f0d5087 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -8,35 +8,6 @@ import ( ) var ( - // ApprovalsColumns holds the columns for the "approvals" table. - ApprovalsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "declined", "approved"}, Default: "pending"}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "updated_at", Type: field.TypeTime}, - {Name: "deployment_id", Type: field.TypeInt, Nullable: true}, - {Name: "user_id", Type: field.TypeInt64, Nullable: true}, - } - // ApprovalsTable holds the schema information for the "approvals" table. - ApprovalsTable = &schema.Table{ - Name: "approvals", - Columns: ApprovalsColumns, - PrimaryKey: []*schema.Column{ApprovalsColumns[0]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "approvals_deployments_approvals", - Columns: []*schema.Column{ApprovalsColumns[4]}, - RefColumns: []*schema.Column{DeploymentsColumns[0]}, - OnDelete: schema.Cascade, - }, - { - Symbol: "approvals_users_approvals", - Columns: []*schema.Column{ApprovalsColumns[5]}, - RefColumns: []*schema.Column{UsersColumns[0]}, - OnDelete: schema.SetNull, - }, - }, - } // CallbacksColumns holds the columns for the "callbacks" table. CallbacksColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -98,10 +69,10 @@ var ( {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}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, + {Name: "is_approval_enabled", Type: field.TypeBool, Nullable: true}, + {Name: "required_approval_count", Type: field.TypeInt, Nullable: true}, {Name: "repo_id", Type: field.TypeInt64, Nullable: true}, {Name: "user_id", Type: field.TypeInt64, Nullable: true}, } @@ -128,17 +99,17 @@ var ( { Name: "deployment_repo_id_env_status_updated_at", Unique: false, - Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[3], DeploymentsColumns[5], DeploymentsColumns[14]}, + Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[3], DeploymentsColumns[5], DeploymentsColumns[12]}, }, { Name: "deployment_repo_id_env_created_at", Unique: false, - Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[3], DeploymentsColumns[13]}, + Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[3], DeploymentsColumns[11]}, }, { Name: "deployment_repo_id_created_at", Unique: false, - Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[13]}, + Columns: []*schema.Column{DeploymentsColumns[15], DeploymentsColumns[11]}, }, { Name: "deployment_number_repo_id", @@ -153,7 +124,7 @@ var ( { Name: "deployment_status_created_at", Unique: false, - Columns: []*schema.Column{DeploymentsColumns[5], DeploymentsColumns[13]}, + Columns: []*schema.Column{DeploymentsColumns[5], DeploymentsColumns[11]}, }, }, } @@ -225,12 +196,13 @@ var ( // EventsColumns holds the columns for the "events" table. EventsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "kind", Type: field.TypeEnum, Enums: []string{"deployment", "approval"}}, + {Name: "kind", Type: field.TypeEnum, Enums: []string{"deployment", "approval", "review"}}, {Name: "type", Type: field.TypeEnum, Enums: []string{"created", "updated", "deleted"}}, {Name: "created_at", Type: field.TypeTime}, - {Name: "deleted_id", Type: field.TypeInt, Nullable: true}, {Name: "approval_id", Type: field.TypeInt, Nullable: true}, + {Name: "deleted_id", Type: field.TypeInt, Nullable: true}, {Name: "deployment_id", Type: field.TypeInt, Nullable: true}, + {Name: "review_id", Type: field.TypeInt, Nullable: true}, } // EventsTable holds the schema information for the "events" table. EventsTable = &schema.Table{ @@ -238,18 +210,18 @@ var ( Columns: EventsColumns, PrimaryKey: []*schema.Column{EventsColumns[0]}, ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "events_approvals_event", - Columns: []*schema.Column{EventsColumns[5]}, - RefColumns: []*schema.Column{ApprovalsColumns[0]}, - OnDelete: schema.Cascade, - }, { Symbol: "events_deployments_event", Columns: []*schema.Column{EventsColumns[6]}, RefColumns: []*schema.Column{DeploymentsColumns[0]}, OnDelete: schema.Cascade, }, + { + Symbol: "events_reviews_event", + Columns: []*schema.Column{EventsColumns[7]}, + RefColumns: []*schema.Column{ReviewsColumns[0]}, + OnDelete: schema.Cascade, + }, }, Indexes: []*schema.Index{ { @@ -392,6 +364,35 @@ var ( }, }, } + // ReviewsColumns holds the columns for the "reviews" table. + ReviewsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "rejected", "approved"}, Default: "pending"}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "deployment_id", Type: field.TypeInt, Nullable: true}, + {Name: "user_id", Type: field.TypeInt64, Nullable: true}, + } + // ReviewsTable holds the schema information for the "reviews" table. + ReviewsTable = &schema.Table{ + Name: "reviews", + Columns: ReviewsColumns, + PrimaryKey: []*schema.Column{ReviewsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "reviews_deployments_reviews", + Columns: []*schema.Column{ReviewsColumns[4]}, + RefColumns: []*schema.Column{DeploymentsColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "reviews_users_reviews", + Columns: []*schema.Column{ReviewsColumns[5]}, + RefColumns: []*schema.Column{UsersColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } // UsersColumns holds the columns for the "users" table. UsersColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, @@ -413,7 +414,6 @@ var ( } // Tables holds all the tables in the schema. Tables = []*schema.Table{ - ApprovalsTable, CallbacksTable, ChatUsersTable, DeploymentsTable, @@ -424,24 +424,25 @@ var ( NotificationRecordsTable, PermsTable, ReposTable, + ReviewsTable, UsersTable, } ) func init() { - ApprovalsTable.ForeignKeys[0].RefTable = DeploymentsTable - ApprovalsTable.ForeignKeys[1].RefTable = UsersTable CallbacksTable.ForeignKeys[0].RefTable = ReposTable 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 + EventsTable.ForeignKeys[0].RefTable = DeploymentsTable + EventsTable.ForeignKeys[1].RefTable = ReviewsTable LocksTable.ForeignKeys[0].RefTable = ReposTable LocksTable.ForeignKeys[1].RefTable = UsersTable NotificationRecordsTable.ForeignKeys[0].RefTable = EventsTable PermsTable.ForeignKeys[0].RefTable = ReposTable PermsTable.ForeignKeys[1].RefTable = UsersTable + ReviewsTable.ForeignKeys[0].RefTable = DeploymentsTable + ReviewsTable.ForeignKeys[1].RefTable = UsersTable } diff --git a/ent/mutation.go b/ent/mutation.go index 1bb2c52d..0a28460a 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -8,7 +8,6 @@ import ( "sync" "time" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/callback" "github.com/gitploy-io/gitploy/ent/chatuser" "github.com/gitploy-io/gitploy/ent/deployment" @@ -20,6 +19,7 @@ import ( "github.com/gitploy-io/gitploy/ent/perm" "github.com/gitploy-io/gitploy/ent/predicate" "github.com/gitploy-io/gitploy/ent/repo" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" "entgo.io/ent" @@ -34,7 +34,6 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeApproval = "Approval" TypeCallback = "Callback" TypeChatUser = "ChatUser" TypeDeployment = "Deployment" @@ -45,42 +44,39 @@ const ( TypeNotificationRecord = "NotificationRecord" TypePerm = "Perm" TypeRepo = "Repo" + TypeReview = "Review" TypeUser = "User" ) -// ApprovalMutation represents an operation that mutates the Approval nodes in the graph. -type ApprovalMutation struct { +// CallbackMutation represents an operation that mutates the Callback nodes in the graph. +type CallbackMutation struct { config - op Op - typ string - id *int - status *approval.Status - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - user *int64 - cleareduser bool - deployment *int - cleareddeployment bool - event map[int]struct{} - removedevent map[int]struct{} - clearedevent bool - done bool - oldValue func(context.Context) (*Approval, error) - predicates []predicate.Approval + op Op + typ string + id *int + hash *string + _type *callback.Type + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + repo *int64 + clearedrepo bool + done bool + oldValue func(context.Context) (*Callback, error) + predicates []predicate.Callback } -var _ ent.Mutation = (*ApprovalMutation)(nil) +var _ ent.Mutation = (*CallbackMutation)(nil) -// approvalOption allows management of the mutation configuration using functional options. -type approvalOption func(*ApprovalMutation) +// callbackOption allows management of the mutation configuration using functional options. +type callbackOption func(*CallbackMutation) -// newApprovalMutation creates new mutation for the Approval entity. -func newApprovalMutation(c config, op Op, opts ...approvalOption) *ApprovalMutation { - m := &ApprovalMutation{ +// newCallbackMutation creates new mutation for the Callback entity. +func newCallbackMutation(c config, op Op, opts ...callbackOption) *CallbackMutation { + m := &CallbackMutation{ config: c, op: op, - typ: TypeApproval, + typ: TypeCallback, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -89,20 +85,20 @@ func newApprovalMutation(c config, op Op, opts ...approvalOption) *ApprovalMutat return m } -// withApprovalID sets the ID field of the mutation. -func withApprovalID(id int) approvalOption { - return func(m *ApprovalMutation) { +// withCallbackID sets the ID field of the mutation. +func withCallbackID(id int) callbackOption { + return func(m *CallbackMutation) { var ( err error once sync.Once - value *Approval + value *Callback ) - m.oldValue = func(ctx context.Context) (*Approval, error) { + m.oldValue = func(ctx context.Context) (*Callback, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { - value, err = m.Client().Approval.Get(ctx, id) + value, err = m.Client().Callback.Get(ctx, id) } }) return value, err @@ -111,10 +107,10 @@ func withApprovalID(id int) approvalOption { } } -// withApproval sets the old Approval of the mutation. -func withApproval(node *Approval) approvalOption { - return func(m *ApprovalMutation) { - m.oldValue = func(context.Context) (*Approval, error) { +// withCallback sets the old Callback of the mutation. +func withCallback(node *Callback) callbackOption { + return func(m *CallbackMutation) { + m.oldValue = func(context.Context) (*Callback, error) { return node, nil } m.id = &node.ID @@ -123,7 +119,7 @@ func withApproval(node *Approval) approvalOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m ApprovalMutation) Client() *Client { +func (m CallbackMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -131,7 +127,7 @@ func (m ApprovalMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ApprovalMutation) Tx() (*Tx, error) { +func (m CallbackMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("ent: mutation is not running in a transaction") } @@ -142,352 +138,272 @@ func (m ApprovalMutation) Tx() (*Tx, error) { // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *ApprovalMutation) ID() (id int, exists bool) { +func (m *CallbackMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } -// SetStatus sets the "status" field. -func (m *ApprovalMutation) SetStatus(a approval.Status) { - m.status = &a +// SetHash sets the "hash" field. +func (m *CallbackMutation) SetHash(s string) { + m.hash = &s } -// Status returns the value of the "status" field in the mutation. -func (m *ApprovalMutation) Status() (r approval.Status, exists bool) { - v := m.status +// Hash returns the value of the "hash" field in the mutation. +func (m *CallbackMutation) Hash() (r string, exists bool) { + v := m.hash if v == nil { return } return *v, true } -// OldStatus returns the old "status" field's value of the Approval entity. -// If the Approval object wasn't provided to the builder, the object is fetched from the database. +// OldHash returns the old "hash" field's value of the Callback entity. +// If the Callback 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 *ApprovalMutation) OldStatus(ctx context.Context) (v approval.Status, err error) { +func (m *CallbackMutation) OldHash(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldHash is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldStatus requires an ID field in the mutation") + return v, fmt.Errorf("OldHash requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldStatus: %w", err) + return v, fmt.Errorf("querying old value for OldHash: %w", err) } - return oldValue.Status, nil + return oldValue.Hash, nil } -// ResetStatus resets all changes to the "status" field. -func (m *ApprovalMutation) ResetStatus() { - m.status = nil +// ResetHash resets all changes to the "hash" field. +func (m *CallbackMutation) ResetHash() { + m.hash = nil } -// SetCreatedAt sets the "created_at" field. -func (m *ApprovalMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// SetType sets the "type" field. +func (m *CallbackMutation) SetType(c callback.Type) { + m._type = &c } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ApprovalMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at +// GetType returns the value of the "type" field in the mutation. +func (m *CallbackMutation) GetType() (r callback.Type, exists bool) { + v := m._type if v == nil { return } return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the Approval entity. -// If the Approval object wasn't provided to the builder, the object is fetched from the database. +// OldType returns the old "type" field's value of the Callback entity. +// If the Callback 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 *ApprovalMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *CallbackMutation) OldType(ctx context.Context) (v callback.Type, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + return v, fmt.Errorf("querying old value for OldType: %w", err) } - return oldValue.CreatedAt, nil + return oldValue.Type, nil } -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ApprovalMutation) ResetCreatedAt() { - m.created_at = nil +// ResetType resets all changes to the "type" field. +func (m *CallbackMutation) ResetType() { + m._type = nil } -// SetUpdatedAt sets the "updated_at" field. -func (m *ApprovalMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t +// SetCreatedAt sets the "created_at" field. +func (m *CallbackMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ApprovalMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *CallbackMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at if v == nil { return } return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the Approval entity. -// If the Approval object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the Callback entity. +// If the Callback 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 *ApprovalMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *CallbackMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.UpdatedAt, nil + return oldValue.CreatedAt, nil } -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ApprovalMutation) ResetUpdatedAt() { - m.updated_at = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *CallbackMutation) ResetCreatedAt() { + m.created_at = nil } -// SetUserID sets the "user_id" field. -func (m *ApprovalMutation) SetUserID(i int64) { - m.user = &i +// SetUpdatedAt sets the "updated_at" field. +func (m *CallbackMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// UserID returns the value of the "user_id" field in the mutation. -func (m *ApprovalMutation) UserID() (r int64, exists bool) { - v := m.user +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *CallbackMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at if v == nil { return } return *v, true } -// OldUserID returns the old "user_id" field's value of the Approval entity. -// If the Approval object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the Callback entity. +// If the Callback 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 *ApprovalMutation) OldUserID(ctx context.Context) (v int64, err error) { +func (m *CallbackMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserID requires an ID field in the mutation") + return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUserID: %w", err) + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - return oldValue.UserID, nil + return oldValue.UpdatedAt, nil } -// ResetUserID resets all changes to the "user_id" field. -func (m *ApprovalMutation) ResetUserID() { - m.user = nil +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *CallbackMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SetDeploymentID sets the "deployment_id" field. -func (m *ApprovalMutation) SetDeploymentID(i int) { - m.deployment = &i +// SetRepoID sets the "repo_id" field. +func (m *CallbackMutation) SetRepoID(i int64) { + m.repo = &i } -// DeploymentID returns the value of the "deployment_id" field in the mutation. -func (m *ApprovalMutation) DeploymentID() (r int, exists bool) { - v := m.deployment +// RepoID returns the value of the "repo_id" field in the mutation. +func (m *CallbackMutation) RepoID() (r int64, exists bool) { + v := m.repo if v == nil { return } return *v, true } -// OldDeploymentID returns the old "deployment_id" field's value of the Approval entity. -// If the Approval object wasn't provided to the builder, the object is fetched from the database. +// OldRepoID returns the old "repo_id" field's value of the Callback entity. +// If the Callback 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 *ApprovalMutation) OldDeploymentID(ctx context.Context) (v int, err error) { +func (m *CallbackMutation) OldRepoID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDeploymentID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDeploymentID requires an ID field in the mutation") + 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 OldDeploymentID: %w", err) + return v, fmt.Errorf("querying old value for OldRepoID: %w", err) } - return oldValue.DeploymentID, nil + return oldValue.RepoID, nil } -// ResetDeploymentID resets all changes to the "deployment_id" field. -func (m *ApprovalMutation) ResetDeploymentID() { - m.deployment = nil +// ResetRepoID resets all changes to the "repo_id" field. +func (m *CallbackMutation) ResetRepoID() { + m.repo = nil } -// ClearUser clears the "user" edge to the User entity. -func (m *ApprovalMutation) ClearUser() { - m.cleareduser = true +// ClearRepo clears the "repo" edge to the Repo entity. +func (m *CallbackMutation) ClearRepo() { + m.clearedrepo = true } -// UserCleared reports if the "user" edge to the User entity was cleared. -func (m *ApprovalMutation) UserCleared() bool { - return m.cleareduser +// RepoCleared reports if the "repo" edge to the Repo entity was cleared. +func (m *CallbackMutation) RepoCleared() bool { + return m.clearedrepo } -// UserIDs returns the "user" edge IDs in the mutation. +// RepoIDs returns the "repo" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// UserID instead. It exists only for internal usage by the builders. -func (m *ApprovalMutation) UserIDs() (ids []int64) { - if id := m.user; id != nil { +// RepoID instead. It exists only for internal usage by the builders. +func (m *CallbackMutation) RepoIDs() (ids []int64) { + if id := m.repo; id != nil { ids = append(ids, *id) } return } -// ResetUser resets all changes to the "user" edge. -func (m *ApprovalMutation) ResetUser() { - m.user = nil - m.cleareduser = false -} - -// ClearDeployment clears the "deployment" edge to the Deployment entity. -func (m *ApprovalMutation) ClearDeployment() { - m.cleareddeployment = true +// ResetRepo resets all changes to the "repo" edge. +func (m *CallbackMutation) ResetRepo() { + m.repo = nil + m.clearedrepo = false } -// DeploymentCleared reports if the "deployment" edge to the Deployment entity was cleared. -func (m *ApprovalMutation) DeploymentCleared() bool { - return m.cleareddeployment +// Where appends a list predicates to the CallbackMutation builder. +func (m *CallbackMutation) Where(ps ...predicate.Callback) { + m.predicates = append(m.predicates, ps...) } -// DeploymentIDs returns the "deployment" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// DeploymentID instead. It exists only for internal usage by the builders. -func (m *ApprovalMutation) DeploymentIDs() (ids []int) { - if id := m.deployment; id != nil { - ids = append(ids, *id) - } - return +// Op returns the operation name. +func (m *CallbackMutation) Op() Op { + return m.op } -// ResetDeployment resets all changes to the "deployment" edge. -func (m *ApprovalMutation) ResetDeployment() { - m.deployment = nil - m.cleareddeployment = false +// Type returns the node type of this mutation (Callback). +func (m *CallbackMutation) Type() string { + return m.typ } -// AddEventIDs adds the "event" edge to the Event entity by ids. -func (m *ApprovalMutation) AddEventIDs(ids ...int) { - if m.event == nil { - m.event = make(map[int]struct{}) +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *CallbackMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.hash != nil { + fields = append(fields, callback.FieldHash) } - for i := range ids { - m.event[ids[i]] = struct{}{} + if m._type != nil { + fields = append(fields, callback.FieldType) } -} - -// ClearEvent clears the "event" edge to the Event entity. -func (m *ApprovalMutation) ClearEvent() { - m.clearedevent = true -} - -// EventCleared reports if the "event" edge to the Event entity was cleared. -func (m *ApprovalMutation) EventCleared() bool { - return m.clearedevent -} - -// RemoveEventIDs removes the "event" edge to the Event entity by IDs. -func (m *ApprovalMutation) RemoveEventIDs(ids ...int) { - if m.removedevent == nil { - m.removedevent = make(map[int]struct{}) - } - for i := range ids { - delete(m.event, ids[i]) - m.removedevent[ids[i]] = struct{}{} - } -} - -// RemovedEvent returns the removed IDs of the "event" edge to the Event entity. -func (m *ApprovalMutation) RemovedEventIDs() (ids []int) { - for id := range m.removedevent { - ids = append(ids, id) - } - return -} - -// EventIDs returns the "event" edge IDs in the mutation. -func (m *ApprovalMutation) EventIDs() (ids []int) { - for id := range m.event { - ids = append(ids, id) - } - return -} - -// ResetEvent resets all changes to the "event" edge. -func (m *ApprovalMutation) ResetEvent() { - m.event = nil - m.clearedevent = false - m.removedevent = nil -} - -// Where appends a list predicates to the ApprovalMutation builder. -func (m *ApprovalMutation) Where(ps ...predicate.Approval) { - m.predicates = append(m.predicates, ps...) -} - -// Op returns the operation name. -func (m *ApprovalMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (Approval). -func (m *ApprovalMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *ApprovalMutation) Fields() []string { - fields := make([]string, 0, 5) - if m.status != nil { - fields = append(fields, approval.FieldStatus) - } - if m.created_at != nil { - fields = append(fields, approval.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, approval.FieldUpdatedAt) - } - if m.user != nil { - fields = append(fields, approval.FieldUserID) - } - if m.deployment != nil { - fields = append(fields, approval.FieldDeploymentID) - } - return fields + if m.created_at != nil { + fields = append(fields, callback.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, callback.FieldUpdatedAt) + } + if m.repo != nil { + fields = append(fields, callback.FieldRepoID) + } + return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *ApprovalMutation) Field(name string) (ent.Value, bool) { +func (m *CallbackMutation) Field(name string) (ent.Value, bool) { switch name { - case approval.FieldStatus: - return m.Status() - case approval.FieldCreatedAt: + case callback.FieldHash: + return m.Hash() + case callback.FieldType: + return m.GetType() + case callback.FieldCreatedAt: return m.CreatedAt() - case approval.FieldUpdatedAt: + case callback.FieldUpdatedAt: return m.UpdatedAt() - case approval.FieldUserID: - return m.UserID() - case approval.FieldDeploymentID: - return m.DeploymentID() + case callback.FieldRepoID: + return m.RepoID() } return nil, false } @@ -495,69 +411,69 @@ func (m *ApprovalMutation) Field(name string) (ent.Value, bool) { // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. -func (m *ApprovalMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *CallbackMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case approval.FieldStatus: - return m.OldStatus(ctx) - case approval.FieldCreatedAt: + case callback.FieldHash: + return m.OldHash(ctx) + case callback.FieldType: + return m.OldType(ctx) + case callback.FieldCreatedAt: return m.OldCreatedAt(ctx) - case approval.FieldUpdatedAt: + case callback.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case approval.FieldUserID: - return m.OldUserID(ctx) - case approval.FieldDeploymentID: - return m.OldDeploymentID(ctx) + case callback.FieldRepoID: + return m.OldRepoID(ctx) } - return nil, fmt.Errorf("unknown Approval field %s", name) + return nil, fmt.Errorf("unknown Callback field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *ApprovalMutation) SetField(name string, value ent.Value) error { +func (m *CallbackMutation) SetField(name string, value ent.Value) error { switch name { - case approval.FieldStatus: - v, ok := value.(approval.Status) + case callback.FieldHash: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetStatus(v) + m.SetHash(v) return nil - case approval.FieldCreatedAt: - v, ok := value.(time.Time) + case callback.FieldType: + v, ok := value.(callback.Type) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetType(v) return nil - case approval.FieldUpdatedAt: + case callback.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetCreatedAt(v) return nil - case approval.FieldUserID: - v, ok := value.(int64) + case callback.FieldUpdatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUserID(v) + m.SetUpdatedAt(v) return nil - case approval.FieldDeploymentID: - v, ok := value.(int) + case callback.FieldRepoID: + v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeploymentID(v) + m.SetRepoID(v) return nil } - return fmt.Errorf("unknown Approval field %s", name) + return fmt.Errorf("unknown Callback field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *ApprovalMutation) AddedFields() []string { +func (m *CallbackMutation) AddedFields() []string { var fields []string return fields } @@ -565,7 +481,7 @@ func (m *ApprovalMutation) AddedFields() []string { // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *ApprovalMutation) AddedField(name string) (ent.Value, bool) { +func (m *CallbackMutation) AddedField(name string) (ent.Value, bool) { switch name { } return nil, false @@ -574,203 +490,161 @@ func (m *ApprovalMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *ApprovalMutation) AddField(name string, value ent.Value) error { +func (m *CallbackMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown Approval numeric field %s", name) + return fmt.Errorf("unknown Callback numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *ApprovalMutation) ClearedFields() []string { +func (m *CallbackMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *ApprovalMutation) FieldCleared(name string) bool { +func (m *CallbackMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *ApprovalMutation) ClearField(name string) error { - return fmt.Errorf("unknown Approval nullable field %s", name) +func (m *CallbackMutation) ClearField(name string) error { + return fmt.Errorf("unknown Callback nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *ApprovalMutation) ResetField(name string) error { +func (m *CallbackMutation) ResetField(name string) error { switch name { - case approval.FieldStatus: - m.ResetStatus() + case callback.FieldHash: + m.ResetHash() + return nil + case callback.FieldType: + m.ResetType() return nil - case approval.FieldCreatedAt: + case callback.FieldCreatedAt: m.ResetCreatedAt() return nil - case approval.FieldUpdatedAt: + case callback.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case approval.FieldUserID: - m.ResetUserID() - return nil - case approval.FieldDeploymentID: - m.ResetDeploymentID() + case callback.FieldRepoID: + m.ResetRepoID() return nil } - return fmt.Errorf("unknown Approval field %s", name) + return fmt.Errorf("unknown Callback field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *ApprovalMutation) AddedEdges() []string { - edges := make([]string, 0, 3) - if m.user != nil { - edges = append(edges, approval.EdgeUser) - } - if m.deployment != nil { - edges = append(edges, approval.EdgeDeployment) - } - if m.event != nil { - edges = append(edges, approval.EdgeEvent) +func (m *CallbackMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.repo != nil { + edges = append(edges, callback.EdgeRepo) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *ApprovalMutation) AddedIDs(name string) []ent.Value { +func (m *CallbackMutation) AddedIDs(name string) []ent.Value { switch name { - case approval.EdgeUser: - if id := m.user; id != nil { - return []ent.Value{*id} - } - case approval.EdgeDeployment: - if id := m.deployment; id != nil { + case callback.EdgeRepo: + if id := m.repo; id != nil { return []ent.Value{*id} } - case approval.EdgeEvent: - ids := make([]ent.Value, 0, len(m.event)) - for id := range m.event { - ids = append(ids, id) - } - return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *ApprovalMutation) RemovedEdges() []string { - edges := make([]string, 0, 3) - if m.removedevent != nil { - edges = append(edges, approval.EdgeEvent) - } +func (m *CallbackMutation) RemovedEdges() []string { + 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 *ApprovalMutation) RemovedIDs(name string) []ent.Value { +func (m *CallbackMutation) RemovedIDs(name string) []ent.Value { switch name { - case approval.EdgeEvent: - ids := make([]ent.Value, 0, len(m.removedevent)) - for id := range m.removedevent { - ids = append(ids, id) - } - return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ApprovalMutation) ClearedEdges() []string { - edges := make([]string, 0, 3) - if m.cleareduser { - edges = append(edges, approval.EdgeUser) - } - if m.cleareddeployment { - edges = append(edges, approval.EdgeDeployment) - } - if m.clearedevent { - edges = append(edges, approval.EdgeEvent) +func (m *CallbackMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedrepo { + edges = append(edges, callback.EdgeRepo) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *ApprovalMutation) EdgeCleared(name string) bool { +func (m *CallbackMutation) EdgeCleared(name string) bool { switch name { - case approval.EdgeUser: - return m.cleareduser - case approval.EdgeDeployment: - return m.cleareddeployment - case approval.EdgeEvent: - return m.clearedevent + case callback.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 *ApprovalMutation) ClearEdge(name string) error { +func (m *CallbackMutation) ClearEdge(name string) error { switch name { - case approval.EdgeUser: - m.ClearUser() - return nil - case approval.EdgeDeployment: - m.ClearDeployment() + case callback.EdgeRepo: + m.ClearRepo() return nil } - return fmt.Errorf("unknown Approval unique edge %s", name) + return fmt.Errorf("unknown Callback 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 *ApprovalMutation) ResetEdge(name string) error { +func (m *CallbackMutation) ResetEdge(name string) error { switch name { - case approval.EdgeUser: - m.ResetUser() - return nil - case approval.EdgeDeployment: - m.ResetDeployment() - return nil - case approval.EdgeEvent: - m.ResetEvent() + case callback.EdgeRepo: + m.ResetRepo() return nil } - return fmt.Errorf("unknown Approval edge %s", name) + return fmt.Errorf("unknown Callback edge %s", name) } -// CallbackMutation represents an operation that mutates the Callback nodes in the graph. -type CallbackMutation struct { +// ChatUserMutation represents an operation that mutates the ChatUser nodes in the graph. +type ChatUserMutation struct { config op Op typ string - id *int - hash *string - _type *callback.Type + id *string + token *string + refresh *string + expiry *time.Time + bot_token *string created_at *time.Time updated_at *time.Time clearedFields map[string]struct{} - repo *int64 - clearedrepo bool + user *int64 + cleareduser bool done bool - oldValue func(context.Context) (*Callback, error) - predicates []predicate.Callback + oldValue func(context.Context) (*ChatUser, error) + predicates []predicate.ChatUser } -var _ ent.Mutation = (*CallbackMutation)(nil) +var _ ent.Mutation = (*ChatUserMutation)(nil) -// callbackOption allows management of the mutation configuration using functional options. -type callbackOption func(*CallbackMutation) +// chatuserOption allows management of the mutation configuration using functional options. +type chatuserOption func(*ChatUserMutation) -// newCallbackMutation creates new mutation for the Callback entity. -func newCallbackMutation(c config, op Op, opts ...callbackOption) *CallbackMutation { - m := &CallbackMutation{ +// newChatUserMutation creates new mutation for the ChatUser entity. +func newChatUserMutation(c config, op Op, opts ...chatuserOption) *ChatUserMutation { + m := &ChatUserMutation{ config: c, op: op, - typ: TypeCallback, + typ: TypeChatUser, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -779,20 +653,20 @@ func newCallbackMutation(c config, op Op, opts ...callbackOption) *CallbackMutat return m } -// withCallbackID sets the ID field of the mutation. -func withCallbackID(id int) callbackOption { - return func(m *CallbackMutation) { +// withChatUserID sets the ID field of the mutation. +func withChatUserID(id string) chatuserOption { + return func(m *ChatUserMutation) { var ( err error once sync.Once - value *Callback + value *ChatUser ) - m.oldValue = func(ctx context.Context) (*Callback, error) { + m.oldValue = func(ctx context.Context) (*ChatUser, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { - value, err = m.Client().Callback.Get(ctx, id) + value, err = m.Client().ChatUser.Get(ctx, id) } }) return value, err @@ -801,10 +675,10 @@ func withCallbackID(id int) callbackOption { } } -// withCallback sets the old Callback of the mutation. -func withCallback(node *Callback) callbackOption { - return func(m *CallbackMutation) { - m.oldValue = func(context.Context) (*Callback, error) { +// withChatUser sets the old ChatUser of the mutation. +func withChatUser(node *ChatUser) chatuserOption { + return func(m *ChatUserMutation) { + m.oldValue = func(context.Context) (*ChatUser, error) { return node, nil } m.id = &node.ID @@ -813,7 +687,7 @@ func withCallback(node *Callback) callbackOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m CallbackMutation) Client() *Client { +func (m ChatUserMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -821,7 +695,7 @@ func (m CallbackMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m CallbackMutation) Tx() (*Tx, error) { +func (m ChatUserMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("ent: mutation is not running in a transaction") } @@ -830,94 +704,172 @@ func (m CallbackMutation) Tx() (*Tx, error) { return tx, nil } -// ID returns the ID value in the mutation. Note that the ID is only available +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of ChatUser entities. +func (m *ChatUserMutation) SetID(id string) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *CallbackMutation) ID() (id int, exists bool) { +func (m *ChatUserMutation) ID() (id string, exists bool) { if m.id == nil { return } return *m.id, true } -// SetHash sets the "hash" field. -func (m *CallbackMutation) SetHash(s string) { - m.hash = &s +// SetToken sets the "token" field. +func (m *ChatUserMutation) SetToken(s string) { + m.token = &s } -// Hash returns the value of the "hash" field in the mutation. -func (m *CallbackMutation) Hash() (r string, exists bool) { - v := m.hash +// Token returns the value of the "token" field in the mutation. +func (m *ChatUserMutation) Token() (r string, exists bool) { + v := m.token if v == nil { return } return *v, true } -// OldHash returns the old "hash" field's value of the Callback entity. -// If the Callback object wasn't provided to the builder, the object is fetched from the database. +// OldToken returns the old "token" field's value of the ChatUser entity. +// If the ChatUser 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 *CallbackMutation) OldHash(ctx context.Context) (v string, err error) { +func (m *ChatUserMutation) OldToken(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldHash is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldToken is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldHash requires an ID field in the mutation") + return v, fmt.Errorf("OldToken requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldHash: %w", err) + return v, fmt.Errorf("querying old value for OldToken: %w", err) } - return oldValue.Hash, nil + return oldValue.Token, nil } -// ResetHash resets all changes to the "hash" field. -func (m *CallbackMutation) ResetHash() { - m.hash = nil +// ResetToken resets all changes to the "token" field. +func (m *ChatUserMutation) ResetToken() { + m.token = nil } -// SetType sets the "type" field. -func (m *CallbackMutation) SetType(c callback.Type) { - m._type = &c +// SetRefresh sets the "refresh" field. +func (m *ChatUserMutation) SetRefresh(s string) { + m.refresh = &s } -// GetType returns the value of the "type" field in the mutation. -func (m *CallbackMutation) GetType() (r callback.Type, exists bool) { - v := m._type +// Refresh returns the value of the "refresh" field in the mutation. +func (m *ChatUserMutation) Refresh() (r string, exists bool) { + v := m.refresh if v == nil { return } return *v, true } -// OldType returns the old "type" field's value of the Callback entity. -// If the Callback object wasn't provided to the builder, the object is fetched from the database. +// OldRefresh returns the old "refresh" field's value of the ChatUser entity. +// If the ChatUser 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 *CallbackMutation) OldType(ctx context.Context) (v callback.Type, err error) { +func (m *ChatUserMutation) OldRefresh(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldRefresh is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldType requires an ID field in the mutation") + return v, fmt.Errorf("OldRefresh requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldType: %w", err) + return v, fmt.Errorf("querying old value for OldRefresh: %w", err) } - return oldValue.Type, nil + return oldValue.Refresh, nil } -// ResetType resets all changes to the "type" field. -func (m *CallbackMutation) ResetType() { - m._type = nil +// ResetRefresh resets all changes to the "refresh" field. +func (m *ChatUserMutation) ResetRefresh() { + m.refresh = nil +} + +// SetExpiry sets the "expiry" field. +func (m *ChatUserMutation) SetExpiry(t time.Time) { + m.expiry = &t +} + +// Expiry returns the value of the "expiry" field in the mutation. +func (m *ChatUserMutation) Expiry() (r time.Time, exists bool) { + v := m.expiry + if v == nil { + return + } + return *v, true +} + +// OldExpiry returns the old "expiry" field's value of the ChatUser entity. +// If the ChatUser 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 *ChatUserMutation) OldExpiry(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldExpiry is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldExpiry requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldExpiry: %w", err) + } + return oldValue.Expiry, nil +} + +// ResetExpiry resets all changes to the "expiry" field. +func (m *ChatUserMutation) ResetExpiry() { + m.expiry = nil +} + +// SetBotToken sets the "bot_token" field. +func (m *ChatUserMutation) SetBotToken(s string) { + m.bot_token = &s +} + +// BotToken returns the value of the "bot_token" field in the mutation. +func (m *ChatUserMutation) BotToken() (r string, exists bool) { + v := m.bot_token + if v == nil { + return + } + return *v, true +} + +// OldBotToken returns the old "bot_token" field's value of the ChatUser entity. +// If the ChatUser 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 *ChatUserMutation) OldBotToken(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldBotToken is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldBotToken requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldBotToken: %w", err) + } + return oldValue.BotToken, nil +} + +// ResetBotToken resets all changes to the "bot_token" field. +func (m *ChatUserMutation) ResetBotToken() { + m.bot_token = nil } // SetCreatedAt sets the "created_at" field. -func (m *CallbackMutation) SetCreatedAt(t time.Time) { +func (m *ChatUserMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *CallbackMutation) CreatedAt() (r time.Time, exists bool) { +func (m *ChatUserMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -925,10 +877,10 @@ func (m *CallbackMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the Callback entity. -// If the Callback object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the ChatUser entity. +// If the ChatUser 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 *CallbackMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChatUserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } @@ -943,17 +895,17 @@ func (m *CallbackMutation) OldCreatedAt(ctx context.Context) (v time.Time, err e } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *CallbackMutation) ResetCreatedAt() { +func (m *ChatUserMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *CallbackMutation) SetUpdatedAt(t time.Time) { +func (m *ChatUserMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *CallbackMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *ChatUserMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -961,10 +913,10 @@ func (m *CallbackMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the Callback entity. -// If the Callback object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the ChatUser entity. +// If the ChatUser 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 *CallbackMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ChatUserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } @@ -979,106 +931,112 @@ func (m *CallbackMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err e } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *CallbackMutation) ResetUpdatedAt() { +func (m *ChatUserMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetRepoID sets the "repo_id" field. -func (m *CallbackMutation) SetRepoID(i int64) { - m.repo = &i +// SetUserID sets the "user_id" field. +func (m *ChatUserMutation) SetUserID(i int64) { + m.user = &i } -// RepoID returns the value of the "repo_id" field in the mutation. -func (m *CallbackMutation) RepoID() (r int64, exists bool) { - v := m.repo +// UserID returns the value of the "user_id" field in the mutation. +func (m *ChatUserMutation) UserID() (r int64, exists bool) { + v := m.user if v == nil { return } return *v, true } -// OldRepoID returns the old "repo_id" field's value of the Callback entity. -// If the Callback object wasn't provided to the builder, the object is fetched from the database. +// OldUserID returns the old "user_id" field's value of the ChatUser entity. +// If the ChatUser 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 *CallbackMutation) OldRepoID(ctx context.Context) (v int64, err error) { +func (m *ChatUserMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldUserID 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") + return v, fmt.Errorf("OldUserID 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 v, fmt.Errorf("querying old value for OldUserID: %w", err) } - return oldValue.RepoID, nil + return oldValue.UserID, nil } -// ResetRepoID resets all changes to the "repo_id" field. -func (m *CallbackMutation) ResetRepoID() { - m.repo = nil +// ResetUserID resets all changes to the "user_id" field. +func (m *ChatUserMutation) ResetUserID() { + m.user = nil } -// ClearRepo clears the "repo" edge to the Repo entity. -func (m *CallbackMutation) ClearRepo() { - m.clearedrepo = true +// ClearUser clears the "user" edge to the User entity. +func (m *ChatUserMutation) ClearUser() { + m.cleareduser = true } -// RepoCleared reports if the "repo" edge to the Repo entity was cleared. -func (m *CallbackMutation) RepoCleared() bool { - return m.clearedrepo +// UserCleared reports if the "user" edge to the User entity was cleared. +func (m *ChatUserMutation) UserCleared() bool { + return m.cleareduser } -// RepoIDs returns the "repo" edge IDs in the mutation. +// UserIDs returns the "user" 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 *CallbackMutation) RepoIDs() (ids []int64) { - if id := m.repo; id != nil { +// UserID instead. It exists only for internal usage by the builders. +func (m *ChatUserMutation) UserIDs() (ids []int64) { + if id := m.user; id != nil { ids = append(ids, *id) } return } -// ResetRepo resets all changes to the "repo" edge. -func (m *CallbackMutation) ResetRepo() { - m.repo = nil - m.clearedrepo = false +// ResetUser resets all changes to the "user" edge. +func (m *ChatUserMutation) ResetUser() { + m.user = nil + m.cleareduser = false } -// Where appends a list predicates to the CallbackMutation builder. -func (m *CallbackMutation) Where(ps ...predicate.Callback) { +// Where appends a list predicates to the ChatUserMutation builder. +func (m *ChatUserMutation) Where(ps ...predicate.ChatUser) { m.predicates = append(m.predicates, ps...) } // Op returns the operation name. -func (m *CallbackMutation) Op() Op { +func (m *ChatUserMutation) Op() Op { return m.op } -// Type returns the node type of this mutation (Callback). -func (m *CallbackMutation) Type() string { +// Type returns the node type of this mutation (ChatUser). +func (m *ChatUserMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). -func (m *CallbackMutation) Fields() []string { - fields := make([]string, 0, 5) - if m.hash != nil { - fields = append(fields, callback.FieldHash) +func (m *ChatUserMutation) Fields() []string { + fields := make([]string, 0, 7) + if m.token != nil { + fields = append(fields, chatuser.FieldToken) } - if m._type != nil { - fields = append(fields, callback.FieldType) + if m.refresh != nil { + fields = append(fields, chatuser.FieldRefresh) } - if m.created_at != nil { - fields = append(fields, callback.FieldCreatedAt) + if m.expiry != nil { + fields = append(fields, chatuser.FieldExpiry) } - if m.updated_at != nil { - fields = append(fields, callback.FieldUpdatedAt) + if m.bot_token != nil { + fields = append(fields, chatuser.FieldBotToken) } - if m.repo != nil { - fields = append(fields, callback.FieldRepoID) + if m.created_at != nil { + fields = append(fields, chatuser.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, chatuser.FieldUpdatedAt) + } + if m.user != nil { + fields = append(fields, chatuser.FieldUserID) } return fields } @@ -1086,18 +1044,22 @@ func (m *CallbackMutation) Fields() []string { // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *CallbackMutation) Field(name string) (ent.Value, bool) { +func (m *ChatUserMutation) Field(name string) (ent.Value, bool) { switch name { - case callback.FieldHash: - return m.Hash() - case callback.FieldType: - return m.GetType() - case callback.FieldCreatedAt: + case chatuser.FieldToken: + return m.Token() + case chatuser.FieldRefresh: + return m.Refresh() + case chatuser.FieldExpiry: + return m.Expiry() + case chatuser.FieldBotToken: + return m.BotToken() + case chatuser.FieldCreatedAt: return m.CreatedAt() - case callback.FieldUpdatedAt: + case chatuser.FieldUpdatedAt: return m.UpdatedAt() - case callback.FieldRepoID: - return m.RepoID() + case chatuser.FieldUserID: + return m.UserID() } return nil, false } @@ -1105,69 +1067,87 @@ func (m *CallbackMutation) Field(name string) (ent.Value, bool) { // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. -func (m *CallbackMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *ChatUserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case callback.FieldHash: - return m.OldHash(ctx) - case callback.FieldType: - return m.OldType(ctx) - case callback.FieldCreatedAt: + case chatuser.FieldToken: + return m.OldToken(ctx) + case chatuser.FieldRefresh: + return m.OldRefresh(ctx) + case chatuser.FieldExpiry: + return m.OldExpiry(ctx) + case chatuser.FieldBotToken: + return m.OldBotToken(ctx) + case chatuser.FieldCreatedAt: return m.OldCreatedAt(ctx) - case callback.FieldUpdatedAt: + case chatuser.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case callback.FieldRepoID: - return m.OldRepoID(ctx) + case chatuser.FieldUserID: + return m.OldUserID(ctx) } - return nil, fmt.Errorf("unknown Callback field %s", name) + return nil, fmt.Errorf("unknown ChatUser field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *CallbackMutation) SetField(name string, value ent.Value) error { +func (m *ChatUserMutation) SetField(name string, value ent.Value) error { switch name { - case callback.FieldHash: + case chatuser.FieldToken: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetHash(v) + m.SetToken(v) return nil - case callback.FieldType: - v, ok := value.(callback.Type) + case chatuser.FieldRefresh: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetType(v) + m.SetRefresh(v) return nil - case callback.FieldCreatedAt: + case chatuser.FieldExpiry: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetExpiry(v) + return nil + case chatuser.FieldBotToken: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetBotToken(v) + return nil + case chatuser.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil - case callback.FieldUpdatedAt: + case chatuser.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil - case callback.FieldRepoID: + case chatuser.FieldUserID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetRepoID(v) + m.SetUserID(v) return nil } - return fmt.Errorf("unknown Callback field %s", name) + return fmt.Errorf("unknown ChatUser field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *CallbackMutation) AddedFields() []string { +func (m *ChatUserMutation) AddedFields() []string { var fields []string return fields } @@ -1175,7 +1155,7 @@ func (m *CallbackMutation) AddedFields() []string { // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *CallbackMutation) AddedField(name string) (ent.Value, bool) { +func (m *ChatUserMutation) AddedField(name string) (ent.Value, bool) { switch name { } return nil, false @@ -1184,69 +1164,75 @@ func (m *CallbackMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *CallbackMutation) AddField(name string, value ent.Value) error { +func (m *ChatUserMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown Callback numeric field %s", name) + return fmt.Errorf("unknown ChatUser numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *CallbackMutation) ClearedFields() []string { +func (m *ChatUserMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *CallbackMutation) FieldCleared(name string) bool { +func (m *ChatUserMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *CallbackMutation) ClearField(name string) error { - return fmt.Errorf("unknown Callback nullable field %s", name) +func (m *ChatUserMutation) ClearField(name string) error { + return fmt.Errorf("unknown ChatUser nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *CallbackMutation) ResetField(name string) error { +func (m *ChatUserMutation) ResetField(name string) error { switch name { - case callback.FieldHash: - m.ResetHash() + case chatuser.FieldToken: + m.ResetToken() return nil - case callback.FieldType: - m.ResetType() + case chatuser.FieldRefresh: + m.ResetRefresh() return nil - case callback.FieldCreatedAt: + case chatuser.FieldExpiry: + m.ResetExpiry() + return nil + case chatuser.FieldBotToken: + m.ResetBotToken() + return nil + case chatuser.FieldCreatedAt: m.ResetCreatedAt() return nil - case callback.FieldUpdatedAt: + case chatuser.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case callback.FieldRepoID: - m.ResetRepoID() + case chatuser.FieldUserID: + m.ResetUserID() return nil } - return fmt.Errorf("unknown Callback field %s", name) + return fmt.Errorf("unknown ChatUser field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *CallbackMutation) AddedEdges() []string { +func (m *ChatUserMutation) AddedEdges() []string { edges := make([]string, 0, 1) - if m.repo != nil { - edges = append(edges, callback.EdgeRepo) + if m.user != nil { + edges = append(edges, chatuser.EdgeUser) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *CallbackMutation) AddedIDs(name string) []ent.Value { +func (m *ChatUserMutation) AddedIDs(name string) []ent.Value { switch name { - case callback.EdgeRepo: - if id := m.repo; id != nil { + case chatuser.EdgeUser: + if id := m.user; id != nil { return []ent.Value{*id} } } @@ -1254,91 +1240,113 @@ func (m *CallbackMutation) AddedIDs(name string) []ent.Value { } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *CallbackMutation) RemovedEdges() []string { +func (m *ChatUserMutation) RemovedEdges() []string { 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 *CallbackMutation) RemovedIDs(name string) []ent.Value { +func (m *ChatUserMutation) RemovedIDs(name string) []ent.Value { switch name { } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *CallbackMutation) ClearedEdges() []string { +func (m *ChatUserMutation) ClearedEdges() []string { edges := make([]string, 0, 1) - if m.clearedrepo { - edges = append(edges, callback.EdgeRepo) + if m.cleareduser { + edges = append(edges, chatuser.EdgeUser) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *CallbackMutation) EdgeCleared(name string) bool { +func (m *ChatUserMutation) EdgeCleared(name string) bool { switch name { - case callback.EdgeRepo: - return m.clearedrepo + case chatuser.EdgeUser: + return m.cleareduser } 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 *CallbackMutation) ClearEdge(name string) error { +func (m *ChatUserMutation) ClearEdge(name string) error { switch name { - case callback.EdgeRepo: - m.ClearRepo() + case chatuser.EdgeUser: + m.ClearUser() return nil } - return fmt.Errorf("unknown Callback unique edge %s", name) + return fmt.Errorf("unknown ChatUser 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 *CallbackMutation) ResetEdge(name string) error { +func (m *ChatUserMutation) ResetEdge(name string) error { switch name { - case callback.EdgeRepo: - m.ResetRepo() + case chatuser.EdgeUser: + m.ResetUser() return nil } - return fmt.Errorf("unknown Callback edge %s", name) + return fmt.Errorf("unknown ChatUser edge %s", name) } -// ChatUserMutation represents an operation that mutates the ChatUser nodes in the graph. -type ChatUserMutation struct { +// DeploymentMutation represents an operation that mutates the Deployment nodes in the graph. +type DeploymentMutation struct { config - op Op - typ string - id *string - token *string - refresh *string - expiry *time.Time - bot_token *string - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - user *int64 - cleareduser bool - done bool - oldValue func(context.Context) (*ChatUser, error) - predicates []predicate.ChatUser + op Op + typ string + id *int + number *int + addnumber *int + _type *deployment.Type + env *string + ref *string + status *deployment.Status + uid *int64 + adduid *int64 + sha *string + html_url *string + production_environment *bool + is_rollback *bool + created_at *time.Time + updated_at *time.Time + is_approval_enabled *bool + required_approval_count *int + addrequired_approval_count *int + clearedFields map[string]struct{} + user *int64 + cleareduser bool + repo *int64 + clearedrepo bool + reviews map[int]struct{} + removedreviews map[int]struct{} + clearedreviews bool + deployment_statuses map[int]struct{} + removeddeployment_statuses map[int]struct{} + cleareddeployment_statuses bool + event map[int]struct{} + removedevent map[int]struct{} + clearedevent bool + done bool + oldValue func(context.Context) (*Deployment, error) + predicates []predicate.Deployment } -var _ ent.Mutation = (*ChatUserMutation)(nil) +var _ ent.Mutation = (*DeploymentMutation)(nil) -// chatuserOption allows management of the mutation configuration using functional options. -type chatuserOption func(*ChatUserMutation) +// deploymentOption allows management of the mutation configuration using functional options. +type deploymentOption func(*DeploymentMutation) -// newChatUserMutation creates new mutation for the ChatUser entity. -func newChatUserMutation(c config, op Op, opts ...chatuserOption) *ChatUserMutation { - m := &ChatUserMutation{ +// newDeploymentMutation creates new mutation for the Deployment entity. +func newDeploymentMutation(c config, op Op, opts ...deploymentOption) *DeploymentMutation { + m := &DeploymentMutation{ config: c, op: op, - typ: TypeChatUser, + typ: TypeDeployment, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -1347,20 +1355,20 @@ func newChatUserMutation(c config, op Op, opts ...chatuserOption) *ChatUserMutat return m } -// withChatUserID sets the ID field of the mutation. -func withChatUserID(id string) chatuserOption { - return func(m *ChatUserMutation) { +// withDeploymentID sets the ID field of the mutation. +func withDeploymentID(id int) deploymentOption { + return func(m *DeploymentMutation) { var ( err error once sync.Once - value *ChatUser + value *Deployment ) - m.oldValue = func(ctx context.Context) (*ChatUser, error) { + m.oldValue = func(ctx context.Context) (*Deployment, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { - value, err = m.Client().ChatUser.Get(ctx, id) + value, err = m.Client().Deployment.Get(ctx, id) } }) return value, err @@ -1369,10 +1377,10 @@ func withChatUserID(id string) chatuserOption { } } -// withChatUser sets the old ChatUser of the mutation. -func withChatUser(node *ChatUser) chatuserOption { - return func(m *ChatUserMutation) { - m.oldValue = func(context.Context) (*ChatUser, error) { +// withDeployment sets the old Deployment of the mutation. +func withDeployment(node *Deployment) deploymentOption { + return func(m *DeploymentMutation) { + m.oldValue = func(context.Context) (*Deployment, error) { return node, nil } m.id = &node.ID @@ -1381,7 +1389,7 @@ func withChatUser(node *ChatUser) chatuserOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m ChatUserMutation) Client() *Client { +func (m DeploymentMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -1389,7 +1397,7 @@ func (m ChatUserMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m ChatUserMutation) Tx() (*Tx, error) { +func (m DeploymentMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("ent: mutation is not running in a transaction") } @@ -1398,1676 +1406,1001 @@ func (m ChatUserMutation) Tx() (*Tx, error) { return tx, nil } -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of ChatUser entities. -func (m *ChatUserMutation) SetID(id string) { - m.id = &id -} - // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *ChatUserMutation) ID() (id string, exists bool) { +func (m *DeploymentMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } -// SetToken sets the "token" field. -func (m *ChatUserMutation) SetToken(s string) { - m.token = &s +// SetNumber sets the "number" field. +func (m *DeploymentMutation) SetNumber(i int) { + m.number = &i + m.addnumber = nil } -// Token returns the value of the "token" field in the mutation. -func (m *ChatUserMutation) Token() (r string, exists bool) { - v := m.token +// Number returns the value of the "number" field in the mutation. +func (m *DeploymentMutation) Number() (r int, exists bool) { + v := m.number if v == nil { return } return *v, true } -// OldToken returns the old "token" field's value of the ChatUser entity. -// If the ChatUser object wasn't provided to the builder, the object is fetched from the database. +// OldNumber returns the old "number" 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 *ChatUserMutation) OldToken(ctx context.Context) (v string, err error) { +func (m *DeploymentMutation) OldNumber(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldToken is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldNumber is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldToken requires an ID field in the mutation") + return v, fmt.Errorf("OldNumber requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldToken: %w", err) + return v, fmt.Errorf("querying old value for OldNumber: %w", err) } - return oldValue.Token, nil -} - -// ResetToken resets all changes to the "token" field. -func (m *ChatUserMutation) ResetToken() { - m.token = nil + return oldValue.Number, nil } -// SetRefresh sets the "refresh" field. -func (m *ChatUserMutation) SetRefresh(s string) { - m.refresh = &s +// AddNumber adds i to the "number" field. +func (m *DeploymentMutation) AddNumber(i int) { + if m.addnumber != nil { + *m.addnumber += i + } else { + m.addnumber = &i + } } -// Refresh returns the value of the "refresh" field in the mutation. -func (m *ChatUserMutation) Refresh() (r string, exists bool) { - v := m.refresh +// AddedNumber returns the value that was added to the "number" field in this mutation. +func (m *DeploymentMutation) AddedNumber() (r int, exists bool) { + v := m.addnumber if v == nil { return } return *v, true } -// OldRefresh returns the old "refresh" field's value of the ChatUser entity. -// If the ChatUser 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 *ChatUserMutation) OldRefresh(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRefresh is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRefresh requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRefresh: %w", err) - } - return oldValue.Refresh, nil -} - -// ResetRefresh resets all changes to the "refresh" field. -func (m *ChatUserMutation) ResetRefresh() { - m.refresh = nil +// ResetNumber resets all changes to the "number" field. +func (m *DeploymentMutation) ResetNumber() { + m.number = nil + m.addnumber = nil } -// SetExpiry sets the "expiry" field. -func (m *ChatUserMutation) SetExpiry(t time.Time) { - m.expiry = &t +// SetType sets the "type" field. +func (m *DeploymentMutation) SetType(d deployment.Type) { + m._type = &d } -// Expiry returns the value of the "expiry" field in the mutation. -func (m *ChatUserMutation) Expiry() (r time.Time, exists bool) { - v := m.expiry +// GetType returns the value of the "type" field in the mutation. +func (m *DeploymentMutation) GetType() (r deployment.Type, exists bool) { + v := m._type if v == nil { return } return *v, true } -// OldExpiry returns the old "expiry" field's value of the ChatUser entity. -// If the ChatUser object wasn't provided to the builder, the object is fetched from the database. +// OldType returns the old "type" 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 *ChatUserMutation) OldExpiry(ctx context.Context) (v time.Time, err error) { +func (m *DeploymentMutation) OldType(ctx context.Context) (v deployment.Type, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldExpiry is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldExpiry requires an ID field in the mutation") + return v, fmt.Errorf("OldType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldExpiry: %w", err) + return v, fmt.Errorf("querying old value for OldType: %w", err) } - return oldValue.Expiry, nil + return oldValue.Type, nil } -// ResetExpiry resets all changes to the "expiry" field. -func (m *ChatUserMutation) ResetExpiry() { - m.expiry = nil +// ResetType resets all changes to the "type" field. +func (m *DeploymentMutation) ResetType() { + m._type = nil } -// SetBotToken sets the "bot_token" field. -func (m *ChatUserMutation) SetBotToken(s string) { - m.bot_token = &s +// SetEnv sets the "env" field. +func (m *DeploymentMutation) SetEnv(s string) { + m.env = &s } -// BotToken returns the value of the "bot_token" field in the mutation. -func (m *ChatUserMutation) BotToken() (r string, exists bool) { - v := m.bot_token +// Env returns the value of the "env" field in the mutation. +func (m *DeploymentMutation) Env() (r string, exists bool) { + v := m.env if v == nil { return } return *v, true } -// OldBotToken returns the old "bot_token" field's value of the ChatUser entity. -// If the ChatUser object wasn't provided to the builder, the object is fetched from the database. +// OldEnv returns the old "env" 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 *ChatUserMutation) OldBotToken(ctx context.Context) (v string, err error) { +func (m *DeploymentMutation) OldEnv(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldBotToken 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("OldBotToken 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 OldBotToken: %w", err) + return v, fmt.Errorf("querying old value for OldEnv: %w", err) } - return oldValue.BotToken, nil + return oldValue.Env, nil } -// ResetBotToken resets all changes to the "bot_token" field. -func (m *ChatUserMutation) ResetBotToken() { - m.bot_token = nil +// ResetEnv resets all changes to the "env" field. +func (m *DeploymentMutation) ResetEnv() { + m.env = nil } -// SetCreatedAt sets the "created_at" field. -func (m *ChatUserMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// SetRef sets the "ref" field. +func (m *DeploymentMutation) SetRef(s string) { + m.ref = &s } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *ChatUserMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at +// Ref returns the value of the "ref" field in the mutation. +func (m *DeploymentMutation) Ref() (r string, exists bool) { + v := m.ref if v == nil { return } return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the ChatUser entity. -// If the ChatUser object wasn't provided to the builder, the object is fetched from the database. +// OldRef returns the old "ref" 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 *ChatUserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *DeploymentMutation) OldRef(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldRef is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldRef requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + return v, fmt.Errorf("querying old value for OldRef: %w", err) } - return oldValue.CreatedAt, nil + return oldValue.Ref, nil } -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *ChatUserMutation) ResetCreatedAt() { - m.created_at = nil +// ResetRef resets all changes to the "ref" field. +func (m *DeploymentMutation) ResetRef() { + m.ref = nil } -// SetUpdatedAt sets the "updated_at" field. -func (m *ChatUserMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t +// SetStatus sets the "status" field. +func (m *DeploymentMutation) SetStatus(d deployment.Status) { + m.status = &d } -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *ChatUserMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at +// Status returns the value of the "status" field in the mutation. +func (m *DeploymentMutation) Status() (r deployment.Status, exists bool) { + v := m.status if v == nil { return } return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the ChatUser entity. -// If the ChatUser object wasn't provided to the builder, the object is fetched from the database. +// OldStatus returns the old "status" 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 *ChatUserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *DeploymentMutation) OldStatus(ctx context.Context) (v deployment.Status, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + return v, fmt.Errorf("querying old value for OldStatus: %w", err) } - return oldValue.UpdatedAt, nil + return oldValue.Status, nil } -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *ChatUserMutation) ResetUpdatedAt() { - m.updated_at = nil +// ResetStatus resets all changes to the "status" field. +func (m *DeploymentMutation) ResetStatus() { + m.status = nil } -// SetUserID sets the "user_id" field. -func (m *ChatUserMutation) SetUserID(i int64) { - m.user = &i +// SetUID sets the "uid" field. +func (m *DeploymentMutation) SetUID(i int64) { + m.uid = &i + m.adduid = nil } -// UserID returns the value of the "user_id" field in the mutation. -func (m *ChatUserMutation) UserID() (r int64, exists bool) { - v := m.user +// UID returns the value of the "uid" field in the mutation. +func (m *DeploymentMutation) UID() (r int64, exists bool) { + v := m.uid if v == nil { return } return *v, true } -// OldUserID returns the old "user_id" field's value of the ChatUser entity. -// If the ChatUser object wasn't provided to the builder, the object is fetched from the database. +// OldUID returns the old "uid" 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 *ChatUserMutation) OldUserID(ctx context.Context) (v int64, err error) { +func (m *DeploymentMutation) OldUID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldUID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserID requires an ID field in the mutation") + return v, fmt.Errorf("OldUID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUserID: %w", err) + return v, fmt.Errorf("querying old value for OldUID: %w", err) } - return oldValue.UserID, nil -} - -// ResetUserID resets all changes to the "user_id" field. -func (m *ChatUserMutation) ResetUserID() { - m.user = nil + return oldValue.UID, nil } -// ClearUser clears the "user" edge to the User entity. -func (m *ChatUserMutation) ClearUser() { - m.cleareduser = true -} - -// UserCleared reports if the "user" edge to the User entity was cleared. -func (m *ChatUserMutation) UserCleared() bool { - return m.cleareduser +// AddUID adds i to the "uid" field. +func (m *DeploymentMutation) AddUID(i int64) { + if m.adduid != nil { + *m.adduid += i + } else { + m.adduid = &i + } } -// UserIDs returns the "user" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// UserID instead. It exists only for internal usage by the builders. -func (m *ChatUserMutation) UserIDs() (ids []int64) { - if id := m.user; id != nil { - ids = append(ids, *id) +// AddedUID returns the value that was added to the "uid" field in this mutation. +func (m *DeploymentMutation) AddedUID() (r int64, exists bool) { + v := m.adduid + if v == nil { + return } - return + return *v, true } -// ResetUser resets all changes to the "user" edge. -func (m *ChatUserMutation) ResetUser() { - m.user = nil - m.cleareduser = false +// ClearUID clears the value of the "uid" field. +func (m *DeploymentMutation) ClearUID() { + m.uid = nil + m.adduid = nil + m.clearedFields[deployment.FieldUID] = struct{}{} } -// Where appends a list predicates to the ChatUserMutation builder. -func (m *ChatUserMutation) Where(ps ...predicate.ChatUser) { - m.predicates = append(m.predicates, ps...) +// UIDCleared returns if the "uid" field was cleared in this mutation. +func (m *DeploymentMutation) UIDCleared() bool { + _, ok := m.clearedFields[deployment.FieldUID] + return ok } -// Op returns the operation name. -func (m *ChatUserMutation) Op() Op { - return m.op +// ResetUID resets all changes to the "uid" field. +func (m *DeploymentMutation) ResetUID() { + m.uid = nil + m.adduid = nil + delete(m.clearedFields, deployment.FieldUID) } -// Type returns the node type of this mutation (ChatUser). -func (m *ChatUserMutation) Type() string { - return m.typ +// SetSha sets the "sha" field. +func (m *DeploymentMutation) SetSha(s string) { + m.sha = &s } -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *ChatUserMutation) Fields() []string { - fields := make([]string, 0, 7) - if m.token != nil { - fields = append(fields, chatuser.FieldToken) - } - if m.refresh != nil { - fields = append(fields, chatuser.FieldRefresh) - } - if m.expiry != nil { - fields = append(fields, chatuser.FieldExpiry) - } - if m.bot_token != nil { - fields = append(fields, chatuser.FieldBotToken) +// Sha returns the value of the "sha" field in the mutation. +func (m *DeploymentMutation) Sha() (r string, exists bool) { + v := m.sha + if v == nil { + return } - if m.created_at != nil { - fields = append(fields, chatuser.FieldCreatedAt) + return *v, true +} + +// OldSha returns the old "sha" 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) OldSha(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldSha is only allowed on UpdateOne operations") } - if m.updated_at != nil { - fields = append(fields, chatuser.FieldUpdatedAt) + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldSha requires an ID field in the mutation") } - if m.user != nil { - fields = append(fields, chatuser.FieldUserID) + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSha: %w", err) } - return fields + return oldValue.Sha, nil } -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *ChatUserMutation) Field(name string) (ent.Value, bool) { - switch name { - case chatuser.FieldToken: - return m.Token() - case chatuser.FieldRefresh: - return m.Refresh() - case chatuser.FieldExpiry: - return m.Expiry() - case chatuser.FieldBotToken: - return m.BotToken() - case chatuser.FieldCreatedAt: - return m.CreatedAt() - case chatuser.FieldUpdatedAt: - return m.UpdatedAt() - case chatuser.FieldUserID: - return m.UserID() - } - return nil, false +// ClearSha clears the value of the "sha" field. +func (m *DeploymentMutation) ClearSha() { + m.sha = nil + m.clearedFields[deployment.FieldSha] = struct{}{} } -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *ChatUserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case chatuser.FieldToken: - return m.OldToken(ctx) - case chatuser.FieldRefresh: - return m.OldRefresh(ctx) - case chatuser.FieldExpiry: - return m.OldExpiry(ctx) - case chatuser.FieldBotToken: - return m.OldBotToken(ctx) - case chatuser.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case chatuser.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case chatuser.FieldUserID: - return m.OldUserID(ctx) - } - return nil, fmt.Errorf("unknown ChatUser field %s", name) +// ShaCleared returns if the "sha" field was cleared in this mutation. +func (m *DeploymentMutation) ShaCleared() bool { + _, ok := m.clearedFields[deployment.FieldSha] + return ok } -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *ChatUserMutation) SetField(name string, value ent.Value) error { - switch name { - case chatuser.FieldToken: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetToken(v) - return nil - case chatuser.FieldRefresh: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetRefresh(v) - return nil - case chatuser.FieldExpiry: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetExpiry(v) - return nil - case chatuser.FieldBotToken: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetBotToken(v) - return nil - case chatuser.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case chatuser.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - case chatuser.FieldUserID: - v, ok := value.(int64) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUserID(v) - return nil - } - return fmt.Errorf("unknown ChatUser field %s", name) +// ResetSha resets all changes to the "sha" field. +func (m *DeploymentMutation) ResetSha() { + m.sha = nil + delete(m.clearedFields, deployment.FieldSha) } -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *ChatUserMutation) AddedFields() []string { - var fields []string - return fields +// SetHTMLURL sets the "html_url" field. +func (m *DeploymentMutation) SetHTMLURL(s string) { + m.html_url = &s } -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *ChatUserMutation) AddedField(name string) (ent.Value, bool) { - switch name { +// HTMLURL returns the value of the "html_url" field in the mutation. +func (m *DeploymentMutation) HTMLURL() (r string, exists bool) { + v := m.html_url + if v == nil { + return } - return nil, false + return *v, true } -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *ChatUserMutation) AddField(name string, value ent.Value) error { - switch name { +// OldHTMLURL returns the old "html_url" 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) OldHTMLURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldHTMLURL is only allowed on UpdateOne operations") } - return fmt.Errorf("unknown ChatUser numeric field %s", name) + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldHTMLURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldHTMLURL: %w", err) + } + return oldValue.HTMLURL, nil } -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *ChatUserMutation) ClearedFields() []string { - return nil -} +// ClearHTMLURL clears the value of the "html_url" field. +func (m *DeploymentMutation) ClearHTMLURL() { + m.html_url = nil + m.clearedFields[deployment.FieldHTMLURL] = struct{}{} +} -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *ChatUserMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] +// HTMLURLCleared returns if the "html_url" field was cleared in this mutation. +func (m *DeploymentMutation) HTMLURLCleared() bool { + _, ok := m.clearedFields[deployment.FieldHTMLURL] return ok } -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *ChatUserMutation) ClearField(name string) error { - return fmt.Errorf("unknown ChatUser nullable field %s", name) +// ResetHTMLURL resets all changes to the "html_url" field. +func (m *DeploymentMutation) ResetHTMLURL() { + m.html_url = nil + delete(m.clearedFields, deployment.FieldHTMLURL) } -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *ChatUserMutation) ResetField(name string) error { - switch name { - case chatuser.FieldToken: - m.ResetToken() - return nil - case chatuser.FieldRefresh: - m.ResetRefresh() - return nil - case chatuser.FieldExpiry: - m.ResetExpiry() - return nil - case chatuser.FieldBotToken: - m.ResetBotToken() - return nil - case chatuser.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case chatuser.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case chatuser.FieldUserID: - m.ResetUserID() - return nil - } - return fmt.Errorf("unknown ChatUser field %s", name) +// SetProductionEnvironment sets the "production_environment" field. +func (m *DeploymentMutation) SetProductionEnvironment(b bool) { + m.production_environment = &b } -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *ChatUserMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.user != nil { - edges = append(edges, chatuser.EdgeUser) +// 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 edges + return *v, true } -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *ChatUserMutation) AddedIDs(name string) []ent.Value { - switch name { - case chatuser.EdgeUser: - if id := m.user; id != nil { - return []ent.Value{*id} - } +// 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") } - return nil + 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 } -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *ChatUserMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - return edges +// ResetProductionEnvironment resets all changes to the "production_environment" field. +func (m *DeploymentMutation) ResetProductionEnvironment() { + m.production_environment = nil } -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *ChatUserMutation) RemovedIDs(name string) []ent.Value { - switch name { - } - return nil +// SetIsRollback sets the "is_rollback" field. +func (m *DeploymentMutation) SetIsRollback(b bool) { + m.is_rollback = &b } -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ChatUserMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.cleareduser { - edges = append(edges, chatuser.EdgeUser) +// IsRollback returns the value of the "is_rollback" field in the mutation. +func (m *DeploymentMutation) IsRollback() (r bool, exists bool) { + v := m.is_rollback + if v == nil { + return } - return edges + return *v, true } -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *ChatUserMutation) EdgeCleared(name string) bool { - switch name { - case chatuser.EdgeUser: - return m.cleareduser +// OldIsRollback returns the old "is_rollback" 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) OldIsRollback(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldIsRollback is only allowed on UpdateOne operations") } - 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 *ChatUserMutation) ClearEdge(name string) error { - switch name { - case chatuser.EdgeUser: - m.ClearUser() - return nil + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldIsRollback requires an ID field in the mutation") } - return fmt.Errorf("unknown ChatUser 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 *ChatUserMutation) ResetEdge(name string) error { - switch name { - case chatuser.EdgeUser: - m.ResetUser() - return nil + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIsRollback: %w", err) } - return fmt.Errorf("unknown ChatUser edge %s", name) + return oldValue.IsRollback, nil } -// DeploymentMutation represents an operation that mutates the Deployment nodes in the graph. -type DeploymentMutation struct { - config - op Op - typ string - id *int - number *int - addnumber *int - _type *deployment.Type - env *string - ref *string - status *deployment.Status - uid *int64 - adduid *int64 - sha *string - html_url *string - production_environment *bool - is_rollback *bool - is_approval_enabled *bool - required_approval_count *int - addrequired_approval_count *int - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - user *int64 - cleareduser bool - repo *int64 - clearedrepo bool - approvals map[int]struct{} - removedapprovals map[int]struct{} - clearedapprovals bool - deployment_statuses map[int]struct{} - removeddeployment_statuses map[int]struct{} - cleareddeployment_statuses bool - event map[int]struct{} - removedevent map[int]struct{} - clearedevent bool - done bool - oldValue func(context.Context) (*Deployment, error) - predicates []predicate.Deployment +// ResetIsRollback resets all changes to the "is_rollback" field. +func (m *DeploymentMutation) ResetIsRollback() { + m.is_rollback = nil } -var _ ent.Mutation = (*DeploymentMutation)(nil) +// SetCreatedAt sets the "created_at" field. +func (m *DeploymentMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} -// deploymentOption allows management of the mutation configuration using functional options. -type deploymentOption func(*DeploymentMutation) +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *DeploymentMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} -// newDeploymentMutation creates new mutation for the Deployment entity. -func newDeploymentMutation(c config, op Op, opts ...deploymentOption) *DeploymentMutation { - m := &DeploymentMutation{ - config: c, - op: op, - typ: TypeDeployment, - clearedFields: make(map[string]struct{}), +// OldCreatedAt returns the old "created_at" 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) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } - for _, opt := range opts { - opt(m) + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") } - return m + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil } -// withDeploymentID sets the ID field of the mutation. -func withDeploymentID(id int) deploymentOption { - return func(m *DeploymentMutation) { - var ( - err error - once sync.Once - value *Deployment - ) - m.oldValue = func(ctx context.Context) (*Deployment, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Deployment.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *DeploymentMutation) ResetCreatedAt() { + m.created_at = nil } -// withDeployment sets the old Deployment of the mutation. -func withDeployment(node *Deployment) deploymentOption { - return func(m *DeploymentMutation) { - m.oldValue = func(context.Context) (*Deployment, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m DeploymentMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m DeploymentMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *DeploymentMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetNumber sets the "number" field. -func (m *DeploymentMutation) SetNumber(i int) { - m.number = &i - m.addnumber = nil +// SetUpdatedAt sets the "updated_at" field. +func (m *DeploymentMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t } -// Number returns the value of the "number" field in the mutation. -func (m *DeploymentMutation) Number() (r int, exists bool) { - v := m.number +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *DeploymentMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at if v == nil { return } return *v, true } -// OldNumber returns the old "number" field's value of the Deployment entity. +// OldUpdatedAt returns the old "updated_at" 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) OldNumber(ctx context.Context) (v int, err error) { +func (m *DeploymentMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldNumber is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldNumber requires an ID field in the mutation") + return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldNumber: %w", err) - } - return oldValue.Number, nil -} - -// AddNumber adds i to the "number" field. -func (m *DeploymentMutation) AddNumber(i int) { - if m.addnumber != nil { - *m.addnumber += i - } else { - m.addnumber = &i - } -} - -// AddedNumber returns the value that was added to the "number" field in this mutation. -func (m *DeploymentMutation) AddedNumber() (r int, exists bool) { - v := m.addnumber - if v == nil { - return + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) } - return *v, true + return oldValue.UpdatedAt, nil } -// ResetNumber resets all changes to the "number" field. -func (m *DeploymentMutation) ResetNumber() { - m.number = nil - m.addnumber = nil +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *DeploymentMutation) ResetUpdatedAt() { + m.updated_at = nil } -// SetType sets the "type" field. -func (m *DeploymentMutation) SetType(d deployment.Type) { - m._type = &d +// SetUserID sets the "user_id" field. +func (m *DeploymentMutation) SetUserID(i int64) { + m.user = &i } -// GetType returns the value of the "type" field in the mutation. -func (m *DeploymentMutation) GetType() (r deployment.Type, exists bool) { - v := m._type +// UserID returns the value of the "user_id" field in the mutation. +func (m *DeploymentMutation) UserID() (r int64, exists bool) { + v := m.user if v == nil { return } return *v, true } -// OldType returns the old "type" field's value of the Deployment entity. +// OldUserID returns the old "user_id" 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) OldType(ctx context.Context) (v deployment.Type, err error) { +func (m *DeploymentMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldType requires an ID field in the mutation") + return v, fmt.Errorf("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldType: %w", err) + return v, fmt.Errorf("querying old value for OldUserID: %w", err) } - return oldValue.Type, nil + return oldValue.UserID, nil } -// ResetType resets all changes to the "type" field. -func (m *DeploymentMutation) ResetType() { - m._type = nil +// ResetUserID resets all changes to the "user_id" field. +func (m *DeploymentMutation) ResetUserID() { + m.user = nil } -// SetEnv sets the "env" field. -func (m *DeploymentMutation) SetEnv(s string) { - m.env = &s +// SetRepoID sets the "repo_id" field. +func (m *DeploymentMutation) SetRepoID(i int64) { + m.repo = &i } -// Env returns the value of the "env" field in the mutation. -func (m *DeploymentMutation) Env() (r string, exists bool) { - v := m.env +// RepoID returns the value of the "repo_id" field in the mutation. +func (m *DeploymentMutation) RepoID() (r int64, exists bool) { + v := m.repo if v == nil { return } return *v, true } -// OldEnv returns the old "env" field's value of the Deployment entity. +// OldRepoID returns the old "repo_id" 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) OldEnv(ctx context.Context) (v string, err error) { +func (m *DeploymentMutation) OldRepoID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEnv is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldRepoID 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("OldRepoID 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 OldRepoID: %w", err) } - return oldValue.Env, nil + return oldValue.RepoID, nil } -// ResetEnv resets all changes to the "env" field. -func (m *DeploymentMutation) ResetEnv() { - m.env = nil +// ResetRepoID resets all changes to the "repo_id" field. +func (m *DeploymentMutation) ResetRepoID() { + m.repo = nil } -// SetRef sets the "ref" field. -func (m *DeploymentMutation) SetRef(s string) { - m.ref = &s +// SetIsApprovalEnabled sets the "is_approval_enabled" field. +func (m *DeploymentMutation) SetIsApprovalEnabled(b bool) { + m.is_approval_enabled = &b } -// Ref returns the value of the "ref" field in the mutation. -func (m *DeploymentMutation) Ref() (r string, exists bool) { - v := m.ref +// IsApprovalEnabled returns the value of the "is_approval_enabled" field in the mutation. +func (m *DeploymentMutation) IsApprovalEnabled() (r bool, exists bool) { + v := m.is_approval_enabled if v == nil { return } return *v, true } -// OldRef returns the old "ref" field's value of the Deployment entity. +// OldIsApprovalEnabled returns the old "is_approval_enabled" 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) OldRef(ctx context.Context) (v string, err error) { +func (m *DeploymentMutation) OldIsApprovalEnabled(ctx context.Context) (v *bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRef is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldIsApprovalEnabled is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRef requires an ID field in the mutation") + return v, fmt.Errorf("OldIsApprovalEnabled requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldRef: %w", err) + return v, fmt.Errorf("querying old value for OldIsApprovalEnabled: %w", err) } - return oldValue.Ref, nil -} - -// ResetRef resets all changes to the "ref" field. -func (m *DeploymentMutation) ResetRef() { - m.ref = nil -} - -// SetStatus sets the "status" field. -func (m *DeploymentMutation) SetStatus(d deployment.Status) { - m.status = &d + return oldValue.IsApprovalEnabled, nil } -// Status returns the value of the "status" field in the mutation. -func (m *DeploymentMutation) Status() (r deployment.Status, exists bool) { - v := m.status - if v == nil { - return - } - return *v, true +// ClearIsApprovalEnabled clears the value of the "is_approval_enabled" field. +func (m *DeploymentMutation) ClearIsApprovalEnabled() { + m.is_approval_enabled = nil + m.clearedFields[deployment.FieldIsApprovalEnabled] = struct{}{} } -// OldStatus returns the old "status" 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) OldStatus(ctx context.Context) (v deployment.Status, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldStatus requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldStatus: %w", err) - } - return oldValue.Status, nil +// IsApprovalEnabledCleared returns if the "is_approval_enabled" field was cleared in this mutation. +func (m *DeploymentMutation) IsApprovalEnabledCleared() bool { + _, ok := m.clearedFields[deployment.FieldIsApprovalEnabled] + return ok } -// ResetStatus resets all changes to the "status" field. -func (m *DeploymentMutation) ResetStatus() { - m.status = nil +// ResetIsApprovalEnabled resets all changes to the "is_approval_enabled" field. +func (m *DeploymentMutation) ResetIsApprovalEnabled() { + m.is_approval_enabled = nil + delete(m.clearedFields, deployment.FieldIsApprovalEnabled) } -// SetUID sets the "uid" field. -func (m *DeploymentMutation) SetUID(i int64) { - m.uid = &i - m.adduid = nil +// SetRequiredApprovalCount sets the "required_approval_count" field. +func (m *DeploymentMutation) SetRequiredApprovalCount(i int) { + m.required_approval_count = &i + m.addrequired_approval_count = nil } -// UID returns the value of the "uid" field in the mutation. -func (m *DeploymentMutation) UID() (r int64, exists bool) { - v := m.uid +// RequiredApprovalCount returns the value of the "required_approval_count" field in the mutation. +func (m *DeploymentMutation) RequiredApprovalCount() (r int, exists bool) { + v := m.required_approval_count if v == nil { return } return *v, true } -// OldUID returns the old "uid" field's value of the Deployment entity. +// OldRequiredApprovalCount returns the old "required_approval_count" 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) OldUID(ctx context.Context) (v int64, err error) { +func (m *DeploymentMutation) OldRequiredApprovalCount(ctx context.Context) (v *int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldRequiredApprovalCount is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUID requires an ID field in the mutation") + return v, fmt.Errorf("OldRequiredApprovalCount requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUID: %w", err) + return v, fmt.Errorf("querying old value for OldRequiredApprovalCount: %w", err) } - return oldValue.UID, nil + return oldValue.RequiredApprovalCount, nil } -// AddUID adds i to the "uid" field. -func (m *DeploymentMutation) AddUID(i int64) { - if m.adduid != nil { - *m.adduid += i +// AddRequiredApprovalCount adds i to the "required_approval_count" field. +func (m *DeploymentMutation) AddRequiredApprovalCount(i int) { + if m.addrequired_approval_count != nil { + *m.addrequired_approval_count += i } else { - m.adduid = &i + m.addrequired_approval_count = &i } } -// AddedUID returns the value that was added to the "uid" field in this mutation. -func (m *DeploymentMutation) AddedUID() (r int64, exists bool) { - v := m.adduid +// AddedRequiredApprovalCount returns the value that was added to the "required_approval_count" field in this mutation. +func (m *DeploymentMutation) AddedRequiredApprovalCount() (r int, exists bool) { + v := m.addrequired_approval_count if v == nil { return } return *v, true } -// ClearUID clears the value of the "uid" field. -func (m *DeploymentMutation) ClearUID() { - m.uid = nil - m.adduid = nil - m.clearedFields[deployment.FieldUID] = struct{}{} +// ClearRequiredApprovalCount clears the value of the "required_approval_count" field. +func (m *DeploymentMutation) ClearRequiredApprovalCount() { + m.required_approval_count = nil + m.addrequired_approval_count = nil + m.clearedFields[deployment.FieldRequiredApprovalCount] = struct{}{} } -// UIDCleared returns if the "uid" field was cleared in this mutation. -func (m *DeploymentMutation) UIDCleared() bool { - _, ok := m.clearedFields[deployment.FieldUID] +// RequiredApprovalCountCleared returns if the "required_approval_count" field was cleared in this mutation. +func (m *DeploymentMutation) RequiredApprovalCountCleared() bool { + _, ok := m.clearedFields[deployment.FieldRequiredApprovalCount] return ok } -// ResetUID resets all changes to the "uid" field. -func (m *DeploymentMutation) ResetUID() { - m.uid = nil - m.adduid = nil - delete(m.clearedFields, deployment.FieldUID) +// ResetRequiredApprovalCount resets all changes to the "required_approval_count" field. +func (m *DeploymentMutation) ResetRequiredApprovalCount() { + m.required_approval_count = nil + m.addrequired_approval_count = nil + delete(m.clearedFields, deployment.FieldRequiredApprovalCount) } -// SetSha sets the "sha" field. -func (m *DeploymentMutation) SetSha(s string) { - m.sha = &s +// ClearUser clears the "user" edge to the User entity. +func (m *DeploymentMutation) ClearUser() { + m.cleareduser = true } -// Sha returns the value of the "sha" field in the mutation. -func (m *DeploymentMutation) Sha() (r string, exists bool) { - v := m.sha - if v == nil { - return - } - return *v, true +// UserCleared reports if the "user" edge to the User entity was cleared. +func (m *DeploymentMutation) UserCleared() bool { + return m.cleareduser } -// OldSha returns the old "sha" 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) OldSha(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSha is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSha requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSha: %w", err) +// UserIDs returns the "user" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// UserID instead. It exists only for internal usage by the builders. +func (m *DeploymentMutation) UserIDs() (ids []int64) { + if id := m.user; id != nil { + ids = append(ids, *id) } - return oldValue.Sha, nil + return } -// ClearSha clears the value of the "sha" field. -func (m *DeploymentMutation) ClearSha() { - m.sha = nil - m.clearedFields[deployment.FieldSha] = struct{}{} +// ResetUser resets all changes to the "user" edge. +func (m *DeploymentMutation) ResetUser() { + m.user = nil + m.cleareduser = false } -// ShaCleared returns if the "sha" field was cleared in this mutation. -func (m *DeploymentMutation) ShaCleared() bool { - _, ok := m.clearedFields[deployment.FieldSha] - return ok +// ClearRepo clears the "repo" edge to the Repo entity. +func (m *DeploymentMutation) ClearRepo() { + m.clearedrepo = true } -// ResetSha resets all changes to the "sha" field. -func (m *DeploymentMutation) ResetSha() { - m.sha = nil - delete(m.clearedFields, deployment.FieldSha) +// RepoCleared reports if the "repo" edge to the Repo entity was cleared. +func (m *DeploymentMutation) RepoCleared() bool { + return m.clearedrepo } -// SetHTMLURL sets the "html_url" field. -func (m *DeploymentMutation) SetHTMLURL(s string) { - m.html_url = &s +// 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 *DeploymentMutation) RepoIDs() (ids []int64) { + if id := m.repo; id != nil { + ids = append(ids, *id) + } + return } -// HTMLURL returns the value of the "html_url" field in the mutation. -func (m *DeploymentMutation) HTMLURL() (r string, exists bool) { - v := m.html_url - if v == nil { - return - } - return *v, true +// ResetRepo resets all changes to the "repo" edge. +func (m *DeploymentMutation) ResetRepo() { + m.repo = nil + m.clearedrepo = false } -// OldHTMLURL returns the old "html_url" 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) OldHTMLURL(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldHTMLURL is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldHTMLURL requires an ID field in the mutation") +// AddReviewIDs adds the "reviews" edge to the Review entity by ids. +func (m *DeploymentMutation) AddReviewIDs(ids ...int) { + if m.reviews == nil { + m.reviews = make(map[int]struct{}) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldHTMLURL: %w", err) + for i := range ids { + m.reviews[ids[i]] = struct{}{} } - return oldValue.HTMLURL, nil } -// ClearHTMLURL clears the value of the "html_url" field. -func (m *DeploymentMutation) ClearHTMLURL() { - m.html_url = nil - m.clearedFields[deployment.FieldHTMLURL] = struct{}{} +// ClearReviews clears the "reviews" edge to the Review entity. +func (m *DeploymentMutation) ClearReviews() { + m.clearedreviews = true } -// HTMLURLCleared returns if the "html_url" field was cleared in this mutation. -func (m *DeploymentMutation) HTMLURLCleared() bool { - _, ok := m.clearedFields[deployment.FieldHTMLURL] - return ok +// ReviewsCleared reports if the "reviews" edge to the Review entity was cleared. +func (m *DeploymentMutation) ReviewsCleared() bool { + return m.clearedreviews } -// ResetHTMLURL resets all changes to the "html_url" field. -func (m *DeploymentMutation) ResetHTMLURL() { - m.html_url = nil - delete(m.clearedFields, deployment.FieldHTMLURL) +// RemoveReviewIDs removes the "reviews" edge to the Review entity by IDs. +func (m *DeploymentMutation) RemoveReviewIDs(ids ...int) { + if m.removedreviews == nil { + m.removedreviews = make(map[int]struct{}) + } + for i := range ids { + delete(m.reviews, ids[i]) + m.removedreviews[ids[i]] = struct{}{} + } } -// SetProductionEnvironment sets the "production_environment" field. -func (m *DeploymentMutation) SetProductionEnvironment(b bool) { - m.production_environment = &b +// RemovedReviews returns the removed IDs of the "reviews" edge to the Review entity. +func (m *DeploymentMutation) RemovedReviewsIDs() (ids []int) { + for id := range m.removedreviews { + ids = append(ids, id) + } + return } -// 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 +// ReviewsIDs returns the "reviews" edge IDs in the mutation. +func (m *DeploymentMutation) ReviewsIDs() (ids []int) { + for id := range m.reviews { + ids = append(ids, id) } - return *v, true + return } -// 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") +// ResetReviews resets all changes to the "reviews" edge. +func (m *DeploymentMutation) ResetReviews() { + m.reviews = nil + m.clearedreviews = false + m.removedreviews = nil +} + +// AddDeploymentStatusIDs adds the "deployment_statuses" edge to the DeploymentStatus entity by ids. +func (m *DeploymentMutation) AddDeploymentStatusIDs(ids ...int) { + if m.deployment_statuses == nil { + m.deployment_statuses = make(map[int]struct{}) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldProductionEnvironment: %w", err) + for i := range ids { + m.deployment_statuses[ids[i]] = struct{}{} } - return oldValue.ProductionEnvironment, nil } -// ResetProductionEnvironment resets all changes to the "production_environment" field. -func (m *DeploymentMutation) ResetProductionEnvironment() { - m.production_environment = nil +// ClearDeploymentStatuses clears the "deployment_statuses" edge to the DeploymentStatus entity. +func (m *DeploymentMutation) ClearDeploymentStatuses() { + m.cleareddeployment_statuses = true } -// SetIsRollback sets the "is_rollback" field. -func (m *DeploymentMutation) SetIsRollback(b bool) { - m.is_rollback = &b +// DeploymentStatusesCleared reports if the "deployment_statuses" edge to the DeploymentStatus entity was cleared. +func (m *DeploymentMutation) DeploymentStatusesCleared() bool { + return m.cleareddeployment_statuses } -// IsRollback returns the value of the "is_rollback" field in the mutation. -func (m *DeploymentMutation) IsRollback() (r bool, exists bool) { - v := m.is_rollback - if v == nil { - return +// RemoveDeploymentStatusIDs removes the "deployment_statuses" edge to the DeploymentStatus entity by IDs. +func (m *DeploymentMutation) RemoveDeploymentStatusIDs(ids ...int) { + if m.removeddeployment_statuses == nil { + m.removeddeployment_statuses = make(map[int]struct{}) + } + for i := range ids { + delete(m.deployment_statuses, ids[i]) + m.removeddeployment_statuses[ids[i]] = struct{}{} } - return *v, true } -// OldIsRollback returns the old "is_rollback" 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) OldIsRollback(ctx context.Context) (v bool, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldIsRollback is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldIsRollback requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIsRollback: %w", err) +// RemovedDeploymentStatuses returns the removed IDs of the "deployment_statuses" edge to the DeploymentStatus entity. +func (m *DeploymentMutation) RemovedDeploymentStatusesIDs() (ids []int) { + for id := range m.removeddeployment_statuses { + ids = append(ids, id) } - return oldValue.IsRollback, nil + return } -// ResetIsRollback resets all changes to the "is_rollback" field. -func (m *DeploymentMutation) ResetIsRollback() { - m.is_rollback = nil +// DeploymentStatusesIDs returns the "deployment_statuses" edge IDs in the mutation. +func (m *DeploymentMutation) DeploymentStatusesIDs() (ids []int) { + for id := range m.deployment_statuses { + ids = append(ids, id) + } + return } -// SetIsApprovalEnabled sets the "is_approval_enabled" field. -func (m *DeploymentMutation) SetIsApprovalEnabled(b bool) { - m.is_approval_enabled = &b +// ResetDeploymentStatuses resets all changes to the "deployment_statuses" edge. +func (m *DeploymentMutation) ResetDeploymentStatuses() { + m.deployment_statuses = nil + m.cleareddeployment_statuses = false + m.removeddeployment_statuses = nil } -// IsApprovalEnabled returns the value of the "is_approval_enabled" field in the mutation. -func (m *DeploymentMutation) IsApprovalEnabled() (r bool, exists bool) { - v := m.is_approval_enabled - if v == nil { - return +// AddEventIDs adds the "event" edge to the Event entity by ids. +func (m *DeploymentMutation) AddEventIDs(ids ...int) { + if m.event == nil { + m.event = make(map[int]struct{}) + } + for i := range ids { + m.event[ids[i]] = struct{}{} } - return *v, true } -// OldIsApprovalEnabled returns the old "is_approval_enabled" 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) OldIsApprovalEnabled(ctx context.Context) (v bool, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldIsApprovalEnabled is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldIsApprovalEnabled requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldIsApprovalEnabled: %w", err) - } - return oldValue.IsApprovalEnabled, nil +// ClearEvent clears the "event" edge to the Event entity. +func (m *DeploymentMutation) ClearEvent() { + m.clearedevent = true } -// ResetIsApprovalEnabled resets all changes to the "is_approval_enabled" field. -func (m *DeploymentMutation) ResetIsApprovalEnabled() { - m.is_approval_enabled = nil +// EventCleared reports if the "event" edge to the Event entity was cleared. +func (m *DeploymentMutation) EventCleared() bool { + return m.clearedevent } -// SetRequiredApprovalCount sets the "required_approval_count" field. -func (m *DeploymentMutation) SetRequiredApprovalCount(i int) { - m.required_approval_count = &i - m.addrequired_approval_count = nil -} - -// RequiredApprovalCount returns the value of the "required_approval_count" field in the mutation. -func (m *DeploymentMutation) RequiredApprovalCount() (r int, exists bool) { - v := m.required_approval_count - if v == nil { - return +// RemoveEventIDs removes the "event" edge to the Event entity by IDs. +func (m *DeploymentMutation) RemoveEventIDs(ids ...int) { + if m.removedevent == nil { + m.removedevent = make(map[int]struct{}) + } + for i := range ids { + delete(m.event, ids[i]) + m.removedevent[ids[i]] = struct{}{} } - return *v, true } -// OldRequiredApprovalCount returns the old "required_approval_count" 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) OldRequiredApprovalCount(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRequiredApprovalCount is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRequiredApprovalCount requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRequiredApprovalCount: %w", err) +// RemovedEvent returns the removed IDs of the "event" edge to the Event entity. +func (m *DeploymentMutation) RemovedEventIDs() (ids []int) { + for id := range m.removedevent { + ids = append(ids, id) } - return oldValue.RequiredApprovalCount, nil + return } -// AddRequiredApprovalCount adds i to the "required_approval_count" field. -func (m *DeploymentMutation) AddRequiredApprovalCount(i int) { - if m.addrequired_approval_count != nil { - *m.addrequired_approval_count += i - } else { - m.addrequired_approval_count = &i +// EventIDs returns the "event" edge IDs in the mutation. +func (m *DeploymentMutation) EventIDs() (ids []int) { + for id := range m.event { + ids = append(ids, id) } + return } -// AddedRequiredApprovalCount returns the value that was added to the "required_approval_count" field in this mutation. -func (m *DeploymentMutation) AddedRequiredApprovalCount() (r int, exists bool) { - v := m.addrequired_approval_count - if v == nil { - return - } - return *v, true +// ResetEvent resets all changes to the "event" edge. +func (m *DeploymentMutation) ResetEvent() { + m.event = nil + m.clearedevent = false + m.removedevent = nil } -// ResetRequiredApprovalCount resets all changes to the "required_approval_count" field. -func (m *DeploymentMutation) ResetRequiredApprovalCount() { - m.required_approval_count = nil - m.addrequired_approval_count = nil +// Where appends a list predicates to the DeploymentMutation builder. +func (m *DeploymentMutation) Where(ps ...predicate.Deployment) { + m.predicates = append(m.predicates, ps...) } -// SetCreatedAt sets the "created_at" field. -func (m *DeploymentMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// Op returns the operation name. +func (m *DeploymentMutation) Op() Op { + return m.op } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *DeploymentMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true +// Type returns the node type of this mutation (Deployment). +func (m *DeploymentMutation) Type() string { + return m.typ } -// OldCreatedAt returns the old "created_at" 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) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *DeploymentMutation) Fields() []string { + fields := make([]string, 0, 16) + if m.number != nil { + fields = append(fields, deployment.FieldNumber) } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") + if m._type != nil { + fields = append(fields, deployment.FieldType) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + if m.env != nil { + fields = append(fields, deployment.FieldEnv) } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *DeploymentMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *DeploymentMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *DeploymentMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return + if m.ref != nil { + fields = append(fields, deployment.FieldRef) } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" 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) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") + if m.status != nil { + fields = append(fields, deployment.FieldStatus) } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") + if m.uid != nil { + fields = append(fields, deployment.FieldUID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + if m.sha != nil { + fields = append(fields, deployment.FieldSha) } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *DeploymentMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetUserID sets the "user_id" field. -func (m *DeploymentMutation) SetUserID(i int64) { - m.user = &i -} - -// UserID returns the value of the "user_id" field in the mutation. -func (m *DeploymentMutation) UserID() (r int64, exists bool) { - v := m.user - if v == nil { - return + if m.html_url != nil { + fields = append(fields, deployment.FieldHTMLURL) } - return *v, true -} - -// OldUserID returns the old "user_id" 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) OldUserID(ctx context.Context) (v int64, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") + if m.production_environment != nil { + fields = append(fields, deployment.FieldProductionEnvironment) } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserID requires an ID field in the mutation") + if m.is_rollback != nil { + fields = append(fields, deployment.FieldIsRollback) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUserID: %w", err) + if m.created_at != nil { + fields = append(fields, deployment.FieldCreatedAt) } - return oldValue.UserID, nil -} - -// ResetUserID resets all changes to the "user_id" field. -func (m *DeploymentMutation) ResetUserID() { - m.user = nil -} - -// SetRepoID sets the "repo_id" field. -func (m *DeploymentMutation) SetRepoID(i int64) { - m.repo = &i -} - -// RepoID returns the value of the "repo_id" field in the mutation. -func (m *DeploymentMutation) RepoID() (r int64, exists bool) { - v := m.repo - if v == nil { - return + if m.updated_at != nil { + fields = append(fields, deployment.FieldUpdatedAt) } - return *v, true -} - -// OldRepoID returns the old "repo_id" 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) 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.user != nil { + fields = append(fields, deployment.FieldUserID) } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRepoID requires an ID field in the mutation") + if m.repo != nil { + fields = append(fields, deployment.FieldRepoID) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRepoID: %w", err) + if m.is_approval_enabled != nil { + fields = append(fields, deployment.FieldIsApprovalEnabled) } - return oldValue.RepoID, nil -} - -// ResetRepoID resets all changes to the "repo_id" field. -func (m *DeploymentMutation) ResetRepoID() { - m.repo = nil -} - -// ClearUser clears the "user" edge to the User entity. -func (m *DeploymentMutation) ClearUser() { - m.cleareduser = true -} - -// UserCleared reports if the "user" edge to the User entity was cleared. -func (m *DeploymentMutation) UserCleared() bool { - return m.cleareduser -} - -// UserIDs returns the "user" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// UserID instead. It exists only for internal usage by the builders. -func (m *DeploymentMutation) UserIDs() (ids []int64) { - if id := m.user; id != nil { - ids = append(ids, *id) + if m.required_approval_count != nil { + fields = append(fields, deployment.FieldRequiredApprovalCount) } - return -} - -// ResetUser resets all changes to the "user" edge. -func (m *DeploymentMutation) ResetUser() { - m.user = nil - m.cleareduser = false -} - -// ClearRepo clears the "repo" edge to the Repo entity. -func (m *DeploymentMutation) ClearRepo() { - m.clearedrepo = true -} - -// RepoCleared reports if the "repo" edge to the Repo entity was cleared. -func (m *DeploymentMutation) 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 *DeploymentMutation) RepoIDs() (ids []int64) { - if id := m.repo; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetRepo resets all changes to the "repo" edge. -func (m *DeploymentMutation) ResetRepo() { - m.repo = nil - m.clearedrepo = false -} - -// AddApprovalIDs adds the "approvals" edge to the Approval entity by ids. -func (m *DeploymentMutation) AddApprovalIDs(ids ...int) { - if m.approvals == nil { - m.approvals = make(map[int]struct{}) - } - for i := range ids { - m.approvals[ids[i]] = struct{}{} - } -} - -// ClearApprovals clears the "approvals" edge to the Approval entity. -func (m *DeploymentMutation) ClearApprovals() { - m.clearedapprovals = true -} - -// ApprovalsCleared reports if the "approvals" edge to the Approval entity was cleared. -func (m *DeploymentMutation) ApprovalsCleared() bool { - return m.clearedapprovals -} - -// RemoveApprovalIDs removes the "approvals" edge to the Approval entity by IDs. -func (m *DeploymentMutation) RemoveApprovalIDs(ids ...int) { - if m.removedapprovals == nil { - m.removedapprovals = make(map[int]struct{}) - } - for i := range ids { - delete(m.approvals, ids[i]) - m.removedapprovals[ids[i]] = struct{}{} - } -} - -// RemovedApprovals returns the removed IDs of the "approvals" edge to the Approval entity. -func (m *DeploymentMutation) RemovedApprovalsIDs() (ids []int) { - for id := range m.removedapprovals { - ids = append(ids, id) - } - return -} - -// ApprovalsIDs returns the "approvals" edge IDs in the mutation. -func (m *DeploymentMutation) ApprovalsIDs() (ids []int) { - for id := range m.approvals { - ids = append(ids, id) - } - return -} - -// ResetApprovals resets all changes to the "approvals" edge. -func (m *DeploymentMutation) ResetApprovals() { - m.approvals = nil - m.clearedapprovals = false - m.removedapprovals = nil -} - -// AddDeploymentStatusIDs adds the "deployment_statuses" edge to the DeploymentStatus entity by ids. -func (m *DeploymentMutation) AddDeploymentStatusIDs(ids ...int) { - if m.deployment_statuses == nil { - m.deployment_statuses = make(map[int]struct{}) - } - for i := range ids { - m.deployment_statuses[ids[i]] = struct{}{} - } -} - -// ClearDeploymentStatuses clears the "deployment_statuses" edge to the DeploymentStatus entity. -func (m *DeploymentMutation) ClearDeploymentStatuses() { - m.cleareddeployment_statuses = true -} - -// DeploymentStatusesCleared reports if the "deployment_statuses" edge to the DeploymentStatus entity was cleared. -func (m *DeploymentMutation) DeploymentStatusesCleared() bool { - return m.cleareddeployment_statuses -} - -// RemoveDeploymentStatusIDs removes the "deployment_statuses" edge to the DeploymentStatus entity by IDs. -func (m *DeploymentMutation) RemoveDeploymentStatusIDs(ids ...int) { - if m.removeddeployment_statuses == nil { - m.removeddeployment_statuses = make(map[int]struct{}) - } - for i := range ids { - delete(m.deployment_statuses, ids[i]) - m.removeddeployment_statuses[ids[i]] = struct{}{} - } -} - -// RemovedDeploymentStatuses returns the removed IDs of the "deployment_statuses" edge to the DeploymentStatus entity. -func (m *DeploymentMutation) RemovedDeploymentStatusesIDs() (ids []int) { - for id := range m.removeddeployment_statuses { - ids = append(ids, id) - } - return -} - -// DeploymentStatusesIDs returns the "deployment_statuses" edge IDs in the mutation. -func (m *DeploymentMutation) DeploymentStatusesIDs() (ids []int) { - for id := range m.deployment_statuses { - ids = append(ids, id) - } - return -} - -// ResetDeploymentStatuses resets all changes to the "deployment_statuses" edge. -func (m *DeploymentMutation) ResetDeploymentStatuses() { - m.deployment_statuses = nil - m.cleareddeployment_statuses = false - m.removeddeployment_statuses = nil -} - -// AddEventIDs adds the "event" edge to the Event entity by ids. -func (m *DeploymentMutation) AddEventIDs(ids ...int) { - if m.event == nil { - m.event = make(map[int]struct{}) - } - for i := range ids { - m.event[ids[i]] = struct{}{} - } -} - -// ClearEvent clears the "event" edge to the Event entity. -func (m *DeploymentMutation) ClearEvent() { - m.clearedevent = true -} - -// EventCleared reports if the "event" edge to the Event entity was cleared. -func (m *DeploymentMutation) EventCleared() bool { - return m.clearedevent -} - -// RemoveEventIDs removes the "event" edge to the Event entity by IDs. -func (m *DeploymentMutation) RemoveEventIDs(ids ...int) { - if m.removedevent == nil { - m.removedevent = make(map[int]struct{}) - } - for i := range ids { - delete(m.event, ids[i]) - m.removedevent[ids[i]] = struct{}{} - } -} - -// RemovedEvent returns the removed IDs of the "event" edge to the Event entity. -func (m *DeploymentMutation) RemovedEventIDs() (ids []int) { - for id := range m.removedevent { - ids = append(ids, id) - } - return -} - -// EventIDs returns the "event" edge IDs in the mutation. -func (m *DeploymentMutation) EventIDs() (ids []int) { - for id := range m.event { - ids = append(ids, id) - } - return -} - -// ResetEvent resets all changes to the "event" edge. -func (m *DeploymentMutation) ResetEvent() { - m.event = nil - m.clearedevent = false - m.removedevent = nil -} - -// Where appends a list predicates to the DeploymentMutation builder. -func (m *DeploymentMutation) Where(ps ...predicate.Deployment) { - m.predicates = append(m.predicates, ps...) -} - -// Op returns the operation name. -func (m *DeploymentMutation) Op() Op { - return m.op -} - -// Type returns the node type of this mutation (Deployment). -func (m *DeploymentMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *DeploymentMutation) Fields() []string { - fields := make([]string, 0, 16) - if m.number != nil { - fields = append(fields, deployment.FieldNumber) - } - if m._type != nil { - fields = append(fields, deployment.FieldType) - } - if m.env != nil { - fields = append(fields, deployment.FieldEnv) - } - if m.ref != nil { - fields = append(fields, deployment.FieldRef) - } - if m.status != nil { - fields = append(fields, deployment.FieldStatus) - } - if m.uid != nil { - fields = append(fields, deployment.FieldUID) - } - if m.sha != nil { - fields = append(fields, deployment.FieldSha) - } - 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) - } - if m.is_approval_enabled != nil { - fields = append(fields, deployment.FieldIsApprovalEnabled) - } - if m.required_approval_count != nil { - fields = append(fields, deployment.FieldRequiredApprovalCount) - } - if m.created_at != nil { - fields = append(fields, deployment.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, deployment.FieldUpdatedAt) - } - if m.user != nil { - fields = append(fields, deployment.FieldUserID) - } - if m.repo != nil { - fields = append(fields, deployment.FieldRepoID) - } - return fields + return fields } // Field returns the value of a field with the given name. The second boolean @@ -3095,10 +2428,6 @@ func (m *DeploymentMutation) Field(name string) (ent.Value, bool) { return m.ProductionEnvironment() case deployment.FieldIsRollback: return m.IsRollback() - case deployment.FieldIsApprovalEnabled: - return m.IsApprovalEnabled() - case deployment.FieldRequiredApprovalCount: - return m.RequiredApprovalCount() case deployment.FieldCreatedAt: return m.CreatedAt() case deployment.FieldUpdatedAt: @@ -3107,6 +2436,10 @@ func (m *DeploymentMutation) Field(name string) (ent.Value, bool) { return m.UserID() case deployment.FieldRepoID: return m.RepoID() + case deployment.FieldIsApprovalEnabled: + return m.IsApprovalEnabled() + case deployment.FieldRequiredApprovalCount: + return m.RequiredApprovalCount() } return nil, false } @@ -3136,10 +2469,6 @@ func (m *DeploymentMutation) OldField(ctx context.Context, name string) (ent.Val return m.OldProductionEnvironment(ctx) case deployment.FieldIsRollback: return m.OldIsRollback(ctx) - case deployment.FieldIsApprovalEnabled: - return m.OldIsApprovalEnabled(ctx) - case deployment.FieldRequiredApprovalCount: - return m.OldRequiredApprovalCount(ctx) case deployment.FieldCreatedAt: return m.OldCreatedAt(ctx) case deployment.FieldUpdatedAt: @@ -3148,6 +2477,10 @@ func (m *DeploymentMutation) OldField(ctx context.Context, name string) (ent.Val return m.OldUserID(ctx) case deployment.FieldRepoID: return m.OldRepoID(ctx) + case deployment.FieldIsApprovalEnabled: + return m.OldIsApprovalEnabled(ctx) + case deployment.FieldRequiredApprovalCount: + return m.OldRequiredApprovalCount(ctx) } return nil, fmt.Errorf("unknown Deployment field %s", name) } @@ -3227,26 +2560,12 @@ func (m *DeploymentMutation) SetField(name string, value ent.Value) error { } m.SetIsRollback(v) return nil - case deployment.FieldIsApprovalEnabled: - v, ok := value.(bool) + case deployment.FieldCreatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetIsApprovalEnabled(v) - return nil - case deployment.FieldRequiredApprovalCount: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetRequiredApprovalCount(v) - return nil - case deployment.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) + m.SetCreatedAt(v) return nil case deployment.FieldUpdatedAt: v, ok := value.(time.Time) @@ -3269,6 +2588,20 @@ func (m *DeploymentMutation) SetField(name string, value ent.Value) error { } m.SetRepoID(v) return nil + case deployment.FieldIsApprovalEnabled: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIsApprovalEnabled(v) + return nil + case deployment.FieldRequiredApprovalCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRequiredApprovalCount(v) + return nil } return fmt.Errorf("unknown Deployment field %s", name) } @@ -3347,6 +2680,12 @@ func (m *DeploymentMutation) ClearedFields() []string { if m.FieldCleared(deployment.FieldHTMLURL) { fields = append(fields, deployment.FieldHTMLURL) } + if m.FieldCleared(deployment.FieldIsApprovalEnabled) { + fields = append(fields, deployment.FieldIsApprovalEnabled) + } + if m.FieldCleared(deployment.FieldRequiredApprovalCount) { + fields = append(fields, deployment.FieldRequiredApprovalCount) + } return fields } @@ -3370,6 +2709,12 @@ func (m *DeploymentMutation) ClearField(name string) error { case deployment.FieldHTMLURL: m.ClearHTMLURL() return nil + case deployment.FieldIsApprovalEnabled: + m.ClearIsApprovalEnabled() + return nil + case deployment.FieldRequiredApprovalCount: + m.ClearRequiredApprovalCount() + return nil } return fmt.Errorf("unknown Deployment nullable field %s", name) } @@ -3408,12 +2753,6 @@ func (m *DeploymentMutation) ResetField(name string) error { case deployment.FieldIsRollback: m.ResetIsRollback() return nil - case deployment.FieldIsApprovalEnabled: - m.ResetIsApprovalEnabled() - return nil - case deployment.FieldRequiredApprovalCount: - m.ResetRequiredApprovalCount() - return nil case deployment.FieldCreatedAt: m.ResetCreatedAt() return nil @@ -3426,6 +2765,12 @@ func (m *DeploymentMutation) ResetField(name string) error { case deployment.FieldRepoID: m.ResetRepoID() return nil + case deployment.FieldIsApprovalEnabled: + m.ResetIsApprovalEnabled() + return nil + case deployment.FieldRequiredApprovalCount: + m.ResetRequiredApprovalCount() + return nil } return fmt.Errorf("unknown Deployment field %s", name) } @@ -3439,8 +2784,8 @@ func (m *DeploymentMutation) AddedEdges() []string { if m.repo != nil { edges = append(edges, deployment.EdgeRepo) } - if m.approvals != nil { - edges = append(edges, deployment.EdgeApprovals) + if m.reviews != nil { + edges = append(edges, deployment.EdgeReviews) } if m.deployment_statuses != nil { edges = append(edges, deployment.EdgeDeploymentStatuses) @@ -3463,9 +2808,9 @@ func (m *DeploymentMutation) AddedIDs(name string) []ent.Value { if id := m.repo; id != nil { return []ent.Value{*id} } - case deployment.EdgeApprovals: - ids := make([]ent.Value, 0, len(m.approvals)) - for id := range m.approvals { + case deployment.EdgeReviews: + ids := make([]ent.Value, 0, len(m.reviews)) + for id := range m.reviews { ids = append(ids, id) } return ids @@ -3488,8 +2833,8 @@ func (m *DeploymentMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *DeploymentMutation) RemovedEdges() []string { edges := make([]string, 0, 5) - if m.removedapprovals != nil { - edges = append(edges, deployment.EdgeApprovals) + if m.removedreviews != nil { + edges = append(edges, deployment.EdgeReviews) } if m.removeddeployment_statuses != nil { edges = append(edges, deployment.EdgeDeploymentStatuses) @@ -3504,9 +2849,9 @@ func (m *DeploymentMutation) RemovedEdges() []string { // the given name in this mutation. func (m *DeploymentMutation) RemovedIDs(name string) []ent.Value { switch name { - case deployment.EdgeApprovals: - ids := make([]ent.Value, 0, len(m.removedapprovals)) - for id := range m.removedapprovals { + case deployment.EdgeReviews: + ids := make([]ent.Value, 0, len(m.removedreviews)) + for id := range m.removedreviews { ids = append(ids, id) } return ids @@ -3535,8 +2880,8 @@ func (m *DeploymentMutation) ClearedEdges() []string { if m.clearedrepo { edges = append(edges, deployment.EdgeRepo) } - if m.clearedapprovals { - edges = append(edges, deployment.EdgeApprovals) + if m.clearedreviews { + edges = append(edges, deployment.EdgeReviews) } if m.cleareddeployment_statuses { edges = append(edges, deployment.EdgeDeploymentStatuses) @@ -3555,8 +2900,8 @@ func (m *DeploymentMutation) EdgeCleared(name string) bool { return m.cleareduser case deployment.EdgeRepo: return m.clearedrepo - case deployment.EdgeApprovals: - return m.clearedapprovals + case deployment.EdgeReviews: + return m.clearedreviews case deployment.EdgeDeploymentStatuses: return m.cleareddeployment_statuses case deployment.EdgeEvent: @@ -3589,8 +2934,8 @@ func (m *DeploymentMutation) ResetEdge(name string) error { case deployment.EdgeRepo: m.ResetRepo() return nil - case deployment.EdgeApprovals: - m.ResetApprovals() + case deployment.EdgeReviews: + m.ResetReviews() return nil case deployment.EdgeDeploymentStatuses: m.ResetDeploymentStatuses() @@ -3851,302 +3196,1117 @@ func (m *DeploymentStatisticsMutation) AddedRollbackCount() (r int, exists bool) if v == nil { return } - return *v, true + return *v, true +} + +// 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 +} + +// 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) OldAdditions(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldAdditions is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + 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 OldAdditions: %w", err) + } + return oldValue.Additions, nil +} + +// AddAdditions adds i to the "additions" field. +func (m *DeploymentStatisticsMutation) AddAdditions(i int) { + if m.addadditions != nil { + *m.addadditions += i + } else { + m.addadditions = &i + } +} + +// 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 +} + +// 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 +} + +// SetLeadTimeSeconds sets the "lead_time_seconds" field. +func (m *DeploymentStatisticsMutation) SetLeadTimeSeconds(i int) { + m.lead_time_seconds = &i + m.addlead_time_seconds = nil +} + +// LeadTimeSeconds returns the value of the "lead_time_seconds" field in the mutation. +func (m *DeploymentStatisticsMutation) LeadTimeSeconds() (r int, exists bool) { + v := m.lead_time_seconds + if v == nil { + return + } + return *v, true +} + +// OldLeadTimeSeconds returns the old "lead_time_seconds" 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) OldLeadTimeSeconds(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldLeadTimeSeconds is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldLeadTimeSeconds requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLeadTimeSeconds: %w", err) + } + return oldValue.LeadTimeSeconds, nil +} + +// AddLeadTimeSeconds adds i to the "lead_time_seconds" field. +func (m *DeploymentStatisticsMutation) AddLeadTimeSeconds(i int) { + if m.addlead_time_seconds != nil { + *m.addlead_time_seconds += i + } else { + m.addlead_time_seconds = &i + } +} + +// AddedLeadTimeSeconds returns the value that was added to the "lead_time_seconds" field in this mutation. +func (m *DeploymentStatisticsMutation) AddedLeadTimeSeconds() (r int, exists bool) { + v := m.addlead_time_seconds + if v == nil { + return + } + return *v, true +} + +// ResetLeadTimeSeconds resets all changes to the "lead_time_seconds" field. +func (m *DeploymentStatisticsMutation) ResetLeadTimeSeconds() { + m.lead_time_seconds = nil + m.addlead_time_seconds = nil +} + +// SetCommitCount sets the "commit_count" field. +func (m *DeploymentStatisticsMutation) SetCommitCount(i int) { + m.commit_count = &i + m.addcommit_count = nil +} + +// CommitCount returns the value of the "commit_count" field in the mutation. +func (m *DeploymentStatisticsMutation) CommitCount() (r int, exists bool) { + v := m.commit_count + if v == nil { + return + } + return *v, true +} + +// OldCommitCount returns the old "commit_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) OldCommitCount(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldCommitCount is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldCommitCount requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCommitCount: %w", err) + } + return oldValue.CommitCount, nil +} + +// AddCommitCount adds i to the "commit_count" field. +func (m *DeploymentStatisticsMutation) AddCommitCount(i int) { + if m.addcommit_count != nil { + *m.addcommit_count += i + } else { + m.addcommit_count = &i + } +} + +// AddedCommitCount returns the value that was added to the "commit_count" field in this mutation. +func (m *DeploymentStatisticsMutation) AddedCommitCount() (r int, exists bool) { + v := m.addcommit_count + if v == nil { + return + } + return *v, true +} + +// ResetCommitCount resets all changes to the "commit_count" field. +func (m *DeploymentStatisticsMutation) ResetCommitCount() { + m.commit_count = nil + m.addcommit_count = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *DeploymentStatisticsMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *DeploymentStatisticsMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" 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) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *DeploymentStatisticsMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *DeploymentStatisticsMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *DeploymentStatisticsMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" 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) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +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...) +} + +// Op returns the operation name. +func (m *DeploymentStatisticsMutation) Op() Op { + return m.op +} + +// Type returns the node type of this mutation (DeploymentStatistics). +func (m *DeploymentStatisticsMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *DeploymentStatisticsMutation) Fields() []string { + fields := make([]string, 0, 11) + 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.lead_time_seconds != nil { + fields = append(fields, deploymentstatistics.FieldLeadTimeSeconds) + } + if m.commit_count != nil { + fields = append(fields, deploymentstatistics.FieldCommitCount) + } + 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 +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *DeploymentStatisticsMutation) Field(name string) (ent.Value, bool) { + switch 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.FieldLeadTimeSeconds: + return m.LeadTimeSeconds() + case deploymentstatistics.FieldCommitCount: + return m.CommitCount() + case deploymentstatistics.FieldCreatedAt: + return m.CreatedAt() + case deploymentstatistics.FieldUpdatedAt: + return m.UpdatedAt() + case deploymentstatistics.FieldRepoID: + return m.RepoID() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *DeploymentStatisticsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + 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.FieldLeadTimeSeconds: + return m.OldLeadTimeSeconds(ctx) + case deploymentstatistics.FieldCommitCount: + return m.OldCommitCount(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) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *DeploymentStatisticsMutation) SetField(name string, value ent.Value) error { + switch name { + case deploymentstatistics.FieldEnv: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEnv(v) + return nil + case deploymentstatistics.FieldCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCount(v) + return nil + case deploymentstatistics.FieldRollbackCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRollbackCount(v) + return nil + case deploymentstatistics.FieldAdditions: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + 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.FieldLeadTimeSeconds: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLeadTimeSeconds(v) + return nil + case deploymentstatistics.FieldCommitCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCommitCount(v) + return nil + case deploymentstatistics.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case deploymentstatistics.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + 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) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *DeploymentStatisticsMutation) AddedFields() []string { + var fields []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) + } + if m.addlead_time_seconds != nil { + fields = append(fields, deploymentstatistics.FieldLeadTimeSeconds) + } + if m.addcommit_count != nil { + fields = append(fields, deploymentstatistics.FieldCommitCount) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +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() + case deploymentstatistics.FieldLeadTimeSeconds: + return m.AddedLeadTimeSeconds() + case deploymentstatistics.FieldCommitCount: + return m.AddedCommitCount() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *DeploymentStatisticsMutation) AddField(name string, value ent.Value) error { + switch name { + case deploymentstatistics.FieldCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + 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 + case deploymentstatistics.FieldLeadTimeSeconds: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddLeadTimeSeconds(v) + return nil + case deploymentstatistics.FieldCommitCount: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCommitCount(v) + return nil + } + return fmt.Errorf("unknown DeploymentStatistics numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *DeploymentStatisticsMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *DeploymentStatisticsMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *DeploymentStatisticsMutation) ClearField(name string) error { + return fmt.Errorf("unknown DeploymentStatistics nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *DeploymentStatisticsMutation) ResetField(name string) error { + switch name { + 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.FieldLeadTimeSeconds: + m.ResetLeadTimeSeconds() + return nil + case deploymentstatistics.FieldCommitCount: + m.ResetCommitCount() + 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, 1) + if m.repo != nil { + edges = append(edges, deploymentstatistics.EdgeRepo) + } + return edges } -// ResetRollbackCount resets all changes to the "rollback_count" field. -func (m *DeploymentStatisticsMutation) ResetRollbackCount() { - m.rollback_count = nil - m.addrollback_count = nil +// 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 } -// SetAdditions sets the "additions" field. -func (m *DeploymentStatisticsMutation) SetAdditions(i int) { - m.additions = &i - m.addadditions = nil +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *DeploymentStatisticsMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges } -// 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 +// 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 *v, true + return nil } -// 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) OldAdditions(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldAdditions is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - 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 OldAdditions: %w", err) +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *DeploymentStatisticsMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedrepo { + edges = append(edges, deploymentstatistics.EdgeRepo) } - return oldValue.Additions, nil + return edges } -// AddAdditions adds i to the "additions" field. -func (m *DeploymentStatisticsMutation) AddAdditions(i int) { - if m.addadditions != nil { - *m.addadditions += i - } else { - m.addadditions = &i +// 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 } -// 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 +// 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 *v, true + return fmt.Errorf("unknown DeploymentStatistics unique edge %s", name) } -// ResetAdditions resets all changes to the "additions" field. -func (m *DeploymentStatisticsMutation) ResetAdditions() { - m.additions = nil - m.addadditions = nil +// 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) } -// SetDeletions sets the "deletions" field. -func (m *DeploymentStatisticsMutation) SetDeletions(i int) { - m.deletions = &i - m.adddeletions = nil +// DeploymentStatusMutation represents an operation that mutates the DeploymentStatus nodes in the graph. +type DeploymentStatusMutation struct { + config + op Op + typ string + id *int + status *string + description *string + log_url *string + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + deployment *int + cleareddeployment bool + done bool + oldValue func(context.Context) (*DeploymentStatus, error) + predicates []predicate.DeploymentStatus } -// 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 -} +var _ ent.Mutation = (*DeploymentStatusMutation)(nil) -// 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") +// deploymentstatusOption allows management of the mutation configuration using functional options. +type deploymentstatusOption func(*DeploymentStatusMutation) + +// newDeploymentStatusMutation creates new mutation for the DeploymentStatus entity. +func newDeploymentStatusMutation(c config, op Op, opts ...deploymentstatusOption) *DeploymentStatusMutation { + m := &DeploymentStatusMutation{ + config: c, + op: op, + typ: TypeDeploymentStatus, + clearedFields: make(map[string]struct{}), } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeletions: %w", err) + for _, opt := range opts { + opt(m) } - return oldValue.Deletions, nil + return m } -// AddDeletions adds i to the "deletions" field. -func (m *DeploymentStatisticsMutation) AddDeletions(i int) { - if m.adddeletions != nil { - *m.adddeletions += i - } else { - m.adddeletions = &i +// withDeploymentStatusID sets the ID field of the mutation. +func withDeploymentStatusID(id int) deploymentstatusOption { + return func(m *DeploymentStatusMutation) { + var ( + err error + once sync.Once + value *DeploymentStatus + ) + m.oldValue = func(ctx context.Context) (*DeploymentStatus, error) { + once.Do(func() { + if m.done { + err = fmt.Errorf("querying old values post mutation is not allowed") + } else { + value, err = m.Client().DeploymentStatus.Get(ctx, id) + } + }) + return value, err + } + m.id = &id } } -// 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 +// withDeploymentStatus sets the old DeploymentStatus of the mutation. +func withDeploymentStatus(node *DeploymentStatus) deploymentstatusOption { + return func(m *DeploymentStatusMutation) { + m.oldValue = func(context.Context) (*DeploymentStatus, error) { + return node, nil + } + m.id = &node.ID } - 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 +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m DeploymentStatusMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client } -// 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 +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m DeploymentStatusMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, fmt.Errorf("ent: mutation is not running in a transaction") } - return *v, true + tx := &Tx{config: m.config} + tx.init() + return tx, nil } -// 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) +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *DeploymentStatusMutation) ID() (id int, exists bool) { + if m.id == nil { + return } - return oldValue.Changes, nil + return *m.id, true } -// AddChanges adds i to the "changes" field. -func (m *DeploymentStatisticsMutation) AddChanges(i int) { - if m.addchanges != nil { - *m.addchanges += i - } else { - m.addchanges = &i - } +// SetStatus sets the "status" field. +func (m *DeploymentStatusMutation) SetStatus(s string) { + m.status = &s } -// 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 +// Status returns the value of the "status" field in the mutation. +func (m *DeploymentStatusMutation) Status() (r string, exists bool) { + v := m.status 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 +// OldStatus returns the old "status" field's value of the DeploymentStatus entity. +// If the DeploymentStatus 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 *DeploymentStatusMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil } -// SetLeadTimeSeconds sets the "lead_time_seconds" field. -func (m *DeploymentStatisticsMutation) SetLeadTimeSeconds(i int) { - m.lead_time_seconds = &i - m.addlead_time_seconds = nil +// ResetStatus resets all changes to the "status" field. +func (m *DeploymentStatusMutation) ResetStatus() { + m.status = nil } -// LeadTimeSeconds returns the value of the "lead_time_seconds" field in the mutation. -func (m *DeploymentStatisticsMutation) LeadTimeSeconds() (r int, exists bool) { - v := m.lead_time_seconds +// SetDescription sets the "description" field. +func (m *DeploymentStatusMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *DeploymentStatusMutation) Description() (r string, exists bool) { + v := m.description if v == nil { return } return *v, true } -// OldLeadTimeSeconds returns the old "lead_time_seconds" field's value of the DeploymentStatistics entity. -// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database. +// OldDescription returns the old "description" field's value of the DeploymentStatus entity. +// If the DeploymentStatus 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) OldLeadTimeSeconds(ctx context.Context) (v int, err error) { +func (m *DeploymentStatusMutation) OldDescription(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLeadTimeSeconds is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldDescription is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLeadTimeSeconds requires an ID field in the mutation") + return v, fmt.Errorf("OldDescription requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldLeadTimeSeconds: %w", err) + return v, fmt.Errorf("querying old value for OldDescription: %w", err) } - return oldValue.LeadTimeSeconds, nil + return oldValue.Description, nil } -// AddLeadTimeSeconds adds i to the "lead_time_seconds" field. -func (m *DeploymentStatisticsMutation) AddLeadTimeSeconds(i int) { - if m.addlead_time_seconds != nil { - *m.addlead_time_seconds += i - } else { - m.addlead_time_seconds = &i - } +// ClearDescription clears the value of the "description" field. +func (m *DeploymentStatusMutation) ClearDescription() { + m.description = nil + m.clearedFields[deploymentstatus.FieldDescription] = struct{}{} } -// AddedLeadTimeSeconds returns the value that was added to the "lead_time_seconds" field in this mutation. -func (m *DeploymentStatisticsMutation) AddedLeadTimeSeconds() (r int, exists bool) { - v := m.addlead_time_seconds - if v == nil { - return - } - return *v, true +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *DeploymentStatusMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[deploymentstatus.FieldDescription] + return ok } -// ResetLeadTimeSeconds resets all changes to the "lead_time_seconds" field. -func (m *DeploymentStatisticsMutation) ResetLeadTimeSeconds() { - m.lead_time_seconds = nil - m.addlead_time_seconds = nil +// ResetDescription resets all changes to the "description" field. +func (m *DeploymentStatusMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, deploymentstatus.FieldDescription) } -// SetCommitCount sets the "commit_count" field. -func (m *DeploymentStatisticsMutation) SetCommitCount(i int) { - m.commit_count = &i - m.addcommit_count = nil +// SetLogURL sets the "log_url" field. +func (m *DeploymentStatusMutation) SetLogURL(s string) { + m.log_url = &s } -// CommitCount returns the value of the "commit_count" field in the mutation. -func (m *DeploymentStatisticsMutation) CommitCount() (r int, exists bool) { - v := m.commit_count +// LogURL returns the value of the "log_url" field in the mutation. +func (m *DeploymentStatusMutation) LogURL() (r string, exists bool) { + v := m.log_url if v == nil { return } return *v, true } -// OldCommitCount returns the old "commit_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. +// OldLogURL returns the old "log_url" field's value of the DeploymentStatus entity. +// If the DeploymentStatus 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) OldCommitCount(ctx context.Context) (v int, err error) { +func (m *DeploymentStatusMutation) OldLogURL(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCommitCount is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldLogURL is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCommitCount requires an ID field in the mutation") + return v, fmt.Errorf("OldLogURL requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCommitCount: %w", err) + return v, fmt.Errorf("querying old value for OldLogURL: %w", err) } - return oldValue.CommitCount, nil + return oldValue.LogURL, nil } -// AddCommitCount adds i to the "commit_count" field. -func (m *DeploymentStatisticsMutation) AddCommitCount(i int) { - if m.addcommit_count != nil { - *m.addcommit_count += i - } else { - m.addcommit_count = &i - } +// ClearLogURL clears the value of the "log_url" field. +func (m *DeploymentStatusMutation) ClearLogURL() { + m.log_url = nil + m.clearedFields[deploymentstatus.FieldLogURL] = struct{}{} } -// AddedCommitCount returns the value that was added to the "commit_count" field in this mutation. -func (m *DeploymentStatisticsMutation) AddedCommitCount() (r int, exists bool) { - v := m.addcommit_count - if v == nil { - return - } - return *v, true +// LogURLCleared returns if the "log_url" field was cleared in this mutation. +func (m *DeploymentStatusMutation) LogURLCleared() bool { + _, ok := m.clearedFields[deploymentstatus.FieldLogURL] + return ok } -// ResetCommitCount resets all changes to the "commit_count" field. -func (m *DeploymentStatisticsMutation) ResetCommitCount() { - m.commit_count = nil - m.addcommit_count = nil +// ResetLogURL resets all changes to the "log_url" field. +func (m *DeploymentStatusMutation) ResetLogURL() { + m.log_url = nil + delete(m.clearedFields, deploymentstatus.FieldLogURL) } // SetCreatedAt sets the "created_at" field. -func (m *DeploymentStatisticsMutation) SetCreatedAt(t time.Time) { +func (m *DeploymentStatusMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *DeploymentStatisticsMutation) CreatedAt() (r time.Time, exists bool) { +func (m *DeploymentStatusMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -4154,10 +4314,10 @@ func (m *DeploymentStatisticsMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the DeploymentStatistics entity. -// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the DeploymentStatus entity. +// If the DeploymentStatus 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) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *DeploymentStatusMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } @@ -4172,17 +4332,17 @@ func (m *DeploymentStatisticsMutation) OldCreatedAt(ctx context.Context) (v time } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *DeploymentStatisticsMutation) ResetCreatedAt() { +func (m *DeploymentStatusMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *DeploymentStatisticsMutation) SetUpdatedAt(t time.Time) { +func (m *DeploymentStatusMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *DeploymentStatisticsMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *DeploymentStatusMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -4190,10 +4350,10 @@ func (m *DeploymentStatisticsMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the DeploymentStatistics entity. -// If the DeploymentStatistics object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the DeploymentStatus entity. +// If the DeploymentStatus 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) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *DeploymentStatusMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } @@ -4208,124 +4368,109 @@ func (m *DeploymentStatisticsMutation) OldUpdatedAt(ctx context.Context) (v time } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *DeploymentStatisticsMutation) ResetUpdatedAt() { +func (m *DeploymentStatusMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetRepoID sets the "repo_id" field. -func (m *DeploymentStatisticsMutation) SetRepoID(i int64) { - m.repo = &i +// SetDeploymentID sets the "deployment_id" field. +func (m *DeploymentStatusMutation) SetDeploymentID(i int) { + m.deployment = &i } -// RepoID returns the value of the "repo_id" field in the mutation. -func (m *DeploymentStatisticsMutation) RepoID() (r int64, exists bool) { - v := m.repo +// DeploymentID returns the value of the "deployment_id" field in the mutation. +func (m *DeploymentStatusMutation) DeploymentID() (r int, exists bool) { + v := m.deployment 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. +// OldDeploymentID returns the old "deployment_id" field's value of the DeploymentStatus entity. +// If the DeploymentStatus 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) { +func (m *DeploymentStatusMutation) OldDeploymentID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldDeploymentID 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") + return v, fmt.Errorf("OldDeploymentID 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 v, fmt.Errorf("querying old value for OldDeploymentID: %w", err) } - return oldValue.RepoID, nil + return oldValue.DeploymentID, nil } -// ResetRepoID resets all changes to the "repo_id" field. -func (m *DeploymentStatisticsMutation) ResetRepoID() { - m.repo = nil +// ResetDeploymentID resets all changes to the "deployment_id" field. +func (m *DeploymentStatusMutation) ResetDeploymentID() { + m.deployment = nil } -// ClearRepo clears the "repo" edge to the Repo entity. -func (m *DeploymentStatisticsMutation) ClearRepo() { - m.clearedrepo = true +// ClearDeployment clears the "deployment" edge to the Deployment entity. +func (m *DeploymentStatusMutation) ClearDeployment() { + m.cleareddeployment = true } -// RepoCleared reports if the "repo" edge to the Repo entity was cleared. -func (m *DeploymentStatisticsMutation) RepoCleared() bool { - return m.clearedrepo +// DeploymentCleared reports if the "deployment" edge to the Deployment entity was cleared. +func (m *DeploymentStatusMutation) DeploymentCleared() bool { + return m.cleareddeployment } -// RepoIDs returns the "repo" edge IDs in the mutation. +// DeploymentIDs returns the "deployment" 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 { +// DeploymentID instead. It exists only for internal usage by the builders. +func (m *DeploymentStatusMutation) DeploymentIDs() (ids []int) { + if id := m.deployment; 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 +// ResetDeployment resets all changes to the "deployment" edge. +func (m *DeploymentStatusMutation) ResetDeployment() { + m.deployment = nil + m.cleareddeployment = false } -// Where appends a list predicates to the DeploymentStatisticsMutation builder. -func (m *DeploymentStatisticsMutation) Where(ps ...predicate.DeploymentStatistics) { +// Where appends a list predicates to the DeploymentStatusMutation builder. +func (m *DeploymentStatusMutation) Where(ps ...predicate.DeploymentStatus) { m.predicates = append(m.predicates, ps...) } // Op returns the operation name. -func (m *DeploymentStatisticsMutation) Op() Op { +func (m *DeploymentStatusMutation) Op() Op { return m.op } - -// Type returns the node type of this mutation (DeploymentStatistics). -func (m *DeploymentStatisticsMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *DeploymentStatisticsMutation) Fields() []string { - fields := make([]string, 0, 11) - 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) + +// Type returns the node type of this mutation (DeploymentStatus). +func (m *DeploymentStatusMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *DeploymentStatusMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.status != nil { + fields = append(fields, deploymentstatus.FieldStatus) } - if m.lead_time_seconds != nil { - fields = append(fields, deploymentstatistics.FieldLeadTimeSeconds) + if m.description != nil { + fields = append(fields, deploymentstatus.FieldDescription) } - if m.commit_count != nil { - fields = append(fields, deploymentstatistics.FieldCommitCount) + if m.log_url != nil { + fields = append(fields, deploymentstatus.FieldLogURL) } if m.created_at != nil { - fields = append(fields, deploymentstatistics.FieldCreatedAt) + fields = append(fields, deploymentstatus.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, deploymentstatistics.FieldUpdatedAt) + fields = append(fields, deploymentstatus.FieldUpdatedAt) } - if m.repo != nil { - fields = append(fields, deploymentstatistics.FieldRepoID) + if m.deployment != nil { + fields = append(fields, deploymentstatus.FieldDeploymentID) } return fields } @@ -4333,30 +4478,20 @@ func (m *DeploymentStatisticsMutation) Fields() []string { // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *DeploymentStatisticsMutation) Field(name string) (ent.Value, bool) { +func (m *DeploymentStatusMutation) Field(name string) (ent.Value, bool) { switch 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.FieldLeadTimeSeconds: - return m.LeadTimeSeconds() - case deploymentstatistics.FieldCommitCount: - return m.CommitCount() - case deploymentstatistics.FieldCreatedAt: + case deploymentstatus.FieldStatus: + return m.Status() + case deploymentstatus.FieldDescription: + return m.Description() + case deploymentstatus.FieldLogURL: + return m.LogURL() + case deploymentstatus.FieldCreatedAt: return m.CreatedAt() - case deploymentstatistics.FieldUpdatedAt: + case deploymentstatus.FieldUpdatedAt: return m.UpdatedAt() - case deploymentstatistics.FieldRepoID: - return m.RepoID() + case deploymentstatus.FieldDeploymentID: + return m.DeploymentID() } return nil, false } @@ -4364,167 +4499,87 @@ func (m *DeploymentStatisticsMutation) Field(name string) (ent.Value, bool) { // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. -func (m *DeploymentStatisticsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *DeploymentStatusMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - 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.FieldLeadTimeSeconds: - return m.OldLeadTimeSeconds(ctx) - case deploymentstatistics.FieldCommitCount: - return m.OldCommitCount(ctx) - case deploymentstatistics.FieldCreatedAt: + case deploymentstatus.FieldStatus: + return m.OldStatus(ctx) + case deploymentstatus.FieldDescription: + return m.OldDescription(ctx) + case deploymentstatus.FieldLogURL: + return m.OldLogURL(ctx) + case deploymentstatus.FieldCreatedAt: return m.OldCreatedAt(ctx) - case deploymentstatistics.FieldUpdatedAt: + case deploymentstatus.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case deploymentstatistics.FieldRepoID: - return m.OldRepoID(ctx) + case deploymentstatus.FieldDeploymentID: + return m.OldDeploymentID(ctx) } - return nil, fmt.Errorf("unknown DeploymentStatistics field %s", name) + return nil, fmt.Errorf("unknown DeploymentStatus field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *DeploymentStatisticsMutation) SetField(name string, value ent.Value) error { +func (m *DeploymentStatusMutation) SetField(name string, value ent.Value) error { switch name { - case deploymentstatistics.FieldEnv: + case deploymentstatus.FieldStatus: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetEnv(v) - return nil - case deploymentstatistics.FieldCount: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCount(v) - return nil - case deploymentstatistics.FieldRollbackCount: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetRollbackCount(v) - return nil - case deploymentstatistics.FieldAdditions: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - 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) + m.SetStatus(v) return nil - case deploymentstatistics.FieldLeadTimeSeconds: - v, ok := value.(int) + case deploymentstatus.FieldDescription: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetLeadTimeSeconds(v) + m.SetDescription(v) return nil - case deploymentstatistics.FieldCommitCount: - v, ok := value.(int) + case deploymentstatus.FieldLogURL: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCommitCount(v) + m.SetLogURL(v) return nil - case deploymentstatistics.FieldCreatedAt: + case deploymentstatus.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil - case deploymentstatistics.FieldUpdatedAt: + case deploymentstatus.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUpdatedAt(v) return nil - case deploymentstatistics.FieldRepoID: - v, ok := value.(int64) + case deploymentstatus.FieldDeploymentID: + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetRepoID(v) + m.SetDeploymentID(v) return nil } - return fmt.Errorf("unknown DeploymentStatistics field %s", name) + return fmt.Errorf("unknown DeploymentStatus field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *DeploymentStatisticsMutation) AddedFields() []string { +func (m *DeploymentStatusMutation) AddedFields() []string { var fields []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) - } - if m.addlead_time_seconds != nil { - fields = append(fields, deploymentstatistics.FieldLeadTimeSeconds) - } - if m.addcommit_count != nil { - fields = append(fields, deploymentstatistics.FieldCommitCount) - } return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *DeploymentStatisticsMutation) AddedField(name string) (ent.Value, bool) { +func (m *DeploymentStatusMutation) 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() - case deploymentstatistics.FieldLeadTimeSeconds: - return m.AddedLeadTimeSeconds() - case deploymentstatistics.FieldCommitCount: - return m.AddedCommitCount() } return nil, false } @@ -4532,136 +4587,87 @@ func (m *DeploymentStatisticsMutation) AddedField(name string) (ent.Value, bool) // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *DeploymentStatisticsMutation) AddField(name string, value ent.Value) error { +func (m *DeploymentStatusMutation) AddField(name string, value ent.Value) error { switch name { - case deploymentstatistics.FieldCount: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - 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 - case deploymentstatistics.FieldLeadTimeSeconds: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddLeadTimeSeconds(v) - return nil - case deploymentstatistics.FieldCommitCount: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddCommitCount(v) - return nil } - return fmt.Errorf("unknown DeploymentStatistics numeric field %s", name) + return fmt.Errorf("unknown DeploymentStatus numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *DeploymentStatisticsMutation) ClearedFields() []string { - return nil +func (m *DeploymentStatusMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(deploymentstatus.FieldDescription) { + fields = append(fields, deploymentstatus.FieldDescription) + } + if m.FieldCleared(deploymentstatus.FieldLogURL) { + fields = append(fields, deploymentstatus.FieldLogURL) + } + return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *DeploymentStatisticsMutation) FieldCleared(name string) bool { +func (m *DeploymentStatusMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *DeploymentStatisticsMutation) ClearField(name string) error { - return fmt.Errorf("unknown DeploymentStatistics nullable field %s", name) +func (m *DeploymentStatusMutation) ClearField(name string) error { + switch name { + case deploymentstatus.FieldDescription: + m.ClearDescription() + return nil + case deploymentstatus.FieldLogURL: + m.ClearLogURL() + return nil + } + return fmt.Errorf("unknown DeploymentStatus nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *DeploymentStatisticsMutation) ResetField(name string) error { +func (m *DeploymentStatusMutation) ResetField(name string) error { switch name { - 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() + case deploymentstatus.FieldStatus: + m.ResetStatus() return nil - case deploymentstatistics.FieldLeadTimeSeconds: - m.ResetLeadTimeSeconds() + case deploymentstatus.FieldDescription: + m.ResetDescription() return nil - case deploymentstatistics.FieldCommitCount: - m.ResetCommitCount() + case deploymentstatus.FieldLogURL: + m.ResetLogURL() return nil - case deploymentstatistics.FieldCreatedAt: + case deploymentstatus.FieldCreatedAt: m.ResetCreatedAt() return nil - case deploymentstatistics.FieldUpdatedAt: + case deploymentstatus.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case deploymentstatistics.FieldRepoID: - m.ResetRepoID() + case deploymentstatus.FieldDeploymentID: + m.ResetDeploymentID() return nil } - return fmt.Errorf("unknown DeploymentStatistics field %s", name) + return fmt.Errorf("unknown DeploymentStatus field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *DeploymentStatisticsMutation) AddedEdges() []string { +func (m *DeploymentStatusMutation) AddedEdges() []string { edges := make([]string, 0, 1) - if m.repo != nil { - edges = append(edges, deploymentstatistics.EdgeRepo) + if m.deployment != nil { + edges = append(edges, deploymentstatus.EdgeDeployment) } 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 { +func (m *DeploymentStatusMutation) AddedIDs(name string) []ent.Value { switch name { - case deploymentstatistics.EdgeRepo: - if id := m.repo; id != nil { + case deploymentstatus.EdgeDeployment: + if id := m.deployment; id != nil { return []ent.Value{*id} } } @@ -4669,90 +4675,96 @@ func (m *DeploymentStatisticsMutation) AddedIDs(name string) []ent.Value { } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *DeploymentStatisticsMutation) RemovedEdges() []string { +func (m *DeploymentStatusMutation) RemovedEdges() []string { 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 { +func (m *DeploymentStatusMutation) 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 { +func (m *DeploymentStatusMutation) ClearedEdges() []string { edges := make([]string, 0, 1) - if m.clearedrepo { - edges = append(edges, deploymentstatistics.EdgeRepo) + if m.cleareddeployment { + edges = append(edges, deploymentstatus.EdgeDeployment) } 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 { +func (m *DeploymentStatusMutation) EdgeCleared(name string) bool { switch name { - case deploymentstatistics.EdgeRepo: - return m.clearedrepo + case deploymentstatus.EdgeDeployment: + return m.cleareddeployment } 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 { +func (m *DeploymentStatusMutation) ClearEdge(name string) error { switch name { - case deploymentstatistics.EdgeRepo: - m.ClearRepo() + case deploymentstatus.EdgeDeployment: + m.ClearDeployment() return nil } - return fmt.Errorf("unknown DeploymentStatistics unique edge %s", name) + return fmt.Errorf("unknown DeploymentStatus 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 { +func (m *DeploymentStatusMutation) ResetEdge(name string) error { switch name { - case deploymentstatistics.EdgeRepo: - m.ResetRepo() + case deploymentstatus.EdgeDeployment: + m.ResetDeployment() return nil } - return fmt.Errorf("unknown DeploymentStatistics edge %s", name) + return fmt.Errorf("unknown DeploymentStatus edge %s", name) } -// DeploymentStatusMutation represents an operation that mutates the DeploymentStatus nodes in the graph. -type DeploymentStatusMutation struct { +// EventMutation represents an operation that mutates the Event nodes in the graph. +type EventMutation struct { config - op Op - typ string - id *int - status *string - description *string - log_url *string - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - deployment *int - cleareddeployment bool - done bool - oldValue func(context.Context) (*DeploymentStatus, error) - predicates []predicate.DeploymentStatus + op Op + typ string + id *int + kind *event.Kind + _type *event.Type + created_at *time.Time + approval_id *int + addapproval_id *int + deleted_id *int + adddeleted_id *int + clearedFields map[string]struct{} + deployment *int + cleareddeployment bool + review *int + clearedreview bool + notification_record *int + clearednotification_record bool + done bool + oldValue func(context.Context) (*Event, error) + predicates []predicate.Event } -var _ ent.Mutation = (*DeploymentStatusMutation)(nil) +var _ ent.Mutation = (*EventMutation)(nil) -// deploymentstatusOption allows management of the mutation configuration using functional options. -type deploymentstatusOption func(*DeploymentStatusMutation) +// eventOption allows management of the mutation configuration using functional options. +type eventOption func(*EventMutation) -// newDeploymentStatusMutation creates new mutation for the DeploymentStatus entity. -func newDeploymentStatusMutation(c config, op Op, opts ...deploymentstatusOption) *DeploymentStatusMutation { - m := &DeploymentStatusMutation{ +// newEventMutation creates new mutation for the Event entity. +func newEventMutation(c config, op Op, opts ...eventOption) *EventMutation { + m := &EventMutation{ config: c, op: op, - typ: TypeDeploymentStatus, + typ: TypeEvent, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -4761,20 +4773,20 @@ func newDeploymentStatusMutation(c config, op Op, opts ...deploymentstatusOption return m } -// withDeploymentStatusID sets the ID field of the mutation. -func withDeploymentStatusID(id int) deploymentstatusOption { - return func(m *DeploymentStatusMutation) { +// withEventID sets the ID field of the mutation. +func withEventID(id int) eventOption { + return func(m *EventMutation) { var ( err error once sync.Once - value *DeploymentStatus + value *Event ) - m.oldValue = func(ctx context.Context) (*DeploymentStatus, error) { + m.oldValue = func(ctx context.Context) (*Event, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { - value, err = m.Client().DeploymentStatus.Get(ctx, id) + value, err = m.Client().Event.Get(ctx, id) } }) return value, err @@ -4783,10 +4795,10 @@ func withDeploymentStatusID(id int) deploymentstatusOption { } } -// withDeploymentStatus sets the old DeploymentStatus of the mutation. -func withDeploymentStatus(node *DeploymentStatus) deploymentstatusOption { - return func(m *DeploymentStatusMutation) { - m.oldValue = func(context.Context) (*DeploymentStatus, error) { +// withEvent sets the old Event of the mutation. +func withEvent(node *Event) eventOption { + return func(m *EventMutation) { + m.oldValue = func(context.Context) (*Event, error) { return node, nil } m.id = &node.ID @@ -4795,7 +4807,7 @@ func withDeploymentStatus(node *DeploymentStatus) deploymentstatusOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m DeploymentStatusMutation) Client() *Client { +func (m EventMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -4803,7 +4815,7 @@ func (m DeploymentStatusMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m DeploymentStatusMutation) Tx() (*Tx, error) { +func (m EventMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("ent: mutation is not running in a transaction") } @@ -4814,318 +4826,490 @@ func (m DeploymentStatusMutation) Tx() (*Tx, error) { // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *DeploymentStatusMutation) ID() (id int, exists bool) { +func (m *EventMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } -// SetStatus sets the "status" field. -func (m *DeploymentStatusMutation) SetStatus(s string) { - m.status = &s +// SetKind sets the "kind" field. +func (m *EventMutation) SetKind(e event.Kind) { + m.kind = &e +} + +// Kind returns the value of the "kind" field in the mutation. +func (m *EventMutation) Kind() (r event.Kind, exists bool) { + v := m.kind + if v == nil { + return + } + return *v, true +} + +// OldKind returns the old "kind" field's value of the Event entity. +// If the Event 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 *EventMutation) OldKind(ctx context.Context) (v event.Kind, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldKind is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldKind requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldKind: %w", err) + } + return oldValue.Kind, nil +} + +// ResetKind resets all changes to the "kind" field. +func (m *EventMutation) ResetKind() { + m.kind = nil +} + +// SetType sets the "type" field. +func (m *EventMutation) SetType(e event.Type) { + m._type = &e +} + +// GetType returns the value of the "type" field in the mutation. +func (m *EventMutation) GetType() (r event.Type, exists bool) { + v := m._type + if v == nil { + return + } + return *v, true +} + +// OldType returns the old "type" field's value of the Event entity. +// If the Event 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 *EventMutation) OldType(ctx context.Context) (v event.Type, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldType: %w", err) + } + return oldValue.Type, nil +} + +// ResetType resets all changes to the "type" field. +func (m *EventMutation) ResetType() { + m._type = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *EventMutation) SetCreatedAt(t time.Time) { + m.created_at = &t } -// Status returns the value of the "status" field in the mutation. -func (m *DeploymentStatusMutation) Status() (r string, exists bool) { - v := m.status +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *EventMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at if v == nil { return } return *v, true } -// OldStatus returns the old "status" field's value of the DeploymentStatus entity. -// If the DeploymentStatus object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the Event entity. +// If the Event 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 *DeploymentStatusMutation) OldStatus(ctx context.Context) (v string, err error) { +func (m *EventMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldStatus requires an ID field in the mutation") + return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldStatus: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.Status, nil + return oldValue.CreatedAt, nil } -// ResetStatus resets all changes to the "status" field. -func (m *DeploymentStatusMutation) ResetStatus() { - m.status = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *EventMutation) ResetCreatedAt() { + m.created_at = nil } -// SetDescription sets the "description" field. -func (m *DeploymentStatusMutation) SetDescription(s string) { - m.description = &s +// SetDeploymentID sets the "deployment_id" field. +func (m *EventMutation) SetDeploymentID(i int) { + m.deployment = &i } -// Description returns the value of the "description" field in the mutation. -func (m *DeploymentStatusMutation) Description() (r string, exists bool) { - v := m.description +// DeploymentID returns the value of the "deployment_id" field in the mutation. +func (m *EventMutation) DeploymentID() (r int, exists bool) { + v := m.deployment if v == nil { return } return *v, true } -// OldDescription returns the old "description" field's value of the DeploymentStatus entity. -// If the DeploymentStatus object wasn't provided to the builder, the object is fetched from the database. +// OldDeploymentID returns the old "deployment_id" field's value of the Event entity. +// If the Event 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 *DeploymentStatusMutation) OldDescription(ctx context.Context) (v string, err error) { +func (m *EventMutation) OldDeploymentID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDescription is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldDeploymentID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDescription requires an ID field in the mutation") + return v, fmt.Errorf("OldDeploymentID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldDescription: %w", err) + return v, fmt.Errorf("querying old value for OldDeploymentID: %w", err) } - return oldValue.Description, nil + return oldValue.DeploymentID, nil } -// ClearDescription clears the value of the "description" field. -func (m *DeploymentStatusMutation) ClearDescription() { - m.description = nil - m.clearedFields[deploymentstatus.FieldDescription] = struct{}{} +// ClearDeploymentID clears the value of the "deployment_id" field. +func (m *EventMutation) ClearDeploymentID() { + m.deployment = nil + m.clearedFields[event.FieldDeploymentID] = struct{}{} } -// DescriptionCleared returns if the "description" field was cleared in this mutation. -func (m *DeploymentStatusMutation) DescriptionCleared() bool { - _, ok := m.clearedFields[deploymentstatus.FieldDescription] +// DeploymentIDCleared returns if the "deployment_id" field was cleared in this mutation. +func (m *EventMutation) DeploymentIDCleared() bool { + _, ok := m.clearedFields[event.FieldDeploymentID] return ok } -// ResetDescription resets all changes to the "description" field. -func (m *DeploymentStatusMutation) ResetDescription() { - m.description = nil - delete(m.clearedFields, deploymentstatus.FieldDescription) +// ResetDeploymentID resets all changes to the "deployment_id" field. +func (m *EventMutation) ResetDeploymentID() { + m.deployment = nil + delete(m.clearedFields, event.FieldDeploymentID) } -// SetLogURL sets the "log_url" field. -func (m *DeploymentStatusMutation) SetLogURL(s string) { - m.log_url = &s +// SetApprovalID sets the "approval_id" field. +func (m *EventMutation) SetApprovalID(i int) { + m.approval_id = &i + m.addapproval_id = nil } -// LogURL returns the value of the "log_url" field in the mutation. -func (m *DeploymentStatusMutation) LogURL() (r string, exists bool) { - v := m.log_url +// ApprovalID returns the value of the "approval_id" field in the mutation. +func (m *EventMutation) ApprovalID() (r int, exists bool) { + v := m.approval_id if v == nil { return } return *v, true } -// OldLogURL returns the old "log_url" field's value of the DeploymentStatus entity. -// If the DeploymentStatus object wasn't provided to the builder, the object is fetched from the database. +// OldApprovalID returns the old "approval_id" field's value of the Event entity. +// If the Event 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 *DeploymentStatusMutation) OldLogURL(ctx context.Context) (v string, err error) { +func (m *EventMutation) OldApprovalID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLogURL is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldApprovalID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLogURL requires an ID field in the mutation") + return v, fmt.Errorf("OldApprovalID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldLogURL: %w", err) + return v, fmt.Errorf("querying old value for OldApprovalID: %w", err) } - return oldValue.LogURL, nil + return oldValue.ApprovalID, nil } -// ClearLogURL clears the value of the "log_url" field. -func (m *DeploymentStatusMutation) ClearLogURL() { - m.log_url = nil - m.clearedFields[deploymentstatus.FieldLogURL] = struct{}{} +// AddApprovalID adds i to the "approval_id" field. +func (m *EventMutation) AddApprovalID(i int) { + if m.addapproval_id != nil { + *m.addapproval_id += i + } else { + m.addapproval_id = &i + } } -// LogURLCleared returns if the "log_url" field was cleared in this mutation. -func (m *DeploymentStatusMutation) LogURLCleared() bool { - _, ok := m.clearedFields[deploymentstatus.FieldLogURL] +// AddedApprovalID returns the value that was added to the "approval_id" field in this mutation. +func (m *EventMutation) AddedApprovalID() (r int, exists bool) { + v := m.addapproval_id + if v == nil { + return + } + return *v, true +} + +// ClearApprovalID clears the value of the "approval_id" field. +func (m *EventMutation) ClearApprovalID() { + m.approval_id = nil + m.addapproval_id = nil + m.clearedFields[event.FieldApprovalID] = struct{}{} +} + +// ApprovalIDCleared returns if the "approval_id" field was cleared in this mutation. +func (m *EventMutation) ApprovalIDCleared() bool { + _, ok := m.clearedFields[event.FieldApprovalID] return ok } -// ResetLogURL resets all changes to the "log_url" field. -func (m *DeploymentStatusMutation) ResetLogURL() { - m.log_url = nil - delete(m.clearedFields, deploymentstatus.FieldLogURL) +// ResetApprovalID resets all changes to the "approval_id" field. +func (m *EventMutation) ResetApprovalID() { + m.approval_id = nil + m.addapproval_id = nil + delete(m.clearedFields, event.FieldApprovalID) } -// SetCreatedAt sets the "created_at" field. -func (m *DeploymentStatusMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// SetReviewID sets the "review_id" field. +func (m *EventMutation) SetReviewID(i int) { + m.review = &i } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *DeploymentStatusMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at +// ReviewID returns the value of the "review_id" field in the mutation. +func (m *EventMutation) ReviewID() (r int, exists bool) { + v := m.review if v == nil { return } return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the DeploymentStatus entity. -// If the DeploymentStatus object wasn't provided to the builder, the object is fetched from the database. +// OldReviewID returns the old "review_id" field's value of the Event entity. +// If the Event 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 *DeploymentStatusMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *EventMutation) OldReviewID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldReviewID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldReviewID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + return v, fmt.Errorf("querying old value for OldReviewID: %w", err) } - return oldValue.CreatedAt, nil + return oldValue.ReviewID, nil } -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *DeploymentStatusMutation) ResetCreatedAt() { - m.created_at = nil +// ClearReviewID clears the value of the "review_id" field. +func (m *EventMutation) ClearReviewID() { + m.review = nil + m.clearedFields[event.FieldReviewID] = struct{}{} } -// SetUpdatedAt sets the "updated_at" field. -func (m *DeploymentStatusMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t +// ReviewIDCleared returns if the "review_id" field was cleared in this mutation. +func (m *EventMutation) ReviewIDCleared() bool { + _, ok := m.clearedFields[event.FieldReviewID] + return ok } -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *DeploymentStatusMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at +// ResetReviewID resets all changes to the "review_id" field. +func (m *EventMutation) ResetReviewID() { + m.review = nil + delete(m.clearedFields, event.FieldReviewID) +} + +// SetDeletedID sets the "deleted_id" field. +func (m *EventMutation) SetDeletedID(i int) { + m.deleted_id = &i + m.adddeleted_id = nil +} + +// DeletedID returns the value of the "deleted_id" field in the mutation. +func (m *EventMutation) DeletedID() (r int, exists bool) { + v := m.deleted_id if v == nil { return } return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the DeploymentStatus entity. -// If the DeploymentStatus object wasn't provided to the builder, the object is fetched from the database. +// OldDeletedID returns the old "deleted_id" field's value of the Event entity. +// If the Event 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 *DeploymentStatusMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *EventMutation) OldDeletedID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldDeletedID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldDeletedID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + return v, fmt.Errorf("querying old value for OldDeletedID: %w", err) } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *DeploymentStatusMutation) ResetUpdatedAt() { - m.updated_at = nil + return oldValue.DeletedID, nil } -// SetDeploymentID sets the "deployment_id" field. -func (m *DeploymentStatusMutation) SetDeploymentID(i int) { - m.deployment = &i +// AddDeletedID adds i to the "deleted_id" field. +func (m *EventMutation) AddDeletedID(i int) { + if m.adddeleted_id != nil { + *m.adddeleted_id += i + } else { + m.adddeleted_id = &i + } } -// DeploymentID returns the value of the "deployment_id" field in the mutation. -func (m *DeploymentStatusMutation) DeploymentID() (r int, exists bool) { - v := m.deployment +// AddedDeletedID returns the value that was added to the "deleted_id" field in this mutation. +func (m *EventMutation) AddedDeletedID() (r int, exists bool) { + v := m.adddeleted_id if v == nil { return } return *v, true } -// OldDeploymentID returns the old "deployment_id" field's value of the DeploymentStatus entity. -// If the DeploymentStatus 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 *DeploymentStatusMutation) OldDeploymentID(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDeploymentID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDeploymentID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeploymentID: %w", err) - } - return oldValue.DeploymentID, nil +// ClearDeletedID clears the value of the "deleted_id" field. +func (m *EventMutation) ClearDeletedID() { + m.deleted_id = nil + m.adddeleted_id = nil + m.clearedFields[event.FieldDeletedID] = struct{}{} +} + +// DeletedIDCleared returns if the "deleted_id" field was cleared in this mutation. +func (m *EventMutation) DeletedIDCleared() bool { + _, ok := m.clearedFields[event.FieldDeletedID] + return ok +} + +// ResetDeletedID resets all changes to the "deleted_id" field. +func (m *EventMutation) ResetDeletedID() { + m.deleted_id = nil + m.adddeleted_id = nil + delete(m.clearedFields, event.FieldDeletedID) +} + +// ClearDeployment clears the "deployment" edge to the Deployment entity. +func (m *EventMutation) ClearDeployment() { + m.cleareddeployment = true +} + +// DeploymentCleared reports if the "deployment" edge to the Deployment entity was cleared. +func (m *EventMutation) DeploymentCleared() bool { + return m.DeploymentIDCleared() || m.cleareddeployment +} + +// DeploymentIDs returns the "deployment" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// DeploymentID instead. It exists only for internal usage by the builders. +func (m *EventMutation) DeploymentIDs() (ids []int) { + if id := m.deployment; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetDeployment resets all changes to the "deployment" edge. +func (m *EventMutation) ResetDeployment() { + m.deployment = nil + m.cleareddeployment = false +} + +// ClearReview clears the "review" edge to the Review entity. +func (m *EventMutation) ClearReview() { + m.clearedreview = true +} + +// ReviewCleared reports if the "review" edge to the Review entity was cleared. +func (m *EventMutation) ReviewCleared() bool { + return m.ReviewIDCleared() || m.clearedreview +} + +// ReviewIDs returns the "review" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// ReviewID instead. It exists only for internal usage by the builders. +func (m *EventMutation) ReviewIDs() (ids []int) { + if id := m.review; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetReview resets all changes to the "review" edge. +func (m *EventMutation) ResetReview() { + m.review = nil + m.clearedreview = false +} + +// SetNotificationRecordID sets the "notification_record" edge to the NotificationRecord entity by id. +func (m *EventMutation) SetNotificationRecordID(id int) { + m.notification_record = &id } -// ResetDeploymentID resets all changes to the "deployment_id" field. -func (m *DeploymentStatusMutation) ResetDeploymentID() { - m.deployment = nil +// ClearNotificationRecord clears the "notification_record" edge to the NotificationRecord entity. +func (m *EventMutation) ClearNotificationRecord() { + m.clearednotification_record = true } -// ClearDeployment clears the "deployment" edge to the Deployment entity. -func (m *DeploymentStatusMutation) ClearDeployment() { - m.cleareddeployment = true +// NotificationRecordCleared reports if the "notification_record" edge to the NotificationRecord entity was cleared. +func (m *EventMutation) NotificationRecordCleared() bool { + return m.clearednotification_record } -// DeploymentCleared reports if the "deployment" edge to the Deployment entity was cleared. -func (m *DeploymentStatusMutation) DeploymentCleared() bool { - return m.cleareddeployment +// NotificationRecordID returns the "notification_record" edge ID in the mutation. +func (m *EventMutation) NotificationRecordID() (id int, exists bool) { + if m.notification_record != nil { + return *m.notification_record, true + } + return } -// DeploymentIDs returns the "deployment" edge IDs in the mutation. +// NotificationRecordIDs returns the "notification_record" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// DeploymentID instead. It exists only for internal usage by the builders. -func (m *DeploymentStatusMutation) DeploymentIDs() (ids []int) { - if id := m.deployment; id != nil { +// NotificationRecordID instead. It exists only for internal usage by the builders. +func (m *EventMutation) NotificationRecordIDs() (ids []int) { + if id := m.notification_record; id != nil { ids = append(ids, *id) } return } -// ResetDeployment resets all changes to the "deployment" edge. -func (m *DeploymentStatusMutation) ResetDeployment() { - m.deployment = nil - m.cleareddeployment = false +// ResetNotificationRecord resets all changes to the "notification_record" edge. +func (m *EventMutation) ResetNotificationRecord() { + m.notification_record = nil + m.clearednotification_record = false } -// Where appends a list predicates to the DeploymentStatusMutation builder. -func (m *DeploymentStatusMutation) Where(ps ...predicate.DeploymentStatus) { +// Where appends a list predicates to the EventMutation builder. +func (m *EventMutation) Where(ps ...predicate.Event) { m.predicates = append(m.predicates, ps...) } // Op returns the operation name. -func (m *DeploymentStatusMutation) Op() Op { +func (m *EventMutation) Op() Op { return m.op } -// Type returns the node type of this mutation (DeploymentStatus). -func (m *DeploymentStatusMutation) Type() string { +// Type returns the node type of this mutation (Event). +func (m *EventMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). -func (m *DeploymentStatusMutation) Fields() []string { - fields := make([]string, 0, 6) - if m.status != nil { - fields = append(fields, deploymentstatus.FieldStatus) - } - if m.description != nil { - fields = append(fields, deploymentstatus.FieldDescription) +func (m *EventMutation) Fields() []string { + fields := make([]string, 0, 7) + if m.kind != nil { + fields = append(fields, event.FieldKind) } - if m.log_url != nil { - fields = append(fields, deploymentstatus.FieldLogURL) + if m._type != nil { + fields = append(fields, event.FieldType) } if m.created_at != nil { - fields = append(fields, deploymentstatus.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, deploymentstatus.FieldUpdatedAt) + fields = append(fields, event.FieldCreatedAt) } if m.deployment != nil { - fields = append(fields, deploymentstatus.FieldDeploymentID) + fields = append(fields, event.FieldDeploymentID) + } + if m.approval_id != nil { + fields = append(fields, event.FieldApprovalID) + } + if m.review != nil { + fields = append(fields, event.FieldReviewID) + } + if m.deleted_id != nil { + fields = append(fields, event.FieldDeletedID) } return fields } @@ -5133,20 +5317,22 @@ func (m *DeploymentStatusMutation) Fields() []string { // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *DeploymentStatusMutation) Field(name string) (ent.Value, bool) { +func (m *EventMutation) Field(name string) (ent.Value, bool) { switch name { - case deploymentstatus.FieldStatus: - return m.Status() - case deploymentstatus.FieldDescription: - return m.Description() - case deploymentstatus.FieldLogURL: - return m.LogURL() - case deploymentstatus.FieldCreatedAt: + case event.FieldKind: + return m.Kind() + case event.FieldType: + return m.GetType() + case event.FieldCreatedAt: return m.CreatedAt() - case deploymentstatus.FieldUpdatedAt: - return m.UpdatedAt() - case deploymentstatus.FieldDeploymentID: + case event.FieldDeploymentID: return m.DeploymentID() + case event.FieldApprovalID: + return m.ApprovalID() + case event.FieldReviewID: + return m.ReviewID() + case event.FieldDeletedID: + return m.DeletedID() } return nil, false } @@ -5154,87 +5340,106 @@ func (m *DeploymentStatusMutation) Field(name string) (ent.Value, bool) { // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. -func (m *DeploymentStatusMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *EventMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case deploymentstatus.FieldStatus: - return m.OldStatus(ctx) - case deploymentstatus.FieldDescription: - return m.OldDescription(ctx) - case deploymentstatus.FieldLogURL: - return m.OldLogURL(ctx) - case deploymentstatus.FieldCreatedAt: + case event.FieldKind: + return m.OldKind(ctx) + case event.FieldType: + return m.OldType(ctx) + case event.FieldCreatedAt: return m.OldCreatedAt(ctx) - case deploymentstatus.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case deploymentstatus.FieldDeploymentID: + case event.FieldDeploymentID: return m.OldDeploymentID(ctx) + case event.FieldApprovalID: + return m.OldApprovalID(ctx) + case event.FieldReviewID: + return m.OldReviewID(ctx) + case event.FieldDeletedID: + return m.OldDeletedID(ctx) } - return nil, fmt.Errorf("unknown DeploymentStatus field %s", name) + return nil, fmt.Errorf("unknown Event field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *DeploymentStatusMutation) SetField(name string, value ent.Value) error { +func (m *EventMutation) SetField(name string, value ent.Value) error { switch name { - case deploymentstatus.FieldStatus: - v, ok := value.(string) + case event.FieldKind: + v, ok := value.(event.Kind) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetStatus(v) + m.SetKind(v) return nil - case deploymentstatus.FieldDescription: - v, ok := value.(string) + case event.FieldType: + v, ok := value.(event.Type) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDescription(v) + m.SetType(v) return nil - case deploymentstatus.FieldLogURL: - v, ok := value.(string) + case event.FieldCreatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetLogURL(v) + m.SetCreatedAt(v) return nil - case deploymentstatus.FieldCreatedAt: - v, ok := value.(time.Time) + case event.FieldDeploymentID: + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetDeploymentID(v) return nil - case deploymentstatus.FieldUpdatedAt: - v, ok := value.(time.Time) + case event.FieldApprovalID: + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetApprovalID(v) return nil - case deploymentstatus.FieldDeploymentID: + case event.FieldReviewID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeploymentID(v) + m.SetReviewID(v) + return nil + case event.FieldDeletedID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDeletedID(v) return nil } - return fmt.Errorf("unknown DeploymentStatus field %s", name) + return fmt.Errorf("unknown Event field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *DeploymentStatusMutation) AddedFields() []string { +func (m *EventMutation) AddedFields() []string { var fields []string + if m.addapproval_id != nil { + fields = append(fields, event.FieldApprovalID) + } + if m.adddeleted_id != nil { + fields = append(fields, event.FieldDeletedID) + } return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *DeploymentStatusMutation) AddedField(name string) (ent.Value, bool) { +func (m *EventMutation) AddedField(name string) (ent.Value, bool) { switch name { + case event.FieldApprovalID: + return m.AddedApprovalID() + case event.FieldDeletedID: + return m.AddedDeletedID() } return nil, false } @@ -5242,182 +5447,243 @@ func (m *DeploymentStatusMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *DeploymentStatusMutation) AddField(name string, value ent.Value) error { +func (m *EventMutation) AddField(name string, value ent.Value) error { switch name { + case event.FieldApprovalID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddApprovalID(v) + return nil + case event.FieldDeletedID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddDeletedID(v) + return nil } - return fmt.Errorf("unknown DeploymentStatus numeric field %s", name) + return fmt.Errorf("unknown Event numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *DeploymentStatusMutation) ClearedFields() []string { +func (m *EventMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(deploymentstatus.FieldDescription) { - fields = append(fields, deploymentstatus.FieldDescription) + if m.FieldCleared(event.FieldDeploymentID) { + fields = append(fields, event.FieldDeploymentID) } - if m.FieldCleared(deploymentstatus.FieldLogURL) { - fields = append(fields, deploymentstatus.FieldLogURL) + if m.FieldCleared(event.FieldApprovalID) { + fields = append(fields, event.FieldApprovalID) + } + if m.FieldCleared(event.FieldReviewID) { + fields = append(fields, event.FieldReviewID) + } + if m.FieldCleared(event.FieldDeletedID) { + fields = append(fields, event.FieldDeletedID) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *DeploymentStatusMutation) FieldCleared(name string) bool { +func (m *EventMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *DeploymentStatusMutation) ClearField(name string) error { +func (m *EventMutation) ClearField(name string) error { switch name { - case deploymentstatus.FieldDescription: - m.ClearDescription() + case event.FieldDeploymentID: + m.ClearDeploymentID() return nil - case deploymentstatus.FieldLogURL: - m.ClearLogURL() + case event.FieldApprovalID: + m.ClearApprovalID() + return nil + case event.FieldReviewID: + m.ClearReviewID() + return nil + case event.FieldDeletedID: + m.ClearDeletedID() return nil } - return fmt.Errorf("unknown DeploymentStatus nullable field %s", name) + return fmt.Errorf("unknown Event nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *DeploymentStatusMutation) ResetField(name string) error { +func (m *EventMutation) ResetField(name string) error { switch name { - case deploymentstatus.FieldStatus: - m.ResetStatus() - return nil - case deploymentstatus.FieldDescription: - m.ResetDescription() + case event.FieldKind: + m.ResetKind() return nil - case deploymentstatus.FieldLogURL: - m.ResetLogURL() + case event.FieldType: + m.ResetType() return nil - case deploymentstatus.FieldCreatedAt: + case event.FieldCreatedAt: m.ResetCreatedAt() return nil - case deploymentstatus.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case deploymentstatus.FieldDeploymentID: + case event.FieldDeploymentID: m.ResetDeploymentID() return nil + case event.FieldApprovalID: + m.ResetApprovalID() + return nil + case event.FieldReviewID: + m.ResetReviewID() + return nil + case event.FieldDeletedID: + m.ResetDeletedID() + return nil } - return fmt.Errorf("unknown DeploymentStatus field %s", name) + return fmt.Errorf("unknown Event field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *DeploymentStatusMutation) AddedEdges() []string { - edges := make([]string, 0, 1) +func (m *EventMutation) AddedEdges() []string { + edges := make([]string, 0, 3) if m.deployment != nil { - edges = append(edges, deploymentstatus.EdgeDeployment) + edges = append(edges, event.EdgeDeployment) + } + if m.review != nil { + edges = append(edges, event.EdgeReview) + } + if m.notification_record != nil { + edges = append(edges, event.EdgeNotificationRecord) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *DeploymentStatusMutation) AddedIDs(name string) []ent.Value { +func (m *EventMutation) AddedIDs(name string) []ent.Value { switch name { - case deploymentstatus.EdgeDeployment: + case event.EdgeDeployment: if id := m.deployment; id != nil { return []ent.Value{*id} } + case event.EdgeReview: + if id := m.review; id != nil { + return []ent.Value{*id} + } + case event.EdgeNotificationRecord: + if id := m.notification_record; id != nil { + return []ent.Value{*id} + } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *DeploymentStatusMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) +func (m *EventMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *DeploymentStatusMutation) RemovedIDs(name string) []ent.Value { +func (m *EventMutation) RemovedIDs(name string) []ent.Value { switch name { } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *DeploymentStatusMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) +func (m *EventMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) if m.cleareddeployment { - edges = append(edges, deploymentstatus.EdgeDeployment) + edges = append(edges, event.EdgeDeployment) + } + if m.clearedreview { + edges = append(edges, event.EdgeReview) + } + if m.clearednotification_record { + edges = append(edges, event.EdgeNotificationRecord) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *DeploymentStatusMutation) EdgeCleared(name string) bool { +func (m *EventMutation) EdgeCleared(name string) bool { switch name { - case deploymentstatus.EdgeDeployment: + case event.EdgeDeployment: return m.cleareddeployment + case event.EdgeReview: + return m.clearedreview + case event.EdgeNotificationRecord: + return m.clearednotification_record } 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 *DeploymentStatusMutation) ClearEdge(name string) error { +func (m *EventMutation) ClearEdge(name string) error { switch name { - case deploymentstatus.EdgeDeployment: + case event.EdgeDeployment: m.ClearDeployment() return nil + case event.EdgeReview: + m.ClearReview() + return nil + case event.EdgeNotificationRecord: + m.ClearNotificationRecord() + return nil } - return fmt.Errorf("unknown DeploymentStatus unique edge %s", name) + return fmt.Errorf("unknown Event 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 *DeploymentStatusMutation) ResetEdge(name string) error { +func (m *EventMutation) ResetEdge(name string) error { switch name { - case deploymentstatus.EdgeDeployment: + case event.EdgeDeployment: m.ResetDeployment() return nil + case event.EdgeReview: + m.ResetReview() + return nil + case event.EdgeNotificationRecord: + m.ResetNotificationRecord() + return nil } - return fmt.Errorf("unknown DeploymentStatus edge %s", name) + return fmt.Errorf("unknown Event edge %s", name) } -// EventMutation represents an operation that mutates the Event nodes in the graph. -type EventMutation struct { +// LockMutation represents an operation that mutates the Lock nodes in the graph. +type LockMutation struct { config - op Op - typ string - id *int - kind *event.Kind - _type *event.Type - created_at *time.Time - deleted_id *int - adddeleted_id *int - clearedFields map[string]struct{} - deployment *int - cleareddeployment bool - approval *int - clearedapproval bool - notification_record *int - clearednotification_record bool - done bool - oldValue func(context.Context) (*Event, error) - predicates []predicate.Event + op Op + typ string + id *int + env *string + expired_at *time.Time + created_at *time.Time + clearedFields map[string]struct{} + user *int64 + cleareduser bool + repo *int64 + clearedrepo bool + done bool + oldValue func(context.Context) (*Lock, error) + predicates []predicate.Lock } -var _ ent.Mutation = (*EventMutation)(nil) +var _ ent.Mutation = (*LockMutation)(nil) -// eventOption allows management of the mutation configuration using functional options. -type eventOption func(*EventMutation) +// lockOption allows management of the mutation configuration using functional options. +type lockOption func(*LockMutation) -// newEventMutation creates new mutation for the Event entity. -func newEventMutation(c config, op Op, opts ...eventOption) *EventMutation { - m := &EventMutation{ +// newLockMutation creates new mutation for the Lock entity. +func newLockMutation(c config, op Op, opts ...lockOption) *LockMutation { + m := &LockMutation{ config: c, op: op, - typ: TypeEvent, + typ: TypeLock, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -5426,20 +5692,20 @@ func newEventMutation(c config, op Op, opts ...eventOption) *EventMutation { return m } -// withEventID sets the ID field of the mutation. -func withEventID(id int) eventOption { - return func(m *EventMutation) { +// withLockID sets the ID field of the mutation. +func withLockID(id int) lockOption { + return func(m *LockMutation) { var ( err error once sync.Once - value *Event + value *Lock ) - m.oldValue = func(ctx context.Context) (*Event, error) { + m.oldValue = func(ctx context.Context) (*Lock, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { - value, err = m.Client().Event.Get(ctx, id) + value, err = m.Client().Lock.Get(ctx, id) } }) return value, err @@ -5448,10 +5714,10 @@ func withEventID(id int) eventOption { } } -// withEvent sets the old Event of the mutation. -func withEvent(node *Event) eventOption { - return func(m *EventMutation) { - m.oldValue = func(context.Context) (*Event, error) { +// withLock sets the old Lock of the mutation. +func withLock(node *Lock) lockOption { + return func(m *LockMutation) { + m.oldValue = func(context.Context) (*Lock, error) { return node, nil } m.id = &node.ID @@ -5460,7 +5726,7 @@ func withEvent(node *Event) eventOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m EventMutation) Client() *Client { +func (m LockMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -5468,7 +5734,7 @@ func (m EventMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m EventMutation) Tx() (*Tx, error) { +func (m LockMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("ent: mutation is not running in a transaction") } @@ -5479,531 +5745,779 @@ func (m EventMutation) Tx() (*Tx, error) { // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *EventMutation) ID() (id int, exists bool) { +func (m *LockMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } -// SetKind sets the "kind" field. -func (m *EventMutation) SetKind(e event.Kind) { - m.kind = &e +// SetEnv sets the "env" field. +func (m *LockMutation) SetEnv(s string) { + m.env = &s } -// Kind returns the value of the "kind" field in the mutation. -func (m *EventMutation) Kind() (r event.Kind, exists bool) { - v := m.kind +// Env returns the value of the "env" field in the mutation. +func (m *LockMutation) Env() (r string, exists bool) { + v := m.env if v == nil { return } return *v, true } -// OldKind returns the old "kind" field's value of the Event entity. -// If the Event object wasn't provided to the builder, the object is fetched from the database. +// OldEnv returns the old "env" field's value of the Lock entity. +// If the Lock 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 *EventMutation) OldKind(ctx context.Context) (v event.Kind, err error) { +func (m *LockMutation) OldEnv(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldKind 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("OldEnv 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 oldValue.Env, nil +} + +// ResetEnv resets all changes to the "env" field. +func (m *LockMutation) ResetEnv() { + m.env = nil +} + +// SetExpiredAt sets the "expired_at" field. +func (m *LockMutation) SetExpiredAt(t time.Time) { + m.expired_at = &t +} + +// ExpiredAt returns the value of the "expired_at" field in the mutation. +func (m *LockMutation) ExpiredAt() (r time.Time, exists bool) { + v := m.expired_at + if v == nil { + return + } + return *v, true +} + +// OldExpiredAt returns the old "expired_at" field's value of the Lock entity. +// If the Lock 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 *LockMutation) OldExpiredAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldExpiredAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldExpiredAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldExpiredAt: %w", err) + } + return oldValue.ExpiredAt, nil +} + +// ClearExpiredAt clears the value of the "expired_at" field. +func (m *LockMutation) ClearExpiredAt() { + m.expired_at = nil + m.clearedFields[lock.FieldExpiredAt] = struct{}{} +} + +// ExpiredAtCleared returns if the "expired_at" field was cleared in this mutation. +func (m *LockMutation) ExpiredAtCleared() bool { + _, ok := m.clearedFields[lock.FieldExpiredAt] + return ok +} + +// ResetExpiredAt resets all changes to the "expired_at" field. +func (m *LockMutation) ResetExpiredAt() { + m.expired_at = nil + delete(m.clearedFields, lock.FieldExpiredAt) +} + +// SetCreatedAt sets the "created_at" field. +func (m *LockMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *LockMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Lock entity. +// If the Lock 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 *LockMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldKind requires an ID field in the mutation") + return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldKind: %w", err) + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } - return oldValue.Kind, nil + return oldValue.CreatedAt, nil } -// ResetKind resets all changes to the "kind" field. -func (m *EventMutation) ResetKind() { - m.kind = nil +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *LockMutation) ResetCreatedAt() { + m.created_at = nil } -// SetType sets the "type" field. -func (m *EventMutation) SetType(e event.Type) { - m._type = &e +// SetUserID sets the "user_id" field. +func (m *LockMutation) SetUserID(i int64) { + m.user = &i } -// GetType returns the value of the "type" field in the mutation. -func (m *EventMutation) GetType() (r event.Type, exists bool) { - v := m._type +// UserID returns the value of the "user_id" field in the mutation. +func (m *LockMutation) UserID() (r int64, exists bool) { + v := m.user if v == nil { return } return *v, true } -// OldType returns the old "type" field's value of the Event entity. -// If the Event object wasn't provided to the builder, the object is fetched from the database. +// OldUserID returns the old "user_id" field's value of the Lock entity. +// If the Lock 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 *EventMutation) OldType(ctx context.Context) (v event.Type, err error) { +func (m *LockMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldType is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldType requires an ID field in the mutation") + return v, fmt.Errorf("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldType: %w", err) + return v, fmt.Errorf("querying old value for OldUserID: %w", err) } - return oldValue.Type, nil + return oldValue.UserID, nil } -// ResetType resets all changes to the "type" field. -func (m *EventMutation) ResetType() { - m._type = nil +// ResetUserID resets all changes to the "user_id" field. +func (m *LockMutation) ResetUserID() { + m.user = nil } -// SetCreatedAt sets the "created_at" field. -func (m *EventMutation) SetCreatedAt(t time.Time) { - m.created_at = &t +// SetRepoID sets the "repo_id" field. +func (m *LockMutation) SetRepoID(i int64) { + m.repo = &i } -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *EventMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at +// RepoID returns the value of the "repo_id" field in the mutation. +func (m *LockMutation) RepoID() (r int64, exists bool) { + v := m.repo if v == nil { return } return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the Event entity. -// If the Event object wasn't provided to the builder, the object is fetched from the database. +// OldRepoID returns the old "repo_id" field's value of the Lock entity. +// If the Lock 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 *EventMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *LockMutation) OldRepoID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldCreatedAt requires an ID field in the mutation") + 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 OldCreatedAt: %w", err) + return v, fmt.Errorf("querying old value for OldRepoID: %w", err) } - return oldValue.CreatedAt, nil + return oldValue.RepoID, nil } -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *EventMutation) ResetCreatedAt() { - m.created_at = nil +// ResetRepoID resets all changes to the "repo_id" field. +func (m *LockMutation) ResetRepoID() { + m.repo = nil } -// SetDeploymentID sets the "deployment_id" field. -func (m *EventMutation) SetDeploymentID(i int) { - m.deployment = &i +// ClearUser clears the "user" edge to the User entity. +func (m *LockMutation) ClearUser() { + m.cleareduser = true } -// DeploymentID returns the value of the "deployment_id" field in the mutation. -func (m *EventMutation) DeploymentID() (r int, exists bool) { - v := m.deployment - if v == nil { - return +// UserCleared reports if the "user" edge to the User entity was cleared. +func (m *LockMutation) UserCleared() bool { + return m.cleareduser +} + +// UserIDs returns the "user" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// UserID instead. It exists only for internal usage by the builders. +func (m *LockMutation) UserIDs() (ids []int64) { + if id := m.user; id != nil { + ids = append(ids, *id) } - return *v, true + return } -// OldDeploymentID returns the old "deployment_id" field's value of the Event entity. -// If the Event 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 *EventMutation) OldDeploymentID(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDeploymentID is only allowed on UpdateOne operations") +// ResetUser resets all changes to the "user" edge. +func (m *LockMutation) ResetUser() { + m.user = nil + m.cleareduser = false +} + +// ClearRepo clears the "repo" edge to the Repo entity. +func (m *LockMutation) ClearRepo() { + m.clearedrepo = true +} + +// RepoCleared reports if the "repo" edge to the Repo entity was cleared. +func (m *LockMutation) 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 *LockMutation) RepoIDs() (ids []int64) { + if id := m.repo; id != nil { + ids = append(ids, *id) } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDeploymentID requires an ID field in the mutation") + return +} + +// ResetRepo resets all changes to the "repo" edge. +func (m *LockMutation) ResetRepo() { + m.repo = nil + m.clearedrepo = false +} + +// Where appends a list predicates to the LockMutation builder. +func (m *LockMutation) Where(ps ...predicate.Lock) { + m.predicates = append(m.predicates, ps...) +} + +// Op returns the operation name. +func (m *LockMutation) Op() Op { + return m.op +} + +// Type returns the node type of this mutation (Lock). +func (m *LockMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *LockMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.env != nil { + fields = append(fields, lock.FieldEnv) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeploymentID: %w", err) + if m.expired_at != nil { + fields = append(fields, lock.FieldExpiredAt) + } + if m.created_at != nil { + fields = append(fields, lock.FieldCreatedAt) + } + if m.user != nil { + fields = append(fields, lock.FieldUserID) + } + if m.repo != nil { + fields = append(fields, lock.FieldRepoID) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *LockMutation) Field(name string) (ent.Value, bool) { + switch name { + case lock.FieldEnv: + return m.Env() + case lock.FieldExpiredAt: + return m.ExpiredAt() + case lock.FieldCreatedAt: + return m.CreatedAt() + case lock.FieldUserID: + return m.UserID() + case lock.FieldRepoID: + return m.RepoID() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *LockMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case lock.FieldEnv: + return m.OldEnv(ctx) + case lock.FieldExpiredAt: + return m.OldExpiredAt(ctx) + case lock.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case lock.FieldUserID: + return m.OldUserID(ctx) + case lock.FieldRepoID: + return m.OldRepoID(ctx) + } + return nil, fmt.Errorf("unknown Lock field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *LockMutation) SetField(name string, value ent.Value) error { + switch name { + case lock.FieldEnv: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEnv(v) + return nil + case lock.FieldExpiredAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetExpiredAt(v) + return nil + case lock.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case lock.FieldUserID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUserID(v) + return nil + case lock.FieldRepoID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRepoID(v) + return nil } - return oldValue.DeploymentID, nil + return fmt.Errorf("unknown Lock field %s", name) } -// ClearDeploymentID clears the value of the "deployment_id" field. -func (m *EventMutation) ClearDeploymentID() { - m.deployment = nil - m.clearedFields[event.FieldDeploymentID] = struct{}{} +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *LockMutation) AddedFields() []string { + var fields []string + return fields } -// DeploymentIDCleared returns if the "deployment_id" field was cleared in this mutation. -func (m *EventMutation) DeploymentIDCleared() bool { - _, ok := m.clearedFields[event.FieldDeploymentID] - return ok +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *LockMutation) AddedField(name string) (ent.Value, bool) { + switch name { + } + return nil, false } -// ResetDeploymentID resets all changes to the "deployment_id" field. -func (m *EventMutation) ResetDeploymentID() { - m.deployment = nil - delete(m.clearedFields, event.FieldDeploymentID) +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *LockMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Lock numeric field %s", name) } -// SetApprovalID sets the "approval_id" field. -func (m *EventMutation) SetApprovalID(i int) { - m.approval = &i +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *LockMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(lock.FieldExpiredAt) { + fields = append(fields, lock.FieldExpiredAt) + } + return fields } -// ApprovalID returns the value of the "approval_id" field in the mutation. -func (m *EventMutation) ApprovalID() (r int, exists bool) { - v := m.approval - if v == nil { - return - } - return *v, true +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *LockMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok } -// OldApprovalID returns the old "approval_id" field's value of the Event entity. -// If the Event 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 *EventMutation) OldApprovalID(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldApprovalID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldApprovalID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldApprovalID: %w", err) +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *LockMutation) ClearField(name string) error { + switch name { + case lock.FieldExpiredAt: + m.ClearExpiredAt() + return nil } - return oldValue.ApprovalID, nil + return fmt.Errorf("unknown Lock nullable field %s", name) } -// ClearApprovalID clears the value of the "approval_id" field. -func (m *EventMutation) ClearApprovalID() { - m.approval = nil - m.clearedFields[event.FieldApprovalID] = struct{}{} +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *LockMutation) ResetField(name string) error { + switch name { + case lock.FieldEnv: + m.ResetEnv() + return nil + case lock.FieldExpiredAt: + m.ResetExpiredAt() + return nil + case lock.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case lock.FieldUserID: + m.ResetUserID() + return nil + case lock.FieldRepoID: + m.ResetRepoID() + return nil + } + return fmt.Errorf("unknown Lock field %s", name) } -// ApprovalIDCleared returns if the "approval_id" field was cleared in this mutation. -func (m *EventMutation) ApprovalIDCleared() bool { - _, ok := m.clearedFields[event.FieldApprovalID] - return ok +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *LockMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.user != nil { + edges = append(edges, lock.EdgeUser) + } + if m.repo != nil { + edges = append(edges, lock.EdgeRepo) + } + return edges } -// ResetApprovalID resets all changes to the "approval_id" field. -func (m *EventMutation) ResetApprovalID() { - m.approval = nil - delete(m.clearedFields, event.FieldApprovalID) +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *LockMutation) AddedIDs(name string) []ent.Value { + switch name { + case lock.EdgeUser: + if id := m.user; id != nil { + return []ent.Value{*id} + } + case lock.EdgeRepo: + if id := m.repo; id != nil { + return []ent.Value{*id} + } + } + return nil } -// SetDeletedID sets the "deleted_id" field. -func (m *EventMutation) SetDeletedID(i int) { - m.deleted_id = &i - m.adddeleted_id = nil +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *LockMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + return edges } -// DeletedID returns the value of the "deleted_id" field in the mutation. -func (m *EventMutation) DeletedID() (r int, exists bool) { - v := m.deleted_id - if v == nil { - return +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *LockMutation) RemovedIDs(name string) []ent.Value { + switch name { } - return *v, true + return nil } -// OldDeletedID returns the old "deleted_id" field's value of the Event entity. -// If the Event 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 *EventMutation) OldDeletedID(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDeletedID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDeletedID requires an ID field in the mutation") +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *LockMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.cleareduser { + edges = append(edges, lock.EdgeUser) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDeletedID: %w", err) + if m.clearedrepo { + edges = append(edges, lock.EdgeRepo) } - return oldValue.DeletedID, nil + return edges } -// AddDeletedID adds i to the "deleted_id" field. -func (m *EventMutation) AddDeletedID(i int) { - if m.adddeleted_id != nil { - *m.adddeleted_id += i - } else { - m.adddeleted_id = &i +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *LockMutation) EdgeCleared(name string) bool { + switch name { + case lock.EdgeUser: + return m.cleareduser + case lock.EdgeRepo: + return m.clearedrepo } + return false } -// AddedDeletedID returns the value that was added to the "deleted_id" field in this mutation. -func (m *EventMutation) AddedDeletedID() (r int, exists bool) { - v := m.adddeleted_id - if v == nil { - return +// 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 *LockMutation) ClearEdge(name string) error { + switch name { + case lock.EdgeUser: + m.ClearUser() + return nil + case lock.EdgeRepo: + m.ClearRepo() + return nil } - return *v, true + return fmt.Errorf("unknown Lock unique edge %s", name) } -// ClearDeletedID clears the value of the "deleted_id" field. -func (m *EventMutation) ClearDeletedID() { - m.deleted_id = nil - m.adddeleted_id = nil - m.clearedFields[event.FieldDeletedID] = struct{}{} +// 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 *LockMutation) ResetEdge(name string) error { + switch name { + case lock.EdgeUser: + m.ResetUser() + return nil + case lock.EdgeRepo: + m.ResetRepo() + return nil + } + return fmt.Errorf("unknown Lock edge %s", name) } -// DeletedIDCleared returns if the "deleted_id" field was cleared in this mutation. -func (m *EventMutation) DeletedIDCleared() bool { - _, ok := m.clearedFields[event.FieldDeletedID] - return ok +// NotificationRecordMutation represents an operation that mutates the NotificationRecord nodes in the graph. +type NotificationRecordMutation struct { + config + op Op + typ string + id *int + clearedFields map[string]struct{} + event *int + clearedevent bool + done bool + oldValue func(context.Context) (*NotificationRecord, error) + predicates []predicate.NotificationRecord } -// ResetDeletedID resets all changes to the "deleted_id" field. -func (m *EventMutation) ResetDeletedID() { - m.deleted_id = nil - m.adddeleted_id = nil - delete(m.clearedFields, event.FieldDeletedID) -} +var _ ent.Mutation = (*NotificationRecordMutation)(nil) -// ClearDeployment clears the "deployment" edge to the Deployment entity. -func (m *EventMutation) ClearDeployment() { - m.cleareddeployment = true +// notificationrecordOption allows management of the mutation configuration using functional options. +type notificationrecordOption func(*NotificationRecordMutation) + +// newNotificationRecordMutation creates new mutation for the NotificationRecord entity. +func newNotificationRecordMutation(c config, op Op, opts ...notificationrecordOption) *NotificationRecordMutation { + m := &NotificationRecordMutation{ + config: c, + op: op, + typ: TypeNotificationRecord, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m } -// DeploymentCleared reports if the "deployment" edge to the Deployment entity was cleared. -func (m *EventMutation) DeploymentCleared() bool { - return m.DeploymentIDCleared() || m.cleareddeployment +// withNotificationRecordID sets the ID field of the mutation. +func withNotificationRecordID(id int) notificationrecordOption { + return func(m *NotificationRecordMutation) { + var ( + err error + once sync.Once + value *NotificationRecord + ) + m.oldValue = func(ctx context.Context) (*NotificationRecord, error) { + once.Do(func() { + if m.done { + err = fmt.Errorf("querying old values post mutation is not allowed") + } else { + value, err = m.Client().NotificationRecord.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } } -// DeploymentIDs returns the "deployment" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// DeploymentID instead. It exists only for internal usage by the builders. -func (m *EventMutation) DeploymentIDs() (ids []int) { - if id := m.deployment; id != nil { - ids = append(ids, *id) +// withNotificationRecord sets the old NotificationRecord of the mutation. +func withNotificationRecord(node *NotificationRecord) notificationrecordOption { + return func(m *NotificationRecordMutation) { + m.oldValue = func(context.Context) (*NotificationRecord, error) { + return node, nil + } + m.id = &node.ID } - return } -// ResetDeployment resets all changes to the "deployment" edge. -func (m *EventMutation) ResetDeployment() { - m.deployment = nil - m.cleareddeployment = false +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m NotificationRecordMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client } -// ClearApproval clears the "approval" edge to the Approval entity. -func (m *EventMutation) ClearApproval() { - m.clearedapproval = true +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m NotificationRecordMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, fmt.Errorf("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil } -// ApprovalCleared reports if the "approval" edge to the Approval entity was cleared. -func (m *EventMutation) ApprovalCleared() bool { - return m.ApprovalIDCleared() || m.clearedapproval +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *NotificationRecordMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true } -// ApprovalIDs returns the "approval" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// ApprovalID instead. It exists only for internal usage by the builders. -func (m *EventMutation) ApprovalIDs() (ids []int) { - if id := m.approval; id != nil { - ids = append(ids, *id) - } - return +// SetEventID sets the "event_id" field. +func (m *NotificationRecordMutation) SetEventID(i int) { + m.event = &i } -// ResetApproval resets all changes to the "approval" edge. -func (m *EventMutation) ResetApproval() { - m.approval = nil - m.clearedapproval = false +// EventID returns the value of the "event_id" field in the mutation. +func (m *NotificationRecordMutation) EventID() (r int, exists bool) { + v := m.event + if v == nil { + return + } + return *v, true } -// SetNotificationRecordID sets the "notification_record" edge to the NotificationRecord entity by id. -func (m *EventMutation) SetNotificationRecordID(id int) { - m.notification_record = &id +// OldEventID returns the old "event_id" field's value of the NotificationRecord entity. +// If the NotificationRecord 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 *NotificationRecordMutation) OldEventID(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldEventID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldEventID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEventID: %w", err) + } + return oldValue.EventID, nil } -// ClearNotificationRecord clears the "notification_record" edge to the NotificationRecord entity. -func (m *EventMutation) ClearNotificationRecord() { - m.clearednotification_record = true +// ResetEventID resets all changes to the "event_id" field. +func (m *NotificationRecordMutation) ResetEventID() { + m.event = nil } -// NotificationRecordCleared reports if the "notification_record" edge to the NotificationRecord entity was cleared. -func (m *EventMutation) NotificationRecordCleared() bool { - return m.clearednotification_record +// ClearEvent clears the "event" edge to the Event entity. +func (m *NotificationRecordMutation) ClearEvent() { + m.clearedevent = true } -// NotificationRecordID returns the "notification_record" edge ID in the mutation. -func (m *EventMutation) NotificationRecordID() (id int, exists bool) { - if m.notification_record != nil { - return *m.notification_record, true - } - return +// EventCleared reports if the "event" edge to the Event entity was cleared. +func (m *NotificationRecordMutation) EventCleared() bool { + return m.clearedevent } -// NotificationRecordIDs returns the "notification_record" edge IDs in the mutation. +// EventIDs returns the "event" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// NotificationRecordID instead. It exists only for internal usage by the builders. -func (m *EventMutation) NotificationRecordIDs() (ids []int) { - if id := m.notification_record; id != nil { +// EventID instead. It exists only for internal usage by the builders. +func (m *NotificationRecordMutation) EventIDs() (ids []int) { + if id := m.event; id != nil { ids = append(ids, *id) } return } -// ResetNotificationRecord resets all changes to the "notification_record" edge. -func (m *EventMutation) ResetNotificationRecord() { - m.notification_record = nil - m.clearednotification_record = false +// ResetEvent resets all changes to the "event" edge. +func (m *NotificationRecordMutation) ResetEvent() { + m.event = nil + m.clearedevent = false } -// Where appends a list predicates to the EventMutation builder. -func (m *EventMutation) Where(ps ...predicate.Event) { +// Where appends a list predicates to the NotificationRecordMutation builder. +func (m *NotificationRecordMutation) Where(ps ...predicate.NotificationRecord) { m.predicates = append(m.predicates, ps...) } // Op returns the operation name. -func (m *EventMutation) Op() Op { +func (m *NotificationRecordMutation) Op() Op { return m.op } -// Type returns the node type of this mutation (Event). -func (m *EventMutation) Type() string { +// Type returns the node type of this mutation (NotificationRecord). +func (m *NotificationRecordMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). -func (m *EventMutation) Fields() []string { - fields := make([]string, 0, 6) - if m.kind != nil { - fields = append(fields, event.FieldKind) - } - if m._type != nil { - fields = append(fields, event.FieldType) - } - if m.created_at != nil { - fields = append(fields, event.FieldCreatedAt) - } - if m.deployment != nil { - fields = append(fields, event.FieldDeploymentID) - } - if m.approval != nil { - fields = append(fields, event.FieldApprovalID) - } - if m.deleted_id != nil { - fields = append(fields, event.FieldDeletedID) +func (m *NotificationRecordMutation) Fields() []string { + fields := make([]string, 0, 1) + if m.event != nil { + fields = append(fields, notificationrecord.FieldEventID) } return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *EventMutation) Field(name string) (ent.Value, bool) { - switch name { - case event.FieldKind: - return m.Kind() - case event.FieldType: - return m.GetType() - case event.FieldCreatedAt: - return m.CreatedAt() - case event.FieldDeploymentID: - return m.DeploymentID() - case event.FieldApprovalID: - return m.ApprovalID() - case event.FieldDeletedID: - return m.DeletedID() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *EventMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case event.FieldKind: - return m.OldKind(ctx) - case event.FieldType: - return m.OldType(ctx) - case event.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case event.FieldDeploymentID: - return m.OldDeploymentID(ctx) - case event.FieldApprovalID: - return m.OldApprovalID(ctx) - case event.FieldDeletedID: - return m.OldDeletedID(ctx) - } - return nil, fmt.Errorf("unknown Event field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *EventMutation) SetField(name string, value ent.Value) error { - switch name { - case event.FieldKind: - v, ok := value.(event.Kind) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetKind(v) - return nil - case event.FieldType: - v, ok := value.(event.Type) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetType(v) - return nil - case event.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case event.FieldDeploymentID: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDeploymentID(v) - return nil - case event.FieldApprovalID: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetApprovalID(v) - return nil - case event.FieldDeletedID: +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *NotificationRecordMutation) Field(name string) (ent.Value, bool) { + switch name { + case notificationrecord.FieldEventID: + return m.EventID() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *NotificationRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case notificationrecord.FieldEventID: + return m.OldEventID(ctx) + } + return nil, fmt.Errorf("unknown NotificationRecord field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *NotificationRecordMutation) SetField(name string, value ent.Value) error { + switch name { + case notificationrecord.FieldEventID: v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDeletedID(v) + m.SetEventID(v) return nil } - return fmt.Errorf("unknown Event field %s", name) + return fmt.Errorf("unknown NotificationRecord field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *EventMutation) AddedFields() []string { +func (m *NotificationRecordMutation) AddedFields() []string { var fields []string - if m.adddeleted_id != nil { - fields = append(fields, event.FieldDeletedID) - } return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *EventMutation) AddedField(name string) (ent.Value, bool) { +func (m *NotificationRecordMutation) AddedField(name string) (ent.Value, bool) { switch name { - case event.FieldDeletedID: - return m.AddedDeletedID() } return nil, false } @@ -6011,114 +6525,57 @@ func (m *EventMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *EventMutation) AddField(name string, value ent.Value) error { +func (m *NotificationRecordMutation) AddField(name string, value ent.Value) error { switch name { - case event.FieldDeletedID: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddDeletedID(v) - return nil } - return fmt.Errorf("unknown Event numeric field %s", name) + return fmt.Errorf("unknown NotificationRecord numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *EventMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(event.FieldDeploymentID) { - fields = append(fields, event.FieldDeploymentID) - } - if m.FieldCleared(event.FieldApprovalID) { - fields = append(fields, event.FieldApprovalID) - } - if m.FieldCleared(event.FieldDeletedID) { - fields = append(fields, event.FieldDeletedID) - } - return fields +func (m *NotificationRecordMutation) ClearedFields() []string { + return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *EventMutation) FieldCleared(name string) bool { +func (m *NotificationRecordMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *EventMutation) ClearField(name string) error { - switch name { - case event.FieldDeploymentID: - m.ClearDeploymentID() - return nil - case event.FieldApprovalID: - m.ClearApprovalID() - return nil - case event.FieldDeletedID: - m.ClearDeletedID() - return nil - } - return fmt.Errorf("unknown Event nullable field %s", name) +func (m *NotificationRecordMutation) ClearField(name string) error { + return fmt.Errorf("unknown NotificationRecord nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *EventMutation) ResetField(name string) error { +func (m *NotificationRecordMutation) ResetField(name string) error { switch name { - case event.FieldKind: - m.ResetKind() - return nil - case event.FieldType: - m.ResetType() - return nil - case event.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case event.FieldDeploymentID: - m.ResetDeploymentID() - return nil - case event.FieldApprovalID: - m.ResetApprovalID() - return nil - case event.FieldDeletedID: - m.ResetDeletedID() + case notificationrecord.FieldEventID: + m.ResetEventID() return nil } - return fmt.Errorf("unknown Event field %s", name) + return fmt.Errorf("unknown NotificationRecord field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *EventMutation) AddedEdges() []string { - edges := make([]string, 0, 3) - if m.deployment != nil { - edges = append(edges, event.EdgeDeployment) - } - if m.approval != nil { - edges = append(edges, event.EdgeApproval) - } - if m.notification_record != nil { - edges = append(edges, event.EdgeNotificationRecord) +func (m *NotificationRecordMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.event != nil { + edges = append(edges, notificationrecord.EdgeEvent) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *EventMutation) AddedIDs(name string) []ent.Value { +func (m *NotificationRecordMutation) AddedIDs(name string) []ent.Value { switch name { - case event.EdgeDeployment: - if id := m.deployment; id != nil { - return []ent.Value{*id} - } - case event.EdgeApproval: - if id := m.approval; id != nil { - return []ent.Value{*id} - } - case event.EdgeNotificationRecord: - if id := m.notification_record; id != nil { + case notificationrecord.EdgeEvent: + if id := m.event; id != nil { return []ent.Value{*id} } } @@ -6126,112 +6583,91 @@ func (m *EventMutation) AddedIDs(name string) []ent.Value { } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *EventMutation) RemovedEdges() []string { - edges := make([]string, 0, 3) +func (m *NotificationRecordMutation) RemovedEdges() []string { + 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 *EventMutation) RemovedIDs(name string) []ent.Value { +func (m *NotificationRecordMutation) RemovedIDs(name string) []ent.Value { switch name { } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *EventMutation) ClearedEdges() []string { - edges := make([]string, 0, 3) - if m.cleareddeployment { - edges = append(edges, event.EdgeDeployment) - } - if m.clearedapproval { - edges = append(edges, event.EdgeApproval) - } - if m.clearednotification_record { - edges = append(edges, event.EdgeNotificationRecord) +func (m *NotificationRecordMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedevent { + edges = append(edges, notificationrecord.EdgeEvent) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *EventMutation) EdgeCleared(name string) bool { +func (m *NotificationRecordMutation) EdgeCleared(name string) bool { switch name { - case event.EdgeDeployment: - return m.cleareddeployment - case event.EdgeApproval: - return m.clearedapproval - case event.EdgeNotificationRecord: - return m.clearednotification_record + case notificationrecord.EdgeEvent: + return m.clearedevent } 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 *EventMutation) ClearEdge(name string) error { +func (m *NotificationRecordMutation) ClearEdge(name string) error { switch name { - case event.EdgeDeployment: - m.ClearDeployment() - return nil - case event.EdgeApproval: - m.ClearApproval() - return nil - case event.EdgeNotificationRecord: - m.ClearNotificationRecord() + case notificationrecord.EdgeEvent: + m.ClearEvent() return nil } - return fmt.Errorf("unknown Event unique edge %s", name) + return fmt.Errorf("unknown NotificationRecord 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 *EventMutation) ResetEdge(name string) error { +func (m *NotificationRecordMutation) ResetEdge(name string) error { switch name { - case event.EdgeDeployment: - m.ResetDeployment() - return nil - case event.EdgeApproval: - m.ResetApproval() - return nil - case event.EdgeNotificationRecord: - m.ResetNotificationRecord() + case notificationrecord.EdgeEvent: + m.ResetEvent() return nil } - return fmt.Errorf("unknown Event edge %s", name) + return fmt.Errorf("unknown NotificationRecord edge %s", name) } -// LockMutation represents an operation that mutates the Lock nodes in the graph. -type LockMutation struct { +// PermMutation represents an operation that mutates the Perm nodes in the graph. +type PermMutation struct { config op Op typ string id *int - env *string - expired_at *time.Time + repo_perm *perm.RepoPerm + synced_at *time.Time created_at *time.Time + updated_at *time.Time clearedFields map[string]struct{} user *int64 cleareduser bool repo *int64 clearedrepo bool done bool - oldValue func(context.Context) (*Lock, error) - predicates []predicate.Lock + oldValue func(context.Context) (*Perm, error) + predicates []predicate.Perm } -var _ ent.Mutation = (*LockMutation)(nil) +var _ ent.Mutation = (*PermMutation)(nil) -// lockOption allows management of the mutation configuration using functional options. -type lockOption func(*LockMutation) +// permOption allows management of the mutation configuration using functional options. +type permOption func(*PermMutation) -// newLockMutation creates new mutation for the Lock entity. -func newLockMutation(c config, op Op, opts ...lockOption) *LockMutation { - m := &LockMutation{ +// newPermMutation creates new mutation for the Perm entity. +func newPermMutation(c config, op Op, opts ...permOption) *PermMutation { + m := &PermMutation{ config: c, op: op, - typ: TypeLock, + typ: TypePerm, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -6240,20 +6676,20 @@ func newLockMutation(c config, op Op, opts ...lockOption) *LockMutation { return m } -// withLockID sets the ID field of the mutation. -func withLockID(id int) lockOption { - return func(m *LockMutation) { +// withPermID sets the ID field of the mutation. +func withPermID(id int) permOption { + return func(m *PermMutation) { var ( err error once sync.Once - value *Lock + value *Perm ) - m.oldValue = func(ctx context.Context) (*Lock, error) { + m.oldValue = func(ctx context.Context) (*Perm, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { - value, err = m.Client().Lock.Get(ctx, id) + value, err = m.Client().Perm.Get(ctx, id) } }) return value, err @@ -6262,10 +6698,10 @@ func withLockID(id int) lockOption { } } -// withLock sets the old Lock of the mutation. -func withLock(node *Lock) lockOption { - return func(m *LockMutation) { - m.oldValue = func(context.Context) (*Lock, error) { +// withPerm sets the old Perm of the mutation. +func withPerm(node *Perm) permOption { + return func(m *PermMutation) { + m.oldValue = func(context.Context) (*Perm, error) { return node, nil } m.id = &node.ID @@ -6274,7 +6710,7 @@ func withLock(node *Lock) lockOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m LockMutation) Client() *Client { +func (m PermMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -6282,7 +6718,7 @@ func (m LockMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m LockMutation) Tx() (*Tx, error) { +func (m PermMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("ent: mutation is not running in a transaction") } @@ -6293,105 +6729,105 @@ func (m LockMutation) Tx() (*Tx, error) { // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *LockMutation) ID() (id int, exists bool) { +func (m *PermMutation) ID() (id int, exists bool) { if m.id == nil { return } return *m.id, true } -// SetEnv sets the "env" field. -func (m *LockMutation) SetEnv(s string) { - m.env = &s +// SetRepoPerm sets the "repo_perm" field. +func (m *PermMutation) SetRepoPerm(pp perm.RepoPerm) { + m.repo_perm = &pp } -// Env returns the value of the "env" field in the mutation. -func (m *LockMutation) Env() (r string, exists bool) { - v := m.env +// RepoPerm returns the value of the "repo_perm" field in the mutation. +func (m *PermMutation) RepoPerm() (r perm.RepoPerm, exists bool) { + v := m.repo_perm if v == nil { return } return *v, true } -// OldEnv returns the old "env" field's value of the Lock entity. -// If the Lock object wasn't provided to the builder, the object is fetched from the database. +// OldRepoPerm returns the old "repo_perm" field's value of the Perm entity. +// If the Perm 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 *LockMutation) OldEnv(ctx context.Context) (v string, err error) { +func (m *PermMutation) OldRepoPerm(ctx context.Context) (v perm.RepoPerm, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEnv is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldRepoPerm 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("OldRepoPerm 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 OldRepoPerm: %w", err) } - return oldValue.Env, nil + return oldValue.RepoPerm, nil } -// ResetEnv resets all changes to the "env" field. -func (m *LockMutation) ResetEnv() { - m.env = nil +// ResetRepoPerm resets all changes to the "repo_perm" field. +func (m *PermMutation) ResetRepoPerm() { + m.repo_perm = nil } -// SetExpiredAt sets the "expired_at" field. -func (m *LockMutation) SetExpiredAt(t time.Time) { - m.expired_at = &t +// SetSyncedAt sets the "synced_at" field. +func (m *PermMutation) SetSyncedAt(t time.Time) { + m.synced_at = &t } -// ExpiredAt returns the value of the "expired_at" field in the mutation. -func (m *LockMutation) ExpiredAt() (r time.Time, exists bool) { - v := m.expired_at +// SyncedAt returns the value of the "synced_at" field in the mutation. +func (m *PermMutation) SyncedAt() (r time.Time, exists bool) { + v := m.synced_at if v == nil { return } return *v, true } -// OldExpiredAt returns the old "expired_at" field's value of the Lock entity. -// If the Lock object wasn't provided to the builder, the object is fetched from the database. +// OldSyncedAt returns the old "synced_at" field's value of the Perm entity. +// If the Perm 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 *LockMutation) OldExpiredAt(ctx context.Context) (v *time.Time, err error) { +func (m *PermMutation) OldSyncedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldExpiredAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldSyncedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldExpiredAt requires an ID field in the mutation") + return v, fmt.Errorf("OldSyncedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldExpiredAt: %w", err) + return v, fmt.Errorf("querying old value for OldSyncedAt: %w", err) } - return oldValue.ExpiredAt, nil + return oldValue.SyncedAt, nil } -// ClearExpiredAt clears the value of the "expired_at" field. -func (m *LockMutation) ClearExpiredAt() { - m.expired_at = nil - m.clearedFields[lock.FieldExpiredAt] = struct{}{} +// ClearSyncedAt clears the value of the "synced_at" field. +func (m *PermMutation) ClearSyncedAt() { + m.synced_at = nil + m.clearedFields[perm.FieldSyncedAt] = struct{}{} } -// ExpiredAtCleared returns if the "expired_at" field was cleared in this mutation. -func (m *LockMutation) ExpiredAtCleared() bool { - _, ok := m.clearedFields[lock.FieldExpiredAt] +// SyncedAtCleared returns if the "synced_at" field was cleared in this mutation. +func (m *PermMutation) SyncedAtCleared() bool { + _, ok := m.clearedFields[perm.FieldSyncedAt] return ok } -// ResetExpiredAt resets all changes to the "expired_at" field. -func (m *LockMutation) ResetExpiredAt() { - m.expired_at = nil - delete(m.clearedFields, lock.FieldExpiredAt) +// ResetSyncedAt resets all changes to the "synced_at" field. +func (m *PermMutation) ResetSyncedAt() { + m.synced_at = nil + delete(m.clearedFields, perm.FieldSyncedAt) } // SetCreatedAt sets the "created_at" field. -func (m *LockMutation) SetCreatedAt(t time.Time) { +func (m *PermMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *LockMutation) CreatedAt() (r time.Time, exists bool) { +func (m *PermMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -6399,10 +6835,10 @@ func (m *LockMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the Lock entity. -// If the Lock object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the Perm entity. +// If the Perm 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 *LockMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *PermMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } @@ -6417,17 +6853,53 @@ func (m *LockMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *LockMutation) ResetCreatedAt() { +func (m *PermMutation) ResetCreatedAt() { m.created_at = nil } +// SetUpdatedAt sets the "updated_at" field. +func (m *PermMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *PermMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Perm entity. +// If the Perm 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 *PermMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *PermMutation) ResetUpdatedAt() { + m.updated_at = nil +} + // SetUserID sets the "user_id" field. -func (m *LockMutation) SetUserID(i int64) { +func (m *PermMutation) SetUserID(i int64) { m.user = &i } // UserID returns the value of the "user_id" field in the mutation. -func (m *LockMutation) UserID() (r int64, exists bool) { +func (m *PermMutation) UserID() (r int64, exists bool) { v := m.user if v == nil { return @@ -6435,10 +6907,10 @@ func (m *LockMutation) UserID() (r int64, exists bool) { return *v, true } -// OldUserID returns the old "user_id" field's value of the Lock entity. -// If the Lock object wasn't provided to the builder, the object is fetched from the database. +// OldUserID returns the old "user_id" field's value of the Perm entity. +// If the Perm 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 *LockMutation) OldUserID(ctx context.Context) (v int64, err error) { +func (m *PermMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") } @@ -6453,17 +6925,17 @@ func (m *LockMutation) OldUserID(ctx context.Context) (v int64, err error) { } // ResetUserID resets all changes to the "user_id" field. -func (m *LockMutation) ResetUserID() { +func (m *PermMutation) ResetUserID() { m.user = nil } // SetRepoID sets the "repo_id" field. -func (m *LockMutation) SetRepoID(i int64) { +func (m *PermMutation) SetRepoID(i int64) { m.repo = &i } // RepoID returns the value of the "repo_id" field in the mutation. -func (m *LockMutation) RepoID() (r int64, exists bool) { +func (m *PermMutation) RepoID() (r int64, exists bool) { v := m.repo if v == nil { return @@ -6471,10 +6943,10 @@ func (m *LockMutation) RepoID() (r int64, exists bool) { return *v, true } -// OldRepoID returns the old "repo_id" field's value of the Lock entity. -// If the Lock object wasn't provided to the builder, the object is fetched from the database. +// OldRepoID returns the old "repo_id" field's value of the Perm entity. +// If the Perm 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 *LockMutation) OldRepoID(ctx context.Context) (v int64, err error) { +func (m *PermMutation) OldRepoID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations") } @@ -6489,24 +6961,24 @@ func (m *LockMutation) OldRepoID(ctx context.Context) (v int64, err error) { } // ResetRepoID resets all changes to the "repo_id" field. -func (m *LockMutation) ResetRepoID() { +func (m *PermMutation) ResetRepoID() { m.repo = nil } // ClearUser clears the "user" edge to the User entity. -func (m *LockMutation) ClearUser() { +func (m *PermMutation) ClearUser() { m.cleareduser = true } // UserCleared reports if the "user" edge to the User entity was cleared. -func (m *LockMutation) UserCleared() bool { +func (m *PermMutation) UserCleared() bool { return m.cleareduser } // UserIDs returns the "user" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // UserID instead. It exists only for internal usage by the builders. -func (m *LockMutation) UserIDs() (ids []int64) { +func (m *PermMutation) UserIDs() (ids []int64) { if id := m.user; id != nil { ids = append(ids, *id) } @@ -6514,25 +6986,25 @@ func (m *LockMutation) UserIDs() (ids []int64) { } // ResetUser resets all changes to the "user" edge. -func (m *LockMutation) ResetUser() { +func (m *PermMutation) ResetUser() { m.user = nil m.cleareduser = false } // ClearRepo clears the "repo" edge to the Repo entity. -func (m *LockMutation) ClearRepo() { +func (m *PermMutation) ClearRepo() { m.clearedrepo = true } // RepoCleared reports if the "repo" edge to the Repo entity was cleared. -func (m *LockMutation) RepoCleared() bool { +func (m *PermMutation) 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 *LockMutation) RepoIDs() (ids []int64) { +func (m *PermMutation) RepoIDs() (ids []int64) { if id := m.repo; id != nil { ids = append(ids, *id) } @@ -6540,45 +7012,48 @@ func (m *LockMutation) RepoIDs() (ids []int64) { } // ResetRepo resets all changes to the "repo" edge. -func (m *LockMutation) ResetRepo() { +func (m *PermMutation) ResetRepo() { m.repo = nil m.clearedrepo = false } -// Where appends a list predicates to the LockMutation builder. -func (m *LockMutation) Where(ps ...predicate.Lock) { +// Where appends a list predicates to the PermMutation builder. +func (m *PermMutation) Where(ps ...predicate.Perm) { m.predicates = append(m.predicates, ps...) } // Op returns the operation name. -func (m *LockMutation) Op() Op { +func (m *PermMutation) Op() Op { return m.op } -// Type returns the node type of this mutation (Lock). -func (m *LockMutation) Type() string { +// Type returns the node type of this mutation (Perm). +func (m *PermMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). -func (m *LockMutation) Fields() []string { - fields := make([]string, 0, 5) - if m.env != nil { - fields = append(fields, lock.FieldEnv) +func (m *PermMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.repo_perm != nil { + fields = append(fields, perm.FieldRepoPerm) } - if m.expired_at != nil { - fields = append(fields, lock.FieldExpiredAt) + if m.synced_at != nil { + fields = append(fields, perm.FieldSyncedAt) } if m.created_at != nil { - fields = append(fields, lock.FieldCreatedAt) + fields = append(fields, perm.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, perm.FieldUpdatedAt) } if m.user != nil { - fields = append(fields, lock.FieldUserID) + fields = append(fields, perm.FieldUserID) } if m.repo != nil { - fields = append(fields, lock.FieldRepoID) + fields = append(fields, perm.FieldRepoID) } return fields } @@ -6586,17 +7061,19 @@ func (m *LockMutation) Fields() []string { // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *LockMutation) Field(name string) (ent.Value, bool) { +func (m *PermMutation) Field(name string) (ent.Value, bool) { switch name { - case lock.FieldEnv: - return m.Env() - case lock.FieldExpiredAt: - return m.ExpiredAt() - case lock.FieldCreatedAt: + case perm.FieldRepoPerm: + return m.RepoPerm() + case perm.FieldSyncedAt: + return m.SyncedAt() + case perm.FieldCreatedAt: return m.CreatedAt() - case lock.FieldUserID: + case perm.FieldUpdatedAt: + return m.UpdatedAt() + case perm.FieldUserID: return m.UserID() - case lock.FieldRepoID: + case perm.FieldRepoID: return m.RepoID() } return nil, false @@ -6605,56 +7082,65 @@ func (m *LockMutation) Field(name string) (ent.Value, bool) { // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. -func (m *LockMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *PermMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case lock.FieldEnv: - return m.OldEnv(ctx) - case lock.FieldExpiredAt: - return m.OldExpiredAt(ctx) - case lock.FieldCreatedAt: + case perm.FieldRepoPerm: + return m.OldRepoPerm(ctx) + case perm.FieldSyncedAt: + return m.OldSyncedAt(ctx) + case perm.FieldCreatedAt: return m.OldCreatedAt(ctx) - case lock.FieldUserID: + case perm.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case perm.FieldUserID: return m.OldUserID(ctx) - case lock.FieldRepoID: + case perm.FieldRepoID: return m.OldRepoID(ctx) } - return nil, fmt.Errorf("unknown Lock field %s", name) + return nil, fmt.Errorf("unknown Perm field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *LockMutation) SetField(name string, value ent.Value) error { +func (m *PermMutation) SetField(name string, value ent.Value) error { switch name { - case lock.FieldEnv: - v, ok := value.(string) + case perm.FieldRepoPerm: + v, ok := value.(perm.RepoPerm) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetEnv(v) + m.SetRepoPerm(v) return nil - case lock.FieldExpiredAt: + case perm.FieldSyncedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetExpiredAt(v) + m.SetSyncedAt(v) return nil - case lock.FieldCreatedAt: + case perm.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil - case lock.FieldUserID: + case perm.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case perm.FieldUserID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetUserID(v) return nil - case lock.FieldRepoID: + case perm.FieldRepoID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) @@ -6662,12 +7148,12 @@ func (m *LockMutation) SetField(name string, value ent.Value) error { m.SetRepoID(v) return nil } - return fmt.Errorf("unknown Lock field %s", name) + return fmt.Errorf("unknown Perm field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *LockMutation) AddedFields() []string { +func (m *PermMutation) AddedFields() []string { var fields []string return fields } @@ -6675,7 +7161,7 @@ func (m *LockMutation) AddedFields() []string { // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *LockMutation) AddedField(name string) (ent.Value, bool) { +func (m *PermMutation) AddedField(name string) (ent.Value, bool) { switch name { } return nil, false @@ -6684,84 +7170,87 @@ func (m *LockMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *LockMutation) AddField(name string, value ent.Value) error { +func (m *PermMutation) AddField(name string, value ent.Value) error { switch name { } - return fmt.Errorf("unknown Lock numeric field %s", name) + return fmt.Errorf("unknown Perm numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *LockMutation) ClearedFields() []string { +func (m *PermMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(lock.FieldExpiredAt) { - fields = append(fields, lock.FieldExpiredAt) + if m.FieldCleared(perm.FieldSyncedAt) { + fields = append(fields, perm.FieldSyncedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *LockMutation) FieldCleared(name string) bool { +func (m *PermMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *LockMutation) ClearField(name string) error { +func (m *PermMutation) ClearField(name string) error { switch name { - case lock.FieldExpiredAt: - m.ClearExpiredAt() + case perm.FieldSyncedAt: + m.ClearSyncedAt() return nil } - return fmt.Errorf("unknown Lock nullable field %s", name) + return fmt.Errorf("unknown Perm nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *LockMutation) ResetField(name string) error { +func (m *PermMutation) ResetField(name string) error { switch name { - case lock.FieldEnv: - m.ResetEnv() + case perm.FieldRepoPerm: + m.ResetRepoPerm() return nil - case lock.FieldExpiredAt: - m.ResetExpiredAt() + case perm.FieldSyncedAt: + m.ResetSyncedAt() return nil - case lock.FieldCreatedAt: + case perm.FieldCreatedAt: m.ResetCreatedAt() return nil - case lock.FieldUserID: + case perm.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case perm.FieldUserID: m.ResetUserID() return nil - case lock.FieldRepoID: + case perm.FieldRepoID: m.ResetRepoID() return nil } - return fmt.Errorf("unknown Lock field %s", name) + return fmt.Errorf("unknown Perm field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *LockMutation) AddedEdges() []string { +func (m *PermMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.user != nil { - edges = append(edges, lock.EdgeUser) + edges = append(edges, perm.EdgeUser) } if m.repo != nil { - edges = append(edges, lock.EdgeRepo) + edges = append(edges, perm.EdgeRepo) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *LockMutation) AddedIDs(name string) []ent.Value { +func (m *PermMutation) AddedIDs(name string) []ent.Value { switch name { - case lock.EdgeUser: + case perm.EdgeUser: if id := m.user; id != nil { return []ent.Value{*id} } - case lock.EdgeRepo: + case perm.EdgeRepo: if id := m.repo; id != nil { return []ent.Value{*id} } @@ -6770,38 +7259,38 @@ func (m *LockMutation) AddedIDs(name string) []ent.Value { } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *LockMutation) RemovedEdges() []string { +func (m *PermMutation) RemovedEdges() []string { edges := make([]string, 0, 2) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *LockMutation) RemovedIDs(name string) []ent.Value { +func (m *PermMutation) RemovedIDs(name string) []ent.Value { switch name { } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *LockMutation) ClearedEdges() []string { +func (m *PermMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.cleareduser { - edges = append(edges, lock.EdgeUser) + edges = append(edges, perm.EdgeUser) } if m.clearedrepo { - edges = append(edges, lock.EdgeRepo) + edges = append(edges, perm.EdgeRepo) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *LockMutation) EdgeCleared(name string) bool { +func (m *PermMutation) EdgeCleared(name string) bool { switch name { - case lock.EdgeUser: + case perm.EdgeUser: return m.cleareduser - case lock.EdgeRepo: + case perm.EdgeRepo: return m.clearedrepo } return false @@ -6809,573 +7298,411 @@ func (m *LockMutation) EdgeCleared(name string) bool { // 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 *LockMutation) ClearEdge(name string) error { +func (m *PermMutation) ClearEdge(name string) error { switch name { - case lock.EdgeUser: + case perm.EdgeUser: m.ClearUser() return nil - case lock.EdgeRepo: + case perm.EdgeRepo: m.ClearRepo() return nil } - return fmt.Errorf("unknown Lock unique edge %s", name) + return fmt.Errorf("unknown Perm 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 *LockMutation) ResetEdge(name string) error { +func (m *PermMutation) ResetEdge(name string) error { switch name { - case lock.EdgeUser: + case perm.EdgeUser: m.ResetUser() return nil - case lock.EdgeRepo: + case perm.EdgeRepo: m.ResetRepo() return nil } - return fmt.Errorf("unknown Lock edge %s", name) + return fmt.Errorf("unknown Perm edge %s", name) } -// NotificationRecordMutation represents an operation that mutates the NotificationRecord nodes in the graph. -type NotificationRecordMutation struct { +// RepoMutation represents an operation that mutates the Repo nodes in the graph. +type RepoMutation struct { config - op Op - typ string - id *int - clearedFields map[string]struct{} - event *int - clearedevent bool - done bool - oldValue func(context.Context) (*NotificationRecord, error) - predicates []predicate.NotificationRecord -} - -var _ ent.Mutation = (*NotificationRecordMutation)(nil) - -// notificationrecordOption allows management of the mutation configuration using functional options. -type notificationrecordOption func(*NotificationRecordMutation) - -// newNotificationRecordMutation creates new mutation for the NotificationRecord entity. -func newNotificationRecordMutation(c config, op Op, opts ...notificationrecordOption) *NotificationRecordMutation { - m := &NotificationRecordMutation{ - config: c, - op: op, - typ: TypeNotificationRecord, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withNotificationRecordID sets the ID field of the mutation. -func withNotificationRecordID(id int) notificationrecordOption { - return func(m *NotificationRecordMutation) { - var ( - err error - once sync.Once - value *NotificationRecord - ) - m.oldValue = func(ctx context.Context) (*NotificationRecord, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().NotificationRecord.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withNotificationRecord sets the old NotificationRecord of the mutation. -func withNotificationRecord(node *NotificationRecord) notificationrecordOption { - return func(m *NotificationRecordMutation) { - m.oldValue = func(context.Context) (*NotificationRecord, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m NotificationRecordMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m NotificationRecordMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *NotificationRecordMutation) ID() (id int, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// SetEventID sets the "event_id" field. -func (m *NotificationRecordMutation) SetEventID(i int) { - m.event = &i -} - -// EventID returns the value of the "event_id" field in the mutation. -func (m *NotificationRecordMutation) EventID() (r int, exists bool) { - v := m.event - if v == nil { - return - } - return *v, true -} - -// OldEventID returns the old "event_id" field's value of the NotificationRecord entity. -// If the NotificationRecord 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 *NotificationRecordMutation) OldEventID(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldEventID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldEventID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldEventID: %w", err) - } - return oldValue.EventID, nil -} - -// ResetEventID resets all changes to the "event_id" field. -func (m *NotificationRecordMutation) ResetEventID() { - m.event = nil -} - -// ClearEvent clears the "event" edge to the Event entity. -func (m *NotificationRecordMutation) ClearEvent() { - m.clearedevent = true -} - -// EventCleared reports if the "event" edge to the Event entity was cleared. -func (m *NotificationRecordMutation) EventCleared() bool { - return m.clearedevent -} - -// EventIDs returns the "event" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// EventID instead. It exists only for internal usage by the builders. -func (m *NotificationRecordMutation) EventIDs() (ids []int) { - if id := m.event; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetEvent resets all changes to the "event" edge. -func (m *NotificationRecordMutation) ResetEvent() { - m.event = nil - m.clearedevent = false -} - -// Where appends a list predicates to the NotificationRecordMutation builder. -func (m *NotificationRecordMutation) Where(ps ...predicate.NotificationRecord) { - m.predicates = append(m.predicates, ps...) + 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 } -// Op returns the operation name. -func (m *NotificationRecordMutation) Op() Op { - return m.op -} +var _ ent.Mutation = (*RepoMutation)(nil) -// Type returns the node type of this mutation (NotificationRecord). -func (m *NotificationRecordMutation) Type() string { - return m.typ -} +// repoOption allows management of the mutation configuration using functional options. +type repoOption func(*RepoMutation) -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *NotificationRecordMutation) Fields() []string { - fields := make([]string, 0, 1) - if m.event != nil { - fields = append(fields, notificationrecord.FieldEventID) +// newRepoMutation creates new mutation for the Repo entity. +func newRepoMutation(c config, op Op, opts ...repoOption) *RepoMutation { + m := &RepoMutation{ + config: c, + op: op, + typ: TypeRepo, + clearedFields: make(map[string]struct{}), } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *NotificationRecordMutation) Field(name string) (ent.Value, bool) { - switch name { - case notificationrecord.FieldEventID: - return m.EventID() + for _, opt := range opts { + opt(m) } - return nil, false + return m } -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *NotificationRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case notificationrecord.FieldEventID: - return m.OldEventID(ctx) +// withRepoID sets the ID field of the mutation. +func withRepoID(id int64) repoOption { + return func(m *RepoMutation) { + var ( + err error + once sync.Once + value *Repo + ) + m.oldValue = func(ctx context.Context) (*Repo, error) { + once.Do(func() { + if m.done { + err = fmt.Errorf("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Repo.Get(ctx, id) + } + }) + return value, err + } + m.id = &id } - return nil, fmt.Errorf("unknown NotificationRecord field %s", name) } -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *NotificationRecordMutation) SetField(name string, value ent.Value) error { - switch name { - case notificationrecord.FieldEventID: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) +// withRepo sets the old Repo of the mutation. +func withRepo(node *Repo) repoOption { + return func(m *RepoMutation) { + m.oldValue = func(context.Context) (*Repo, error) { + return node, nil } - m.SetEventID(v) - return nil + m.id = &node.ID } - return fmt.Errorf("unknown NotificationRecord field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *NotificationRecordMutation) AddedFields() []string { - var fields []string - return fields } -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *NotificationRecordMutation) AddedField(name string) (ent.Value, bool) { - switch name { - } - return nil, false +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m RepoMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client } -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *NotificationRecordMutation) AddField(name string, value ent.Value) error { - switch name { +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m RepoMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, fmt.Errorf("ent: mutation is not running in a transaction") } - return fmt.Errorf("unknown NotificationRecord numeric field %s", name) + tx := &Tx{config: m.config} + tx.init() + return tx, nil } -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *NotificationRecordMutation) ClearedFields() []string { - return nil +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Repo entities. +func (m *RepoMutation) SetID(id int64) { + m.id = &id } -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *NotificationRecordMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *RepoMutation) ID() (id int64, exists bool) { + if m.id == nil { + return + } + return *m.id, true } -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *NotificationRecordMutation) ClearField(name string) error { - return fmt.Errorf("unknown NotificationRecord nullable field %s", name) +// SetNamespace sets the "namespace" field. +func (m *RepoMutation) SetNamespace(s string) { + m.namespace = &s } -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *NotificationRecordMutation) ResetField(name string) error { - switch name { - case notificationrecord.FieldEventID: - m.ResetEventID() - return nil +// Namespace returns the value of the "namespace" field in the mutation. +func (m *RepoMutation) Namespace() (r string, exists bool) { + v := m.namespace + if v == nil { + return } - return fmt.Errorf("unknown NotificationRecord field %s", name) + return *v, true } -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *NotificationRecordMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.event != nil { - edges = append(edges, notificationrecord.EdgeEvent) +// OldNamespace returns the old "namespace" field's value of the Repo entity. +// If the Repo 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 *RepoMutation) OldNamespace(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldNamespace is only allowed on UpdateOne operations") } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *NotificationRecordMutation) AddedIDs(name string) []ent.Value { - switch name { - case notificationrecord.EdgeEvent: - if id := m.event; id != nil { - return []ent.Value{*id} - } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldNamespace requires an ID field in the mutation") } - return nil + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNamespace: %w", err) + } + return oldValue.Namespace, nil } -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *NotificationRecordMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - return edges +// ResetNamespace resets all changes to the "namespace" field. +func (m *RepoMutation) ResetNamespace() { + m.namespace = nil } -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *NotificationRecordMutation) RemovedIDs(name string) []ent.Value { - switch name { - } - return nil +// SetName sets the "name" field. +func (m *RepoMutation) SetName(s string) { + m.name = &s } -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *NotificationRecordMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedevent { - edges = append(edges, notificationrecord.EdgeEvent) +// Name returns the value of the "name" field in the mutation. +func (m *RepoMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return } - return edges + return *v, true } -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *NotificationRecordMutation) EdgeCleared(name string) bool { - switch name { - case notificationrecord.EdgeEvent: - return m.clearedevent +// OldName returns the old "name" field's value of the Repo entity. +// If the Repo 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 *RepoMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldName is only allowed on UpdateOne operations") } - 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 *NotificationRecordMutation) ClearEdge(name string) error { - switch name { - case notificationrecord.EdgeEvent: - m.ClearEvent() - return nil + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldName 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 fmt.Errorf("unknown NotificationRecord unique edge %s", name) + return oldValue.Name, nil } -// 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 *NotificationRecordMutation) ResetEdge(name string) error { - switch name { - case notificationrecord.EdgeEvent: - m.ResetEvent() - return nil - } - return fmt.Errorf("unknown NotificationRecord edge %s", name) +// ResetName resets all changes to the "name" field. +func (m *RepoMutation) ResetName() { + m.name = nil } -// PermMutation represents an operation that mutates the Perm nodes in the graph. -type PermMutation struct { - config - op Op - typ string - id *int - repo_perm *perm.RepoPerm - synced_at *time.Time - created_at *time.Time - updated_at *time.Time - clearedFields map[string]struct{} - user *int64 - cleareduser bool - repo *int64 - clearedrepo bool - done bool - oldValue func(context.Context) (*Perm, error) - predicates []predicate.Perm +// SetDescription sets the "description" field. +func (m *RepoMutation) SetDescription(s string) { + m.description = &s } -var _ ent.Mutation = (*PermMutation)(nil) - -// permOption allows management of the mutation configuration using functional options. -type permOption func(*PermMutation) - -// newPermMutation creates new mutation for the Perm entity. -func newPermMutation(c config, op Op, opts ...permOption) *PermMutation { - m := &PermMutation{ - config: c, - op: op, - typ: TypePerm, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) +// Description returns the value of the "description" field in the mutation. +func (m *RepoMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return } - return m + return *v, true } -// withPermID sets the ID field of the mutation. -func withPermID(id int) permOption { - return func(m *PermMutation) { - var ( - err error - once sync.Once - value *Perm - ) - m.oldValue = func(ctx context.Context) (*Perm, error) { - once.Do(func() { - if m.done { - err = fmt.Errorf("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Perm.Get(ctx, id) - } - }) - return value, err - } - m.id = &id +// OldDescription returns the old "description" field's value of the Repo entity. +// If the Repo 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 *RepoMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) } + return oldValue.Description, nil } -// withPerm sets the old Perm of the mutation. -func withPerm(node *Perm) permOption { - return func(m *PermMutation) { - m.oldValue = func(context.Context) (*Perm, error) { - return node, nil - } - m.id = &node.ID - } +// ResetDescription resets all changes to the "description" field. +func (m *RepoMutation) ResetDescription() { + m.description = nil } -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m PermMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client +// SetConfigPath sets the "config_path" field. +func (m *RepoMutation) SetConfigPath(s string) { + m.config_path = &s } -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m PermMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, fmt.Errorf("ent: mutation is not running in a transaction") +// ConfigPath returns the value of the "config_path" field in the mutation. +func (m *RepoMutation) ConfigPath() (r string, exists bool) { + v := m.config_path + if v == nil { + return } - tx := &Tx{config: m.config} - tx.init() - return tx, nil + return *v, true } -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *PermMutation) ID() (id int, exists bool) { - if m.id == nil { - return +// OldConfigPath returns the old "config_path" field's value of the Repo entity. +// If the Repo 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 *RepoMutation) OldConfigPath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldConfigPath is only allowed on UpdateOne operations") } - return *m.id, true + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldConfigPath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldConfigPath: %w", err) + } + return oldValue.ConfigPath, nil } -// SetRepoPerm sets the "repo_perm" field. -func (m *PermMutation) SetRepoPerm(pp perm.RepoPerm) { - m.repo_perm = &pp +// ResetConfigPath resets all changes to the "config_path" field. +func (m *RepoMutation) ResetConfigPath() { + m.config_path = nil } -// RepoPerm returns the value of the "repo_perm" field in the mutation. -func (m *PermMutation) RepoPerm() (r perm.RepoPerm, exists bool) { - v := m.repo_perm +// SetActive sets the "active" field. +func (m *RepoMutation) SetActive(b bool) { + m.active = &b +} + +// Active returns the value of the "active" field in the mutation. +func (m *RepoMutation) Active() (r bool, exists bool) { + v := m.active if v == nil { return } return *v, true } -// OldRepoPerm returns the old "repo_perm" field's value of the Perm entity. -// If the Perm object wasn't provided to the builder, the object is fetched from the database. +// OldActive returns the old "active" field's value of the Repo entity. +// If the Repo 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 *PermMutation) OldRepoPerm(ctx context.Context) (v perm.RepoPerm, err error) { +func (m *RepoMutation) OldActive(ctx context.Context) (v bool, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRepoPerm is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldActive is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRepoPerm requires an ID field in the mutation") + return v, fmt.Errorf("OldActive requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldRepoPerm: %w", err) + return v, fmt.Errorf("querying old value for OldActive: %w", err) } - return oldValue.RepoPerm, nil + return oldValue.Active, nil } -// ResetRepoPerm resets all changes to the "repo_perm" field. -func (m *PermMutation) ResetRepoPerm() { - m.repo_perm = nil +// ResetActive resets all changes to the "active" field. +func (m *RepoMutation) ResetActive() { + m.active = nil } -// SetSyncedAt sets the "synced_at" field. -func (m *PermMutation) SetSyncedAt(t time.Time) { - m.synced_at = &t +// SetWebhookID sets the "webhook_id" field. +func (m *RepoMutation) SetWebhookID(i int64) { + m.webhook_id = &i + m.addwebhook_id = nil } -// SyncedAt returns the value of the "synced_at" field in the mutation. -func (m *PermMutation) SyncedAt() (r time.Time, exists bool) { - v := m.synced_at +// WebhookID returns the value of the "webhook_id" field in the mutation. +func (m *RepoMutation) WebhookID() (r int64, exists bool) { + v := m.webhook_id if v == nil { return } return *v, true } -// OldSyncedAt returns the old "synced_at" field's value of the Perm entity. -// If the Perm object wasn't provided to the builder, the object is fetched from the database. +// OldWebhookID returns the old "webhook_id" field's value of the Repo entity. +// If the Repo 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 *PermMutation) OldSyncedAt(ctx context.Context) (v time.Time, err error) { +func (m *RepoMutation) OldWebhookID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldSyncedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldWebhookID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldSyncedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldWebhookID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldSyncedAt: %w", err) + return v, fmt.Errorf("querying old value for OldWebhookID: %w", err) } - return oldValue.SyncedAt, nil + return oldValue.WebhookID, nil } -// ClearSyncedAt clears the value of the "synced_at" field. -func (m *PermMutation) ClearSyncedAt() { - m.synced_at = nil - m.clearedFields[perm.FieldSyncedAt] = struct{}{} +// AddWebhookID adds i to the "webhook_id" field. +func (m *RepoMutation) AddWebhookID(i int64) { + if m.addwebhook_id != nil { + *m.addwebhook_id += i + } else { + m.addwebhook_id = &i + } } -// SyncedAtCleared returns if the "synced_at" field was cleared in this mutation. -func (m *PermMutation) SyncedAtCleared() bool { - _, ok := m.clearedFields[perm.FieldSyncedAt] +// AddedWebhookID returns the value that was added to the "webhook_id" field in this mutation. +func (m *RepoMutation) AddedWebhookID() (r int64, exists bool) { + v := m.addwebhook_id + if v == nil { + return + } + return *v, true +} + +// ClearWebhookID clears the value of the "webhook_id" field. +func (m *RepoMutation) ClearWebhookID() { + m.webhook_id = nil + m.addwebhook_id = nil + m.clearedFields[repo.FieldWebhookID] = struct{}{} +} + +// WebhookIDCleared returns if the "webhook_id" field was cleared in this mutation. +func (m *RepoMutation) WebhookIDCleared() bool { + _, ok := m.clearedFields[repo.FieldWebhookID] return ok } -// ResetSyncedAt resets all changes to the "synced_at" field. -func (m *PermMutation) ResetSyncedAt() { - m.synced_at = nil - delete(m.clearedFields, perm.FieldSyncedAt) +// ResetWebhookID resets all changes to the "webhook_id" field. +func (m *RepoMutation) ResetWebhookID() { + m.webhook_id = nil + m.addwebhook_id = nil + delete(m.clearedFields, repo.FieldWebhookID) } // SetCreatedAt sets the "created_at" field. -func (m *PermMutation) SetCreatedAt(t time.Time) { +func (m *RepoMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *PermMutation) CreatedAt() (r time.Time, exists bool) { +func (m *RepoMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -7383,10 +7710,10 @@ func (m *PermMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the Perm entity. -// If the Perm object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the Repo entity. +// If the Repo 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 *PermMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *RepoMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } @@ -7401,17 +7728,17 @@ func (m *PermMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *PermMutation) ResetCreatedAt() { +func (m *RepoMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *PermMutation) SetUpdatedAt(t time.Time) { +func (m *RepoMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *PermMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *RepoMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -7419,10 +7746,10 @@ func (m *PermMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the Perm entity. -// If the Perm object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the Repo entity. +// If the Repo 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 *PermMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *RepoMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } @@ -7437,171 +7764,375 @@ func (m *PermMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *PermMutation) ResetUpdatedAt() { +func (m *RepoMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetUserID sets the "user_id" field. -func (m *PermMutation) SetUserID(i int64) { - m.user = &i +// SetLatestDeployedAt sets the "latest_deployed_at" field. +func (m *RepoMutation) SetLatestDeployedAt(t time.Time) { + m.latest_deployed_at = &t } -// UserID returns the value of the "user_id" field in the mutation. -func (m *PermMutation) UserID() (r int64, exists bool) { - v := m.user +// LatestDeployedAt returns the value of the "latest_deployed_at" field in the mutation. +func (m *RepoMutation) LatestDeployedAt() (r time.Time, exists bool) { + v := m.latest_deployed_at if v == nil { return } return *v, true } -// OldUserID returns the old "user_id" field's value of the Perm entity. -// If the Perm object wasn't provided to the builder, the object is fetched from the database. +// OldLatestDeployedAt returns the old "latest_deployed_at" field's value of the Repo entity. +// If the Repo 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 *PermMutation) OldUserID(ctx context.Context) (v int64, err error) { +func (m *RepoMutation) OldLatestDeployedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldLatestDeployedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldUserID requires an ID field in the mutation") + return v, fmt.Errorf("OldLatestDeployedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldUserID: %w", err) + return v, fmt.Errorf("querying old value for OldLatestDeployedAt: %w", err) } - return oldValue.UserID, nil + return oldValue.LatestDeployedAt, nil } -// ResetUserID resets all changes to the "user_id" field. -func (m *PermMutation) ResetUserID() { - m.user = nil +// ClearLatestDeployedAt clears the value of the "latest_deployed_at" field. +func (m *RepoMutation) ClearLatestDeployedAt() { + m.latest_deployed_at = nil + m.clearedFields[repo.FieldLatestDeployedAt] = struct{}{} } -// SetRepoID sets the "repo_id" field. -func (m *PermMutation) SetRepoID(i int64) { - m.repo = &i +// LatestDeployedAtCleared returns if the "latest_deployed_at" field was cleared in this mutation. +func (m *RepoMutation) LatestDeployedAtCleared() bool { + _, ok := m.clearedFields[repo.FieldLatestDeployedAt] + return ok } -// RepoID returns the value of the "repo_id" field in the mutation. -func (m *PermMutation) RepoID() (r int64, exists bool) { - v := m.repo - if v == nil { - return +// ResetLatestDeployedAt resets all changes to the "latest_deployed_at" field. +func (m *RepoMutation) ResetLatestDeployedAt() { + m.latest_deployed_at = nil + delete(m.clearedFields, repo.FieldLatestDeployedAt) +} + +// AddPermIDs adds the "perms" edge to the Perm entity by ids. +func (m *RepoMutation) AddPermIDs(ids ...int) { + if m.perms == nil { + m.perms = make(map[int]struct{}) + } + for i := range ids { + m.perms[ids[i]] = struct{}{} } - return *v, true } -// OldRepoID returns the old "repo_id" field's value of the Perm entity. -// If the Perm 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 *PermMutation) OldRepoID(ctx context.Context) (v int64, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldRepoID is only allowed on UpdateOne operations") +// ClearPerms clears the "perms" edge to the Perm entity. +func (m *RepoMutation) ClearPerms() { + m.clearedperms = true +} + +// PermsCleared reports if the "perms" edge to the Perm entity was cleared. +func (m *RepoMutation) PermsCleared() bool { + return m.clearedperms +} + +// RemovePermIDs removes the "perms" edge to the Perm entity by IDs. +func (m *RepoMutation) RemovePermIDs(ids ...int) { + if m.removedperms == nil { + m.removedperms = make(map[int]struct{}) } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldRepoID requires an ID field in the mutation") + for i := range ids { + delete(m.perms, ids[i]) + m.removedperms[ids[i]] = struct{}{} + } +} + +// RemovedPerms returns the removed IDs of the "perms" edge to the Perm entity. +func (m *RepoMutation) RemovedPermsIDs() (ids []int) { + for id := range m.removedperms { + ids = append(ids, id) + } + return +} + +// PermsIDs returns the "perms" edge IDs in the mutation. +func (m *RepoMutation) PermsIDs() (ids []int) { + for id := range m.perms { + ids = append(ids, id) + } + return +} + +// ResetPerms resets all changes to the "perms" edge. +func (m *RepoMutation) ResetPerms() { + m.perms = nil + m.clearedperms = false + m.removedperms = nil +} + +// AddDeploymentIDs adds the "deployments" edge to the Deployment entity by ids. +func (m *RepoMutation) AddDeploymentIDs(ids ...int) { + if m.deployments == nil { + m.deployments = make(map[int]struct{}) + } + for i := range ids { + m.deployments[ids[i]] = struct{}{} + } +} + +// ClearDeployments clears the "deployments" edge to the Deployment entity. +func (m *RepoMutation) ClearDeployments() { + m.cleareddeployments = true +} + +// DeploymentsCleared reports if the "deployments" edge to the Deployment entity was cleared. +func (m *RepoMutation) DeploymentsCleared() bool { + return m.cleareddeployments +} + +// RemoveDeploymentIDs removes the "deployments" edge to the Deployment entity by IDs. +func (m *RepoMutation) RemoveDeploymentIDs(ids ...int) { + if m.removeddeployments == nil { + m.removeddeployments = make(map[int]struct{}) + } + for i := range ids { + delete(m.deployments, ids[i]) + m.removeddeployments[ids[i]] = struct{}{} + } +} + +// RemovedDeployments returns the removed IDs of the "deployments" edge to the Deployment entity. +func (m *RepoMutation) RemovedDeploymentsIDs() (ids []int) { + for id := range m.removeddeployments { + ids = append(ids, id) + } + return +} + +// DeploymentsIDs returns the "deployments" edge IDs in the mutation. +func (m *RepoMutation) DeploymentsIDs() (ids []int) { + for id := range m.deployments { + ids = append(ids, id) + } + return +} + +// ResetDeployments resets all changes to the "deployments" edge. +func (m *RepoMutation) ResetDeployments() { + m.deployments = nil + m.cleareddeployments = false + m.removeddeployments = nil +} + +// AddCallbackIDs adds the "callback" edge to the Callback entity by ids. +func (m *RepoMutation) AddCallbackIDs(ids ...int) { + if m.callback == nil { + m.callback = make(map[int]struct{}) + } + for i := range ids { + m.callback[ids[i]] = struct{}{} + } +} + +// ClearCallback clears the "callback" edge to the Callback entity. +func (m *RepoMutation) ClearCallback() { + m.clearedcallback = true +} + +// CallbackCleared reports if the "callback" edge to the Callback entity was cleared. +func (m *RepoMutation) CallbackCleared() bool { + return m.clearedcallback +} + +// RemoveCallbackIDs removes the "callback" edge to the Callback entity by IDs. +func (m *RepoMutation) RemoveCallbackIDs(ids ...int) { + if m.removedcallback == nil { + m.removedcallback = make(map[int]struct{}) + } + for i := range ids { + delete(m.callback, ids[i]) + m.removedcallback[ids[i]] = struct{}{} + } +} + +// RemovedCallback returns the removed IDs of the "callback" edge to the Callback entity. +func (m *RepoMutation) RemovedCallbackIDs() (ids []int) { + for id := range m.removedcallback { + ids = append(ids, id) + } + return +} + +// CallbackIDs returns the "callback" edge IDs in the mutation. +func (m *RepoMutation) CallbackIDs() (ids []int) { + for id := range m.callback { + ids = append(ids, id) + } + return +} + +// ResetCallback resets all changes to the "callback" edge. +func (m *RepoMutation) ResetCallback() { + m.callback = nil + m.clearedcallback = false + m.removedcallback = nil +} + +// AddLockIDs adds the "locks" edge to the Lock entity by ids. +func (m *RepoMutation) AddLockIDs(ids ...int) { + if m.locks == nil { + m.locks = make(map[int]struct{}) + } + for i := range ids { + m.locks[ids[i]] = struct{}{} + } +} + +// ClearLocks clears the "locks" edge to the Lock entity. +func (m *RepoMutation) ClearLocks() { + m.clearedlocks = true +} + +// LocksCleared reports if the "locks" edge to the Lock entity was cleared. +func (m *RepoMutation) LocksCleared() bool { + return m.clearedlocks +} + +// RemoveLockIDs removes the "locks" edge to the Lock entity by IDs. +func (m *RepoMutation) RemoveLockIDs(ids ...int) { + if m.removedlocks == nil { + m.removedlocks = make(map[int]struct{}) } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldRepoID: %w", err) + for i := range ids { + delete(m.locks, ids[i]) + m.removedlocks[ids[i]] = struct{}{} } - return oldValue.RepoID, nil } -// ResetRepoID resets all changes to the "repo_id" field. -func (m *PermMutation) ResetRepoID() { - m.repo = nil +// RemovedLocks returns the removed IDs of the "locks" edge to the Lock entity. +func (m *RepoMutation) RemovedLocksIDs() (ids []int) { + for id := range m.removedlocks { + ids = append(ids, id) + } + return } -// ClearUser clears the "user" edge to the User entity. -func (m *PermMutation) ClearUser() { - m.cleareduser = true +// LocksIDs returns the "locks" edge IDs in the mutation. +func (m *RepoMutation) LocksIDs() (ids []int) { + for id := range m.locks { + ids = append(ids, id) + } + return } -// UserCleared reports if the "user" edge to the User entity was cleared. -func (m *PermMutation) UserCleared() bool { - return m.cleareduser +// ResetLocks resets all changes to the "locks" edge. +func (m *RepoMutation) ResetLocks() { + m.locks = nil + m.clearedlocks = false + m.removedlocks = nil } -// UserIDs returns the "user" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// UserID instead. It exists only for internal usage by the builders. -func (m *PermMutation) UserIDs() (ids []int64) { - if id := m.user; id != nil { - ids = append(ids, *id) +// 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{}{} } - return } -// ResetUser resets all changes to the "user" edge. -func (m *PermMutation) ResetUser() { - m.user = nil - m.cleareduser = false +// ClearDeploymentStatistics clears the "deployment_statistics" edge to the DeploymentStatistics entity. +func (m *RepoMutation) ClearDeploymentStatistics() { + m.cleareddeployment_statistics = true } -// ClearRepo clears the "repo" edge to the Repo entity. -func (m *PermMutation) ClearRepo() { - m.clearedrepo = true +// DeploymentStatisticsCleared reports if the "deployment_statistics" edge to the DeploymentStatistics entity was cleared. +func (m *RepoMutation) DeploymentStatisticsCleared() bool { + return m.cleareddeployment_statistics } -// RepoCleared reports if the "repo" edge to the Repo entity was cleared. -func (m *PermMutation) RepoCleared() bool { - return m.clearedrepo +// 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{}{} + } } -// 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 *PermMutation) RepoIDs() (ids []int64) { - if id := m.repo; id != nil { - ids = append(ids, *id) +// 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 } -// ResetRepo resets all changes to the "repo" edge. -func (m *PermMutation) ResetRepo() { - m.repo = nil - m.clearedrepo = false +// 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 } -// Where appends a list predicates to the PermMutation builder. -func (m *PermMutation) Where(ps ...predicate.Perm) { +// 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...) } // Op returns the operation name. -func (m *PermMutation) Op() Op { +func (m *RepoMutation) Op() Op { return m.op } -// Type returns the node type of this mutation (Perm). -func (m *PermMutation) Type() string { +// Type returns the node type of this mutation (Repo). +func (m *RepoMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). -func (m *PermMutation) Fields() []string { - fields := make([]string, 0, 6) - if m.repo_perm != nil { - fields = append(fields, perm.FieldRepoPerm) +func (m *RepoMutation) Fields() []string { + fields := make([]string, 0, 9) + if m.namespace != nil { + fields = append(fields, repo.FieldNamespace) } - if m.synced_at != nil { - fields = append(fields, perm.FieldSyncedAt) + if m.name != nil { + fields = append(fields, repo.FieldName) + } + if m.description != nil { + fields = append(fields, repo.FieldDescription) + } + if m.config_path != nil { + fields = append(fields, repo.FieldConfigPath) + } + if m.active != nil { + fields = append(fields, repo.FieldActive) + } + if m.webhook_id != nil { + fields = append(fields, repo.FieldWebhookID) } if m.created_at != nil { - fields = append(fields, perm.FieldCreatedAt) + fields = append(fields, repo.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, perm.FieldUpdatedAt) - } - if m.user != nil { - fields = append(fields, perm.FieldUserID) + fields = append(fields, repo.FieldUpdatedAt) } - if m.repo != nil { - fields = append(fields, perm.FieldRepoID) + if m.latest_deployed_at != nil { + fields = append(fields, repo.FieldLatestDeployedAt) } return fields } @@ -7609,20 +8140,26 @@ func (m *PermMutation) Fields() []string { // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *PermMutation) Field(name string) (ent.Value, bool) { +func (m *RepoMutation) Field(name string) (ent.Value, bool) { switch name { - case perm.FieldRepoPerm: - return m.RepoPerm() - case perm.FieldSyncedAt: - return m.SyncedAt() - case perm.FieldCreatedAt: + case repo.FieldNamespace: + return m.Namespace() + case repo.FieldName: + return m.Name() + case repo.FieldDescription: + return m.Description() + case repo.FieldConfigPath: + return m.ConfigPath() + case repo.FieldActive: + return m.Active() + case repo.FieldWebhookID: + return m.WebhookID() + case repo.FieldCreatedAt: return m.CreatedAt() - case perm.FieldUpdatedAt: + case repo.FieldUpdatedAt: return m.UpdatedAt() - case perm.FieldUserID: - return m.UserID() - case perm.FieldRepoID: - return m.RepoID() + case repo.FieldLatestDeployedAt: + return m.LatestDeployedAt() } return nil, false } @@ -7630,87 +8167,119 @@ func (m *PermMutation) Field(name string) (ent.Value, bool) { // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. -func (m *PermMutation) OldField(ctx context.Context, name string) (ent.Value, error) { +func (m *RepoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case perm.FieldRepoPerm: - return m.OldRepoPerm(ctx) - case perm.FieldSyncedAt: - return m.OldSyncedAt(ctx) - case perm.FieldCreatedAt: + case repo.FieldNamespace: + return m.OldNamespace(ctx) + case repo.FieldName: + return m.OldName(ctx) + case repo.FieldDescription: + return m.OldDescription(ctx) + case repo.FieldConfigPath: + return m.OldConfigPath(ctx) + case repo.FieldActive: + return m.OldActive(ctx) + case repo.FieldWebhookID: + return m.OldWebhookID(ctx) + case repo.FieldCreatedAt: return m.OldCreatedAt(ctx) - case perm.FieldUpdatedAt: + case repo.FieldUpdatedAt: return m.OldUpdatedAt(ctx) - case perm.FieldUserID: - return m.OldUserID(ctx) - case perm.FieldRepoID: - return m.OldRepoID(ctx) + case repo.FieldLatestDeployedAt: + return m.OldLatestDeployedAt(ctx) } - return nil, fmt.Errorf("unknown Perm field %s", name) + return nil, fmt.Errorf("unknown Repo field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *PermMutation) SetField(name string, value ent.Value) error { +func (m *RepoMutation) SetField(name string, value ent.Value) error { switch name { - case perm.FieldRepoPerm: - v, ok := value.(perm.RepoPerm) + case repo.FieldNamespace: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetRepoPerm(v) + m.SetNamespace(v) return nil - case perm.FieldSyncedAt: - v, ok := value.(time.Time) + case repo.FieldName: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSyncedAt(v) + m.SetName(v) return nil - case perm.FieldCreatedAt: - v, ok := value.(time.Time) + case repo.FieldDescription: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetDescription(v) return nil - case perm.FieldUpdatedAt: - v, ok := value.(time.Time) + case repo.FieldConfigPath: + v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetConfigPath(v) return nil - case perm.FieldUserID: + case repo.FieldActive: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetActive(v) + return nil + case repo.FieldWebhookID: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUserID(v) + m.SetWebhookID(v) + return nil + case repo.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case repo.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) return nil - case perm.FieldRepoID: - v, ok := value.(int64) + case repo.FieldLatestDeployedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetRepoID(v) + m.SetLatestDeployedAt(v) return nil } - return fmt.Errorf("unknown Perm field %s", name) + return fmt.Errorf("unknown Repo field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *PermMutation) AddedFields() []string { +func (m *RepoMutation) AddedFields() []string { var fields []string + if m.addwebhook_id != nil { + fields = append(fields, repo.FieldWebhookID) + } return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *PermMutation) AddedField(name string) (ent.Value, bool) { +func (m *RepoMutation) AddedField(name string) (ent.Value, bool) { switch name { + case repo.FieldWebhookID: + return m.AddedWebhookID() } return nil, false } @@ -7718,208 +8287,309 @@ func (m *PermMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *PermMutation) AddField(name string, value ent.Value) error { +func (m *RepoMutation) AddField(name string, value ent.Value) error { switch name { + case repo.FieldWebhookID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddWebhookID(v) + return nil } - return fmt.Errorf("unknown Perm numeric field %s", name) + return fmt.Errorf("unknown Repo numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *PermMutation) ClearedFields() []string { +func (m *RepoMutation) ClearedFields() []string { var fields []string - if m.FieldCleared(perm.FieldSyncedAt) { - fields = append(fields, perm.FieldSyncedAt) + if m.FieldCleared(repo.FieldWebhookID) { + fields = append(fields, repo.FieldWebhookID) + } + if m.FieldCleared(repo.FieldLatestDeployedAt) { + fields = append(fields, repo.FieldLatestDeployedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *PermMutation) FieldCleared(name string) bool { +func (m *RepoMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *PermMutation) ClearField(name string) error { +func (m *RepoMutation) ClearField(name string) error { switch name { - case perm.FieldSyncedAt: - m.ClearSyncedAt() + case repo.FieldWebhookID: + m.ClearWebhookID() + return nil + case repo.FieldLatestDeployedAt: + m.ClearLatestDeployedAt() return nil } - return fmt.Errorf("unknown Perm nullable field %s", name) + return fmt.Errorf("unknown Repo nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *PermMutation) ResetField(name string) error { +func (m *RepoMutation) ResetField(name string) error { switch name { - case perm.FieldRepoPerm: - m.ResetRepoPerm() + case repo.FieldNamespace: + m.ResetNamespace() return nil - case perm.FieldSyncedAt: - m.ResetSyncedAt() + case repo.FieldName: + m.ResetName() return nil - case perm.FieldCreatedAt: + case repo.FieldDescription: + m.ResetDescription() + return nil + case repo.FieldConfigPath: + m.ResetConfigPath() + return nil + case repo.FieldActive: + m.ResetActive() + return nil + case repo.FieldWebhookID: + m.ResetWebhookID() + return nil + case repo.FieldCreatedAt: m.ResetCreatedAt() return nil - case perm.FieldUpdatedAt: + case repo.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case perm.FieldUserID: - m.ResetUserID() - return nil - case perm.FieldRepoID: - m.ResetRepoID() + case repo.FieldLatestDeployedAt: + m.ResetLatestDeployedAt() return nil } - return fmt.Errorf("unknown Perm field %s", name) + return fmt.Errorf("unknown Repo field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *PermMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.user != nil { - edges = append(edges, perm.EdgeUser) +func (m *RepoMutation) AddedEdges() []string { + edges := make([]string, 0, 5) + if m.perms != nil { + edges = append(edges, repo.EdgePerms) } - if m.repo != nil { - edges = append(edges, perm.EdgeRepo) + if m.deployments != nil { + edges = append(edges, repo.EdgeDeployments) + } + if m.callback != nil { + edges = append(edges, repo.EdgeCallback) + } + if m.locks != nil { + edges = append(edges, repo.EdgeLocks) + } + if m.deployment_statistics != nil { + edges = append(edges, repo.EdgeDeploymentStatistics) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *PermMutation) AddedIDs(name string) []ent.Value { +func (m *RepoMutation) AddedIDs(name string) []ent.Value { switch name { - case perm.EdgeUser: - if id := m.user; id != nil { - return []ent.Value{*id} + case repo.EdgePerms: + ids := make([]ent.Value, 0, len(m.perms)) + for id := range m.perms { + ids = append(ids, id) } - case perm.EdgeRepo: - if id := m.repo; id != nil { - return []ent.Value{*id} + return ids + case repo.EdgeDeployments: + ids := make([]ent.Value, 0, len(m.deployments)) + for id := range m.deployments { + ids = append(ids, id) + } + return ids + case repo.EdgeCallback: + ids := make([]ent.Value, 0, len(m.callback)) + for id := range m.callback { + ids = append(ids, id) + } + return ids + case repo.EdgeLocks: + ids := make([]ent.Value, 0, len(m.locks)) + for id := range m.locks { + 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 *PermMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) +func (m *RepoMutation) RemovedEdges() []string { + edges := make([]string, 0, 5) + if m.removedperms != nil { + edges = append(edges, repo.EdgePerms) + } + if m.removeddeployments != nil { + edges = append(edges, repo.EdgeDeployments) + } + if m.removedcallback != nil { + edges = append(edges, repo.EdgeCallback) + } + if m.removedlocks != nil { + edges = append(edges, repo.EdgeLocks) + } + if m.removeddeployment_statistics != nil { + edges = append(edges, repo.EdgeDeploymentStatistics) + } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *PermMutation) RemovedIDs(name string) []ent.Value { +func (m *RepoMutation) RemovedIDs(name string) []ent.Value { switch name { + case repo.EdgePerms: + ids := make([]ent.Value, 0, len(m.removedperms)) + for id := range m.removedperms { + ids = append(ids, id) + } + return ids + case repo.EdgeDeployments: + ids := make([]ent.Value, 0, len(m.removeddeployments)) + for id := range m.removeddeployments { + ids = append(ids, id) + } + return ids + case repo.EdgeCallback: + ids := make([]ent.Value, 0, len(m.removedcallback)) + for id := range m.removedcallback { + ids = append(ids, id) + } + return ids + case repo.EdgeLocks: + ids := make([]ent.Value, 0, len(m.removedlocks)) + for id := range m.removedlocks { + 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 *PermMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.cleareduser { - edges = append(edges, perm.EdgeUser) +func (m *RepoMutation) ClearedEdges() []string { + edges := make([]string, 0, 5) + if m.clearedperms { + edges = append(edges, repo.EdgePerms) } - if m.clearedrepo { - edges = append(edges, perm.EdgeRepo) + if m.cleareddeployments { + edges = append(edges, repo.EdgeDeployments) + } + if m.clearedcallback { + edges = append(edges, repo.EdgeCallback) + } + if m.clearedlocks { + edges = append(edges, repo.EdgeLocks) + } + if m.cleareddeployment_statistics { + edges = append(edges, repo.EdgeDeploymentStatistics) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *PermMutation) EdgeCleared(name string) bool { +func (m *RepoMutation) EdgeCleared(name string) bool { switch name { - case perm.EdgeUser: - return m.cleareduser - case perm.EdgeRepo: - return m.clearedrepo + case repo.EdgePerms: + return m.clearedperms + case repo.EdgeDeployments: + return m.cleareddeployments + case repo.EdgeCallback: + return m.clearedcallback + case repo.EdgeLocks: + return m.clearedlocks + case repo.EdgeDeploymentStatistics: + return m.cleareddeployment_statistics } 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 *PermMutation) ClearEdge(name string) error { +func (m *RepoMutation) ClearEdge(name string) error { switch name { - case perm.EdgeUser: - m.ClearUser() - return nil - case perm.EdgeRepo: - m.ClearRepo() - return nil } - return fmt.Errorf("unknown Perm unique edge %s", name) + return fmt.Errorf("unknown Repo 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 *PermMutation) ResetEdge(name string) error { +func (m *RepoMutation) ResetEdge(name string) error { switch name { - case perm.EdgeUser: - m.ResetUser() + case repo.EdgePerms: + m.ResetPerms() + return nil + case repo.EdgeDeployments: + m.ResetDeployments() + return nil + case repo.EdgeCallback: + m.ResetCallback() + return nil + case repo.EdgeLocks: + m.ResetLocks() return nil - case perm.EdgeRepo: - m.ResetRepo() + case repo.EdgeDeploymentStatistics: + m.ResetDeploymentStatistics() return nil } - return fmt.Errorf("unknown Perm edge %s", name) + return fmt.Errorf("unknown Repo edge %s", name) } -// RepoMutation represents an operation that mutates the Repo nodes in the graph. -type RepoMutation struct { +// ReviewMutation represents an operation that mutates the Review nodes in the graph. +type ReviewMutation 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 - deployment_statistics map[int]struct{} - removeddeployment_statistics map[int]struct{} - cleareddeployment_statistics bool - done bool - oldValue func(context.Context) (*Repo, error) - predicates []predicate.Repo + op Op + typ string + id *int + status *review.Status + created_at *time.Time + updated_at *time.Time + clearedFields map[string]struct{} + user *int64 + cleareduser bool + deployment *int + cleareddeployment bool + event map[int]struct{} + removedevent map[int]struct{} + clearedevent bool + done bool + oldValue func(context.Context) (*Review, error) + predicates []predicate.Review } -var _ ent.Mutation = (*RepoMutation)(nil) +var _ ent.Mutation = (*ReviewMutation)(nil) -// repoOption allows management of the mutation configuration using functional options. -type repoOption func(*RepoMutation) +// reviewOption allows management of the mutation configuration using functional options. +type reviewOption func(*ReviewMutation) -// newRepoMutation creates new mutation for the Repo entity. -func newRepoMutation(c config, op Op, opts ...repoOption) *RepoMutation { - m := &RepoMutation{ +// newReviewMutation creates new mutation for the Review entity. +func newReviewMutation(c config, op Op, opts ...reviewOption) *ReviewMutation { + m := &ReviewMutation{ config: c, op: op, - typ: TypeRepo, + typ: TypeReview, clearedFields: make(map[string]struct{}), } for _, opt := range opts { @@ -7928,20 +8598,20 @@ func newRepoMutation(c config, op Op, opts ...repoOption) *RepoMutation { return m } -// withRepoID sets the ID field of the mutation. -func withRepoID(id int64) repoOption { - return func(m *RepoMutation) { +// withReviewID sets the ID field of the mutation. +func withReviewID(id int) reviewOption { + return func(m *ReviewMutation) { var ( err error once sync.Once - value *Repo + value *Review ) - m.oldValue = func(ctx context.Context) (*Repo, error) { + m.oldValue = func(ctx context.Context) (*Review, error) { once.Do(func() { if m.done { err = fmt.Errorf("querying old values post mutation is not allowed") } else { - value, err = m.Client().Repo.Get(ctx, id) + value, err = m.Client().Review.Get(ctx, id) } }) return value, err @@ -7950,10 +8620,10 @@ func withRepoID(id int64) repoOption { } } -// withRepo sets the old Repo of the mutation. -func withRepo(node *Repo) repoOption { - return func(m *RepoMutation) { - m.oldValue = func(context.Context) (*Repo, error) { +// withReview sets the old Review of the mutation. +func withReview(node *Review) reviewOption { + return func(m *ReviewMutation) { + m.oldValue = func(context.Context) (*Review, error) { return node, nil } m.id = &node.ID @@ -7962,7 +8632,7 @@ func withRepo(node *Repo) repoOption { // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. -func (m RepoMutation) Client() *Client { +func (m ReviewMutation) Client() *Client { client := &Client{config: m.config} client.init() return client @@ -7970,7 +8640,7 @@ func (m RepoMutation) Client() *Client { // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. -func (m RepoMutation) Tx() (*Tx, error) { +func (m ReviewMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, fmt.Errorf("ent: mutation is not running in a transaction") } @@ -7979,278 +8649,58 @@ func (m RepoMutation) Tx() (*Tx, error) { return tx, nil } -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of Repo entities. -func (m *RepoMutation) SetID(id int64) { - m.id = &id -} - // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. -func (m *RepoMutation) ID() (id int64, exists bool) { +func (m *ReviewMutation) ID() (id int, exists bool) { if m.id == nil { - return - } - return *m.id, true -} - -// SetNamespace sets the "namespace" field. -func (m *RepoMutation) SetNamespace(s string) { - m.namespace = &s -} - -// Namespace returns the value of the "namespace" field in the mutation. -func (m *RepoMutation) Namespace() (r string, exists bool) { - v := m.namespace - if v == nil { - return - } - return *v, true -} - -// OldNamespace returns the old "namespace" field's value of the Repo entity. -// If the Repo 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 *RepoMutation) OldNamespace(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldNamespace 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") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldNamespace: %w", err) - } - return oldValue.Namespace, nil -} - -// ResetNamespace resets all changes to the "namespace" field. -func (m *RepoMutation) ResetNamespace() { - m.namespace = nil -} - -// SetName sets the "name" field. -func (m *RepoMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *RepoMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "name" field's value of the Repo entity. -// If the Repo 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 *RepoMutation) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldName 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") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *RepoMutation) ResetName() { - m.name = nil -} - -// SetDescription sets the "description" field. -func (m *RepoMutation) SetDescription(s string) { - m.description = &s -} - -// Description returns the value of the "description" field in the mutation. -func (m *RepoMutation) Description() (r string, exists bool) { - v := m.description - if v == nil { - return - } - return *v, true -} - -// OldDescription returns the old "description" field's value of the Repo entity. -// If the Repo 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 *RepoMutation) OldDescription(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldDescription is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldDescription requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDescription: %w", err) - } - return oldValue.Description, nil -} - -// ResetDescription resets all changes to the "description" field. -func (m *RepoMutation) ResetDescription() { - m.description = nil -} - -// SetConfigPath sets the "config_path" field. -func (m *RepoMutation) SetConfigPath(s string) { - m.config_path = &s -} - -// ConfigPath returns the value of the "config_path" field in the mutation. -func (m *RepoMutation) ConfigPath() (r string, exists bool) { - v := m.config_path - if v == nil { - return - } - return *v, true -} - -// OldConfigPath returns the old "config_path" field's value of the Repo entity. -// If the Repo 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 *RepoMutation) OldConfigPath(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldConfigPath is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldConfigPath requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldConfigPath: %w", err) - } - return oldValue.ConfigPath, nil -} - -// ResetConfigPath resets all changes to the "config_path" field. -func (m *RepoMutation) ResetConfigPath() { - m.config_path = nil -} - -// SetActive sets the "active" field. -func (m *RepoMutation) SetActive(b bool) { - m.active = &b -} - -// Active returns the value of the "active" field in the mutation. -func (m *RepoMutation) Active() (r bool, exists bool) { - v := m.active - if v == nil { - return - } - return *v, true -} - -// OldActive returns the old "active" field's value of the Repo entity. -// If the Repo 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 *RepoMutation) OldActive(ctx context.Context) (v bool, err error) { - if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldActive is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldActive requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldActive: %w", err) + return } - return oldValue.Active, nil -} - -// ResetActive resets all changes to the "active" field. -func (m *RepoMutation) ResetActive() { - m.active = nil + return *m.id, true } -// SetWebhookID sets the "webhook_id" field. -func (m *RepoMutation) SetWebhookID(i int64) { - m.webhook_id = &i - m.addwebhook_id = nil +// SetStatus sets the "status" field. +func (m *ReviewMutation) SetStatus(r review.Status) { + m.status = &r } -// WebhookID returns the value of the "webhook_id" field in the mutation. -func (m *RepoMutation) WebhookID() (r int64, exists bool) { - v := m.webhook_id +// Status returns the value of the "status" field in the mutation. +func (m *ReviewMutation) Status() (r review.Status, exists bool) { + v := m.status if v == nil { return } return *v, true } -// OldWebhookID returns the old "webhook_id" field's value of the Repo entity. -// If the Repo object wasn't provided to the builder, the object is fetched from the database. +// OldStatus returns the old "status" field's value of the Review entity. +// If the Review 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 *RepoMutation) OldWebhookID(ctx context.Context) (v int64, err error) { +func (m *ReviewMutation) OldStatus(ctx context.Context) (v review.Status, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldWebhookID is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldStatus is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldWebhookID requires an ID field in the mutation") + return v, fmt.Errorf("OldStatus requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldWebhookID: %w", err) - } - return oldValue.WebhookID, nil -} - -// AddWebhookID adds i to the "webhook_id" field. -func (m *RepoMutation) AddWebhookID(i int64) { - if m.addwebhook_id != nil { - *m.addwebhook_id += i - } else { - m.addwebhook_id = &i - } -} - -// AddedWebhookID returns the value that was added to the "webhook_id" field in this mutation. -func (m *RepoMutation) AddedWebhookID() (r int64, exists bool) { - v := m.addwebhook_id - if v == nil { - return + return v, fmt.Errorf("querying old value for OldStatus: %w", err) } - return *v, true -} - -// ClearWebhookID clears the value of the "webhook_id" field. -func (m *RepoMutation) ClearWebhookID() { - m.webhook_id = nil - m.addwebhook_id = nil - m.clearedFields[repo.FieldWebhookID] = struct{}{} -} - -// WebhookIDCleared returns if the "webhook_id" field was cleared in this mutation. -func (m *RepoMutation) WebhookIDCleared() bool { - _, ok := m.clearedFields[repo.FieldWebhookID] - return ok + return oldValue.Status, nil } -// ResetWebhookID resets all changes to the "webhook_id" field. -func (m *RepoMutation) ResetWebhookID() { - m.webhook_id = nil - m.addwebhook_id = nil - delete(m.clearedFields, repo.FieldWebhookID) +// ResetStatus resets all changes to the "status" field. +func (m *ReviewMutation) ResetStatus() { + m.status = nil } // SetCreatedAt sets the "created_at" field. -func (m *RepoMutation) SetCreatedAt(t time.Time) { +func (m *ReviewMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. -func (m *RepoMutation) CreatedAt() (r time.Time, exists bool) { +func (m *ReviewMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return @@ -8258,10 +8708,10 @@ func (m *RepoMutation) CreatedAt() (r time.Time, exists bool) { return *v, true } -// OldCreatedAt returns the old "created_at" field's value of the Repo entity. -// If the Repo object wasn't provided to the builder, the object is fetched from the database. +// OldCreatedAt returns the old "created_at" field's value of the Review entity. +// If the Review 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 *RepoMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ReviewMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldCreatedAt is only allowed on UpdateOne operations") } @@ -8276,17 +8726,17 @@ func (m *RepoMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error } // ResetCreatedAt resets all changes to the "created_at" field. -func (m *RepoMutation) ResetCreatedAt() { +func (m *ReviewMutation) ResetCreatedAt() { m.created_at = nil } // SetUpdatedAt sets the "updated_at" field. -func (m *RepoMutation) SetUpdatedAt(t time.Time) { +func (m *ReviewMutation) SetUpdatedAt(t time.Time) { m.updated_at = &t } // UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *RepoMutation) UpdatedAt() (r time.Time, exists bool) { +func (m *ReviewMutation) UpdatedAt() (r time.Time, exists bool) { v := m.updated_at if v == nil { return @@ -8294,10 +8744,10 @@ func (m *RepoMutation) UpdatedAt() (r time.Time, exists bool) { return *v, true } -// OldUpdatedAt returns the old "updated_at" field's value of the Repo entity. -// If the Repo object wasn't provided to the builder, the object is fetched from the database. +// OldUpdatedAt returns the old "updated_at" field's value of the Review entity. +// If the Review 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 *RepoMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { +func (m *ReviewMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, fmt.Errorf("OldUpdatedAt is only allowed on UpdateOne operations") } @@ -8312,375 +8762,222 @@ func (m *RepoMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error } // ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *RepoMutation) ResetUpdatedAt() { +func (m *ReviewMutation) ResetUpdatedAt() { m.updated_at = nil } -// SetLatestDeployedAt sets the "latest_deployed_at" field. -func (m *RepoMutation) SetLatestDeployedAt(t time.Time) { - m.latest_deployed_at = &t +// SetUserID sets the "user_id" field. +func (m *ReviewMutation) SetUserID(i int64) { + m.user = &i } -// LatestDeployedAt returns the value of the "latest_deployed_at" field in the mutation. -func (m *RepoMutation) LatestDeployedAt() (r time.Time, exists bool) { - v := m.latest_deployed_at +// UserID returns the value of the "user_id" field in the mutation. +func (m *ReviewMutation) UserID() (r int64, exists bool) { + v := m.user if v == nil { return } return *v, true } -// OldLatestDeployedAt returns the old "latest_deployed_at" field's value of the Repo entity. -// If the Repo object wasn't provided to the builder, the object is fetched from the database. +// OldUserID returns the old "user_id" field's value of the Review entity. +// If the Review 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 *RepoMutation) OldLatestDeployedAt(ctx context.Context) (v time.Time, err error) { +func (m *ReviewMutation) OldUserID(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, fmt.Errorf("OldLatestDeployedAt is only allowed on UpdateOne operations") + return v, fmt.Errorf("OldUserID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, fmt.Errorf("OldLatestDeployedAt requires an ID field in the mutation") + return v, fmt.Errorf("OldUserID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldLatestDeployedAt: %w", err) - } - return oldValue.LatestDeployedAt, nil -} - -// ClearLatestDeployedAt clears the value of the "latest_deployed_at" field. -func (m *RepoMutation) ClearLatestDeployedAt() { - m.latest_deployed_at = nil - m.clearedFields[repo.FieldLatestDeployedAt] = struct{}{} -} - -// LatestDeployedAtCleared returns if the "latest_deployed_at" field was cleared in this mutation. -func (m *RepoMutation) LatestDeployedAtCleared() bool { - _, ok := m.clearedFields[repo.FieldLatestDeployedAt] - return ok -} - -// ResetLatestDeployedAt resets all changes to the "latest_deployed_at" field. -func (m *RepoMutation) ResetLatestDeployedAt() { - m.latest_deployed_at = nil - delete(m.clearedFields, repo.FieldLatestDeployedAt) -} - -// AddPermIDs adds the "perms" edge to the Perm entity by ids. -func (m *RepoMutation) AddPermIDs(ids ...int) { - if m.perms == nil { - m.perms = make(map[int]struct{}) - } - for i := range ids { - m.perms[ids[i]] = struct{}{} - } -} - -// ClearPerms clears the "perms" edge to the Perm entity. -func (m *RepoMutation) ClearPerms() { - m.clearedperms = true -} - -// PermsCleared reports if the "perms" edge to the Perm entity was cleared. -func (m *RepoMutation) PermsCleared() bool { - return m.clearedperms -} - -// RemovePermIDs removes the "perms" edge to the Perm entity by IDs. -func (m *RepoMutation) RemovePermIDs(ids ...int) { - if m.removedperms == nil { - m.removedperms = make(map[int]struct{}) - } - for i := range ids { - delete(m.perms, ids[i]) - m.removedperms[ids[i]] = struct{}{} - } -} - -// RemovedPerms returns the removed IDs of the "perms" edge to the Perm entity. -func (m *RepoMutation) RemovedPermsIDs() (ids []int) { - for id := range m.removedperms { - ids = append(ids, id) - } - return -} - -// PermsIDs returns the "perms" edge IDs in the mutation. -func (m *RepoMutation) PermsIDs() (ids []int) { - for id := range m.perms { - ids = append(ids, id) - } - return -} - -// ResetPerms resets all changes to the "perms" edge. -func (m *RepoMutation) ResetPerms() { - m.perms = nil - m.clearedperms = false - m.removedperms = nil -} - -// AddDeploymentIDs adds the "deployments" edge to the Deployment entity by ids. -func (m *RepoMutation) AddDeploymentIDs(ids ...int) { - if m.deployments == nil { - m.deployments = make(map[int]struct{}) - } - for i := range ids { - m.deployments[ids[i]] = struct{}{} + return v, fmt.Errorf("querying old value for OldUserID: %w", err) } + return oldValue.UserID, nil } -// ClearDeployments clears the "deployments" edge to the Deployment entity. -func (m *RepoMutation) ClearDeployments() { - m.cleareddeployments = true -} - -// DeploymentsCleared reports if the "deployments" edge to the Deployment entity was cleared. -func (m *RepoMutation) DeploymentsCleared() bool { - return m.cleareddeployments -} - -// RemoveDeploymentIDs removes the "deployments" edge to the Deployment entity by IDs. -func (m *RepoMutation) RemoveDeploymentIDs(ids ...int) { - if m.removeddeployments == nil { - m.removeddeployments = make(map[int]struct{}) - } - for i := range ids { - delete(m.deployments, ids[i]) - m.removeddeployments[ids[i]] = struct{}{} - } +// ResetUserID resets all changes to the "user_id" field. +func (m *ReviewMutation) ResetUserID() { + m.user = nil } -// RemovedDeployments returns the removed IDs of the "deployments" edge to the Deployment entity. -func (m *RepoMutation) RemovedDeploymentsIDs() (ids []int) { - for id := range m.removeddeployments { - ids = append(ids, id) - } - return +// SetDeploymentID sets the "deployment_id" field. +func (m *ReviewMutation) SetDeploymentID(i int) { + m.deployment = &i } -// DeploymentsIDs returns the "deployments" edge IDs in the mutation. -func (m *RepoMutation) DeploymentsIDs() (ids []int) { - for id := range m.deployments { - ids = append(ids, id) +// DeploymentID returns the value of the "deployment_id" field in the mutation. +func (m *ReviewMutation) DeploymentID() (r int, exists bool) { + v := m.deployment + if v == nil { + return } - return -} - -// ResetDeployments resets all changes to the "deployments" edge. -func (m *RepoMutation) ResetDeployments() { - m.deployments = nil - m.cleareddeployments = false - m.removeddeployments = nil + return *v, true } -// AddCallbackIDs adds the "callback" edge to the Callback entity by ids. -func (m *RepoMutation) AddCallbackIDs(ids ...int) { - if m.callback == nil { - m.callback = make(map[int]struct{}) - } - for i := range ids { - m.callback[ids[i]] = struct{}{} +// OldDeploymentID returns the old "deployment_id" field's value of the Review entity. +// If the Review 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 *ReviewMutation) OldDeploymentID(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, fmt.Errorf("OldDeploymentID is only allowed on UpdateOne operations") } -} - -// ClearCallback clears the "callback" edge to the Callback entity. -func (m *RepoMutation) ClearCallback() { - m.clearedcallback = true -} - -// CallbackCleared reports if the "callback" edge to the Callback entity was cleared. -func (m *RepoMutation) CallbackCleared() bool { - return m.clearedcallback -} - -// RemoveCallbackIDs removes the "callback" edge to the Callback entity by IDs. -func (m *RepoMutation) RemoveCallbackIDs(ids ...int) { - if m.removedcallback == nil { - m.removedcallback = make(map[int]struct{}) + if m.id == nil || m.oldValue == nil { + return v, fmt.Errorf("OldDeploymentID requires an ID field in the mutation") } - for i := range ids { - delete(m.callback, ids[i]) - m.removedcallback[ids[i]] = struct{}{} + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDeploymentID: %w", err) } + return oldValue.DeploymentID, nil } -// RemovedCallback returns the removed IDs of the "callback" edge to the Callback entity. -func (m *RepoMutation) RemovedCallbackIDs() (ids []int) { - for id := range m.removedcallback { - ids = append(ids, id) - } - return +// ResetDeploymentID resets all changes to the "deployment_id" field. +func (m *ReviewMutation) ResetDeploymentID() { + m.deployment = nil } -// CallbackIDs returns the "callback" edge IDs in the mutation. -func (m *RepoMutation) CallbackIDs() (ids []int) { - for id := range m.callback { - ids = append(ids, id) - } - return +// ClearUser clears the "user" edge to the User entity. +func (m *ReviewMutation) ClearUser() { + m.cleareduser = true } -// ResetCallback resets all changes to the "callback" edge. -func (m *RepoMutation) ResetCallback() { - m.callback = nil - m.clearedcallback = false - m.removedcallback = nil +// UserCleared reports if the "user" edge to the User entity was cleared. +func (m *ReviewMutation) UserCleared() bool { + return m.cleareduser } -// AddLockIDs adds the "locks" edge to the Lock entity by ids. -func (m *RepoMutation) AddLockIDs(ids ...int) { - if m.locks == nil { - m.locks = make(map[int]struct{}) - } - for i := range ids { - m.locks[ids[i]] = struct{}{} +// UserIDs returns the "user" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// UserID instead. It exists only for internal usage by the builders. +func (m *ReviewMutation) UserIDs() (ids []int64) { + if id := m.user; id != nil { + ids = append(ids, *id) } + return } -// ClearLocks clears the "locks" edge to the Lock entity. -func (m *RepoMutation) ClearLocks() { - m.clearedlocks = true -} - -// LocksCleared reports if the "locks" edge to the Lock entity was cleared. -func (m *RepoMutation) LocksCleared() bool { - return m.clearedlocks +// ResetUser resets all changes to the "user" edge. +func (m *ReviewMutation) ResetUser() { + m.user = nil + m.cleareduser = false } -// RemoveLockIDs removes the "locks" edge to the Lock entity by IDs. -func (m *RepoMutation) RemoveLockIDs(ids ...int) { - if m.removedlocks == nil { - m.removedlocks = make(map[int]struct{}) - } - for i := range ids { - delete(m.locks, ids[i]) - m.removedlocks[ids[i]] = struct{}{} - } +// ClearDeployment clears the "deployment" edge to the Deployment entity. +func (m *ReviewMutation) ClearDeployment() { + m.cleareddeployment = true } -// RemovedLocks returns the removed IDs of the "locks" edge to the Lock entity. -func (m *RepoMutation) RemovedLocksIDs() (ids []int) { - for id := range m.removedlocks { - ids = append(ids, id) - } - return +// DeploymentCleared reports if the "deployment" edge to the Deployment entity was cleared. +func (m *ReviewMutation) DeploymentCleared() bool { + return m.cleareddeployment } -// LocksIDs returns the "locks" edge IDs in the mutation. -func (m *RepoMutation) LocksIDs() (ids []int) { - for id := range m.locks { - ids = append(ids, id) +// DeploymentIDs returns the "deployment" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// DeploymentID instead. It exists only for internal usage by the builders. +func (m *ReviewMutation) DeploymentIDs() (ids []int) { + if id := m.deployment; id != nil { + ids = append(ids, *id) } return } -// ResetLocks resets all changes to the "locks" edge. -func (m *RepoMutation) ResetLocks() { - m.locks = nil - m.clearedlocks = false - m.removedlocks = nil +// ResetDeployment resets all changes to the "deployment" edge. +func (m *ReviewMutation) ResetDeployment() { + m.deployment = nil + m.cleareddeployment = false } -// 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{}) +// AddEventIDs adds the "event" edge to the Event entity by ids. +func (m *ReviewMutation) AddEventIDs(ids ...int) { + if m.event == nil { + m.event = make(map[int]struct{}) } for i := range ids { - m.deployment_statistics[ids[i]] = struct{}{} + m.event[ids[i]] = struct{}{} } } -// ClearDeploymentStatistics clears the "deployment_statistics" edge to the DeploymentStatistics entity. -func (m *RepoMutation) ClearDeploymentStatistics() { - m.cleareddeployment_statistics = true +// ClearEvent clears the "event" edge to the Event entity. +func (m *ReviewMutation) ClearEvent() { + m.clearedevent = true } -// DeploymentStatisticsCleared reports if the "deployment_statistics" edge to the DeploymentStatistics entity was cleared. -func (m *RepoMutation) DeploymentStatisticsCleared() bool { - return m.cleareddeployment_statistics +// EventCleared reports if the "event" edge to the Event entity was cleared. +func (m *ReviewMutation) EventCleared() bool { + return m.clearedevent } -// 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{}) +// RemoveEventIDs removes the "event" edge to the Event entity by IDs. +func (m *ReviewMutation) RemoveEventIDs(ids ...int) { + if m.removedevent == nil { + m.removedevent = make(map[int]struct{}) } for i := range ids { - delete(m.deployment_statistics, ids[i]) - m.removeddeployment_statistics[ids[i]] = struct{}{} + delete(m.event, ids[i]) + m.removedevent[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 { +// RemovedEvent returns the removed IDs of the "event" edge to the Event entity. +func (m *ReviewMutation) RemovedEventIDs() (ids []int) { + for id := range m.removedevent { 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 { +// EventIDs returns the "event" edge IDs in the mutation. +func (m *ReviewMutation) EventIDs() (ids []int) { + for id := range m.event { 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 +// ResetEvent resets all changes to the "event" edge. +func (m *ReviewMutation) ResetEvent() { + m.event = nil + m.clearedevent = false + m.removedevent = nil } -// Where appends a list predicates to the RepoMutation builder. -func (m *RepoMutation) Where(ps ...predicate.Repo) { +// Where appends a list predicates to the ReviewMutation builder. +func (m *ReviewMutation) Where(ps ...predicate.Review) { m.predicates = append(m.predicates, ps...) } // Op returns the operation name. -func (m *RepoMutation) Op() Op { +func (m *ReviewMutation) Op() Op { return m.op } -// Type returns the node type of this mutation (Repo). -func (m *RepoMutation) Type() string { +// Type returns the node type of this mutation (Review). +func (m *ReviewMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). -func (m *RepoMutation) Fields() []string { - fields := make([]string, 0, 9) - if m.namespace != nil { - fields = append(fields, repo.FieldNamespace) - } - if m.name != nil { - fields = append(fields, repo.FieldName) - } - if m.description != nil { - fields = append(fields, repo.FieldDescription) - } - if m.config_path != nil { - fields = append(fields, repo.FieldConfigPath) - } - if m.active != nil { - fields = append(fields, repo.FieldActive) - } - if m.webhook_id != nil { - fields = append(fields, repo.FieldWebhookID) +func (m *ReviewMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.status != nil { + fields = append(fields, review.FieldStatus) } if m.created_at != nil { - fields = append(fields, repo.FieldCreatedAt) + fields = append(fields, review.FieldCreatedAt) } if m.updated_at != nil { - fields = append(fields, repo.FieldUpdatedAt) + fields = append(fields, review.FieldUpdatedAt) } - if m.latest_deployed_at != nil { - fields = append(fields, repo.FieldLatestDeployedAt) + if m.user != nil { + fields = append(fields, review.FieldUserID) + } + if m.deployment != nil { + fields = append(fields, review.FieldDeploymentID) } return fields } @@ -8688,146 +8985,97 @@ func (m *RepoMutation) Fields() []string { // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. -func (m *RepoMutation) Field(name string) (ent.Value, bool) { +func (m *ReviewMutation) Field(name string) (ent.Value, bool) { switch name { - case repo.FieldNamespace: - return m.Namespace() - case repo.FieldName: - return m.Name() - case repo.FieldDescription: - return m.Description() - case repo.FieldConfigPath: - return m.ConfigPath() - case repo.FieldActive: - return m.Active() - case repo.FieldWebhookID: - return m.WebhookID() - case repo.FieldCreatedAt: + case review.FieldStatus: + return m.Status() + case review.FieldCreatedAt: return m.CreatedAt() - case repo.FieldUpdatedAt: + case review.FieldUpdatedAt: return m.UpdatedAt() - case repo.FieldLatestDeployedAt: - return m.LatestDeployedAt() + case review.FieldUserID: + return m.UserID() + case review.FieldDeploymentID: + return m.DeploymentID() } return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *RepoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case repo.FieldNamespace: - return m.OldNamespace(ctx) - case repo.FieldName: - return m.OldName(ctx) - case repo.FieldDescription: - return m.OldDescription(ctx) - case repo.FieldConfigPath: - return m.OldConfigPath(ctx) - case repo.FieldActive: - return m.OldActive(ctx) - case repo.FieldWebhookID: - return m.OldWebhookID(ctx) - case repo.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case repo.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case repo.FieldLatestDeployedAt: - return m.OldLatestDeployedAt(ctx) - } - return nil, fmt.Errorf("unknown Repo field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *RepoMutation) SetField(name string, value ent.Value) error { - switch name { - case repo.FieldNamespace: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetNamespace(v) - return nil - case repo.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case repo.FieldDescription: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDescription(v) - return nil - case repo.FieldConfigPath: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetConfigPath(v) - return nil - case repo.FieldActive: - v, ok := value.(bool) +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *ReviewMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case review.FieldStatus: + return m.OldStatus(ctx) + case review.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case review.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case review.FieldUserID: + return m.OldUserID(ctx) + case review.FieldDeploymentID: + return m.OldDeploymentID(ctx) + } + return nil, fmt.Errorf("unknown Review field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *ReviewMutation) SetField(name string, value ent.Value) error { + switch name { + case review.FieldStatus: + v, ok := value.(review.Status) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetActive(v) + m.SetStatus(v) return nil - case repo.FieldWebhookID: - v, ok := value.(int64) + case review.FieldCreatedAt: + v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetWebhookID(v) + m.SetCreatedAt(v) return nil - case repo.FieldCreatedAt: + case review.FieldUpdatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetCreatedAt(v) + m.SetUpdatedAt(v) return nil - case repo.FieldUpdatedAt: - v, ok := value.(time.Time) + case review.FieldUserID: + v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetUpdatedAt(v) + m.SetUserID(v) return nil - case repo.FieldLatestDeployedAt: - v, ok := value.(time.Time) + case review.FieldDeploymentID: + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetLatestDeployedAt(v) + m.SetDeploymentID(v) return nil } - return fmt.Errorf("unknown Repo field %s", name) + return fmt.Errorf("unknown Review field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. -func (m *RepoMutation) AddedFields() []string { +func (m *ReviewMutation) AddedFields() []string { var fields []string - if m.addwebhook_id != nil { - fields = append(fields, repo.FieldWebhookID) - } return fields } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. -func (m *RepoMutation) AddedField(name string) (ent.Value, bool) { +func (m *ReviewMutation) AddedField(name string) (ent.Value, bool) { switch name { - case repo.FieldWebhookID: - return m.AddedWebhookID() } return nil, false } @@ -8835,140 +9083,84 @@ func (m *RepoMutation) AddedField(name string) (ent.Value, bool) { // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. -func (m *RepoMutation) AddField(name string, value ent.Value) error { +func (m *ReviewMutation) AddField(name string, value ent.Value) error { switch name { - case repo.FieldWebhookID: - v, ok := value.(int64) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddWebhookID(v) - return nil } - return fmt.Errorf("unknown Repo numeric field %s", name) + return fmt.Errorf("unknown Review numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. -func (m *RepoMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(repo.FieldWebhookID) { - fields = append(fields, repo.FieldWebhookID) - } - if m.FieldCleared(repo.FieldLatestDeployedAt) { - fields = append(fields, repo.FieldLatestDeployedAt) - } - return fields +func (m *ReviewMutation) ClearedFields() []string { + return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. -func (m *RepoMutation) FieldCleared(name string) bool { +func (m *ReviewMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. -func (m *RepoMutation) ClearField(name string) error { - switch name { - case repo.FieldWebhookID: - m.ClearWebhookID() - return nil - case repo.FieldLatestDeployedAt: - m.ClearLatestDeployedAt() - return nil - } - return fmt.Errorf("unknown Repo nullable field %s", name) +func (m *ReviewMutation) ClearField(name string) error { + return fmt.Errorf("unknown Review nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. -func (m *RepoMutation) ResetField(name string) error { +func (m *ReviewMutation) ResetField(name string) error { switch name { - case repo.FieldNamespace: - m.ResetNamespace() - return nil - case repo.FieldName: - m.ResetName() - return nil - case repo.FieldDescription: - m.ResetDescription() - return nil - case repo.FieldConfigPath: - m.ResetConfigPath() - return nil - case repo.FieldActive: - m.ResetActive() - return nil - case repo.FieldWebhookID: - m.ResetWebhookID() + case review.FieldStatus: + m.ResetStatus() return nil - case repo.FieldCreatedAt: + case review.FieldCreatedAt: m.ResetCreatedAt() return nil - case repo.FieldUpdatedAt: + case review.FieldUpdatedAt: m.ResetUpdatedAt() return nil - case repo.FieldLatestDeployedAt: - m.ResetLatestDeployedAt() + case review.FieldUserID: + m.ResetUserID() + return nil + case review.FieldDeploymentID: + m.ResetDeploymentID() return nil } - return fmt.Errorf("unknown Repo field %s", name) + return fmt.Errorf("unknown Review field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. -func (m *RepoMutation) AddedEdges() []string { - edges := make([]string, 0, 5) - if m.perms != nil { - edges = append(edges, repo.EdgePerms) - } - if m.deployments != nil { - edges = append(edges, repo.EdgeDeployments) - } - if m.callback != nil { - edges = append(edges, repo.EdgeCallback) +func (m *ReviewMutation) AddedEdges() []string { + edges := make([]string, 0, 3) + if m.user != nil { + edges = append(edges, review.EdgeUser) } - if m.locks != nil { - edges = append(edges, repo.EdgeLocks) + if m.deployment != nil { + edges = append(edges, review.EdgeDeployment) } - if m.deployment_statistics != nil { - edges = append(edges, repo.EdgeDeploymentStatistics) + if m.event != nil { + edges = append(edges, review.EdgeEvent) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. -func (m *RepoMutation) AddedIDs(name string) []ent.Value { +func (m *ReviewMutation) AddedIDs(name string) []ent.Value { switch name { - case repo.EdgePerms: - ids := make([]ent.Value, 0, len(m.perms)) - for id := range m.perms { - ids = append(ids, id) - } - return ids - case repo.EdgeDeployments: - ids := make([]ent.Value, 0, len(m.deployments)) - for id := range m.deployments { - ids = append(ids, id) - } - return ids - case repo.EdgeCallback: - ids := make([]ent.Value, 0, len(m.callback)) - for id := range m.callback { - ids = append(ids, id) + case review.EdgeUser: + if id := m.user; id != nil { + return []ent.Value{*id} } - return ids - case repo.EdgeLocks: - ids := make([]ent.Value, 0, len(m.locks)) - for id := range m.locks { - ids = append(ids, id) + case review.EdgeDeployment: + if id := m.deployment; id != nil { + return []ent.Value{*id} } - return ids - case repo.EdgeDeploymentStatistics: - ids := make([]ent.Value, 0, len(m.deployment_statistics)) - for id := range m.deployment_statistics { + case review.EdgeEvent: + ids := make([]ent.Value, 0, len(m.event)) + for id := range m.event { ids = append(ids, id) } return ids @@ -8977,57 +9169,21 @@ func (m *RepoMutation) AddedIDs(name string) []ent.Value { } // RemovedEdges returns all edge names that were removed in this mutation. -func (m *RepoMutation) RemovedEdges() []string { - edges := make([]string, 0, 5) - if m.removedperms != nil { - edges = append(edges, repo.EdgePerms) - } - if m.removeddeployments != nil { - edges = append(edges, repo.EdgeDeployments) - } - if m.removedcallback != nil { - edges = append(edges, repo.EdgeCallback) - } - if m.removedlocks != nil { - edges = append(edges, repo.EdgeLocks) - } - if m.removeddeployment_statistics != nil { - edges = append(edges, repo.EdgeDeploymentStatistics) +func (m *ReviewMutation) RemovedEdges() []string { + edges := make([]string, 0, 3) + if m.removedevent != nil { + edges = append(edges, review.EdgeEvent) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. -func (m *RepoMutation) RemovedIDs(name string) []ent.Value { +func (m *ReviewMutation) RemovedIDs(name string) []ent.Value { switch name { - case repo.EdgePerms: - ids := make([]ent.Value, 0, len(m.removedperms)) - for id := range m.removedperms { - ids = append(ids, id) - } - return ids - case repo.EdgeDeployments: - ids := make([]ent.Value, 0, len(m.removeddeployments)) - for id := range m.removeddeployments { - ids = append(ids, id) - } - return ids - case repo.EdgeCallback: - ids := make([]ent.Value, 0, len(m.removedcallback)) - for id := range m.removedcallback { - ids = append(ids, id) - } - return ids - case repo.EdgeLocks: - ids := make([]ent.Value, 0, len(m.removedlocks)) - for id := range m.removedlocks { - ids = append(ids, id) - } - return ids - case repo.EdgeDeploymentStatistics: - ids := make([]ent.Value, 0, len(m.removeddeployment_statistics)) - for id := range m.removeddeployment_statistics { + case review.EdgeEvent: + ids := make([]ent.Value, 0, len(m.removedevent)) + for id := range m.removedevent { ids = append(ids, id) } return ids @@ -9036,73 +9192,63 @@ func (m *RepoMutation) RemovedIDs(name string) []ent.Value { } // ClearedEdges returns all edge names that were cleared in this mutation. -func (m *RepoMutation) ClearedEdges() []string { - edges := make([]string, 0, 5) - if m.clearedperms { - edges = append(edges, repo.EdgePerms) - } - if m.cleareddeployments { - edges = append(edges, repo.EdgeDeployments) - } - if m.clearedcallback { - edges = append(edges, repo.EdgeCallback) +func (m *ReviewMutation) ClearedEdges() []string { + edges := make([]string, 0, 3) + if m.cleareduser { + edges = append(edges, review.EdgeUser) } - if m.clearedlocks { - edges = append(edges, repo.EdgeLocks) + if m.cleareddeployment { + edges = append(edges, review.EdgeDeployment) } - if m.cleareddeployment_statistics { - edges = append(edges, repo.EdgeDeploymentStatistics) + if m.clearedevent { + edges = append(edges, review.EdgeEvent) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. -func (m *RepoMutation) EdgeCleared(name string) bool { +func (m *ReviewMutation) EdgeCleared(name string) bool { switch name { - case repo.EdgePerms: - return m.clearedperms - case repo.EdgeDeployments: - return m.cleareddeployments - case repo.EdgeCallback: - return m.clearedcallback - case repo.EdgeLocks: - return m.clearedlocks - case repo.EdgeDeploymentStatistics: - return m.cleareddeployment_statistics + case review.EdgeUser: + return m.cleareduser + case review.EdgeDeployment: + return m.cleareddeployment + case review.EdgeEvent: + return m.clearedevent } 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 *RepoMutation) ClearEdge(name string) error { +func (m *ReviewMutation) ClearEdge(name string) error { switch name { + case review.EdgeUser: + m.ClearUser() + return nil + case review.EdgeDeployment: + m.ClearDeployment() + return nil } - return fmt.Errorf("unknown Repo unique edge %s", name) + return fmt.Errorf("unknown Review 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 *RepoMutation) ResetEdge(name string) error { +func (m *ReviewMutation) ResetEdge(name string) error { switch name { - case repo.EdgePerms: - m.ResetPerms() - return nil - case repo.EdgeDeployments: - m.ResetDeployments() - return nil - case repo.EdgeCallback: - m.ResetCallback() + case review.EdgeUser: + m.ResetUser() return nil - case repo.EdgeLocks: - m.ResetLocks() + case review.EdgeDeployment: + m.ResetDeployment() return nil - case repo.EdgeDeploymentStatistics: - m.ResetDeploymentStatistics() + case review.EdgeEvent: + m.ResetEvent() return nil } - return fmt.Errorf("unknown Repo edge %s", name) + return fmt.Errorf("unknown Review edge %s", name) } // UserMutation represents an operation that mutates the User nodes in the graph. @@ -9129,9 +9275,9 @@ type UserMutation struct { deployments map[int]struct{} removeddeployments map[int]struct{} cleareddeployments bool - approvals map[int]struct{} - removedapprovals map[int]struct{} - clearedapprovals bool + reviews map[int]struct{} + removedreviews map[int]struct{} + clearedreviews bool locks map[int]struct{} removedlocks map[int]struct{} clearedlocks bool @@ -9696,58 +9842,58 @@ func (m *UserMutation) ResetDeployments() { m.removeddeployments = nil } -// AddApprovalIDs adds the "approvals" edge to the Approval entity by ids. -func (m *UserMutation) AddApprovalIDs(ids ...int) { - if m.approvals == nil { - m.approvals = make(map[int]struct{}) +// AddReviewIDs adds the "reviews" edge to the Review entity by ids. +func (m *UserMutation) AddReviewIDs(ids ...int) { + if m.reviews == nil { + m.reviews = make(map[int]struct{}) } for i := range ids { - m.approvals[ids[i]] = struct{}{} + m.reviews[ids[i]] = struct{}{} } } -// ClearApprovals clears the "approvals" edge to the Approval entity. -func (m *UserMutation) ClearApprovals() { - m.clearedapprovals = true +// ClearReviews clears the "reviews" edge to the Review entity. +func (m *UserMutation) ClearReviews() { + m.clearedreviews = true } -// ApprovalsCleared reports if the "approvals" edge to the Approval entity was cleared. -func (m *UserMutation) ApprovalsCleared() bool { - return m.clearedapprovals +// ReviewsCleared reports if the "reviews" edge to the Review entity was cleared. +func (m *UserMutation) ReviewsCleared() bool { + return m.clearedreviews } -// RemoveApprovalIDs removes the "approvals" edge to the Approval entity by IDs. -func (m *UserMutation) RemoveApprovalIDs(ids ...int) { - if m.removedapprovals == nil { - m.removedapprovals = make(map[int]struct{}) +// RemoveReviewIDs removes the "reviews" edge to the Review entity by IDs. +func (m *UserMutation) RemoveReviewIDs(ids ...int) { + if m.removedreviews == nil { + m.removedreviews = make(map[int]struct{}) } for i := range ids { - delete(m.approvals, ids[i]) - m.removedapprovals[ids[i]] = struct{}{} + delete(m.reviews, ids[i]) + m.removedreviews[ids[i]] = struct{}{} } } -// RemovedApprovals returns the removed IDs of the "approvals" edge to the Approval entity. -func (m *UserMutation) RemovedApprovalsIDs() (ids []int) { - for id := range m.removedapprovals { +// RemovedReviews returns the removed IDs of the "reviews" edge to the Review entity. +func (m *UserMutation) RemovedReviewsIDs() (ids []int) { + for id := range m.removedreviews { ids = append(ids, id) } return } -// ApprovalsIDs returns the "approvals" edge IDs in the mutation. -func (m *UserMutation) ApprovalsIDs() (ids []int) { - for id := range m.approvals { +// ReviewsIDs returns the "reviews" edge IDs in the mutation. +func (m *UserMutation) ReviewsIDs() (ids []int) { + for id := range m.reviews { ids = append(ids, id) } return } -// ResetApprovals resets all changes to the "approvals" edge. -func (m *UserMutation) ResetApprovals() { - m.approvals = nil - m.clearedapprovals = false - m.removedapprovals = nil +// ResetReviews resets all changes to the "reviews" edge. +func (m *UserMutation) ResetReviews() { + m.reviews = nil + m.clearedreviews = false + m.removedreviews = nil } // AddLockIDs adds the "locks" edge to the Lock entity by ids. @@ -10068,8 +10214,8 @@ func (m *UserMutation) AddedEdges() []string { if m.deployments != nil { edges = append(edges, user.EdgeDeployments) } - if m.approvals != nil { - edges = append(edges, user.EdgeApprovals) + if m.reviews != nil { + edges = append(edges, user.EdgeReviews) } if m.locks != nil { edges = append(edges, user.EdgeLocks) @@ -10097,9 +10243,9 @@ func (m *UserMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case user.EdgeApprovals: - ids := make([]ent.Value, 0, len(m.approvals)) - for id := range m.approvals { + case user.EdgeReviews: + ids := make([]ent.Value, 0, len(m.reviews)) + for id := range m.reviews { ids = append(ids, id) } return ids @@ -10122,8 +10268,8 @@ func (m *UserMutation) RemovedEdges() []string { if m.removeddeployments != nil { edges = append(edges, user.EdgeDeployments) } - if m.removedapprovals != nil { - edges = append(edges, user.EdgeApprovals) + if m.removedreviews != nil { + edges = append(edges, user.EdgeReviews) } if m.removedlocks != nil { edges = append(edges, user.EdgeLocks) @@ -10147,9 +10293,9 @@ func (m *UserMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case user.EdgeApprovals: - ids := make([]ent.Value, 0, len(m.removedapprovals)) - for id := range m.removedapprovals { + case user.EdgeReviews: + ids := make([]ent.Value, 0, len(m.removedreviews)) + for id := range m.removedreviews { ids = append(ids, id) } return ids @@ -10175,8 +10321,8 @@ func (m *UserMutation) ClearedEdges() []string { if m.cleareddeployments { edges = append(edges, user.EdgeDeployments) } - if m.clearedapprovals { - edges = append(edges, user.EdgeApprovals) + if m.clearedreviews { + edges = append(edges, user.EdgeReviews) } if m.clearedlocks { edges = append(edges, user.EdgeLocks) @@ -10194,8 +10340,8 @@ func (m *UserMutation) EdgeCleared(name string) bool { return m.clearedperms case user.EdgeDeployments: return m.cleareddeployments - case user.EdgeApprovals: - return m.clearedapprovals + case user.EdgeReviews: + return m.clearedreviews case user.EdgeLocks: return m.clearedlocks } @@ -10226,8 +10372,8 @@ func (m *UserMutation) ResetEdge(name string) error { case user.EdgeDeployments: m.ResetDeployments() return nil - case user.EdgeApprovals: - m.ResetApprovals() + case user.EdgeReviews: + m.ResetReviews() return nil case user.EdgeLocks: m.ResetLocks() diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go index 1c6cf729..f8a59094 100644 --- a/ent/predicate/predicate.go +++ b/ent/predicate/predicate.go @@ -6,9 +6,6 @@ import ( "entgo.io/ent/dialect/sql" ) -// Approval is the predicate function for approval builders. -type Approval func(*sql.Selector) - // Callback is the predicate function for callback builders. type Callback func(*sql.Selector) @@ -39,5 +36,8 @@ type Perm func(*sql.Selector) // Repo is the predicate function for repo builders. type Repo func(*sql.Selector) +// Review is the predicate function for review builders. +type Review func(*sql.Selector) + // User is the predicate function for user builders. type User func(*sql.Selector) diff --git a/ent/approval.go b/ent/review.go similarity index 58% rename from ent/approval.go rename to ent/review.go index 338432cc..1c9afa3e 100644 --- a/ent/approval.go +++ b/ent/review.go @@ -8,18 +8,18 @@ import ( "time" "entgo.io/ent/dialect/sql" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) -// Approval is the model entity for the Approval schema. -type Approval struct { +// Review is the model entity for the Review schema. +type Review struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // Status holds the value of the "status" field. - Status approval.Status `json:"status"` + Status review.Status `json:"status"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at"` // UpdatedAt holds the value of the "updated_at" field. @@ -29,12 +29,12 @@ type Approval struct { // DeploymentID holds the value of the "deployment_id" field. DeploymentID int `json:"deployment_id"` // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the ApprovalQuery when eager-loading is set. - Edges ApprovalEdges `json:"edges"` + // The values are being populated by the ReviewQuery when eager-loading is set. + Edges ReviewEdges `json:"edges"` } -// ApprovalEdges holds the relations/edges for other nodes in the graph. -type ApprovalEdges struct { +// ReviewEdges holds the relations/edges for other nodes in the graph. +type ReviewEdges struct { // User holds the value of the user edge. User *User `json:"user,omitempty"` // Deployment holds the value of the deployment edge. @@ -48,7 +48,7 @@ type ApprovalEdges struct { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. -func (e ApprovalEdges) UserOrErr() (*User, error) { +func (e ReviewEdges) UserOrErr() (*User, error) { if e.loadedTypes[0] { if e.User == nil { // The edge user was loaded in eager-loading, @@ -62,7 +62,7 @@ func (e ApprovalEdges) UserOrErr() (*User, error) { // DeploymentOrErr returns the Deployment value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. -func (e ApprovalEdges) DeploymentOrErr() (*Deployment, error) { +func (e ReviewEdges) DeploymentOrErr() (*Deployment, error) { if e.loadedTypes[1] { if e.Deployment == nil { // The edge deployment was loaded in eager-loading, @@ -76,7 +76,7 @@ func (e ApprovalEdges) DeploymentOrErr() (*Deployment, error) { // EventOrErr returns the Event value or an error if the edge // was not loaded in eager-loading. -func (e ApprovalEdges) EventOrErr() ([]*Event, error) { +func (e ReviewEdges) EventOrErr() ([]*Event, error) { if e.loadedTypes[2] { return e.Event, nil } @@ -84,129 +84,129 @@ func (e ApprovalEdges) EventOrErr() ([]*Event, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Approval) scanValues(columns []string) ([]interface{}, error) { +func (*Review) scanValues(columns []string) ([]interface{}, error) { values := make([]interface{}, len(columns)) for i := range columns { switch columns[i] { - case approval.FieldID, approval.FieldUserID, approval.FieldDeploymentID: + case review.FieldID, review.FieldUserID, review.FieldDeploymentID: values[i] = new(sql.NullInt64) - case approval.FieldStatus: + case review.FieldStatus: values[i] = new(sql.NullString) - case approval.FieldCreatedAt, approval.FieldUpdatedAt: + case review.FieldCreatedAt, review.FieldUpdatedAt: values[i] = new(sql.NullTime) default: - return nil, fmt.Errorf("unexpected column %q for type Approval", columns[i]) + return nil, fmt.Errorf("unexpected column %q for type Review", columns[i]) } } return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Approval fields. -func (a *Approval) assignValues(columns []string, values []interface{}) error { +// to the Review fields. +func (r *Review) assignValues(columns []string, values []interface{}) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } for i := range columns { switch columns[i] { - case approval.FieldID: + case review.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } - a.ID = int(value.Int64) - case approval.FieldStatus: + r.ID = int(value.Int64) + case review.FieldStatus: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) } else if value.Valid { - a.Status = approval.Status(value.String) + r.Status = review.Status(value.String) } - case approval.FieldCreatedAt: + case review.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { - a.CreatedAt = value.Time + r.CreatedAt = value.Time } - case approval.FieldUpdatedAt: + case review.FieldUpdatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field updated_at", values[i]) } else if value.Valid { - a.UpdatedAt = value.Time + r.UpdatedAt = value.Time } - case approval.FieldUserID: + case review.FieldUserID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field user_id", values[i]) } else if value.Valid { - a.UserID = value.Int64 + r.UserID = value.Int64 } - case approval.FieldDeploymentID: + case review.FieldDeploymentID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field deployment_id", values[i]) } else if value.Valid { - a.DeploymentID = int(value.Int64) + r.DeploymentID = int(value.Int64) } } } return nil } -// QueryUser queries the "user" edge of the Approval entity. -func (a *Approval) QueryUser() *UserQuery { - return (&ApprovalClient{config: a.config}).QueryUser(a) +// QueryUser queries the "user" edge of the Review entity. +func (r *Review) QueryUser() *UserQuery { + return (&ReviewClient{config: r.config}).QueryUser(r) } -// QueryDeployment queries the "deployment" edge of the Approval entity. -func (a *Approval) QueryDeployment() *DeploymentQuery { - return (&ApprovalClient{config: a.config}).QueryDeployment(a) +// QueryDeployment queries the "deployment" edge of the Review entity. +func (r *Review) QueryDeployment() *DeploymentQuery { + return (&ReviewClient{config: r.config}).QueryDeployment(r) } -// QueryEvent queries the "event" edge of the Approval entity. -func (a *Approval) QueryEvent() *EventQuery { - return (&ApprovalClient{config: a.config}).QueryEvent(a) +// QueryEvent queries the "event" edge of the Review entity. +func (r *Review) QueryEvent() *EventQuery { + return (&ReviewClient{config: r.config}).QueryEvent(r) } -// Update returns a builder for updating this Approval. -// Note that you need to call Approval.Unwrap() before calling this method if this Approval +// Update returns a builder for updating this Review. +// Note that you need to call Review.Unwrap() before calling this method if this Review // was returned from a transaction, and the transaction was committed or rolled back. -func (a *Approval) Update() *ApprovalUpdateOne { - return (&ApprovalClient{config: a.config}).UpdateOne(a) +func (r *Review) Update() *ReviewUpdateOne { + return (&ReviewClient{config: r.config}).UpdateOne(r) } -// Unwrap unwraps the Approval entity that was returned from a transaction after it was closed, +// Unwrap unwraps the Review entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. -func (a *Approval) Unwrap() *Approval { - tx, ok := a.config.driver.(*txDriver) +func (r *Review) Unwrap() *Review { + tx, ok := r.config.driver.(*txDriver) if !ok { - panic("ent: Approval is not a transactional entity") + panic("ent: Review is not a transactional entity") } - a.config.driver = tx.drv - return a + r.config.driver = tx.drv + return r } // String implements the fmt.Stringer. -func (a *Approval) String() string { +func (r *Review) String() string { var builder strings.Builder - builder.WriteString("Approval(") - builder.WriteString(fmt.Sprintf("id=%v", a.ID)) + builder.WriteString("Review(") + builder.WriteString(fmt.Sprintf("id=%v", r.ID)) builder.WriteString(", status=") - builder.WriteString(fmt.Sprintf("%v", a.Status)) + builder.WriteString(fmt.Sprintf("%v", r.Status)) builder.WriteString(", created_at=") - builder.WriteString(a.CreatedAt.Format(time.ANSIC)) + builder.WriteString(r.CreatedAt.Format(time.ANSIC)) builder.WriteString(", updated_at=") - builder.WriteString(a.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(r.UpdatedAt.Format(time.ANSIC)) builder.WriteString(", user_id=") - builder.WriteString(fmt.Sprintf("%v", a.UserID)) + builder.WriteString(fmt.Sprintf("%v", r.UserID)) builder.WriteString(", deployment_id=") - builder.WriteString(fmt.Sprintf("%v", a.DeploymentID)) + builder.WriteString(fmt.Sprintf("%v", r.DeploymentID)) builder.WriteByte(')') return builder.String() } -// Approvals is a parsable slice of Approval. -type Approvals []*Approval +// Reviews is a parsable slice of Review. +type Reviews []*Review -func (a Approvals) config(cfg config) { - for _i := range a { - a[_i].config = cfg +func (r Reviews) config(cfg config) { + for _i := range r { + r[_i].config = cfg } } diff --git a/ent/approval/approval.go b/ent/review/review.go similarity index 86% rename from ent/approval/approval.go rename to ent/review/review.go index f240c2df..f29dc884 100644 --- a/ent/approval/approval.go +++ b/ent/review/review.go @@ -1,6 +1,6 @@ // Code generated by entc, DO NOT EDIT. -package approval +package review import ( "fmt" @@ -8,8 +8,8 @@ import ( ) const ( - // Label holds the string label denoting the approval type in the database. - Label = "approval" + // Label holds the string label denoting the review type in the database. + Label = "review" // FieldID holds the string denoting the id field in the database. FieldID = "id" // FieldStatus holds the string denoting the status field in the database. @@ -28,17 +28,17 @@ const ( EdgeDeployment = "deployment" // EdgeEvent holds the string denoting the event edge name in mutations. EdgeEvent = "event" - // Table holds the table name of the approval in the database. - Table = "approvals" + // Table holds the table name of the review in the database. + Table = "reviews" // UserTable is the table that holds the user relation/edge. - UserTable = "approvals" + UserTable = "reviews" // UserInverseTable is the table name for the User entity. // It exists in this package in order to avoid circular dependency with the "user" package. UserInverseTable = "users" // UserColumn is the table column denoting the user relation/edge. UserColumn = "user_id" // DeploymentTable is the table that holds the deployment relation/edge. - DeploymentTable = "approvals" + DeploymentTable = "reviews" // DeploymentInverseTable is the table name for the Deployment entity. // It exists in this package in order to avoid circular dependency with the "deployment" package. DeploymentInverseTable = "deployments" @@ -50,10 +50,10 @@ const ( // It exists in this package in order to avoid circular dependency with the "event" package. EventInverseTable = "events" // EventColumn is the table column denoting the event relation/edge. - EventColumn = "approval_id" + EventColumn = "review_id" ) -// Columns holds all SQL columns for approval fields. +// Columns holds all SQL columns for review fields. var Columns = []string{ FieldID, FieldStatus, @@ -91,7 +91,7 @@ const DefaultStatus = StatusPending // Status values. const ( StatusPending Status = "pending" - StatusDeclined Status = "declined" + StatusRejected Status = "rejected" StatusApproved Status = "approved" ) @@ -102,9 +102,9 @@ func (s Status) String() string { // StatusValidator is a validator for the "status" field enum values. It is called by the builders before save. func StatusValidator(s Status) error { switch s { - case StatusPending, StatusDeclined, StatusApproved: + case StatusPending, StatusRejected, StatusApproved: return nil default: - return fmt.Errorf("approval: invalid enum value for status field: %q", s) + return fmt.Errorf("review: invalid enum value for status field: %q", s) } } diff --git a/ent/approval/where.go b/ent/review/where.go similarity index 68% rename from ent/approval/where.go rename to ent/review/where.go index 51a7de25..6647c386 100644 --- a/ent/approval/where.go +++ b/ent/review/where.go @@ -1,6 +1,6 @@ // Code generated by entc, DO NOT EDIT. -package approval +package review import ( "time" @@ -11,29 +11,29 @@ import ( ) // ID filters vertices based on their ID field. -func ID(id int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func ID(id int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) }) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDEQ(id int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldID), id)) }) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDNEQ(id int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.NEQ(s.C(FieldID), id)) }) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDIn(ids ...int) predicate.Review { + return predicate.Review(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(ids) == 0 { @@ -49,8 +49,8 @@ func IDIn(ids ...int) predicate.Approval { } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDNotIn(ids ...int) predicate.Review { + return predicate.Review(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(ids) == 0 { @@ -66,82 +66,82 @@ func IDNotIn(ids ...int) predicate.Approval { } // IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDGT(id int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.GT(s.C(FieldID), id)) }) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDGTE(id int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.GTE(s.C(FieldID), id)) }) } // IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDLT(id int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.LT(s.C(FieldID), id)) }) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func IDLTE(id int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.LTE(s.C(FieldID), id)) }) } // CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func CreatedAt(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldCreatedAt), v)) }) } // UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UpdatedAt(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) }) } // UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. -func UserID(v int64) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UserID(v int64) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldUserID), v)) }) } // DeploymentID applies equality check predicate on the "deployment_id" field. It's identical to DeploymentIDEQ. -func DeploymentID(v int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func DeploymentID(v int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldDeploymentID), v)) }) } // StatusEQ applies the EQ predicate on the "status" field. -func StatusEQ(v Status) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func StatusEQ(v Status) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldStatus), v)) }) } // StatusNEQ applies the NEQ predicate on the "status" field. -func StatusNEQ(v Status) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func StatusNEQ(v Status) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.NEQ(s.C(FieldStatus), v)) }) } // StatusIn applies the In predicate on the "status" field. -func StatusIn(vs ...Status) predicate.Approval { +func StatusIn(vs ...Status) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -153,12 +153,12 @@ func StatusIn(vs ...Status) predicate.Approval { } // StatusNotIn applies the NotIn predicate on the "status" field. -func StatusNotIn(vs ...Status) predicate.Approval { +func StatusNotIn(vs ...Status) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -170,26 +170,26 @@ func StatusNotIn(vs ...Status) predicate.Approval { } // CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func CreatedAtEQ(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldCreatedAt), v)) }) } // CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func CreatedAtNEQ(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.NEQ(s.C(FieldCreatedAt), v)) }) } // CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Approval { +func CreatedAtIn(vs ...time.Time) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -201,12 +201,12 @@ func CreatedAtIn(vs ...time.Time) predicate.Approval { } // CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Approval { +func CreatedAtNotIn(vs ...time.Time) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -218,54 +218,54 @@ func CreatedAtNotIn(vs ...time.Time) predicate.Approval { } // CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func CreatedAtGT(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.GT(s.C(FieldCreatedAt), v)) }) } // CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func CreatedAtGTE(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.GTE(s.C(FieldCreatedAt), v)) }) } // CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func CreatedAtLT(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.LT(s.C(FieldCreatedAt), v)) }) } // CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func CreatedAtLTE(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.LTE(s.C(FieldCreatedAt), v)) }) } // UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UpdatedAtEQ(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldUpdatedAt), v)) }) } // UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UpdatedAtNEQ(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.NEQ(s.C(FieldUpdatedAt), v)) }) } // UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Approval { +func UpdatedAtIn(vs ...time.Time) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -277,12 +277,12 @@ func UpdatedAtIn(vs ...time.Time) predicate.Approval { } // UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Approval { +func UpdatedAtNotIn(vs ...time.Time) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -294,54 +294,54 @@ func UpdatedAtNotIn(vs ...time.Time) predicate.Approval { } // UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UpdatedAtGT(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.GT(s.C(FieldUpdatedAt), v)) }) } // UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UpdatedAtGTE(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.GTE(s.C(FieldUpdatedAt), v)) }) } // UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UpdatedAtLT(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.LT(s.C(FieldUpdatedAt), v)) }) } // UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UpdatedAtLTE(v time.Time) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.LTE(s.C(FieldUpdatedAt), v)) }) } // UserIDEQ applies the EQ predicate on the "user_id" field. -func UserIDEQ(v int64) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UserIDEQ(v int64) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldUserID), v)) }) } // UserIDNEQ applies the NEQ predicate on the "user_id" field. -func UserIDNEQ(v int64) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func UserIDNEQ(v int64) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.NEQ(s.C(FieldUserID), v)) }) } // UserIDIn applies the In predicate on the "user_id" field. -func UserIDIn(vs ...int64) predicate.Approval { +func UserIDIn(vs ...int64) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -353,12 +353,12 @@ func UserIDIn(vs ...int64) predicate.Approval { } // UserIDNotIn applies the NotIn predicate on the "user_id" field. -func UserIDNotIn(vs ...int64) predicate.Approval { +func UserIDNotIn(vs ...int64) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -370,26 +370,26 @@ func UserIDNotIn(vs ...int64) predicate.Approval { } // DeploymentIDEQ applies the EQ predicate on the "deployment_id" field. -func DeploymentIDEQ(v int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func DeploymentIDEQ(v int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.EQ(s.C(FieldDeploymentID), v)) }) } // DeploymentIDNEQ applies the NEQ predicate on the "deployment_id" field. -func DeploymentIDNEQ(v int) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func DeploymentIDNEQ(v int) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s.Where(sql.NEQ(s.C(FieldDeploymentID), v)) }) } // DeploymentIDIn applies the In predicate on the "deployment_id" field. -func DeploymentIDIn(vs ...int) predicate.Approval { +func DeploymentIDIn(vs ...int) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -401,12 +401,12 @@ func DeploymentIDIn(vs ...int) predicate.Approval { } // DeploymentIDNotIn applies the NotIn predicate on the "deployment_id" field. -func DeploymentIDNotIn(vs ...int) predicate.Approval { +func DeploymentIDNotIn(vs ...int) predicate.Review { v := make([]interface{}, len(vs)) for i := range v { v[i] = vs[i] } - return predicate.Approval(func(s *sql.Selector) { + return predicate.Review(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 { @@ -418,8 +418,8 @@ func DeploymentIDNotIn(vs ...int) predicate.Approval { } // HasUser applies the HasEdge predicate on the "user" edge. -func HasUser() predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func HasUser() predicate.Review { + return predicate.Review(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), sqlgraph.To(UserTable, FieldID), @@ -430,8 +430,8 @@ func HasUser() predicate.Approval { } // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). -func HasUserWith(preds ...predicate.User) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func HasUserWith(preds ...predicate.User) predicate.Review { + return predicate.Review(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), sqlgraph.To(UserInverseTable, FieldID), @@ -446,8 +446,8 @@ func HasUserWith(preds ...predicate.User) predicate.Approval { } // HasDeployment applies the HasEdge predicate on the "deployment" edge. -func HasDeployment() predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func HasDeployment() predicate.Review { + return predicate.Review(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), sqlgraph.To(DeploymentTable, FieldID), @@ -458,8 +458,8 @@ func HasDeployment() predicate.Approval { } // HasDeploymentWith applies the HasEdge predicate on the "deployment" edge with a given conditions (other predicates). -func HasDeploymentWith(preds ...predicate.Deployment) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func HasDeploymentWith(preds ...predicate.Deployment) predicate.Review { + return predicate.Review(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), sqlgraph.To(DeploymentInverseTable, FieldID), @@ -474,8 +474,8 @@ func HasDeploymentWith(preds ...predicate.Deployment) predicate.Approval { } // HasEvent applies the HasEdge predicate on the "event" edge. -func HasEvent() predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func HasEvent() predicate.Review { + return predicate.Review(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), sqlgraph.To(EventTable, FieldID), @@ -486,8 +486,8 @@ func HasEvent() predicate.Approval { } // HasEventWith applies the HasEdge predicate on the "event" edge with a given conditions (other predicates). -func HasEventWith(preds ...predicate.Event) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func HasEventWith(preds ...predicate.Event) predicate.Review { + return predicate.Review(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), sqlgraph.To(EventInverseTable, FieldID), @@ -502,8 +502,8 @@ func HasEventWith(preds ...predicate.Event) predicate.Approval { } // And groups predicates with the AND operator between them. -func And(predicates ...predicate.Approval) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func And(predicates ...predicate.Review) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) for _, p := range predicates { p(s1) @@ -513,8 +513,8 @@ func And(predicates ...predicate.Approval) predicate.Approval { } // Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Approval) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func Or(predicates ...predicate.Review) predicate.Review { + return predicate.Review(func(s *sql.Selector) { s1 := s.Clone().SetP(nil) for i, p := range predicates { if i > 0 { @@ -527,8 +527,8 @@ func Or(predicates ...predicate.Approval) predicate.Approval { } // Not applies the not operator on the given predicate. -func Not(p predicate.Approval) predicate.Approval { - return predicate.Approval(func(s *sql.Selector) { +func Not(p predicate.Review) predicate.Review { + return predicate.Review(func(s *sql.Selector) { p(s.Not()) }) } diff --git a/ent/approval_create.go b/ent/review_create.go similarity index 54% rename from ent/approval_create.go rename to ent/review_create.go index bc1befd6..dacf6f7d 100644 --- a/ent/approval_create.go +++ b/ent/review_create.go @@ -10,139 +10,139 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) -// ApprovalCreate is the builder for creating a Approval entity. -type ApprovalCreate struct { +// ReviewCreate is the builder for creating a Review entity. +type ReviewCreate struct { config - mutation *ApprovalMutation + mutation *ReviewMutation hooks []Hook } // SetStatus sets the "status" field. -func (ac *ApprovalCreate) SetStatus(a approval.Status) *ApprovalCreate { - ac.mutation.SetStatus(a) - return ac +func (rc *ReviewCreate) SetStatus(r review.Status) *ReviewCreate { + rc.mutation.SetStatus(r) + return rc } // SetNillableStatus sets the "status" field if the given value is not nil. -func (ac *ApprovalCreate) SetNillableStatus(a *approval.Status) *ApprovalCreate { - if a != nil { - ac.SetStatus(*a) +func (rc *ReviewCreate) SetNillableStatus(r *review.Status) *ReviewCreate { + if r != nil { + rc.SetStatus(*r) } - return ac + return rc } // SetCreatedAt sets the "created_at" field. -func (ac *ApprovalCreate) SetCreatedAt(t time.Time) *ApprovalCreate { - ac.mutation.SetCreatedAt(t) - return ac +func (rc *ReviewCreate) SetCreatedAt(t time.Time) *ReviewCreate { + rc.mutation.SetCreatedAt(t) + return rc } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (ac *ApprovalCreate) SetNillableCreatedAt(t *time.Time) *ApprovalCreate { +func (rc *ReviewCreate) SetNillableCreatedAt(t *time.Time) *ReviewCreate { if t != nil { - ac.SetCreatedAt(*t) + rc.SetCreatedAt(*t) } - return ac + return rc } // SetUpdatedAt sets the "updated_at" field. -func (ac *ApprovalCreate) SetUpdatedAt(t time.Time) *ApprovalCreate { - ac.mutation.SetUpdatedAt(t) - return ac +func (rc *ReviewCreate) SetUpdatedAt(t time.Time) *ReviewCreate { + rc.mutation.SetUpdatedAt(t) + return rc } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (ac *ApprovalCreate) SetNillableUpdatedAt(t *time.Time) *ApprovalCreate { +func (rc *ReviewCreate) SetNillableUpdatedAt(t *time.Time) *ReviewCreate { if t != nil { - ac.SetUpdatedAt(*t) + rc.SetUpdatedAt(*t) } - return ac + return rc } // SetUserID sets the "user_id" field. -func (ac *ApprovalCreate) SetUserID(i int64) *ApprovalCreate { - ac.mutation.SetUserID(i) - return ac +func (rc *ReviewCreate) SetUserID(i int64) *ReviewCreate { + rc.mutation.SetUserID(i) + return rc } // SetDeploymentID sets the "deployment_id" field. -func (ac *ApprovalCreate) SetDeploymentID(i int) *ApprovalCreate { - ac.mutation.SetDeploymentID(i) - return ac +func (rc *ReviewCreate) SetDeploymentID(i int) *ReviewCreate { + rc.mutation.SetDeploymentID(i) + return rc } // SetUser sets the "user" edge to the User entity. -func (ac *ApprovalCreate) SetUser(u *User) *ApprovalCreate { - return ac.SetUserID(u.ID) +func (rc *ReviewCreate) SetUser(u *User) *ReviewCreate { + return rc.SetUserID(u.ID) } // SetDeployment sets the "deployment" edge to the Deployment entity. -func (ac *ApprovalCreate) SetDeployment(d *Deployment) *ApprovalCreate { - return ac.SetDeploymentID(d.ID) +func (rc *ReviewCreate) SetDeployment(d *Deployment) *ReviewCreate { + return rc.SetDeploymentID(d.ID) } // AddEventIDs adds the "event" edge to the Event entity by IDs. -func (ac *ApprovalCreate) AddEventIDs(ids ...int) *ApprovalCreate { - ac.mutation.AddEventIDs(ids...) - return ac +func (rc *ReviewCreate) AddEventIDs(ids ...int) *ReviewCreate { + rc.mutation.AddEventIDs(ids...) + return rc } // AddEvent adds the "event" edges to the Event entity. -func (ac *ApprovalCreate) AddEvent(e ...*Event) *ApprovalCreate { +func (rc *ReviewCreate) AddEvent(e ...*Event) *ReviewCreate { ids := make([]int, len(e)) for i := range e { ids[i] = e[i].ID } - return ac.AddEventIDs(ids...) + return rc.AddEventIDs(ids...) } -// Mutation returns the ApprovalMutation object of the builder. -func (ac *ApprovalCreate) Mutation() *ApprovalMutation { - return ac.mutation +// Mutation returns the ReviewMutation object of the builder. +func (rc *ReviewCreate) Mutation() *ReviewMutation { + return rc.mutation } -// Save creates the Approval in the database. -func (ac *ApprovalCreate) Save(ctx context.Context) (*Approval, error) { +// Save creates the Review in the database. +func (rc *ReviewCreate) Save(ctx context.Context) (*Review, error) { var ( err error - node *Approval + node *Review ) - ac.defaults() - if len(ac.hooks) == 0 { - if err = ac.check(); err != nil { + rc.defaults() + if len(rc.hooks) == 0 { + if err = rc.check(); err != nil { return nil, err } - node, err = ac.sqlSave(ctx) + node, err = rc.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ApprovalMutation) + mutation, ok := m.(*ReviewMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } - if err = ac.check(); err != nil { + if err = rc.check(); err != nil { return nil, err } - ac.mutation = mutation - if node, err = ac.sqlSave(ctx); err != nil { + rc.mutation = mutation + if node, err = rc.sqlSave(ctx); err != nil { return nil, err } mutation.id = &node.ID mutation.done = true return node, err }) - for i := len(ac.hooks) - 1; i >= 0; i-- { - if ac.hooks[i] == nil { + for i := len(rc.hooks) - 1; i >= 0; i-- { + if rc.hooks[i] == nil { return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } - mut = ac.hooks[i](mut) + mut = rc.hooks[i](mut) } - if _, err := mut.Mutate(ctx, ac.mutation); err != nil { + if _, err := mut.Mutate(ctx, rc.mutation); err != nil { return nil, err } } @@ -150,8 +150,8 @@ func (ac *ApprovalCreate) Save(ctx context.Context) (*Approval, error) { } // SaveX calls Save and panics if Save returns an error. -func (ac *ApprovalCreate) SaveX(ctx context.Context) *Approval { - v, err := ac.Save(ctx) +func (rc *ReviewCreate) SaveX(ctx context.Context) *Review { + v, err := rc.Save(ctx) if err != nil { panic(err) } @@ -159,68 +159,68 @@ func (ac *ApprovalCreate) SaveX(ctx context.Context) *Approval { } // Exec executes the query. -func (ac *ApprovalCreate) Exec(ctx context.Context) error { - _, err := ac.Save(ctx) +func (rc *ReviewCreate) Exec(ctx context.Context) error { + _, err := rc.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (ac *ApprovalCreate) ExecX(ctx context.Context) { - if err := ac.Exec(ctx); err != nil { +func (rc *ReviewCreate) ExecX(ctx context.Context) { + if err := rc.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. -func (ac *ApprovalCreate) defaults() { - if _, ok := ac.mutation.Status(); !ok { - v := approval.DefaultStatus - ac.mutation.SetStatus(v) +func (rc *ReviewCreate) defaults() { + if _, ok := rc.mutation.Status(); !ok { + v := review.DefaultStatus + rc.mutation.SetStatus(v) } - if _, ok := ac.mutation.CreatedAt(); !ok { - v := approval.DefaultCreatedAt() - ac.mutation.SetCreatedAt(v) + if _, ok := rc.mutation.CreatedAt(); !ok { + v := review.DefaultCreatedAt() + rc.mutation.SetCreatedAt(v) } - if _, ok := ac.mutation.UpdatedAt(); !ok { - v := approval.DefaultUpdatedAt() - ac.mutation.SetUpdatedAt(v) + if _, ok := rc.mutation.UpdatedAt(); !ok { + v := review.DefaultUpdatedAt() + rc.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. -func (ac *ApprovalCreate) check() error { - if _, ok := ac.mutation.Status(); !ok { +func (rc *ReviewCreate) check() error { + if _, ok := rc.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "status"`)} } - if v, ok := ac.mutation.Status(); ok { - if err := approval.StatusValidator(v); err != nil { + if v, ok := rc.mutation.Status(); ok { + if err := review.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "status": %w`, err)} } } - if _, ok := ac.mutation.CreatedAt(); !ok { + if _, ok := rc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "created_at"`)} } - if _, ok := ac.mutation.UpdatedAt(); !ok { + if _, ok := rc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "updated_at"`)} } - if _, ok := ac.mutation.UserID(); !ok { + if _, ok := rc.mutation.UserID(); !ok { return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "user_id"`)} } - if _, ok := ac.mutation.DeploymentID(); !ok { + if _, ok := rc.mutation.DeploymentID(); !ok { return &ValidationError{Name: "deployment_id", err: errors.New(`ent: missing required field "deployment_id"`)} } - if _, ok := ac.mutation.UserID(); !ok { + if _, ok := rc.mutation.UserID(); !ok { return &ValidationError{Name: "user", err: errors.New("ent: missing required edge \"user\"")} } - if _, ok := ac.mutation.DeploymentID(); !ok { + if _, ok := rc.mutation.DeploymentID(); !ok { return &ValidationError{Name: "deployment", err: errors.New("ent: missing required edge \"deployment\"")} } return nil } -func (ac *ApprovalCreate) sqlSave(ctx context.Context) (*Approval, error) { - _node, _spec := ac.createSpec() - if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil { +func (rc *ReviewCreate) sqlSave(ctx context.Context) (*Review, error) { + _node, _spec := rc.createSpec() + if err := sqlgraph.CreateNode(ctx, rc.driver, _spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{err.Error(), err} } @@ -231,47 +231,47 @@ func (ac *ApprovalCreate) sqlSave(ctx context.Context) (*Approval, error) { return _node, nil } -func (ac *ApprovalCreate) createSpec() (*Approval, *sqlgraph.CreateSpec) { +func (rc *ReviewCreate) createSpec() (*Review, *sqlgraph.CreateSpec) { var ( - _node = &Approval{config: ac.config} + _node = &Review{config: rc.config} _spec = &sqlgraph.CreateSpec{ - Table: approval.Table, + Table: review.Table, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, } ) - if value, ok := ac.mutation.Status(); ok { + if value, ok := rc.mutation.Status(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeEnum, Value: value, - Column: approval.FieldStatus, + Column: review.FieldStatus, }) _node.Status = value } - if value, ok := ac.mutation.CreatedAt(); ok { + if value, ok := rc.mutation.CreatedAt(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, - Column: approval.FieldCreatedAt, + Column: review.FieldCreatedAt, }) _node.CreatedAt = value } - if value, ok := ac.mutation.UpdatedAt(); ok { + if value, ok := rc.mutation.UpdatedAt(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, - Column: approval.FieldUpdatedAt, + Column: review.FieldUpdatedAt, }) _node.UpdatedAt = value } - if nodes := ac.mutation.UserIDs(); len(nodes) > 0 { + if nodes := rc.mutation.UserIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.UserTable, - Columns: []string{approval.UserColumn}, + Table: review.UserTable, + Columns: []string{review.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -286,12 +286,12 @@ func (ac *ApprovalCreate) createSpec() (*Approval, *sqlgraph.CreateSpec) { _node.UserID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } - if nodes := ac.mutation.DeploymentIDs(); len(nodes) > 0 { + if nodes := rc.mutation.DeploymentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.DeploymentTable, - Columns: []string{approval.DeploymentColumn}, + Table: review.DeploymentTable, + Columns: []string{review.DeploymentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -306,12 +306,12 @@ func (ac *ApprovalCreate) createSpec() (*Approval, *sqlgraph.CreateSpec) { _node.DeploymentID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } - if nodes := ac.mutation.EventIDs(); len(nodes) > 0 { + if nodes := rc.mutation.EventIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: approval.EventTable, - Columns: []string{approval.EventColumn}, + Table: review.EventTable, + Columns: []string{review.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -328,23 +328,23 @@ func (ac *ApprovalCreate) createSpec() (*Approval, *sqlgraph.CreateSpec) { return _node, _spec } -// ApprovalCreateBulk is the builder for creating many Approval entities in bulk. -type ApprovalCreateBulk struct { +// ReviewCreateBulk is the builder for creating many Review entities in bulk. +type ReviewCreateBulk struct { config - builders []*ApprovalCreate + builders []*ReviewCreate } -// Save creates the Approval entities in the database. -func (acb *ApprovalCreateBulk) Save(ctx context.Context) ([]*Approval, error) { - specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) - nodes := make([]*Approval, len(acb.builders)) - mutators := make([]Mutator, len(acb.builders)) - for i := range acb.builders { +// Save creates the Review entities in the database. +func (rcb *ReviewCreateBulk) Save(ctx context.Context) ([]*Review, error) { + specs := make([]*sqlgraph.CreateSpec, len(rcb.builders)) + nodes := make([]*Review, len(rcb.builders)) + mutators := make([]Mutator, len(rcb.builders)) + for i := range rcb.builders { func(i int, root context.Context) { - builder := acb.builders[i] + builder := rcb.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ApprovalMutation) + mutation, ok := m.(*ReviewMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } @@ -355,11 +355,11 @@ func (acb *ApprovalCreateBulk) Save(ctx context.Context) ([]*Approval, error) { nodes[i], specs[i] = builder.createSpec() var err error if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation) + _, err = mutators[i+1].Mutate(root, rcb.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, acb.driver, spec); err != nil { + if err = sqlgraph.BatchCreate(ctx, rcb.driver, spec); err != nil { if sqlgraph.IsConstraintError(err) { err = &ConstraintError{err.Error(), err} } @@ -383,7 +383,7 @@ func (acb *ApprovalCreateBulk) Save(ctx context.Context) ([]*Approval, error) { }(i, ctx) } if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil { + if _, err := mutators[0].Mutate(ctx, rcb.builders[0].mutation); err != nil { return nil, err } } @@ -391,8 +391,8 @@ func (acb *ApprovalCreateBulk) Save(ctx context.Context) ([]*Approval, error) { } // SaveX is like Save, but panics if an error occurs. -func (acb *ApprovalCreateBulk) SaveX(ctx context.Context) []*Approval { - v, err := acb.Save(ctx) +func (rcb *ReviewCreateBulk) SaveX(ctx context.Context) []*Review { + v, err := rcb.Save(ctx) if err != nil { panic(err) } @@ -400,14 +400,14 @@ func (acb *ApprovalCreateBulk) SaveX(ctx context.Context) []*Approval { } // Exec executes the query. -func (acb *ApprovalCreateBulk) Exec(ctx context.Context) error { - _, err := acb.Save(ctx) +func (rcb *ReviewCreateBulk) Exec(ctx context.Context) error { + _, err := rcb.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (acb *ApprovalCreateBulk) ExecX(ctx context.Context) { - if err := acb.Exec(ctx); err != nil { +func (rcb *ReviewCreateBulk) ExecX(ctx context.Context) { + if err := rcb.Exec(ctx); err != nil { panic(err) } } diff --git a/ent/review_delete.go b/ent/review_delete.go new file mode 100644 index 00000000..456eb6a7 --- /dev/null +++ b/ent/review_delete.go @@ -0,0 +1,111 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/gitploy-io/gitploy/ent/predicate" + "github.com/gitploy-io/gitploy/ent/review" +) + +// ReviewDelete is the builder for deleting a Review entity. +type ReviewDelete struct { + config + hooks []Hook + mutation *ReviewMutation +} + +// Where appends a list predicates to the ReviewDelete builder. +func (rd *ReviewDelete) Where(ps ...predicate.Review) *ReviewDelete { + rd.mutation.Where(ps...) + return rd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (rd *ReviewDelete) Exec(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(rd.hooks) == 0 { + affected, err = rd.sqlExec(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*ReviewMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + rd.mutation = mutation + affected, err = rd.sqlExec(ctx) + mutation.done = true + return affected, err + }) + for i := len(rd.hooks) - 1; i >= 0; i-- { + if rd.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = rd.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, rd.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// ExecX is like Exec, but panics if an error occurs. +func (rd *ReviewDelete) ExecX(ctx context.Context) int { + n, err := rd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (rd *ReviewDelete) sqlExec(ctx context.Context) (int, error) { + _spec := &sqlgraph.DeleteSpec{ + Node: &sqlgraph.NodeSpec{ + Table: review.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt, + Column: review.FieldID, + }, + }, + } + if ps := rd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return sqlgraph.DeleteNodes(ctx, rd.driver, _spec) +} + +// ReviewDeleteOne is the builder for deleting a single Review entity. +type ReviewDeleteOne struct { + rd *ReviewDelete +} + +// Exec executes the deletion query. +func (rdo *ReviewDeleteOne) Exec(ctx context.Context) error { + n, err := rdo.rd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{review.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (rdo *ReviewDeleteOne) ExecX(ctx context.Context) { + rdo.rd.ExecX(ctx) +} diff --git a/ent/approval_query.go b/ent/review_query.go similarity index 50% rename from ent/approval_query.go rename to ent/review_query.go index 68612fb1..9d08ae58 100644 --- a/ent/approval_query.go +++ b/ent/review_query.go @@ -13,22 +13,22 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/predicate" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) -// ApprovalQuery is the builder for querying Approval entities. -type ApprovalQuery struct { +// ReviewQuery is the builder for querying Review entities. +type ReviewQuery struct { config limit *int offset *int unique *bool order []OrderFunc fields []string - predicates []predicate.Approval + predicates []predicate.Review // eager-loading edges. withUser *UserQuery withDeployment *DeploymentQuery @@ -39,153 +39,153 @@ type ApprovalQuery struct { path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the ApprovalQuery builder. -func (aq *ApprovalQuery) Where(ps ...predicate.Approval) *ApprovalQuery { - aq.predicates = append(aq.predicates, ps...) - return aq +// Where adds a new predicate for the ReviewQuery builder. +func (rq *ReviewQuery) Where(ps ...predicate.Review) *ReviewQuery { + rq.predicates = append(rq.predicates, ps...) + return rq } // Limit adds a limit step to the query. -func (aq *ApprovalQuery) Limit(limit int) *ApprovalQuery { - aq.limit = &limit - return aq +func (rq *ReviewQuery) Limit(limit int) *ReviewQuery { + rq.limit = &limit + return rq } // Offset adds an offset step to the query. -func (aq *ApprovalQuery) Offset(offset int) *ApprovalQuery { - aq.offset = &offset - return aq +func (rq *ReviewQuery) Offset(offset int) *ReviewQuery { + rq.offset = &offset + return rq } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. -func (aq *ApprovalQuery) Unique(unique bool) *ApprovalQuery { - aq.unique = &unique - return aq +func (rq *ReviewQuery) Unique(unique bool) *ReviewQuery { + rq.unique = &unique + return rq } // Order adds an order step to the query. -func (aq *ApprovalQuery) Order(o ...OrderFunc) *ApprovalQuery { - aq.order = append(aq.order, o...) - return aq +func (rq *ReviewQuery) Order(o ...OrderFunc) *ReviewQuery { + rq.order = append(rq.order, o...) + return rq } // QueryUser chains the current query on the "user" edge. -func (aq *ApprovalQuery) QueryUser() *UserQuery { - query := &UserQuery{config: aq.config} +func (rq *ReviewQuery) QueryUser() *UserQuery { + query := &UserQuery{config: rq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { + if err := rq.prepareQuery(ctx); err != nil { return nil, err } - selector := aq.sqlQuery(ctx) + selector := rq.sqlQuery(ctx) if err := selector.Err(); err != nil { return nil, err } step := sqlgraph.NewStep( - sqlgraph.From(approval.Table, approval.FieldID, selector), + sqlgraph.From(review.Table, review.FieldID, selector), sqlgraph.To(user.Table, user.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, approval.UserTable, approval.UserColumn), + sqlgraph.Edge(sqlgraph.M2O, true, review.UserTable, review.UserColumn), ) - fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + fromU = sqlgraph.SetNeighbors(rq.driver.Dialect(), step) return fromU, nil } return query } // QueryDeployment chains the current query on the "deployment" edge. -func (aq *ApprovalQuery) QueryDeployment() *DeploymentQuery { - query := &DeploymentQuery{config: aq.config} +func (rq *ReviewQuery) QueryDeployment() *DeploymentQuery { + query := &DeploymentQuery{config: rq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { + if err := rq.prepareQuery(ctx); err != nil { return nil, err } - selector := aq.sqlQuery(ctx) + selector := rq.sqlQuery(ctx) if err := selector.Err(); err != nil { return nil, err } step := sqlgraph.NewStep( - sqlgraph.From(approval.Table, approval.FieldID, selector), + sqlgraph.From(review.Table, review.FieldID, selector), sqlgraph.To(deployment.Table, deployment.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, approval.DeploymentTable, approval.DeploymentColumn), + sqlgraph.Edge(sqlgraph.M2O, true, review.DeploymentTable, review.DeploymentColumn), ) - fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + fromU = sqlgraph.SetNeighbors(rq.driver.Dialect(), step) return fromU, nil } return query } // QueryEvent chains the current query on the "event" edge. -func (aq *ApprovalQuery) QueryEvent() *EventQuery { - query := &EventQuery{config: aq.config} +func (rq *ReviewQuery) QueryEvent() *EventQuery { + query := &EventQuery{config: rq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { + if err := rq.prepareQuery(ctx); err != nil { return nil, err } - selector := aq.sqlQuery(ctx) + selector := rq.sqlQuery(ctx) if err := selector.Err(); err != nil { return nil, err } step := sqlgraph.NewStep( - sqlgraph.From(approval.Table, approval.FieldID, selector), + sqlgraph.From(review.Table, review.FieldID, selector), sqlgraph.To(event.Table, event.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, approval.EventTable, approval.EventColumn), + sqlgraph.Edge(sqlgraph.O2M, false, review.EventTable, review.EventColumn), ) - fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + fromU = sqlgraph.SetNeighbors(rq.driver.Dialect(), step) return fromU, nil } return query } -// First returns the first Approval entity from the query. -// Returns a *NotFoundError when no Approval was found. -func (aq *ApprovalQuery) First(ctx context.Context) (*Approval, error) { - nodes, err := aq.Limit(1).All(ctx) +// First returns the first Review entity from the query. +// Returns a *NotFoundError when no Review was found. +func (rq *ReviewQuery) First(ctx context.Context) (*Review, error) { + nodes, err := rq.Limit(1).All(ctx) if err != nil { return nil, err } if len(nodes) == 0 { - return nil, &NotFoundError{approval.Label} + return nil, &NotFoundError{review.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. -func (aq *ApprovalQuery) FirstX(ctx context.Context) *Approval { - node, err := aq.First(ctx) +func (rq *ReviewQuery) FirstX(ctx context.Context) *Review { + node, err := rq.First(ctx) if err != nil && !IsNotFound(err) { panic(err) } return node } -// FirstID returns the first Approval ID from the query. -// Returns a *NotFoundError when no Approval ID was found. -func (aq *ApprovalQuery) FirstID(ctx context.Context) (id int, err error) { +// FirstID returns the first Review ID from the query. +// Returns a *NotFoundError when no Review ID was found. +func (rq *ReviewQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = aq.Limit(1).IDs(ctx); err != nil { + if ids, err = rq.Limit(1).IDs(ctx); err != nil { return } if len(ids) == 0 { - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. -func (aq *ApprovalQuery) FirstIDX(ctx context.Context) int { - id, err := aq.FirstID(ctx) +func (rq *ReviewQuery) FirstIDX(ctx context.Context) int { + id, err := rq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) } return id } -// Only returns a single Approval entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when exactly one Approval entity is not found. -// Returns a *NotFoundError when no Approval entities are found. -func (aq *ApprovalQuery) Only(ctx context.Context) (*Approval, error) { - nodes, err := aq.Limit(2).All(ctx) +// Only returns a single Review entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when exactly one Review entity is not found. +// Returns a *NotFoundError when no Review entities are found. +func (rq *ReviewQuery) Only(ctx context.Context) (*Review, error) { + nodes, err := rq.Limit(2).All(ctx) if err != nil { return nil, err } @@ -193,78 +193,78 @@ func (aq *ApprovalQuery) Only(ctx context.Context) (*Approval, error) { case 1: return nodes[0], nil case 0: - return nil, &NotFoundError{approval.Label} + return nil, &NotFoundError{review.Label} default: - return nil, &NotSingularError{approval.Label} + return nil, &NotSingularError{review.Label} } } // OnlyX is like Only, but panics if an error occurs. -func (aq *ApprovalQuery) OnlyX(ctx context.Context) *Approval { - node, err := aq.Only(ctx) +func (rq *ReviewQuery) OnlyX(ctx context.Context) *Review { + node, err := rq.Only(ctx) if err != nil { panic(err) } return node } -// OnlyID is like Only, but returns the only Approval ID in the query. -// Returns a *NotSingularError when exactly one Approval ID is not found. +// OnlyID is like Only, but returns the only Review ID in the query. +// Returns a *NotSingularError when exactly one Review ID is not found. // Returns a *NotFoundError when no entities are found. -func (aq *ApprovalQuery) OnlyID(ctx context.Context) (id int, err error) { +func (rq *ReviewQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = aq.Limit(2).IDs(ctx); err != nil { + if ids, err = rq.Limit(2).IDs(ctx); err != nil { return } switch len(ids) { case 1: id = ids[0] case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = &NotSingularError{approval.Label} + err = &NotSingularError{review.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (aq *ApprovalQuery) OnlyIDX(ctx context.Context) int { - id, err := aq.OnlyID(ctx) +func (rq *ReviewQuery) OnlyIDX(ctx context.Context) int { + id, err := rq.OnlyID(ctx) if err != nil { panic(err) } return id } -// All executes the query and returns a list of Approvals. -func (aq *ApprovalQuery) All(ctx context.Context) ([]*Approval, error) { - if err := aq.prepareQuery(ctx); err != nil { +// All executes the query and returns a list of Reviews. +func (rq *ReviewQuery) All(ctx context.Context) ([]*Review, error) { + if err := rq.prepareQuery(ctx); err != nil { return nil, err } - return aq.sqlAll(ctx) + return rq.sqlAll(ctx) } // AllX is like All, but panics if an error occurs. -func (aq *ApprovalQuery) AllX(ctx context.Context) []*Approval { - nodes, err := aq.All(ctx) +func (rq *ReviewQuery) AllX(ctx context.Context) []*Review { + nodes, err := rq.All(ctx) if err != nil { panic(err) } return nodes } -// IDs executes the query and returns a list of Approval IDs. -func (aq *ApprovalQuery) IDs(ctx context.Context) ([]int, error) { +// IDs executes the query and returns a list of Review IDs. +func (rq *ReviewQuery) IDs(ctx context.Context) ([]int, error) { var ids []int - if err := aq.Select(approval.FieldID).Scan(ctx, &ids); err != nil { + if err := rq.Select(review.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. -func (aq *ApprovalQuery) IDsX(ctx context.Context) []int { - ids, err := aq.IDs(ctx) +func (rq *ReviewQuery) IDsX(ctx context.Context) []int { + ids, err := rq.IDs(ctx) if err != nil { panic(err) } @@ -272,16 +272,16 @@ func (aq *ApprovalQuery) IDsX(ctx context.Context) []int { } // Count returns the count of the given query. -func (aq *ApprovalQuery) Count(ctx context.Context) (int, error) { - if err := aq.prepareQuery(ctx); err != nil { +func (rq *ReviewQuery) Count(ctx context.Context) (int, error) { + if err := rq.prepareQuery(ctx); err != nil { return 0, err } - return aq.sqlCount(ctx) + return rq.sqlCount(ctx) } // CountX is like Count, but panics if an error occurs. -func (aq *ApprovalQuery) CountX(ctx context.Context) int { - count, err := aq.Count(ctx) +func (rq *ReviewQuery) CountX(ctx context.Context) int { + count, err := rq.Count(ctx) if err != nil { panic(err) } @@ -289,74 +289,74 @@ func (aq *ApprovalQuery) CountX(ctx context.Context) int { } // Exist returns true if the query has elements in the graph. -func (aq *ApprovalQuery) Exist(ctx context.Context) (bool, error) { - if err := aq.prepareQuery(ctx); err != nil { +func (rq *ReviewQuery) Exist(ctx context.Context) (bool, error) { + if err := rq.prepareQuery(ctx); err != nil { return false, err } - return aq.sqlExist(ctx) + return rq.sqlExist(ctx) } // ExistX is like Exist, but panics if an error occurs. -func (aq *ApprovalQuery) ExistX(ctx context.Context) bool { - exist, err := aq.Exist(ctx) +func (rq *ReviewQuery) ExistX(ctx context.Context) bool { + exist, err := rq.Exist(ctx) if err != nil { panic(err) } return exist } -// Clone returns a duplicate of the ApprovalQuery builder, including all associated steps. It can be +// Clone returns a duplicate of the ReviewQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. -func (aq *ApprovalQuery) Clone() *ApprovalQuery { - if aq == nil { +func (rq *ReviewQuery) Clone() *ReviewQuery { + if rq == nil { return nil } - return &ApprovalQuery{ - config: aq.config, - limit: aq.limit, - offset: aq.offset, - order: append([]OrderFunc{}, aq.order...), - predicates: append([]predicate.Approval{}, aq.predicates...), - withUser: aq.withUser.Clone(), - withDeployment: aq.withDeployment.Clone(), - withEvent: aq.withEvent.Clone(), + return &ReviewQuery{ + config: rq.config, + limit: rq.limit, + offset: rq.offset, + order: append([]OrderFunc{}, rq.order...), + predicates: append([]predicate.Review{}, rq.predicates...), + withUser: rq.withUser.Clone(), + withDeployment: rq.withDeployment.Clone(), + withEvent: rq.withEvent.Clone(), // clone intermediate query. - sql: aq.sql.Clone(), - path: aq.path, + sql: rq.sql.Clone(), + path: rq.path, } } // WithUser tells the query-builder to eager-load the nodes that are connected to // the "user" edge. The optional arguments are used to configure the query builder of the edge. -func (aq *ApprovalQuery) WithUser(opts ...func(*UserQuery)) *ApprovalQuery { - query := &UserQuery{config: aq.config} +func (rq *ReviewQuery) WithUser(opts ...func(*UserQuery)) *ReviewQuery { + query := &UserQuery{config: rq.config} for _, opt := range opts { opt(query) } - aq.withUser = query - return aq + rq.withUser = query + return rq } // WithDeployment tells the query-builder to eager-load the nodes that are connected to // the "deployment" edge. The optional arguments are used to configure the query builder of the edge. -func (aq *ApprovalQuery) WithDeployment(opts ...func(*DeploymentQuery)) *ApprovalQuery { - query := &DeploymentQuery{config: aq.config} +func (rq *ReviewQuery) WithDeployment(opts ...func(*DeploymentQuery)) *ReviewQuery { + query := &DeploymentQuery{config: rq.config} for _, opt := range opts { opt(query) } - aq.withDeployment = query - return aq + rq.withDeployment = query + return rq } // WithEvent tells the query-builder to eager-load the nodes that are connected to // the "event" edge. The optional arguments are used to configure the query builder of the edge. -func (aq *ApprovalQuery) WithEvent(opts ...func(*EventQuery)) *ApprovalQuery { - query := &EventQuery{config: aq.config} +func (rq *ReviewQuery) WithEvent(opts ...func(*EventQuery)) *ReviewQuery { + query := &EventQuery{config: rq.config} for _, opt := range opts { opt(query) } - aq.withEvent = query - return aq + rq.withEvent = query + return rq } // GroupBy is used to group vertices by one or more fields/columns. @@ -365,23 +365,23 @@ func (aq *ApprovalQuery) WithEvent(opts ...func(*EventQuery)) *ApprovalQuery { // Example: // // var v []struct { -// Status approval.Status `json:"status"` +// Status review.Status `json:"status"` // Count int `json:"count,omitempty"` // } // -// client.Approval.Query(). -// GroupBy(approval.FieldStatus). +// client.Review.Query(). +// GroupBy(review.FieldStatus). // Aggregate(ent.Count()). // Scan(ctx, &v) // -func (aq *ApprovalQuery) GroupBy(field string, fields ...string) *ApprovalGroupBy { - group := &ApprovalGroupBy{config: aq.config} +func (rq *ReviewQuery) GroupBy(field string, fields ...string) *ReviewGroupBy { + group := &ReviewGroupBy{config: rq.config} group.fields = append([]string{field}, fields...) group.path = func(ctx context.Context) (prev *sql.Selector, err error) { - if err := aq.prepareQuery(ctx); err != nil { + if err := rq.prepareQuery(ctx); err != nil { return nil, err } - return aq.sqlQuery(ctx), nil + return rq.sqlQuery(ctx), nil } return group } @@ -392,46 +392,46 @@ func (aq *ApprovalQuery) GroupBy(field string, fields ...string) *ApprovalGroupB // Example: // // var v []struct { -// Status approval.Status `json:"status"` +// Status review.Status `json:"status"` // } // -// client.Approval.Query(). -// Select(approval.FieldStatus). +// client.Review.Query(). +// Select(review.FieldStatus). // Scan(ctx, &v) // -func (aq *ApprovalQuery) Select(fields ...string) *ApprovalSelect { - aq.fields = append(aq.fields, fields...) - return &ApprovalSelect{ApprovalQuery: aq} +func (rq *ReviewQuery) Select(fields ...string) *ReviewSelect { + rq.fields = append(rq.fields, fields...) + return &ReviewSelect{ReviewQuery: rq} } -func (aq *ApprovalQuery) prepareQuery(ctx context.Context) error { - for _, f := range aq.fields { - if !approval.ValidColumn(f) { +func (rq *ReviewQuery) prepareQuery(ctx context.Context) error { + for _, f := range rq.fields { + if !review.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } - if aq.path != nil { - prev, err := aq.path(ctx) + if rq.path != nil { + prev, err := rq.path(ctx) if err != nil { return err } - aq.sql = prev + rq.sql = prev } return nil } -func (aq *ApprovalQuery) sqlAll(ctx context.Context) ([]*Approval, error) { +func (rq *ReviewQuery) sqlAll(ctx context.Context) ([]*Review, error) { var ( - nodes = []*Approval{} - _spec = aq.querySpec() + nodes = []*Review{} + _spec = rq.querySpec() loadedTypes = [3]bool{ - aq.withUser != nil, - aq.withDeployment != nil, - aq.withEvent != nil, + rq.withUser != nil, + rq.withDeployment != nil, + rq.withEvent != nil, } ) _spec.ScanValues = func(columns []string) ([]interface{}, error) { - node := &Approval{config: aq.config} + node := &Review{config: rq.config} nodes = append(nodes, node) return node.scanValues(columns) } @@ -443,19 +443,19 @@ func (aq *ApprovalQuery) sqlAll(ctx context.Context) ([]*Approval, error) { node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) } - if len(aq.modifiers) > 0 { - _spec.Modifiers = aq.modifiers + if len(rq.modifiers) > 0 { + _spec.Modifiers = rq.modifiers } - if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil { + if err := sqlgraph.QueryNodes(ctx, rq.driver, _spec); err != nil { return nil, err } if len(nodes) == 0 { return nodes, nil } - if query := aq.withUser; query != nil { + if query := rq.withUser; query != nil { ids := make([]int64, 0, len(nodes)) - nodeids := make(map[int64][]*Approval) + nodeids := make(map[int64][]*Review) for i := range nodes { fk := nodes[i].UserID if _, ok := nodeids[fk]; !ok { @@ -479,9 +479,9 @@ func (aq *ApprovalQuery) sqlAll(ctx context.Context) ([]*Approval, error) { } } - if query := aq.withDeployment; query != nil { + if query := rq.withDeployment; query != nil { ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*Approval) + nodeids := make(map[int][]*Review) for i := range nodes { fk := nodes[i].DeploymentID if _, ok := nodeids[fk]; !ok { @@ -505,26 +505,26 @@ func (aq *ApprovalQuery) sqlAll(ctx context.Context) ([]*Approval, error) { } } - if query := aq.withEvent; query != nil { + if query := rq.withEvent; query != nil { fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Approval) + nodeids := make(map[int]*Review) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] nodes[i].Edges.Event = []*Event{} } query.Where(predicate.Event(func(s *sql.Selector) { - s.Where(sql.InValues(approval.EventColumn, fks...)) + s.Where(sql.InValues(review.EventColumn, fks...)) })) neighbors, err := query.All(ctx) if err != nil { return nil, err } for _, n := range neighbors { - fk := n.ApprovalID + fk := n.ReviewID node, ok := nodeids[fk] if !ok { - return nil, fmt.Errorf(`unexpected foreign-key "approval_id" returned %v for node %v`, fk, n.ID) + return nil, fmt.Errorf(`unexpected foreign-key "review_id" returned %v for node %v`, fk, n.ID) } node.Edges.Event = append(node.Edges.Event, n) } @@ -533,61 +533,61 @@ func (aq *ApprovalQuery) sqlAll(ctx context.Context) ([]*Approval, error) { return nodes, nil } -func (aq *ApprovalQuery) sqlCount(ctx context.Context) (int, error) { - _spec := aq.querySpec() - if len(aq.modifiers) > 0 { - _spec.Modifiers = aq.modifiers +func (rq *ReviewQuery) sqlCount(ctx context.Context) (int, error) { + _spec := rq.querySpec() + if len(rq.modifiers) > 0 { + _spec.Modifiers = rq.modifiers } - return sqlgraph.CountNodes(ctx, aq.driver, _spec) + return sqlgraph.CountNodes(ctx, rq.driver, _spec) } -func (aq *ApprovalQuery) sqlExist(ctx context.Context) (bool, error) { - n, err := aq.sqlCount(ctx) +func (rq *ReviewQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := rq.sqlCount(ctx) if err != nil { return false, fmt.Errorf("ent: check existence: %w", err) } return n > 0, nil } -func (aq *ApprovalQuery) querySpec() *sqlgraph.QuerySpec { +func (rq *ReviewQuery) querySpec() *sqlgraph.QuerySpec { _spec := &sqlgraph.QuerySpec{ Node: &sqlgraph.NodeSpec{ - Table: approval.Table, - Columns: approval.Columns, + Table: review.Table, + Columns: review.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, - From: aq.sql, + From: rq.sql, Unique: true, } - if unique := aq.unique; unique != nil { + if unique := rq.unique; unique != nil { _spec.Unique = *unique } - if fields := aq.fields; len(fields) > 0 { + if fields := rq.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, approval.FieldID) + _spec.Node.Columns = append(_spec.Node.Columns, review.FieldID) for i := range fields { - if fields[i] != approval.FieldID { + if fields[i] != review.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } } - if ps := aq.predicates; len(ps) > 0 { + if ps := rq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } - if limit := aq.limit; limit != nil { + if limit := rq.limit; limit != nil { _spec.Limit = *limit } - if offset := aq.offset; offset != nil { + if offset := rq.offset; offset != nil { _spec.Offset = *offset } - if ps := aq.order; len(ps) > 0 { + if ps := rq.order; len(ps) > 0 { _spec.Order = func(selector *sql.Selector) { for i := range ps { ps[i](selector) @@ -597,33 +597,33 @@ func (aq *ApprovalQuery) querySpec() *sqlgraph.QuerySpec { return _spec } -func (aq *ApprovalQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(aq.driver.Dialect()) - t1 := builder.Table(approval.Table) - columns := aq.fields +func (rq *ReviewQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(rq.driver.Dialect()) + t1 := builder.Table(review.Table) + columns := rq.fields if len(columns) == 0 { - columns = approval.Columns + columns = review.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) - if aq.sql != nil { - selector = aq.sql + if rq.sql != nil { + selector = rq.sql selector.Select(selector.Columns(columns...)...) } - for _, m := range aq.modifiers { + for _, m := range rq.modifiers { m(selector) } - for _, p := range aq.predicates { + for _, p := range rq.predicates { p(selector) } - for _, p := range aq.order { + for _, p := range rq.order { p(selector) } - if offset := aq.offset; offset != nil { + if offset := rq.offset; offset != nil { // limit is mandatory for offset clause. We start // with default value, and override it below if needed. selector.Offset(*offset).Limit(math.MaxInt32) } - if limit := aq.limit; limit != nil { + if limit := rq.limit; limit != nil { selector.Limit(*limit) } return selector @@ -632,31 +632,31 @@ func (aq *ApprovalQuery) sqlQuery(ctx context.Context) *sql.Selector { // ForUpdate locks the selected rows against concurrent updates, and prevent them from being // updated, deleted or "selected ... for update" by other sessions, until the transaction is // either committed or rolled-back. -func (aq *ApprovalQuery) ForUpdate(opts ...sql.LockOption) *ApprovalQuery { - if aq.driver.Dialect() == dialect.Postgres { - aq.Unique(false) +func (rq *ReviewQuery) ForUpdate(opts ...sql.LockOption) *ReviewQuery { + if rq.driver.Dialect() == dialect.Postgres { + rq.Unique(false) } - aq.modifiers = append(aq.modifiers, func(s *sql.Selector) { + rq.modifiers = append(rq.modifiers, func(s *sql.Selector) { s.ForUpdate(opts...) }) - return aq + return rq } // ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock // on any rows that are read. Other sessions can read the rows, but cannot modify them // until your transaction commits. -func (aq *ApprovalQuery) ForShare(opts ...sql.LockOption) *ApprovalQuery { - if aq.driver.Dialect() == dialect.Postgres { - aq.Unique(false) +func (rq *ReviewQuery) ForShare(opts ...sql.LockOption) *ReviewQuery { + if rq.driver.Dialect() == dialect.Postgres { + rq.Unique(false) } - aq.modifiers = append(aq.modifiers, func(s *sql.Selector) { + rq.modifiers = append(rq.modifiers, func(s *sql.Selector) { s.ForShare(opts...) }) - return aq + return rq } -// ApprovalGroupBy is the group-by builder for Approval entities. -type ApprovalGroupBy struct { +// ReviewGroupBy is the group-by builder for Review entities. +type ReviewGroupBy struct { config fields []string fns []AggregateFunc @@ -666,44 +666,44 @@ type ApprovalGroupBy struct { } // Aggregate adds the given aggregation functions to the group-by query. -func (agb *ApprovalGroupBy) Aggregate(fns ...AggregateFunc) *ApprovalGroupBy { - agb.fns = append(agb.fns, fns...) - return agb +func (rgb *ReviewGroupBy) Aggregate(fns ...AggregateFunc) *ReviewGroupBy { + rgb.fns = append(rgb.fns, fns...) + return rgb } // Scan applies the group-by query and scans the result into the given value. -func (agb *ApprovalGroupBy) Scan(ctx context.Context, v interface{}) error { - query, err := agb.path(ctx) +func (rgb *ReviewGroupBy) Scan(ctx context.Context, v interface{}) error { + query, err := rgb.path(ctx) if err != nil { return err } - agb.sql = query - return agb.sqlScan(ctx, v) + rgb.sql = query + return rgb.sqlScan(ctx, v) } // ScanX is like Scan, but panics if an error occurs. -func (agb *ApprovalGroupBy) ScanX(ctx context.Context, v interface{}) { - if err := agb.Scan(ctx, v); err != nil { +func (rgb *ReviewGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := rgb.Scan(ctx, v); err != nil { panic(err) } } // Strings returns list of strings from group-by. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) Strings(ctx context.Context) ([]string, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ApprovalGroupBy.Strings is not achievable when grouping more than 1 field") +func (rgb *ReviewGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(rgb.fields) > 1 { + return nil, errors.New("ent: ReviewGroupBy.Strings is not achievable when grouping more than 1 field") } var v []string - if err := agb.Scan(ctx, &v); err != nil { + if err := rgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // StringsX is like Strings, but panics if an error occurs. -func (agb *ApprovalGroupBy) StringsX(ctx context.Context) []string { - v, err := agb.Strings(ctx) +func (rgb *ReviewGroupBy) StringsX(ctx context.Context) []string { + v, err := rgb.Strings(ctx) if err != nil { panic(err) } @@ -712,25 +712,25 @@ func (agb *ApprovalGroupBy) StringsX(ctx context.Context) []string { // String returns a single string from a group-by query. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) String(ctx context.Context) (_ string, err error) { +func (rgb *ReviewGroupBy) String(ctx context.Context) (_ string, err error) { var v []string - if v, err = agb.Strings(ctx); err != nil { + if v, err = rgb.Strings(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalGroupBy.Strings returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewGroupBy.Strings returned %d results when one was expected", len(v)) } return } // StringX is like String, but panics if an error occurs. -func (agb *ApprovalGroupBy) StringX(ctx context.Context) string { - v, err := agb.String(ctx) +func (rgb *ReviewGroupBy) StringX(ctx context.Context) string { + v, err := rgb.String(ctx) if err != nil { panic(err) } @@ -739,20 +739,20 @@ func (agb *ApprovalGroupBy) StringX(ctx context.Context) string { // Ints returns list of ints from group-by. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) Ints(ctx context.Context) ([]int, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ApprovalGroupBy.Ints is not achievable when grouping more than 1 field") +func (rgb *ReviewGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(rgb.fields) > 1 { + return nil, errors.New("ent: ReviewGroupBy.Ints is not achievable when grouping more than 1 field") } var v []int - if err := agb.Scan(ctx, &v); err != nil { + if err := rgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // IntsX is like Ints, but panics if an error occurs. -func (agb *ApprovalGroupBy) IntsX(ctx context.Context) []int { - v, err := agb.Ints(ctx) +func (rgb *ReviewGroupBy) IntsX(ctx context.Context) []int { + v, err := rgb.Ints(ctx) if err != nil { panic(err) } @@ -761,25 +761,25 @@ func (agb *ApprovalGroupBy) IntsX(ctx context.Context) []int { // Int returns a single int from a group-by query. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) Int(ctx context.Context) (_ int, err error) { +func (rgb *ReviewGroupBy) Int(ctx context.Context) (_ int, err error) { var v []int - if v, err = agb.Ints(ctx); err != nil { + if v, err = rgb.Ints(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalGroupBy.Ints returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewGroupBy.Ints returned %d results when one was expected", len(v)) } return } // IntX is like Int, but panics if an error occurs. -func (agb *ApprovalGroupBy) IntX(ctx context.Context) int { - v, err := agb.Int(ctx) +func (rgb *ReviewGroupBy) IntX(ctx context.Context) int { + v, err := rgb.Int(ctx) if err != nil { panic(err) } @@ -788,20 +788,20 @@ func (agb *ApprovalGroupBy) IntX(ctx context.Context) int { // Float64s returns list of float64s from group-by. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) Float64s(ctx context.Context) ([]float64, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ApprovalGroupBy.Float64s is not achievable when grouping more than 1 field") +func (rgb *ReviewGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(rgb.fields) > 1 { + return nil, errors.New("ent: ReviewGroupBy.Float64s is not achievable when grouping more than 1 field") } var v []float64 - if err := agb.Scan(ctx, &v); err != nil { + if err := rgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // Float64sX is like Float64s, but panics if an error occurs. -func (agb *ApprovalGroupBy) Float64sX(ctx context.Context) []float64 { - v, err := agb.Float64s(ctx) +func (rgb *ReviewGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := rgb.Float64s(ctx) if err != nil { panic(err) } @@ -810,25 +810,25 @@ func (agb *ApprovalGroupBy) Float64sX(ctx context.Context) []float64 { // Float64 returns a single float64 from a group-by query. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) Float64(ctx context.Context) (_ float64, err error) { +func (rgb *ReviewGroupBy) Float64(ctx context.Context) (_ float64, err error) { var v []float64 - if v, err = agb.Float64s(ctx); err != nil { + if v, err = rgb.Float64s(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalGroupBy.Float64s returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewGroupBy.Float64s returned %d results when one was expected", len(v)) } return } // Float64X is like Float64, but panics if an error occurs. -func (agb *ApprovalGroupBy) Float64X(ctx context.Context) float64 { - v, err := agb.Float64(ctx) +func (rgb *ReviewGroupBy) Float64X(ctx context.Context) float64 { + v, err := rgb.Float64(ctx) if err != nil { panic(err) } @@ -837,20 +837,20 @@ func (agb *ApprovalGroupBy) Float64X(ctx context.Context) float64 { // Bools returns list of bools from group-by. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) Bools(ctx context.Context) ([]bool, error) { - if len(agb.fields) > 1 { - return nil, errors.New("ent: ApprovalGroupBy.Bools is not achievable when grouping more than 1 field") +func (rgb *ReviewGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(rgb.fields) > 1 { + return nil, errors.New("ent: ReviewGroupBy.Bools is not achievable when grouping more than 1 field") } var v []bool - if err := agb.Scan(ctx, &v); err != nil { + if err := rgb.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // BoolsX is like Bools, but panics if an error occurs. -func (agb *ApprovalGroupBy) BoolsX(ctx context.Context) []bool { - v, err := agb.Bools(ctx) +func (rgb *ReviewGroupBy) BoolsX(ctx context.Context) []bool { + v, err := rgb.Bools(ctx) if err != nil { panic(err) } @@ -859,61 +859,61 @@ func (agb *ApprovalGroupBy) BoolsX(ctx context.Context) []bool { // Bool returns a single bool from a group-by query. // It is only allowed when executing a group-by query with one field. -func (agb *ApprovalGroupBy) Bool(ctx context.Context) (_ bool, err error) { +func (rgb *ReviewGroupBy) Bool(ctx context.Context) (_ bool, err error) { var v []bool - if v, err = agb.Bools(ctx); err != nil { + if v, err = rgb.Bools(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalGroupBy.Bools returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewGroupBy.Bools returned %d results when one was expected", len(v)) } return } // BoolX is like Bool, but panics if an error occurs. -func (agb *ApprovalGroupBy) BoolX(ctx context.Context) bool { - v, err := agb.Bool(ctx) +func (rgb *ReviewGroupBy) BoolX(ctx context.Context) bool { + v, err := rgb.Bool(ctx) if err != nil { panic(err) } return v } -func (agb *ApprovalGroupBy) sqlScan(ctx context.Context, v interface{}) error { - for _, f := range agb.fields { - if !approval.ValidColumn(f) { +func (rgb *ReviewGroupBy) sqlScan(ctx context.Context, v interface{}) error { + for _, f := range rgb.fields { + if !review.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} } } - selector := agb.sqlQuery() + selector := rgb.sqlQuery() if err := selector.Err(); err != nil { return err } rows := &sql.Rows{} query, args := selector.Query() - if err := agb.driver.Query(ctx, query, args, rows); err != nil { + if err := rgb.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() return sql.ScanSlice(rows, v) } -func (agb *ApprovalGroupBy) sqlQuery() *sql.Selector { - selector := agb.sql.Select() - aggregation := make([]string, 0, len(agb.fns)) - for _, fn := range agb.fns { +func (rgb *ReviewGroupBy) sqlQuery() *sql.Selector { + selector := rgb.sql.Select() + aggregation := make([]string, 0, len(rgb.fns)) + for _, fn := range rgb.fns { aggregation = append(aggregation, fn(selector)) } // If no columns were selected in a custom aggregation function, the default // selection is the fields used for "group-by", and the aggregation functions. if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(agb.fields)+len(agb.fns)) - for _, f := range agb.fields { + columns := make([]string, 0, len(rgb.fields)+len(rgb.fns)) + for _, f := range rgb.fields { columns = append(columns, selector.C(f)) } for _, c := range aggregation { @@ -921,47 +921,47 @@ func (agb *ApprovalGroupBy) sqlQuery() *sql.Selector { } selector.Select(columns...) } - return selector.GroupBy(selector.Columns(agb.fields...)...) + return selector.GroupBy(selector.Columns(rgb.fields...)...) } -// ApprovalSelect is the builder for selecting fields of Approval entities. -type ApprovalSelect struct { - *ApprovalQuery +// ReviewSelect is the builder for selecting fields of Review entities. +type ReviewSelect struct { + *ReviewQuery // intermediate query (i.e. traversal path). sql *sql.Selector } // Scan applies the selector query and scans the result into the given value. -func (as *ApprovalSelect) Scan(ctx context.Context, v interface{}) error { - if err := as.prepareQuery(ctx); err != nil { +func (rs *ReviewSelect) Scan(ctx context.Context, v interface{}) error { + if err := rs.prepareQuery(ctx); err != nil { return err } - as.sql = as.ApprovalQuery.sqlQuery(ctx) - return as.sqlScan(ctx, v) + rs.sql = rs.ReviewQuery.sqlQuery(ctx) + return rs.sqlScan(ctx, v) } // ScanX is like Scan, but panics if an error occurs. -func (as *ApprovalSelect) ScanX(ctx context.Context, v interface{}) { - if err := as.Scan(ctx, v); err != nil { +func (rs *ReviewSelect) ScanX(ctx context.Context, v interface{}) { + if err := rs.Scan(ctx, v); err != nil { panic(err) } } // Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) Strings(ctx context.Context) ([]string, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ApprovalSelect.Strings is not achievable when selecting more than 1 field") +func (rs *ReviewSelect) Strings(ctx context.Context) ([]string, error) { + if len(rs.fields) > 1 { + return nil, errors.New("ent: ReviewSelect.Strings is not achievable when selecting more than 1 field") } var v []string - if err := as.Scan(ctx, &v); err != nil { + if err := rs.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // StringsX is like Strings, but panics if an error occurs. -func (as *ApprovalSelect) StringsX(ctx context.Context) []string { - v, err := as.Strings(ctx) +func (rs *ReviewSelect) StringsX(ctx context.Context) []string { + v, err := rs.Strings(ctx) if err != nil { panic(err) } @@ -969,25 +969,25 @@ func (as *ApprovalSelect) StringsX(ctx context.Context) []string { } // String returns a single string from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) String(ctx context.Context) (_ string, err error) { +func (rs *ReviewSelect) String(ctx context.Context) (_ string, err error) { var v []string - if v, err = as.Strings(ctx); err != nil { + if v, err = rs.Strings(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalSelect.Strings returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewSelect.Strings returned %d results when one was expected", len(v)) } return } // StringX is like String, but panics if an error occurs. -func (as *ApprovalSelect) StringX(ctx context.Context) string { - v, err := as.String(ctx) +func (rs *ReviewSelect) StringX(ctx context.Context) string { + v, err := rs.String(ctx) if err != nil { panic(err) } @@ -995,20 +995,20 @@ func (as *ApprovalSelect) StringX(ctx context.Context) string { } // Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) Ints(ctx context.Context) ([]int, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ApprovalSelect.Ints is not achievable when selecting more than 1 field") +func (rs *ReviewSelect) Ints(ctx context.Context) ([]int, error) { + if len(rs.fields) > 1 { + return nil, errors.New("ent: ReviewSelect.Ints is not achievable when selecting more than 1 field") } var v []int - if err := as.Scan(ctx, &v); err != nil { + if err := rs.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // IntsX is like Ints, but panics if an error occurs. -func (as *ApprovalSelect) IntsX(ctx context.Context) []int { - v, err := as.Ints(ctx) +func (rs *ReviewSelect) IntsX(ctx context.Context) []int { + v, err := rs.Ints(ctx) if err != nil { panic(err) } @@ -1016,25 +1016,25 @@ func (as *ApprovalSelect) IntsX(ctx context.Context) []int { } // Int returns a single int from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) Int(ctx context.Context) (_ int, err error) { +func (rs *ReviewSelect) Int(ctx context.Context) (_ int, err error) { var v []int - if v, err = as.Ints(ctx); err != nil { + if v, err = rs.Ints(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalSelect.Ints returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewSelect.Ints returned %d results when one was expected", len(v)) } return } // IntX is like Int, but panics if an error occurs. -func (as *ApprovalSelect) IntX(ctx context.Context) int { - v, err := as.Int(ctx) +func (rs *ReviewSelect) IntX(ctx context.Context) int { + v, err := rs.Int(ctx) if err != nil { panic(err) } @@ -1042,20 +1042,20 @@ func (as *ApprovalSelect) IntX(ctx context.Context) int { } // Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) Float64s(ctx context.Context) ([]float64, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ApprovalSelect.Float64s is not achievable when selecting more than 1 field") +func (rs *ReviewSelect) Float64s(ctx context.Context) ([]float64, error) { + if len(rs.fields) > 1 { + return nil, errors.New("ent: ReviewSelect.Float64s is not achievable when selecting more than 1 field") } var v []float64 - if err := as.Scan(ctx, &v); err != nil { + if err := rs.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // Float64sX is like Float64s, but panics if an error occurs. -func (as *ApprovalSelect) Float64sX(ctx context.Context) []float64 { - v, err := as.Float64s(ctx) +func (rs *ReviewSelect) Float64sX(ctx context.Context) []float64 { + v, err := rs.Float64s(ctx) if err != nil { panic(err) } @@ -1063,25 +1063,25 @@ func (as *ApprovalSelect) Float64sX(ctx context.Context) []float64 { } // Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) Float64(ctx context.Context) (_ float64, err error) { +func (rs *ReviewSelect) Float64(ctx context.Context) (_ float64, err error) { var v []float64 - if v, err = as.Float64s(ctx); err != nil { + if v, err = rs.Float64s(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalSelect.Float64s returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewSelect.Float64s returned %d results when one was expected", len(v)) } return } // Float64X is like Float64, but panics if an error occurs. -func (as *ApprovalSelect) Float64X(ctx context.Context) float64 { - v, err := as.Float64(ctx) +func (rs *ReviewSelect) Float64X(ctx context.Context) float64 { + v, err := rs.Float64(ctx) if err != nil { panic(err) } @@ -1089,20 +1089,20 @@ func (as *ApprovalSelect) Float64X(ctx context.Context) float64 { } // Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) Bools(ctx context.Context) ([]bool, error) { - if len(as.fields) > 1 { - return nil, errors.New("ent: ApprovalSelect.Bools is not achievable when selecting more than 1 field") +func (rs *ReviewSelect) Bools(ctx context.Context) ([]bool, error) { + if len(rs.fields) > 1 { + return nil, errors.New("ent: ReviewSelect.Bools is not achievable when selecting more than 1 field") } var v []bool - if err := as.Scan(ctx, &v); err != nil { + if err := rs.Scan(ctx, &v); err != nil { return nil, err } return v, nil } // BoolsX is like Bools, but panics if an error occurs. -func (as *ApprovalSelect) BoolsX(ctx context.Context) []bool { - v, err := as.Bools(ctx) +func (rs *ReviewSelect) BoolsX(ctx context.Context) []bool { + v, err := rs.Bools(ctx) if err != nil { panic(err) } @@ -1110,35 +1110,35 @@ func (as *ApprovalSelect) BoolsX(ctx context.Context) []bool { } // Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (as *ApprovalSelect) Bool(ctx context.Context) (_ bool, err error) { +func (rs *ReviewSelect) Bool(ctx context.Context) (_ bool, err error) { var v []bool - if v, err = as.Bools(ctx); err != nil { + if v, err = rs.Bools(ctx); err != nil { return } switch len(v) { case 1: return v[0], nil case 0: - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} default: - err = fmt.Errorf("ent: ApprovalSelect.Bools returned %d results when one was expected", len(v)) + err = fmt.Errorf("ent: ReviewSelect.Bools returned %d results when one was expected", len(v)) } return } // BoolX is like Bool, but panics if an error occurs. -func (as *ApprovalSelect) BoolX(ctx context.Context) bool { - v, err := as.Bool(ctx) +func (rs *ReviewSelect) BoolX(ctx context.Context) bool { + v, err := rs.Bool(ctx) if err != nil { panic(err) } return v } -func (as *ApprovalSelect) sqlScan(ctx context.Context, v interface{}) error { +func (rs *ReviewSelect) sqlScan(ctx context.Context, v interface{}) error { rows := &sql.Rows{} - query, args := as.sql.Query() - if err := as.driver.Query(ctx, query, args, rows); err != nil { + query, args := rs.sql.Query() + if err := rs.driver.Query(ctx, query, args, rows); err != nil { return err } defer rows.Close() diff --git a/ent/approval_update.go b/ent/review_update.go similarity index 54% rename from ent/approval_update.go rename to ent/review_update.go index 9071ab0a..aa728633 100644 --- a/ent/approval_update.go +++ b/ent/review_update.go @@ -11,168 +11,168 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" "github.com/gitploy-io/gitploy/ent/predicate" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) -// ApprovalUpdate is the builder for updating Approval entities. -type ApprovalUpdate struct { +// ReviewUpdate is the builder for updating Review entities. +type ReviewUpdate struct { config hooks []Hook - mutation *ApprovalMutation + mutation *ReviewMutation } -// Where appends a list predicates to the ApprovalUpdate builder. -func (au *ApprovalUpdate) Where(ps ...predicate.Approval) *ApprovalUpdate { - au.mutation.Where(ps...) - return au +// Where appends a list predicates to the ReviewUpdate builder. +func (ru *ReviewUpdate) Where(ps ...predicate.Review) *ReviewUpdate { + ru.mutation.Where(ps...) + return ru } // SetStatus sets the "status" field. -func (au *ApprovalUpdate) SetStatus(a approval.Status) *ApprovalUpdate { - au.mutation.SetStatus(a) - return au +func (ru *ReviewUpdate) SetStatus(r review.Status) *ReviewUpdate { + ru.mutation.SetStatus(r) + return ru } // SetNillableStatus sets the "status" field if the given value is not nil. -func (au *ApprovalUpdate) SetNillableStatus(a *approval.Status) *ApprovalUpdate { - if a != nil { - au.SetStatus(*a) +func (ru *ReviewUpdate) SetNillableStatus(r *review.Status) *ReviewUpdate { + if r != nil { + ru.SetStatus(*r) } - return au + return ru } // SetCreatedAt sets the "created_at" field. -func (au *ApprovalUpdate) SetCreatedAt(t time.Time) *ApprovalUpdate { - au.mutation.SetCreatedAt(t) - return au +func (ru *ReviewUpdate) SetCreatedAt(t time.Time) *ReviewUpdate { + ru.mutation.SetCreatedAt(t) + return ru } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (au *ApprovalUpdate) SetNillableCreatedAt(t *time.Time) *ApprovalUpdate { +func (ru *ReviewUpdate) SetNillableCreatedAt(t *time.Time) *ReviewUpdate { if t != nil { - au.SetCreatedAt(*t) + ru.SetCreatedAt(*t) } - return au + return ru } // SetUpdatedAt sets the "updated_at" field. -func (au *ApprovalUpdate) SetUpdatedAt(t time.Time) *ApprovalUpdate { - au.mutation.SetUpdatedAt(t) - return au +func (ru *ReviewUpdate) SetUpdatedAt(t time.Time) *ReviewUpdate { + ru.mutation.SetUpdatedAt(t) + return ru } // SetUserID sets the "user_id" field. -func (au *ApprovalUpdate) SetUserID(i int64) *ApprovalUpdate { - au.mutation.SetUserID(i) - return au +func (ru *ReviewUpdate) SetUserID(i int64) *ReviewUpdate { + ru.mutation.SetUserID(i) + return ru } // SetDeploymentID sets the "deployment_id" field. -func (au *ApprovalUpdate) SetDeploymentID(i int) *ApprovalUpdate { - au.mutation.SetDeploymentID(i) - return au +func (ru *ReviewUpdate) SetDeploymentID(i int) *ReviewUpdate { + ru.mutation.SetDeploymentID(i) + return ru } // SetUser sets the "user" edge to the User entity. -func (au *ApprovalUpdate) SetUser(u *User) *ApprovalUpdate { - return au.SetUserID(u.ID) +func (ru *ReviewUpdate) SetUser(u *User) *ReviewUpdate { + return ru.SetUserID(u.ID) } // SetDeployment sets the "deployment" edge to the Deployment entity. -func (au *ApprovalUpdate) SetDeployment(d *Deployment) *ApprovalUpdate { - return au.SetDeploymentID(d.ID) +func (ru *ReviewUpdate) SetDeployment(d *Deployment) *ReviewUpdate { + return ru.SetDeploymentID(d.ID) } // AddEventIDs adds the "event" edge to the Event entity by IDs. -func (au *ApprovalUpdate) AddEventIDs(ids ...int) *ApprovalUpdate { - au.mutation.AddEventIDs(ids...) - return au +func (ru *ReviewUpdate) AddEventIDs(ids ...int) *ReviewUpdate { + ru.mutation.AddEventIDs(ids...) + return ru } // AddEvent adds the "event" edges to the Event entity. -func (au *ApprovalUpdate) AddEvent(e ...*Event) *ApprovalUpdate { +func (ru *ReviewUpdate) AddEvent(e ...*Event) *ReviewUpdate { ids := make([]int, len(e)) for i := range e { ids[i] = e[i].ID } - return au.AddEventIDs(ids...) + return ru.AddEventIDs(ids...) } -// Mutation returns the ApprovalMutation object of the builder. -func (au *ApprovalUpdate) Mutation() *ApprovalMutation { - return au.mutation +// Mutation returns the ReviewMutation object of the builder. +func (ru *ReviewUpdate) Mutation() *ReviewMutation { + return ru.mutation } // ClearUser clears the "user" edge to the User entity. -func (au *ApprovalUpdate) ClearUser() *ApprovalUpdate { - au.mutation.ClearUser() - return au +func (ru *ReviewUpdate) ClearUser() *ReviewUpdate { + ru.mutation.ClearUser() + return ru } // ClearDeployment clears the "deployment" edge to the Deployment entity. -func (au *ApprovalUpdate) ClearDeployment() *ApprovalUpdate { - au.mutation.ClearDeployment() - return au +func (ru *ReviewUpdate) ClearDeployment() *ReviewUpdate { + ru.mutation.ClearDeployment() + return ru } // ClearEvent clears all "event" edges to the Event entity. -func (au *ApprovalUpdate) ClearEvent() *ApprovalUpdate { - au.mutation.ClearEvent() - return au +func (ru *ReviewUpdate) ClearEvent() *ReviewUpdate { + ru.mutation.ClearEvent() + return ru } // RemoveEventIDs removes the "event" edge to Event entities by IDs. -func (au *ApprovalUpdate) RemoveEventIDs(ids ...int) *ApprovalUpdate { - au.mutation.RemoveEventIDs(ids...) - return au +func (ru *ReviewUpdate) RemoveEventIDs(ids ...int) *ReviewUpdate { + ru.mutation.RemoveEventIDs(ids...) + return ru } // RemoveEvent removes "event" edges to Event entities. -func (au *ApprovalUpdate) RemoveEvent(e ...*Event) *ApprovalUpdate { +func (ru *ReviewUpdate) RemoveEvent(e ...*Event) *ReviewUpdate { ids := make([]int, len(e)) for i := range e { ids[i] = e[i].ID } - return au.RemoveEventIDs(ids...) + return ru.RemoveEventIDs(ids...) } // Save executes the query and returns the number of nodes affected by the update operation. -func (au *ApprovalUpdate) Save(ctx context.Context) (int, error) { +func (ru *ReviewUpdate) Save(ctx context.Context) (int, error) { var ( err error affected int ) - au.defaults() - if len(au.hooks) == 0 { - if err = au.check(); err != nil { + ru.defaults() + if len(ru.hooks) == 0 { + if err = ru.check(); err != nil { return 0, err } - affected, err = au.sqlSave(ctx) + affected, err = ru.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ApprovalMutation) + mutation, ok := m.(*ReviewMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } - if err = au.check(); err != nil { + if err = ru.check(); err != nil { return 0, err } - au.mutation = mutation - affected, err = au.sqlSave(ctx) + ru.mutation = mutation + affected, err = ru.sqlSave(ctx) mutation.done = true return affected, err }) - for i := len(au.hooks) - 1; i >= 0; i-- { - if au.hooks[i] == nil { + for i := len(ru.hooks) - 1; i >= 0; i-- { + if ru.hooks[i] == nil { return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } - mut = au.hooks[i](mut) + mut = ru.hooks[i](mut) } - if _, err := mut.Mutate(ctx, au.mutation); err != nil { + if _, err := mut.Mutate(ctx, ru.mutation); err != nil { return 0, err } } @@ -180,8 +180,8 @@ func (au *ApprovalUpdate) Save(ctx context.Context) (int, error) { } // SaveX is like Save, but panics if an error occurs. -func (au *ApprovalUpdate) SaveX(ctx context.Context) int { - affected, err := au.Save(ctx) +func (ru *ReviewUpdate) SaveX(ctx context.Context) int { + affected, err := ru.Save(ctx) if err != nil { panic(err) } @@ -189,87 +189,87 @@ func (au *ApprovalUpdate) SaveX(ctx context.Context) int { } // Exec executes the query. -func (au *ApprovalUpdate) Exec(ctx context.Context) error { - _, err := au.Save(ctx) +func (ru *ReviewUpdate) Exec(ctx context.Context) error { + _, err := ru.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (au *ApprovalUpdate) ExecX(ctx context.Context) { - if err := au.Exec(ctx); err != nil { +func (ru *ReviewUpdate) ExecX(ctx context.Context) { + if err := ru.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. -func (au *ApprovalUpdate) defaults() { - if _, ok := au.mutation.UpdatedAt(); !ok { - v := approval.UpdateDefaultUpdatedAt() - au.mutation.SetUpdatedAt(v) +func (ru *ReviewUpdate) defaults() { + if _, ok := ru.mutation.UpdatedAt(); !ok { + v := review.UpdateDefaultUpdatedAt() + ru.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. -func (au *ApprovalUpdate) check() error { - if v, ok := au.mutation.Status(); ok { - if err := approval.StatusValidator(v); err != nil { +func (ru *ReviewUpdate) check() error { + if v, ok := ru.mutation.Status(); ok { + if err := review.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf("ent: validator failed for field \"status\": %w", err)} } } - if _, ok := au.mutation.UserID(); au.mutation.UserCleared() && !ok { + if _, ok := ru.mutation.UserID(); ru.mutation.UserCleared() && !ok { return errors.New("ent: clearing a required unique edge \"user\"") } - if _, ok := au.mutation.DeploymentID(); au.mutation.DeploymentCleared() && !ok { + if _, ok := ru.mutation.DeploymentID(); ru.mutation.DeploymentCleared() && !ok { return errors.New("ent: clearing a required unique edge \"deployment\"") } return nil } -func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { +func (ru *ReviewUpdate) sqlSave(ctx context.Context) (n int, err error) { _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ - Table: approval.Table, - Columns: approval.Columns, + Table: review.Table, + Columns: review.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } - if ps := au.mutation.predicates; len(ps) > 0 { + if ps := ru.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } - if value, ok := au.mutation.Status(); ok { + if value, ok := ru.mutation.Status(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeEnum, Value: value, - Column: approval.FieldStatus, + Column: review.FieldStatus, }) } - if value, ok := au.mutation.CreatedAt(); ok { + if value, ok := ru.mutation.CreatedAt(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, - Column: approval.FieldCreatedAt, + Column: review.FieldCreatedAt, }) } - if value, ok := au.mutation.UpdatedAt(); ok { + if value, ok := ru.mutation.UpdatedAt(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, - Column: approval.FieldUpdatedAt, + Column: review.FieldUpdatedAt, }) } - if au.mutation.UserCleared() { + if ru.mutation.UserCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.UserTable, - Columns: []string{approval.UserColumn}, + Table: review.UserTable, + Columns: []string{review.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -280,12 +280,12 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := au.mutation.UserIDs(); len(nodes) > 0 { + if nodes := ru.mutation.UserIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.UserTable, - Columns: []string{approval.UserColumn}, + Table: review.UserTable, + Columns: []string{review.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -299,12 +299,12 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if au.mutation.DeploymentCleared() { + if ru.mutation.DeploymentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.DeploymentTable, - Columns: []string{approval.DeploymentColumn}, + Table: review.DeploymentTable, + Columns: []string{review.DeploymentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -315,12 +315,12 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := au.mutation.DeploymentIDs(); len(nodes) > 0 { + if nodes := ru.mutation.DeploymentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.DeploymentTable, - Columns: []string{approval.DeploymentColumn}, + Table: review.DeploymentTable, + Columns: []string{review.DeploymentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -334,12 +334,12 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if au.mutation.EventCleared() { + if ru.mutation.EventCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: approval.EventTable, - Columns: []string{approval.EventColumn}, + Table: review.EventTable, + Columns: []string{review.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -350,12 +350,12 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := au.mutation.RemovedEventIDs(); len(nodes) > 0 && !au.mutation.EventCleared() { + if nodes := ru.mutation.RemovedEventIDs(); len(nodes) > 0 && !ru.mutation.EventCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: approval.EventTable, - Columns: []string{approval.EventColumn}, + Table: review.EventTable, + Columns: []string{review.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -369,12 +369,12 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := au.mutation.EventIDs(); len(nodes) > 0 { + if nodes := ru.mutation.EventIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: approval.EventTable, - Columns: []string{approval.EventColumn}, + Table: review.EventTable, + Columns: []string{review.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -388,9 +388,9 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { + if n, err = sqlgraph.UpdateNodes(ctx, ru.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{err.Error(), err} } @@ -399,163 +399,163 @@ func (au *ApprovalUpdate) sqlSave(ctx context.Context) (n int, err error) { return n, nil } -// ApprovalUpdateOne is the builder for updating a single Approval entity. -type ApprovalUpdateOne struct { +// ReviewUpdateOne is the builder for updating a single Review entity. +type ReviewUpdateOne struct { config fields []string hooks []Hook - mutation *ApprovalMutation + mutation *ReviewMutation } // SetStatus sets the "status" field. -func (auo *ApprovalUpdateOne) SetStatus(a approval.Status) *ApprovalUpdateOne { - auo.mutation.SetStatus(a) - return auo +func (ruo *ReviewUpdateOne) SetStatus(r review.Status) *ReviewUpdateOne { + ruo.mutation.SetStatus(r) + return ruo } // SetNillableStatus sets the "status" field if the given value is not nil. -func (auo *ApprovalUpdateOne) SetNillableStatus(a *approval.Status) *ApprovalUpdateOne { - if a != nil { - auo.SetStatus(*a) +func (ruo *ReviewUpdateOne) SetNillableStatus(r *review.Status) *ReviewUpdateOne { + if r != nil { + ruo.SetStatus(*r) } - return auo + return ruo } // SetCreatedAt sets the "created_at" field. -func (auo *ApprovalUpdateOne) SetCreatedAt(t time.Time) *ApprovalUpdateOne { - auo.mutation.SetCreatedAt(t) - return auo +func (ruo *ReviewUpdateOne) SetCreatedAt(t time.Time) *ReviewUpdateOne { + ruo.mutation.SetCreatedAt(t) + return ruo } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (auo *ApprovalUpdateOne) SetNillableCreatedAt(t *time.Time) *ApprovalUpdateOne { +func (ruo *ReviewUpdateOne) SetNillableCreatedAt(t *time.Time) *ReviewUpdateOne { if t != nil { - auo.SetCreatedAt(*t) + ruo.SetCreatedAt(*t) } - return auo + return ruo } // SetUpdatedAt sets the "updated_at" field. -func (auo *ApprovalUpdateOne) SetUpdatedAt(t time.Time) *ApprovalUpdateOne { - auo.mutation.SetUpdatedAt(t) - return auo +func (ruo *ReviewUpdateOne) SetUpdatedAt(t time.Time) *ReviewUpdateOne { + ruo.mutation.SetUpdatedAt(t) + return ruo } // SetUserID sets the "user_id" field. -func (auo *ApprovalUpdateOne) SetUserID(i int64) *ApprovalUpdateOne { - auo.mutation.SetUserID(i) - return auo +func (ruo *ReviewUpdateOne) SetUserID(i int64) *ReviewUpdateOne { + ruo.mutation.SetUserID(i) + return ruo } // SetDeploymentID sets the "deployment_id" field. -func (auo *ApprovalUpdateOne) SetDeploymentID(i int) *ApprovalUpdateOne { - auo.mutation.SetDeploymentID(i) - return auo +func (ruo *ReviewUpdateOne) SetDeploymentID(i int) *ReviewUpdateOne { + ruo.mutation.SetDeploymentID(i) + return ruo } // SetUser sets the "user" edge to the User entity. -func (auo *ApprovalUpdateOne) SetUser(u *User) *ApprovalUpdateOne { - return auo.SetUserID(u.ID) +func (ruo *ReviewUpdateOne) SetUser(u *User) *ReviewUpdateOne { + return ruo.SetUserID(u.ID) } // SetDeployment sets the "deployment" edge to the Deployment entity. -func (auo *ApprovalUpdateOne) SetDeployment(d *Deployment) *ApprovalUpdateOne { - return auo.SetDeploymentID(d.ID) +func (ruo *ReviewUpdateOne) SetDeployment(d *Deployment) *ReviewUpdateOne { + return ruo.SetDeploymentID(d.ID) } // AddEventIDs adds the "event" edge to the Event entity by IDs. -func (auo *ApprovalUpdateOne) AddEventIDs(ids ...int) *ApprovalUpdateOne { - auo.mutation.AddEventIDs(ids...) - return auo +func (ruo *ReviewUpdateOne) AddEventIDs(ids ...int) *ReviewUpdateOne { + ruo.mutation.AddEventIDs(ids...) + return ruo } // AddEvent adds the "event" edges to the Event entity. -func (auo *ApprovalUpdateOne) AddEvent(e ...*Event) *ApprovalUpdateOne { +func (ruo *ReviewUpdateOne) AddEvent(e ...*Event) *ReviewUpdateOne { ids := make([]int, len(e)) for i := range e { ids[i] = e[i].ID } - return auo.AddEventIDs(ids...) + return ruo.AddEventIDs(ids...) } -// Mutation returns the ApprovalMutation object of the builder. -func (auo *ApprovalUpdateOne) Mutation() *ApprovalMutation { - return auo.mutation +// Mutation returns the ReviewMutation object of the builder. +func (ruo *ReviewUpdateOne) Mutation() *ReviewMutation { + return ruo.mutation } // ClearUser clears the "user" edge to the User entity. -func (auo *ApprovalUpdateOne) ClearUser() *ApprovalUpdateOne { - auo.mutation.ClearUser() - return auo +func (ruo *ReviewUpdateOne) ClearUser() *ReviewUpdateOne { + ruo.mutation.ClearUser() + return ruo } // ClearDeployment clears the "deployment" edge to the Deployment entity. -func (auo *ApprovalUpdateOne) ClearDeployment() *ApprovalUpdateOne { - auo.mutation.ClearDeployment() - return auo +func (ruo *ReviewUpdateOne) ClearDeployment() *ReviewUpdateOne { + ruo.mutation.ClearDeployment() + return ruo } // ClearEvent clears all "event" edges to the Event entity. -func (auo *ApprovalUpdateOne) ClearEvent() *ApprovalUpdateOne { - auo.mutation.ClearEvent() - return auo +func (ruo *ReviewUpdateOne) ClearEvent() *ReviewUpdateOne { + ruo.mutation.ClearEvent() + return ruo } // RemoveEventIDs removes the "event" edge to Event entities by IDs. -func (auo *ApprovalUpdateOne) RemoveEventIDs(ids ...int) *ApprovalUpdateOne { - auo.mutation.RemoveEventIDs(ids...) - return auo +func (ruo *ReviewUpdateOne) RemoveEventIDs(ids ...int) *ReviewUpdateOne { + ruo.mutation.RemoveEventIDs(ids...) + return ruo } // RemoveEvent removes "event" edges to Event entities. -func (auo *ApprovalUpdateOne) RemoveEvent(e ...*Event) *ApprovalUpdateOne { +func (ruo *ReviewUpdateOne) RemoveEvent(e ...*Event) *ReviewUpdateOne { ids := make([]int, len(e)) for i := range e { ids[i] = e[i].ID } - return auo.RemoveEventIDs(ids...) + return ruo.RemoveEventIDs(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 (auo *ApprovalUpdateOne) Select(field string, fields ...string) *ApprovalUpdateOne { - auo.fields = append([]string{field}, fields...) - return auo +func (ruo *ReviewUpdateOne) Select(field string, fields ...string) *ReviewUpdateOne { + ruo.fields = append([]string{field}, fields...) + return ruo } -// Save executes the query and returns the updated Approval entity. -func (auo *ApprovalUpdateOne) Save(ctx context.Context) (*Approval, error) { +// Save executes the query and returns the updated Review entity. +func (ruo *ReviewUpdateOne) Save(ctx context.Context) (*Review, error) { var ( err error - node *Approval + node *Review ) - auo.defaults() - if len(auo.hooks) == 0 { - if err = auo.check(); err != nil { + ruo.defaults() + if len(ruo.hooks) == 0 { + if err = ruo.check(); err != nil { return nil, err } - node, err = auo.sqlSave(ctx) + node, err = ruo.sqlSave(ctx) } else { var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*ApprovalMutation) + mutation, ok := m.(*ReviewMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } - if err = auo.check(); err != nil { + if err = ruo.check(); err != nil { return nil, err } - auo.mutation = mutation - node, err = auo.sqlSave(ctx) + ruo.mutation = mutation + node, err = ruo.sqlSave(ctx) mutation.done = true return node, err }) - for i := len(auo.hooks) - 1; i >= 0; i-- { - if auo.hooks[i] == nil { + for i := len(ruo.hooks) - 1; i >= 0; i-- { + if ruo.hooks[i] == nil { return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") } - mut = auo.hooks[i](mut) + mut = ruo.hooks[i](mut) } - if _, err := mut.Mutate(ctx, auo.mutation); err != nil { + if _, err := mut.Mutate(ctx, ruo.mutation); err != nil { return nil, err } } @@ -563,8 +563,8 @@ func (auo *ApprovalUpdateOne) Save(ctx context.Context) (*Approval, error) { } // SaveX is like Save, but panics if an error occurs. -func (auo *ApprovalUpdateOne) SaveX(ctx context.Context) *Approval { - node, err := auo.Save(ctx) +func (ruo *ReviewUpdateOne) SaveX(ctx context.Context) *Review { + node, err := ruo.Save(ctx) if err != nil { panic(err) } @@ -572,104 +572,104 @@ func (auo *ApprovalUpdateOne) SaveX(ctx context.Context) *Approval { } // Exec executes the query on the entity. -func (auo *ApprovalUpdateOne) Exec(ctx context.Context) error { - _, err := auo.Save(ctx) +func (ruo *ReviewUpdateOne) Exec(ctx context.Context) error { + _, err := ruo.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (auo *ApprovalUpdateOne) ExecX(ctx context.Context) { - if err := auo.Exec(ctx); err != nil { +func (ruo *ReviewUpdateOne) ExecX(ctx context.Context) { + if err := ruo.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. -func (auo *ApprovalUpdateOne) defaults() { - if _, ok := auo.mutation.UpdatedAt(); !ok { - v := approval.UpdateDefaultUpdatedAt() - auo.mutation.SetUpdatedAt(v) +func (ruo *ReviewUpdateOne) defaults() { + if _, ok := ruo.mutation.UpdatedAt(); !ok { + v := review.UpdateDefaultUpdatedAt() + ruo.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. -func (auo *ApprovalUpdateOne) check() error { - if v, ok := auo.mutation.Status(); ok { - if err := approval.StatusValidator(v); err != nil { +func (ruo *ReviewUpdateOne) check() error { + if v, ok := ruo.mutation.Status(); ok { + if err := review.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf("ent: validator failed for field \"status\": %w", err)} } } - if _, ok := auo.mutation.UserID(); auo.mutation.UserCleared() && !ok { + if _, ok := ruo.mutation.UserID(); ruo.mutation.UserCleared() && !ok { return errors.New("ent: clearing a required unique edge \"user\"") } - if _, ok := auo.mutation.DeploymentID(); auo.mutation.DeploymentCleared() && !ok { + if _, ok := ruo.mutation.DeploymentID(); ruo.mutation.DeploymentCleared() && !ok { return errors.New("ent: clearing a required unique edge \"deployment\"") } return nil } -func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err error) { +func (ruo *ReviewUpdateOne) sqlSave(ctx context.Context) (_node *Review, err error) { _spec := &sqlgraph.UpdateSpec{ Node: &sqlgraph.NodeSpec{ - Table: approval.Table, - Columns: approval.Columns, + Table: review.Table, + Columns: review.Columns, ID: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } - id, ok := auo.mutation.ID() + id, ok := ruo.mutation.ID() if !ok { - return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Approval.ID for update")} + return nil, &ValidationError{Name: "ID", err: fmt.Errorf("missing Review.ID for update")} } _spec.Node.ID.Value = id - if fields := auo.fields; len(fields) > 0 { + if fields := ruo.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, approval.FieldID) + _spec.Node.Columns = append(_spec.Node.Columns, review.FieldID) for _, f := range fields { - if !approval.ValidColumn(f) { + if !review.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } - if f != approval.FieldID { + if f != review.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } } - if ps := auo.mutation.predicates; len(ps) > 0 { + if ps := ruo.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { ps[i](selector) } } } - if value, ok := auo.mutation.Status(); ok { + if value, ok := ruo.mutation.Status(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeEnum, Value: value, - Column: approval.FieldStatus, + Column: review.FieldStatus, }) } - if value, ok := auo.mutation.CreatedAt(); ok { + if value, ok := ruo.mutation.CreatedAt(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, - Column: approval.FieldCreatedAt, + Column: review.FieldCreatedAt, }) } - if value, ok := auo.mutation.UpdatedAt(); ok { + if value, ok := ruo.mutation.UpdatedAt(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, Value: value, - Column: approval.FieldUpdatedAt, + Column: review.FieldUpdatedAt, }) } - if auo.mutation.UserCleared() { + if ruo.mutation.UserCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.UserTable, - Columns: []string{approval.UserColumn}, + Table: review.UserTable, + Columns: []string{review.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -680,12 +680,12 @@ func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := auo.mutation.UserIDs(); len(nodes) > 0 { + if nodes := ruo.mutation.UserIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.UserTable, - Columns: []string{approval.UserColumn}, + Table: review.UserTable, + Columns: []string{review.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -699,12 +699,12 @@ func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if auo.mutation.DeploymentCleared() { + if ruo.mutation.DeploymentCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.DeploymentTable, - Columns: []string{approval.DeploymentColumn}, + Table: review.DeploymentTable, + Columns: []string{review.DeploymentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -715,12 +715,12 @@ func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := auo.mutation.DeploymentIDs(); len(nodes) > 0 { + if nodes := ruo.mutation.DeploymentIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: approval.DeploymentTable, - Columns: []string{approval.DeploymentColumn}, + Table: review.DeploymentTable, + Columns: []string{review.DeploymentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -734,12 +734,12 @@ func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if auo.mutation.EventCleared() { + if ruo.mutation.EventCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: approval.EventTable, - Columns: []string{approval.EventColumn}, + Table: review.EventTable, + Columns: []string{review.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -750,12 +750,12 @@ func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := auo.mutation.RemovedEventIDs(); len(nodes) > 0 && !auo.mutation.EventCleared() { + if nodes := ruo.mutation.RemovedEventIDs(); len(nodes) > 0 && !ruo.mutation.EventCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: approval.EventTable, - Columns: []string{approval.EventColumn}, + Table: review.EventTable, + Columns: []string{review.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -769,12 +769,12 @@ func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := auo.mutation.EventIDs(); len(nodes) > 0 { + if nodes := ruo.mutation.EventIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: approval.EventTable, - Columns: []string{approval.EventColumn}, + Table: review.EventTable, + Columns: []string{review.EventColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ @@ -788,12 +788,12 @@ func (auo *ApprovalUpdateOne) sqlSave(ctx context.Context) (_node *Approval, err } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - _node = &Approval{config: auo.config} + _node = &Review{config: ruo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { + if err = sqlgraph.UpdateNode(ctx, ruo.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{approval.Label} + err = &NotFoundError{review.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{err.Error(), err} } diff --git a/ent/runtime.go b/ent/runtime.go index da22dd25..e7b9a14c 100644 --- a/ent/runtime.go +++ b/ent/runtime.go @@ -5,7 +5,6 @@ package ent import ( "time" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/callback" "github.com/gitploy-io/gitploy/ent/chatuser" "github.com/gitploy-io/gitploy/ent/deployment" @@ -15,6 +14,7 @@ import ( "github.com/gitploy-io/gitploy/ent/lock" "github.com/gitploy-io/gitploy/ent/perm" "github.com/gitploy-io/gitploy/ent/repo" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/schema" "github.com/gitploy-io/gitploy/ent/user" ) @@ -23,18 +23,6 @@ import ( // (default values, validators, hooks and policies) and stitches it // to their package variables. func init() { - approvalFields := schema.Approval{}.Fields() - _ = approvalFields - // approvalDescCreatedAt is the schema descriptor for created_at field. - approvalDescCreatedAt := approvalFields[1].Descriptor() - // approval.DefaultCreatedAt holds the default value on creation for the created_at field. - approval.DefaultCreatedAt = approvalDescCreatedAt.Default.(func() time.Time) - // approvalDescUpdatedAt is the schema descriptor for updated_at field. - approvalDescUpdatedAt := approvalFields[2].Descriptor() - // approval.DefaultUpdatedAt holds the default value on creation for the updated_at field. - approval.DefaultUpdatedAt = approvalDescUpdatedAt.Default.(func() time.Time) - // approval.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. - approval.UpdateDefaultUpdatedAt = approvalDescUpdatedAt.UpdateDefault.(func() time.Time) callbackFields := schema.Callback{}.Fields() _ = callbackFields // callbackDescHash is the schema descriptor for hash field. @@ -77,20 +65,12 @@ func init() { 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[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[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[12].Descriptor() + deploymentDescCreatedAt := deploymentFields[10].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[13].Descriptor() + deploymentDescUpdatedAt := deploymentFields[11].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. @@ -191,6 +171,18 @@ func init() { repo.DefaultUpdatedAt = repoDescUpdatedAt.Default.(func() time.Time) // repo.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. repo.UpdateDefaultUpdatedAt = repoDescUpdatedAt.UpdateDefault.(func() time.Time) + reviewFields := schema.Review{}.Fields() + _ = reviewFields + // reviewDescCreatedAt is the schema descriptor for created_at field. + reviewDescCreatedAt := reviewFields[1].Descriptor() + // review.DefaultCreatedAt holds the default value on creation for the created_at field. + review.DefaultCreatedAt = reviewDescCreatedAt.Default.(func() time.Time) + // reviewDescUpdatedAt is the schema descriptor for updated_at field. + reviewDescUpdatedAt := reviewFields[2].Descriptor() + // review.DefaultUpdatedAt holds the default value on creation for the updated_at field. + review.DefaultUpdatedAt = reviewDescUpdatedAt.Default.(func() time.Time) + // review.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + review.UpdateDefaultUpdatedAt = reviewDescUpdatedAt.UpdateDefault.(func() time.Time) userFields := schema.User{}.Fields() _ = userFields // userDescAdmin is the schema descriptor for admin field. diff --git a/ent/schema/deployment.go b/ent/schema/deployment.go index 54f4c020..e8c08b65 100644 --- a/ent/schema/deployment.go +++ b/ent/schema/deployment.go @@ -49,10 +49,6 @@ func (Deployment) Fields() []ent.Field { Default(false), field.Bool("is_rollback"). Default(false), - field.Bool("is_approval_enabled"). - Default(false), - field.Int("required_approval_count"). - Default(0), field.Time("created_at"). Default(nowUTC), field.Time("updated_at"). @@ -61,6 +57,14 @@ func (Deployment) Fields() []ent.Field { // Edges field.Int64("user_id"), field.Int64("repo_id"), + + // Deprecated fields. + field.Bool("is_approval_enabled"). + Optional(). + Nillable(), + field.Int("required_approval_count"). + Optional(). + Nillable(), } } @@ -77,7 +81,7 @@ func (Deployment) Edges() []ent.Edge { Field("repo_id"). Unique(). Required(), - edge.To("approvals", Approval.Type). + edge.To("reviews", Review.Type). Annotations(entsql.Annotation{ OnDelete: entsql.Cascade, }), diff --git a/ent/schema/event.go b/ent/schema/event.go index 2f9f7fec..624bfeb8 100644 --- a/ent/schema/event.go +++ b/ent/schema/event.go @@ -19,6 +19,7 @@ func (Event) Fields() []ent.Field { Values( "deployment", "approval", + "review", ), field.Enum("type"). Values( @@ -32,6 +33,8 @@ func (Event) Fields() []ent.Field { Optional(), field.Int("approval_id"). Optional(), + field.Int("review_id"). + Optional(), // This field is filled when the type is 'deleted'. field.Int("deleted_id"). Optional(), @@ -45,9 +48,9 @@ func (Event) Edges() []ent.Edge { Ref("event"). Field("deployment_id"). Unique(), - edge.From("approval", Approval.Type). + edge.From("review", Review.Type). Ref("event"). - Field("approval_id"). + Field("review_id"). Unique(), edge.To("notification_record", NotificationRecord.Type). Unique(), diff --git a/ent/schema/approval.go b/ent/schema/review.go similarity index 64% rename from ent/schema/approval.go rename to ent/schema/review.go index c1a2cb3a..ae16cd84 100644 --- a/ent/schema/approval.go +++ b/ent/schema/review.go @@ -5,21 +5,20 @@ import ( "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" - "entgo.io/ent/schema/index" ) -// Approval holds the schema definition for the Approval entity. -type Approval struct { +// Review holds the schema definition for the Review entity. +type Review struct { ent.Schema } -// Fields of the Approval. -func (Approval) Fields() []ent.Field { +// Fields of the Review. +func (Review) Fields() []ent.Field { return []ent.Field{ field.Enum("status"). Values( "pending", - "declined", + "rejected", "approved", ). Default("pending"), @@ -34,16 +33,16 @@ func (Approval) Fields() []ent.Field { } } -// Edges of the Approval. -func (Approval) Edges() []ent.Edge { +// Edges of the Review. +func (Review) Edges() []ent.Edge { return []ent.Edge{ edge.From("user", User.Type). - Ref("approvals"). + Ref("reviews"). Field("user_id"). Unique(). Required(), edge.From("deployment", Deployment.Type). - Ref("approvals"). + Ref("reviews"). Field("deployment_id"). Unique(). Required(), @@ -53,10 +52,3 @@ func (Approval) Edges() []ent.Edge { }), } } - -func (Approval) Index() []ent.Index { - return []ent.Index{ - index.Fields("deployment_id", "user_id"). - Unique(), - } -} diff --git a/ent/schema/user.go b/ent/schema/user.go index 0b15689d..002b1bb1 100644 --- a/ent/schema/user.go +++ b/ent/schema/user.go @@ -52,7 +52,7 @@ func (User) Edges() []ent.Edge { OnDelete: entsql.Cascade, }), edge.To("deployments", Deployment.Type), - edge.To("approvals", Approval.Type), + edge.To("reviews", Review.Type), edge.To("locks", Lock.Type), } } diff --git a/ent/tx.go b/ent/tx.go index ee298594..dce19ed1 100644 --- a/ent/tx.go +++ b/ent/tx.go @@ -12,8 +12,6 @@ import ( // Tx is a transactional client that is created by calling Client.Tx(). type Tx struct { config - // Approval is the client for interacting with the Approval builders. - Approval *ApprovalClient // Callback is the client for interacting with the Callback builders. Callback *CallbackClient // ChatUser is the client for interacting with the ChatUser builders. @@ -34,6 +32,8 @@ type Tx struct { Perm *PermClient // Repo is the client for interacting with the Repo builders. Repo *RepoClient + // Review is the client for interacting with the Review builders. + Review *ReviewClient // User is the client for interacting with the User builders. User *UserClient @@ -171,7 +171,6 @@ func (tx *Tx) Client() *Client { } func (tx *Tx) init() { - tx.Approval = NewApprovalClient(tx.config) tx.Callback = NewCallbackClient(tx.config) tx.ChatUser = NewChatUserClient(tx.config) tx.Deployment = NewDeploymentClient(tx.config) @@ -182,6 +181,7 @@ func (tx *Tx) init() { tx.NotificationRecord = NewNotificationRecordClient(tx.config) tx.Perm = NewPermClient(tx.config) tx.Repo = NewRepoClient(tx.config) + tx.Review = NewReviewClient(tx.config) tx.User = NewUserClient(tx.config) } @@ -192,7 +192,7 @@ func (tx *Tx) init() { // of them in order to commit or rollback the transaction. // // If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: Approval.QueryXXX(), the query will be executed +// applies a query, for example: Callback.QueryXXX(), the query will be executed // through the driver which created this transaction. // // Note that txDriver is not goroutine safe. diff --git a/ent/user.go b/ent/user.go index 64e13632..af049bcf 100644 --- a/ent/user.go +++ b/ent/user.go @@ -48,8 +48,8 @@ type UserEdges struct { Perms []*Perm `json:"perms,omitempty"` // Deployments holds the value of the deployments edge. Deployments []*Deployment `json:"deployments,omitempty"` - // Approvals holds the value of the approvals edge. - Approvals []*Approval `json:"approvals,omitempty"` + // Reviews holds the value of the reviews edge. + Reviews []*Review `json:"reviews,omitempty"` // Locks holds the value of the locks edge. Locks []*Lock `json:"locks,omitempty"` // loadedTypes holds the information for reporting if a @@ -89,13 +89,13 @@ func (e UserEdges) DeploymentsOrErr() ([]*Deployment, error) { return nil, &NotLoadedError{edge: "deployments"} } -// ApprovalsOrErr returns the Approvals value or an error if the edge +// ReviewsOrErr returns the Reviews value or an error if the edge // was not loaded in eager-loading. -func (e UserEdges) ApprovalsOrErr() ([]*Approval, error) { +func (e UserEdges) ReviewsOrErr() ([]*Review, error) { if e.loadedTypes[3] { - return e.Approvals, nil + return e.Reviews, nil } - return nil, &NotLoadedError{edge: "approvals"} + return nil, &NotLoadedError{edge: "reviews"} } // LocksOrErr returns the Locks value or an error if the edge @@ -215,9 +215,9 @@ func (u *User) QueryDeployments() *DeploymentQuery { return (&UserClient{config: u.config}).QueryDeployments(u) } -// QueryApprovals queries the "approvals" edge of the User entity. -func (u *User) QueryApprovals() *ApprovalQuery { - return (&UserClient{config: u.config}).QueryApprovals(u) +// QueryReviews queries the "reviews" edge of the User entity. +func (u *User) QueryReviews() *ReviewQuery { + return (&UserClient{config: u.config}).QueryReviews(u) } // QueryLocks queries the "locks" edge of the User entity. diff --git a/ent/user/user.go b/ent/user/user.go index 4848ee67..9532cbe1 100644 --- a/ent/user/user.go +++ b/ent/user/user.go @@ -35,8 +35,8 @@ const ( EdgePerms = "perms" // EdgeDeployments holds the string denoting the deployments edge name in mutations. EdgeDeployments = "deployments" - // EdgeApprovals holds the string denoting the approvals edge name in mutations. - EdgeApprovals = "approvals" + // EdgeReviews holds the string denoting the reviews edge name in mutations. + EdgeReviews = "reviews" // EdgeLocks holds the string denoting the locks edge name in mutations. EdgeLocks = "locks" // Table holds the table name of the user in the database. @@ -62,13 +62,13 @@ const ( DeploymentsInverseTable = "deployments" // DeploymentsColumn is the table column denoting the deployments relation/edge. DeploymentsColumn = "user_id" - // ApprovalsTable is the table that holds the approvals relation/edge. - ApprovalsTable = "approvals" - // ApprovalsInverseTable is the table name for the Approval entity. - // It exists in this package in order to avoid circular dependency with the "approval" package. - ApprovalsInverseTable = "approvals" - // ApprovalsColumn is the table column denoting the approvals relation/edge. - ApprovalsColumn = "user_id" + // ReviewsTable is the table that holds the reviews relation/edge. + ReviewsTable = "reviews" + // ReviewsInverseTable is the table name for the Review entity. + // It exists in this package in order to avoid circular dependency with the "review" package. + ReviewsInverseTable = "reviews" + // ReviewsColumn is the table column denoting the reviews relation/edge. + ReviewsColumn = "user_id" // LocksTable is the table that holds the locks relation/edge. LocksTable = "locks" // LocksInverseTable is the table name for the Lock entity. diff --git a/ent/user/where.go b/ent/user/where.go index 633314ee..a3780593 100644 --- a/ent/user/where.go +++ b/ent/user/where.go @@ -1037,25 +1037,25 @@ func HasDeploymentsWith(preds ...predicate.Deployment) predicate.User { }) } -// HasApprovals applies the HasEdge predicate on the "approvals" edge. -func HasApprovals() predicate.User { +// HasReviews applies the HasEdge predicate on the "reviews" edge. +func HasReviews() predicate.User { return predicate.User(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ApprovalsTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, ApprovalsTable, ApprovalsColumn), + sqlgraph.To(ReviewsTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ReviewsTable, ReviewsColumn), ) sqlgraph.HasNeighbors(s, step) }) } -// HasApprovalsWith applies the HasEdge predicate on the "approvals" edge with a given conditions (other predicates). -func HasApprovalsWith(preds ...predicate.Approval) predicate.User { +// HasReviewsWith applies the HasEdge predicate on the "reviews" edge with a given conditions (other predicates). +func HasReviewsWith(preds ...predicate.Review) predicate.User { return predicate.User(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(ApprovalsInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, ApprovalsTable, ApprovalsColumn), + sqlgraph.To(ReviewsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, ReviewsTable, ReviewsColumn), ) sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { diff --git a/ent/user_create.go b/ent/user_create.go index d0177f13..7cbc3f3e 100644 --- a/ent/user_create.go +++ b/ent/user_create.go @@ -10,11 +10,11 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/chatuser" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/lock" "github.com/gitploy-io/gitploy/ent/perm" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) @@ -166,19 +166,19 @@ func (uc *UserCreate) AddDeployments(d ...*Deployment) *UserCreate { return uc.AddDeploymentIDs(ids...) } -// AddApprovalIDs adds the "approvals" edge to the Approval entity by IDs. -func (uc *UserCreate) AddApprovalIDs(ids ...int) *UserCreate { - uc.mutation.AddApprovalIDs(ids...) +// AddReviewIDs adds the "reviews" edge to the Review entity by IDs. +func (uc *UserCreate) AddReviewIDs(ids ...int) *UserCreate { + uc.mutation.AddReviewIDs(ids...) return uc } -// AddApprovals adds the "approvals" edges to the Approval entity. -func (uc *UserCreate) AddApprovals(a ...*Approval) *UserCreate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// AddReviews adds the "reviews" edges to the Review entity. +func (uc *UserCreate) AddReviews(r ...*Review) *UserCreate { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return uc.AddApprovalIDs(ids...) + return uc.AddReviewIDs(ids...) } // AddLockIDs adds the "locks" edge to the Lock entity by IDs. @@ -476,17 +476,17 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } - if nodes := uc.mutation.ApprovalsIDs(); len(nodes) > 0 { + if nodes := uc.mutation.ReviewsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: user.ApprovalsTable, - Columns: []string{user.ApprovalsColumn}, + Table: user.ReviewsTable, + Columns: []string{user.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } diff --git a/ent/user_query.go b/ent/user_query.go index 55231f89..5750d407 100644 --- a/ent/user_query.go +++ b/ent/user_query.go @@ -13,12 +13,12 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/chatuser" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/lock" "github.com/gitploy-io/gitploy/ent/perm" "github.com/gitploy-io/gitploy/ent/predicate" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) @@ -35,7 +35,7 @@ type UserQuery struct { withChatUser *ChatUserQuery withPerms *PermQuery withDeployments *DeploymentQuery - withApprovals *ApprovalQuery + withReviews *ReviewQuery withLocks *LockQuery modifiers []func(s *sql.Selector) // intermediate query (i.e. traversal path). @@ -140,9 +140,9 @@ func (uq *UserQuery) QueryDeployments() *DeploymentQuery { return query } -// QueryApprovals chains the current query on the "approvals" edge. -func (uq *UserQuery) QueryApprovals() *ApprovalQuery { - query := &ApprovalQuery{config: uq.config} +// QueryReviews chains the current query on the "reviews" edge. +func (uq *UserQuery) QueryReviews() *ReviewQuery { + query := &ReviewQuery{config: uq.config} query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := uq.prepareQuery(ctx); err != nil { return nil, err @@ -153,8 +153,8 @@ func (uq *UserQuery) QueryApprovals() *ApprovalQuery { } step := sqlgraph.NewStep( sqlgraph.From(user.Table, user.FieldID, selector), - sqlgraph.To(approval.Table, approval.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, user.ApprovalsTable, user.ApprovalsColumn), + sqlgraph.To(review.Table, review.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, user.ReviewsTable, user.ReviewsColumn), ) fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step) return fromU, nil @@ -368,7 +368,7 @@ func (uq *UserQuery) Clone() *UserQuery { withChatUser: uq.withChatUser.Clone(), withPerms: uq.withPerms.Clone(), withDeployments: uq.withDeployments.Clone(), - withApprovals: uq.withApprovals.Clone(), + withReviews: uq.withReviews.Clone(), withLocks: uq.withLocks.Clone(), // clone intermediate query. sql: uq.sql.Clone(), @@ -409,14 +409,14 @@ func (uq *UserQuery) WithDeployments(opts ...func(*DeploymentQuery)) *UserQuery return uq } -// WithApprovals tells the query-builder to eager-load the nodes that are connected to -// the "approvals" edge. The optional arguments are used to configure the query builder of the edge. -func (uq *UserQuery) WithApprovals(opts ...func(*ApprovalQuery)) *UserQuery { - query := &ApprovalQuery{config: uq.config} +// WithReviews tells the query-builder to eager-load the nodes that are connected to +// the "reviews" edge. The optional arguments are used to configure the query builder of the edge. +func (uq *UserQuery) WithReviews(opts ...func(*ReviewQuery)) *UserQuery { + query := &ReviewQuery{config: uq.config} for _, opt := range opts { opt(query) } - uq.withApprovals = query + uq.withReviews = query return uq } @@ -500,7 +500,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { uq.withChatUser != nil, uq.withPerms != nil, uq.withDeployments != nil, - uq.withApprovals != nil, + uq.withReviews != nil, uq.withLocks != nil, } ) @@ -601,16 +601,16 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { } } - if query := uq.withApprovals; query != nil { + if query := uq.withReviews; query != nil { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[int64]*User) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] - nodes[i].Edges.Approvals = []*Approval{} + nodes[i].Edges.Reviews = []*Review{} } - query.Where(predicate.Approval(func(s *sql.Selector) { - s.Where(sql.InValues(user.ApprovalsColumn, fks...)) + query.Where(predicate.Review(func(s *sql.Selector) { + s.Where(sql.InValues(user.ReviewsColumn, fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -622,7 +622,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) { if !ok { return nil, fmt.Errorf(`unexpected foreign-key "user_id" returned %v for node %v`, fk, n.ID) } - node.Edges.Approvals = append(node.Edges.Approvals, n) + node.Edges.Reviews = append(node.Edges.Reviews, n) } } diff --git a/ent/user_update.go b/ent/user_update.go index 351b885c..d8b699cc 100644 --- a/ent/user_update.go +++ b/ent/user_update.go @@ -10,12 +10,12 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/chatuser" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/lock" "github.com/gitploy-io/gitploy/ent/perm" "github.com/gitploy-io/gitploy/ent/predicate" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/ent/user" ) @@ -145,19 +145,19 @@ func (uu *UserUpdate) AddDeployments(d ...*Deployment) *UserUpdate { return uu.AddDeploymentIDs(ids...) } -// AddApprovalIDs adds the "approvals" edge to the Approval entity by IDs. -func (uu *UserUpdate) AddApprovalIDs(ids ...int) *UserUpdate { - uu.mutation.AddApprovalIDs(ids...) +// AddReviewIDs adds the "reviews" edge to the Review entity by IDs. +func (uu *UserUpdate) AddReviewIDs(ids ...int) *UserUpdate { + uu.mutation.AddReviewIDs(ids...) return uu } -// AddApprovals adds the "approvals" edges to the Approval entity. -func (uu *UserUpdate) AddApprovals(a ...*Approval) *UserUpdate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// AddReviews adds the "reviews" edges to the Review entity. +func (uu *UserUpdate) AddReviews(r ...*Review) *UserUpdate { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return uu.AddApprovalIDs(ids...) + return uu.AddReviewIDs(ids...) } // AddLockIDs adds the "locks" edge to the Lock entity by IDs. @@ -228,25 +228,25 @@ func (uu *UserUpdate) RemoveDeployments(d ...*Deployment) *UserUpdate { return uu.RemoveDeploymentIDs(ids...) } -// ClearApprovals clears all "approvals" edges to the Approval entity. -func (uu *UserUpdate) ClearApprovals() *UserUpdate { - uu.mutation.ClearApprovals() +// ClearReviews clears all "reviews" edges to the Review entity. +func (uu *UserUpdate) ClearReviews() *UserUpdate { + uu.mutation.ClearReviews() return uu } -// RemoveApprovalIDs removes the "approvals" edge to Approval entities by IDs. -func (uu *UserUpdate) RemoveApprovalIDs(ids ...int) *UserUpdate { - uu.mutation.RemoveApprovalIDs(ids...) +// RemoveReviewIDs removes the "reviews" edge to Review entities by IDs. +func (uu *UserUpdate) RemoveReviewIDs(ids ...int) *UserUpdate { + uu.mutation.RemoveReviewIDs(ids...) return uu } -// RemoveApprovals removes "approvals" edges to Approval entities. -func (uu *UserUpdate) RemoveApprovals(a ...*Approval) *UserUpdate { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// RemoveReviews removes "reviews" edges to Review entities. +func (uu *UserUpdate) RemoveReviews(r ...*Review) *UserUpdate { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return uu.RemoveApprovalIDs(ids...) + return uu.RemoveReviewIDs(ids...) } // ClearLocks clears all "locks" edges to the Lock entity. @@ -550,33 +550,33 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if uu.mutation.ApprovalsCleared() { + if uu.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: user.ApprovalsTable, - Columns: []string{user.ApprovalsColumn}, + Table: user.ReviewsTable, + Columns: []string{user.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := uu.mutation.RemovedApprovalsIDs(); len(nodes) > 0 && !uu.mutation.ApprovalsCleared() { + if nodes := uu.mutation.RemovedReviewsIDs(); len(nodes) > 0 && !uu.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: user.ApprovalsTable, - Columns: []string{user.ApprovalsColumn}, + Table: user.ReviewsTable, + Columns: []string{user.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } @@ -585,17 +585,17 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := uu.mutation.ApprovalsIDs(); len(nodes) > 0 { + if nodes := uu.mutation.ReviewsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: user.ApprovalsTable, - Columns: []string{user.ApprovalsColumn}, + Table: user.ReviewsTable, + Columns: []string{user.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } @@ -790,19 +790,19 @@ func (uuo *UserUpdateOne) AddDeployments(d ...*Deployment) *UserUpdateOne { return uuo.AddDeploymentIDs(ids...) } -// AddApprovalIDs adds the "approvals" edge to the Approval entity by IDs. -func (uuo *UserUpdateOne) AddApprovalIDs(ids ...int) *UserUpdateOne { - uuo.mutation.AddApprovalIDs(ids...) +// AddReviewIDs adds the "reviews" edge to the Review entity by IDs. +func (uuo *UserUpdateOne) AddReviewIDs(ids ...int) *UserUpdateOne { + uuo.mutation.AddReviewIDs(ids...) return uuo } -// AddApprovals adds the "approvals" edges to the Approval entity. -func (uuo *UserUpdateOne) AddApprovals(a ...*Approval) *UserUpdateOne { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// AddReviews adds the "reviews" edges to the Review entity. +func (uuo *UserUpdateOne) AddReviews(r ...*Review) *UserUpdateOne { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return uuo.AddApprovalIDs(ids...) + return uuo.AddReviewIDs(ids...) } // AddLockIDs adds the "locks" edge to the Lock entity by IDs. @@ -873,25 +873,25 @@ func (uuo *UserUpdateOne) RemoveDeployments(d ...*Deployment) *UserUpdateOne { return uuo.RemoveDeploymentIDs(ids...) } -// ClearApprovals clears all "approvals" edges to the Approval entity. -func (uuo *UserUpdateOne) ClearApprovals() *UserUpdateOne { - uuo.mutation.ClearApprovals() +// ClearReviews clears all "reviews" edges to the Review entity. +func (uuo *UserUpdateOne) ClearReviews() *UserUpdateOne { + uuo.mutation.ClearReviews() return uuo } -// RemoveApprovalIDs removes the "approvals" edge to Approval entities by IDs. -func (uuo *UserUpdateOne) RemoveApprovalIDs(ids ...int) *UserUpdateOne { - uuo.mutation.RemoveApprovalIDs(ids...) +// RemoveReviewIDs removes the "reviews" edge to Review entities by IDs. +func (uuo *UserUpdateOne) RemoveReviewIDs(ids ...int) *UserUpdateOne { + uuo.mutation.RemoveReviewIDs(ids...) return uuo } -// RemoveApprovals removes "approvals" edges to Approval entities. -func (uuo *UserUpdateOne) RemoveApprovals(a ...*Approval) *UserUpdateOne { - ids := make([]int, len(a)) - for i := range a { - ids[i] = a[i].ID +// RemoveReviews removes "reviews" edges to Review entities. +func (uuo *UserUpdateOne) RemoveReviews(r ...*Review) *UserUpdateOne { + ids := make([]int, len(r)) + for i := range r { + ids[i] = r[i].ID } - return uuo.RemoveApprovalIDs(ids...) + return uuo.RemoveReviewIDs(ids...) } // ClearLocks clears all "locks" edges to the Lock entity. @@ -1219,33 +1219,33 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if uuo.mutation.ApprovalsCleared() { + if uuo.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: user.ApprovalsTable, - Columns: []string{user.ApprovalsColumn}, + Table: user.ReviewsTable, + Columns: []string{user.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := uuo.mutation.RemovedApprovalsIDs(); len(nodes) > 0 && !uuo.mutation.ApprovalsCleared() { + if nodes := uuo.mutation.RemovedReviewsIDs(); len(nodes) > 0 && !uuo.mutation.ReviewsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: user.ApprovalsTable, - Columns: []string{user.ApprovalsColumn}, + Table: user.ReviewsTable, + Columns: []string{user.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } @@ -1254,17 +1254,17 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := uuo.mutation.ApprovalsIDs(); len(nodes) > 0 { + if nodes := uuo.mutation.ReviewsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: user.ApprovalsTable, - Columns: []string{user.ApprovalsColumn}, + Table: user.ReviewsTable, + Columns: []string{user.ReviewsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: &sqlgraph.FieldSpec{ Type: field.TypeInt, - Column: approval.FieldID, + Column: review.FieldID, }, }, } diff --git a/internal/interactor/deployment.go b/internal/interactor/deployment.go index 56a6207b..a123ec16 100644 --- a/internal/interactor/deployment.go +++ b/internal/interactor/deployment.go @@ -7,15 +7,13 @@ import ( "github.com/AlekSi/pointer" "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/pkg/e" "github.com/gitploy-io/gitploy/vo" "go.uber.org/zap" ) -// Deploy creates a new remote deployment basically. -// But if the approval flag is enabled, it saves the deployment only. func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, env *vo.Env) (*ent.Deployment, error) { if locked, err := i.Store.HasLockOfRepoForEnv(ctx, r, d.Env); locked { return nil, e.NewError( @@ -34,7 +32,7 @@ func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *en ) } - if env.IsApprovalEabled() { + if env.HasReview() { d := &ent.Deployment{ Number: number, Type: d.Type, @@ -43,14 +41,24 @@ func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *en Status: deployment.StatusWaiting, ProductionEnvironment: env.IsProductionEnvironment(), IsRollback: d.IsRollback, - IsApprovalEnabled: true, - RequiredApprovalCount: env.Approval.RequiredCount, UserID: u.ID, RepoID: r.ID, } - i.log.Debug("Save a new deployment to wait approvals.", zap.Any("deployment", d)) - return i.Store.CreateDeployment(ctx, d) + i.log.Debug("Save the deployment to wait reviews.") + d, err = i.Store.CreateDeployment(ctx, d) + if err != nil { + return nil, err + } + + for _, rvr := range env.Review.Reviewers { + i.log.Debug(fmt.Sprintf("Request a review to %s.", rvr)) + if _, err := i.requestReviewByLogin(ctx, d, rvr); err != nil { + i.log.Error("Failed to request the review.", zap.Error(err)) + } + } + + return d, nil } i.log.Debug("Create a new remote deployment.") @@ -70,8 +78,6 @@ func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *en HTMLURL: rd.HTLMURL, ProductionEnvironment: env.IsProductionEnvironment(), IsRollback: d.IsRollback, - IsApprovalEnabled: false, - RequiredApprovalCount: 0, UserID: u.ID, RepoID: r.ID, } @@ -92,16 +98,21 @@ func (i *Interactor) Deploy(ctx context.Context, u *ent.User, r *ent.Repo, d *en } func (i *Interactor) IsApproved(ctx context.Context, d *ent.Deployment) bool { - as, _ := i.ListApprovals(ctx, d) + rvs, _ := i.ListReviews(ctx, d) + + for _, r := range rvs { + if r.Status == review.StatusRejected { + return false + } + } - approved := 0 - for _, a := range as { - if a.Status == approval.StatusApproved { - approved = approved + 1 + for _, r := range rvs { + if r.Status == review.StatusApproved { + return true } } - return approved >= d.RequiredApprovalCount + return false } // DeployToRemote create a new remote deployment after the deployment was approved. @@ -115,9 +126,9 @@ func (i *Interactor) DeployToRemote(ctx context.Context, u *ent.User, r *ent.Rep return nil, err } - if d.IsApprovalEnabled && !i.IsApproved(ctx, d) { + if !i.IsApproved(ctx, d) { return nil, e.NewError( - e.ErrorCodeDeploymentUnapproved, + e.ErrorCodeDeploymentNotApproved, nil, ) } diff --git a/internal/interactor/deployment_test.go b/internal/interactor/deployment_test.go index e3e139d1..0d79f209 100644 --- a/internal/interactor/deployment_test.go +++ b/internal/interactor/deployment_test.go @@ -7,6 +7,7 @@ import ( "github.com/gitploy-io/gitploy/ent" "github.com/gitploy-io/gitploy/ent/deployment" + "github.com/gitploy-io/gitploy/ent/review" "github.com/gitploy-io/gitploy/internal/interactor/mock" "github.com/gitploy-io/gitploy/vo" "github.com/golang/mock/gomock" @@ -24,23 +25,15 @@ func newMockInteractor(store Store, scm SCM) *Interactor { func TestInteractor_Deploy(t *testing.T) { ctx := gomock.Any() - t.Run("create a new deployment.", func(t *testing.T) { + t.Run("Return a new deployment.", func(t *testing.T) { input := struct { - u *ent.User - r *ent.Repo d *ent.Deployment e *vo.Env }{ - u: &ent.User{ - ID: 1, - }, - r: &ent.Repo{ - ID: 1, - }, d: &ent.Deployment{ - Type: deployment.TypeCommit, - Ref: "3ee3221", - Env: "local", + Type: deployment.TypeBranch, + Ref: "main", + Env: "production", }, e: &vo.Env{}, } @@ -50,45 +43,39 @@ func TestInteractor_Deploy(t *testing.T) { scm := mock.NewMockSCM(ctrl) const ( - ID = 1 UID = 1000 ) - t.Log("MOCK - Check the environment is locked.") store. EXPECT(). - HasLockOfRepoForEnv(ctx, gomock.Eq(input.r), gomock.Eq(input.d.Env)). + HasLockOfRepoForEnv(ctx, gomock.AssignableToTypeOf(&ent.Repo{}), gomock.AssignableToTypeOf("")). Return(false, nil) - t.Log("MOCK - Get the next deployment number.") store. EXPECT(). - GetNextDeploymentNumberOfRepo(ctx, gomock.Eq(input.r)). + GetNextDeploymentNumberOfRepo(ctx, gomock.AssignableToTypeOf(&ent.Repo{})). Return(1, nil) - t.Logf("Returns a new remote deployment with UID = %d", UID) scm. EXPECT(). - CreateRemoteDeployment(ctx, gomock.Eq(input.u), gomock.Eq(input.r), gomock.Eq(input.d), gomock.Eq(input.e)). + CreateRemoteDeployment(ctx, gomock.Eq(&ent.User{}), gomock.Eq(&ent.Repo{}), gomock.AssignableToTypeOf(&ent.Deployment{}), gomock.Eq(&vo.Env{})). Return(&vo.RemoteDeployment{ UID: UID, }, nil) - t.Logf("Check the deployment input has UID") + t.Logf("MOCK - compare the deployment parameter.") store. EXPECT(). CreateDeployment(ctx, gomock.Eq(&ent.Deployment{ - Number: 1, + Number: 1, // The next deployment number. Type: input.d.Type, Ref: input.d.Ref, Env: input.d.Env, UID: UID, Status: deployment.StatusCreated, - UserID: input.u.ID, - RepoID: input.r.ID, })). DoAndReturn(func(ctx context.Context, d *ent.Deployment) (interface{}, interface{}) { - d.ID = ID + d.ID = 1 return d, nil }) @@ -98,51 +85,41 @@ func TestInteractor_Deploy(t *testing.T) { i := newMockInteractor(store, scm) - d, err := i.Deploy(context.Background(), input.u, input.r, input.d, input.e) + d, err := i.Deploy(context.Background(), &ent.User{}, &ent.Repo{}, input.d, input.e) if err != nil { t.Errorf("Deploy returns a error: %s", err) t.FailNow() } expected := &ent.Deployment{ - ID: ID, + ID: 1, Number: 1, Type: input.d.Type, Ref: input.d.Ref, Env: input.d.Env, UID: UID, Status: deployment.StatusCreated, - UserID: input.u.ID, - RepoID: input.r.ID, } if !reflect.DeepEqual(d, expected) { t.Errorf("Deploy = %v, wanted %v", d, expected) } }) - t.Run("create a new deployment with the approval configuration.", func(t *testing.T) { + t.Run("Return the waiting deployment and reviews.", func(t *testing.T) { input := struct { - u *ent.User - r *ent.Repo d *ent.Deployment e *vo.Env }{ - u: &ent.User{ - ID: 1, - }, - r: &ent.Repo{ - ID: 1, - }, d: &ent.Deployment{ Number: 3, - Type: deployment.TypeCommit, - Ref: "3ee3221", - Env: "local", + Type: deployment.TypeBranch, + Ref: "main", + Env: "production", }, e: &vo.Env{ - Approval: &vo.Approval{ - Enabled: true, - RequiredCount: 1, + Review: &vo.Review{ + Enabled: true, + Reviewers: []string{"octocat"}, }, }, } @@ -151,60 +128,61 @@ func TestInteractor_Deploy(t *testing.T) { store := mock.NewMockStore(ctrl) scm := mock.NewMockSCM(ctrl) - const ( - ID = 1 - ) - - t.Log("MOCK - Check the environment is locked.") store. EXPECT(). - HasLockOfRepoForEnv(ctx, gomock.Eq(input.r), gomock.Eq(input.d.Env)). + HasLockOfRepoForEnv(ctx, gomock.AssignableToTypeOf(&ent.Repo{}), gomock.AssignableToTypeOf("")). Return(false, nil) - t.Log("MOCK - Get the next deployment number.") store. EXPECT(). - GetNextDeploymentNumberOfRepo(ctx, gomock.Eq(input.r)). + GetNextDeploymentNumberOfRepo(ctx, gomock.AssignableToTypeOf(&ent.Repo{})). Return(1, nil) - t.Logf("Check the deployment has configurations of approval.") + t.Logf("MOCK - compare the deployment parameter.") store. EXPECT(). CreateDeployment(ctx, gomock.Eq(&ent.Deployment{ - Number: 1, - Type: input.d.Type, - Ref: input.d.Ref, - Env: input.d.Env, - IsApprovalEnabled: true, - RequiredApprovalCount: input.e.Approval.RequiredCount, - Status: deployment.StatusWaiting, - UserID: input.u.ID, - RepoID: input.r.ID, + Number: 1, + Type: input.d.Type, + Ref: input.d.Ref, + Env: input.d.Env, + Status: deployment.StatusWaiting, })). DoAndReturn(func(ctx context.Context, d *ent.Deployment) (interface{}, interface{}) { - d.ID = ID + d.ID = 1 return d, nil }) + store. + EXPECT(). + FindUserByLogin(ctx, gomock.AssignableToTypeOf("")). + Return(&ent.User{}, nil) + + store. + EXPECT(). + CreateReview(ctx, gomock.AssignableToTypeOf(&ent.Review{})). + Return(&ent.Review{}, nil) + + store. + EXPECT(). + CreateEvent(ctx, gomock.AssignableToTypeOf(&ent.Event{})). + Return(&ent.Event{}, nil) + i := newMockInteractor(store, scm) - d, err := i.Deploy(context.Background(), input.u, input.r, input.d, input.e) + d, err := i.Deploy(context.Background(), &ent.User{}, &ent.Repo{}, input.d, input.e) if err != nil { t.Errorf("Deploy returns a error: %s", err) t.FailNow() } expected := &ent.Deployment{ - ID: ID, - Number: 1, - Type: input.d.Type, - Ref: input.d.Ref, - Env: input.d.Env, - IsApprovalEnabled: true, - RequiredApprovalCount: input.e.Approval.RequiredCount, - Status: deployment.StatusWaiting, - UserID: input.u.ID, - RepoID: input.r.ID, + ID: 1, + Number: 1, + Type: input.d.Type, + Ref: input.d.Ref, + Env: input.d.Env, + Status: deployment.StatusWaiting, } if !reflect.DeepEqual(d, expected) { t.Errorf("Deploy = %v, wanted %v", d, expected) @@ -217,16 +195,10 @@ func TestInteractor_DeployToRemote(t *testing.T) { t.Run("create a new remote deployment and update the deployment.", func(t *testing.T) { input := struct { - u *ent.User - r *ent.Repo d *ent.Deployment e *vo.Env }{ - u: &ent.User{}, - r: &ent.Repo{}, - d: &ent.Deployment{ - ID: 1, - }, + d: &ent.Deployment{}, e: &vo.Env{}, } @@ -238,26 +210,32 @@ func TestInteractor_DeployToRemote(t *testing.T) { UID = 1000 ) - t.Log("MOCK - Check the environment is locked.") store. EXPECT(). HasLockOfRepoForEnv(ctx, gomock.AssignableToTypeOf(&ent.Repo{}), gomock.AssignableToTypeOf("")). Return(false, nil) - t.Logf("MOCK - Returns a new remote deployment with UID = %d", UID) + // Return a approved review. + store. + EXPECT(). + ListReviews(ctx, gomock.AssignableToTypeOf(&ent.Deployment{})). + Return([]*ent.Review{ + { + Status: review.StatusApproved, + }, + }, nil) + scm. EXPECT(). - CreateRemoteDeployment(ctx, gomock.Eq(input.u), gomock.Eq(input.r), gomock.Eq(input.d), gomock.Eq(input.e)). + CreateRemoteDeployment(ctx, gomock.AssignableToTypeOf(&ent.User{}), gomock.AssignableToTypeOf(&ent.Repo{}), gomock.AssignableToTypeOf(&ent.Deployment{}), gomock.AssignableToTypeOf(&vo.Env{})). Return(&vo.RemoteDeployment{ UID: UID, }, nil) - t.Logf("MOCK - Check the deployment input has UID") + t.Log("MOCK - Compare the deployment parameter.") store. EXPECT(). UpdateDeployment(ctx, gomock.Eq(&ent.Deployment{ - ID: input.d.ID, - Env: input.d.Env, UID: UID, Status: deployment.StatusCreated, })). @@ -271,7 +249,7 @@ func TestInteractor_DeployToRemote(t *testing.T) { i := newMockInteractor(store, scm) - d, err := i.DeployToRemote(context.Background(), input.u, input.r, input.d, input.e) + d, err := i.DeployToRemote(context.Background(), &ent.User{}, &ent.Repo{}, input.d, input.e) if err != nil { t.Errorf("CreateRemoteDeployment returns a error: %s", err) t.FailNow() diff --git a/internal/interactor/interface.go b/internal/interactor/interface.go index 44cb915a..67565be3 100644 --- a/internal/interactor/interface.go +++ b/internal/interactor/interface.go @@ -7,7 +7,6 @@ import ( "time" "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/vo" ) @@ -70,13 +69,12 @@ type ( CreateCallback(ctx context.Context, cb *ent.Callback) (*ent.Callback, error) FindCallbackByHash(ctx context.Context, hash string) (*ent.Callback, error) - SearchApprovals(ctx context.Context, u *ent.User, s []approval.Status, from time.Time, to time.Time, page, perPage int) ([]*ent.Approval, error) - ListApprovals(ctx context.Context, d *ent.Deployment) ([]*ent.Approval, error) - FindApprovalByID(ctx context.Context, id int) (*ent.Approval, error) - FindApprovalOfUser(ctx context.Context, d *ent.Deployment, u *ent.User) (*ent.Approval, error) - CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) - UpdateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) - DeleteApproval(ctx context.Context, a *ent.Approval) error + SearchReviews(ctx context.Context, u *ent.User) ([]*ent.Review, error) + ListReviews(ctx context.Context, d *ent.Deployment) ([]*ent.Review, error) + FindReviewOfUser(ctx context.Context, u *ent.User, d *ent.Deployment) (*ent.Review, error) + FindReviewByID(ctx context.Context, id int) (*ent.Review, error) + CreateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) + UpdateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) ListExpiredLocksLessThanTime(ctx context.Context, t time.Time) ([]*ent.Lock, error) ListLocksOfRepo(ctx context.Context, r *ent.Repo) ([]*ent.Lock, error) diff --git a/internal/interactor/mock/pkg.go b/internal/interactor/mock/pkg.go index 940bb143..ca337e3b 100644 --- a/internal/interactor/mock/pkg.go +++ b/internal/interactor/mock/pkg.go @@ -10,7 +10,6 @@ import ( time "time" ent "github.com/gitploy-io/gitploy/ent" - approval "github.com/gitploy-io/gitploy/ent/approval" deployment "github.com/gitploy-io/gitploy/ent/deployment" vo "github.com/gitploy-io/gitploy/vo" gomock "github.com/golang/mock/gomock" @@ -128,21 +127,6 @@ func (mr *MockStoreMockRecorder) CountUsers(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CountUsers", reflect.TypeOf((*MockStore)(nil).CountUsers), arg0) } -// CreateApproval mocks base method. -func (m *MockStore) CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateApproval", ctx, a) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CreateApproval indicates an expected call of CreateApproval. -func (mr *MockStoreMockRecorder) CreateApproval(ctx, a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateApproval", reflect.TypeOf((*MockStore)(nil).CreateApproval), ctx, a) -} - // CreateCallback mocks base method. func (m *MockStore) CreateCallback(ctx context.Context, cb *ent.Callback) (*ent.Callback, error) { m.ctrl.T.Helper() @@ -263,6 +247,21 @@ func (mr *MockStoreMockRecorder) CreatePerm(ctx, p interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreatePerm", reflect.TypeOf((*MockStore)(nil).CreatePerm), ctx, p) } +// CreateReview mocks base method. +func (m *MockStore) CreateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateReview", ctx, rv) + ret0, _ := ret[0].(*ent.Review) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// CreateReview indicates an expected call of CreateReview. +func (mr *MockStoreMockRecorder) CreateReview(ctx, rv interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateReview", reflect.TypeOf((*MockStore)(nil).CreateReview), ctx, rv) +} + // CreateUser mocks base method. func (m *MockStore) CreateUser(ctx context.Context, u *ent.User) (*ent.User, error) { m.ctrl.T.Helper() @@ -293,20 +292,6 @@ func (mr *MockStoreMockRecorder) Deactivate(ctx, r interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Deactivate", reflect.TypeOf((*MockStore)(nil).Deactivate), ctx, r) } -// DeleteApproval mocks base method. -func (m *MockStore) DeleteApproval(ctx context.Context, a *ent.Approval) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteApproval", ctx, a) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteApproval indicates an expected call of DeleteApproval. -func (mr *MockStoreMockRecorder) DeleteApproval(ctx, a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteApproval", reflect.TypeOf((*MockStore)(nil).DeleteApproval), ctx, a) -} - // DeleteChatUser mocks base method. func (m *MockStore) DeleteChatUser(ctx context.Context, cu *ent.ChatUser) error { m.ctrl.T.Helper() @@ -364,36 +349,6 @@ func (mr *MockStoreMockRecorder) DeleteUser(ctx, u interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteUser", reflect.TypeOf((*MockStore)(nil).DeleteUser), ctx, u) } -// FindApprovalByID mocks base method. -func (m *MockStore) FindApprovalByID(ctx context.Context, id int) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindApprovalByID", ctx, id) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindApprovalByID indicates an expected call of FindApprovalByID. -func (mr *MockStoreMockRecorder) FindApprovalByID(ctx, id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindApprovalByID", reflect.TypeOf((*MockStore)(nil).FindApprovalByID), ctx, id) -} - -// FindApprovalOfUser mocks base method. -func (m *MockStore) FindApprovalOfUser(ctx context.Context, d *ent.Deployment, u *ent.User) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindApprovalOfUser", ctx, d, u) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindApprovalOfUser indicates an expected call of FindApprovalOfUser. -func (mr *MockStoreMockRecorder) FindApprovalOfUser(ctx, d, u interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindApprovalOfUser", reflect.TypeOf((*MockStore)(nil).FindApprovalOfUser), ctx, d, u) -} - // FindCallbackByHash mocks base method. func (m *MockStore) FindCallbackByHash(ctx context.Context, hash string) (*ent.Callback, error) { m.ctrl.T.Helper() @@ -589,6 +544,36 @@ func (mr *MockStoreMockRecorder) FindRepoOfUserByNamespaceName(ctx, u, namespace return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindRepoOfUserByNamespaceName", reflect.TypeOf((*MockStore)(nil).FindRepoOfUserByNamespaceName), ctx, u, namespace, name) } +// FindReviewByID mocks base method. +func (m *MockStore) FindReviewByID(ctx context.Context, id int) (*ent.Review, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindReviewByID", ctx, id) + ret0, _ := ret[0].(*ent.Review) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FindReviewByID indicates an expected call of FindReviewByID. +func (mr *MockStoreMockRecorder) FindReviewByID(ctx, id interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindReviewByID", reflect.TypeOf((*MockStore)(nil).FindReviewByID), ctx, id) +} + +// FindReviewOfUser mocks base method. +func (m *MockStore) FindReviewOfUser(ctx context.Context, u *ent.User, d *ent.Deployment) (*ent.Review, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindReviewOfUser", ctx, u, d) + ret0, _ := ret[0].(*ent.Review) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FindReviewOfUser indicates an expected call of FindReviewOfUser. +func (mr *MockStoreMockRecorder) FindReviewOfUser(ctx, u, d interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindReviewOfUser", reflect.TypeOf((*MockStore)(nil).FindReviewOfUser), ctx, u, d) +} + // FindUserByHash mocks base method. func (m *MockStore) FindUserByHash(ctx context.Context, hash string) (*ent.User, error) { m.ctrl.T.Helper() @@ -679,21 +664,6 @@ func (mr *MockStoreMockRecorder) ListAllDeploymentStatistics(ctx interface{}) *g return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListAllDeploymentStatistics", reflect.TypeOf((*MockStore)(nil).ListAllDeploymentStatistics), ctx) } -// ListApprovals mocks base method. -func (m *MockStore) ListApprovals(ctx context.Context, d *ent.Deployment) ([]*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListApprovals", ctx, d) - ret0, _ := ret[0].([]*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListApprovals indicates an expected call of ListApprovals. -func (mr *MockStoreMockRecorder) ListApprovals(ctx, d interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListApprovals", reflect.TypeOf((*MockStore)(nil).ListApprovals), ctx, d) -} - // ListDeploymentStatisticsGreaterThanTime mocks base method. func (m *MockStore) ListDeploymentStatisticsGreaterThanTime(ctx context.Context, updated time.Time) ([]*ent.DeploymentStatistics, error) { m.ctrl.T.Helper() @@ -814,34 +784,34 @@ func (mr *MockStoreMockRecorder) ListReposOfUser(ctx, u, q, namespace, name, sor return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListReposOfUser", reflect.TypeOf((*MockStore)(nil).ListReposOfUser), ctx, u, q, namespace, name, sorted, page, perPage) } -// ListUsers mocks base method. -func (m *MockStore) ListUsers(ctx context.Context, login string, page, perPage int) ([]*ent.User, error) { +// ListReviews mocks base method. +func (m *MockStore) ListReviews(ctx context.Context, d *ent.Deployment) ([]*ent.Review, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListUsers", ctx, login, page, perPage) - ret0, _ := ret[0].([]*ent.User) + ret := m.ctrl.Call(m, "ListReviews", ctx, d) + ret0, _ := ret[0].([]*ent.Review) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListUsers indicates an expected call of ListUsers. -func (mr *MockStoreMockRecorder) ListUsers(ctx, login, page, perPage interface{}) *gomock.Call { +// ListReviews indicates an expected call of ListReviews. +func (mr *MockStoreMockRecorder) ListReviews(ctx, d interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListUsers", reflect.TypeOf((*MockStore)(nil).ListUsers), ctx, login, page, perPage) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListReviews", reflect.TypeOf((*MockStore)(nil).ListReviews), ctx, d) } -// SearchApprovals mocks base method. -func (m *MockStore) SearchApprovals(ctx context.Context, u *ent.User, s []approval.Status, from, to time.Time, page, perPage int) ([]*ent.Approval, error) { +// ListUsers mocks base method. +func (m *MockStore) ListUsers(ctx context.Context, login string, page, perPage int) ([]*ent.User, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SearchApprovals", ctx, u, s, from, to, page, perPage) - ret0, _ := ret[0].([]*ent.Approval) + ret := m.ctrl.Call(m, "ListUsers", ctx, login, page, perPage) + ret0, _ := ret[0].([]*ent.User) ret1, _ := ret[1].(error) return ret0, ret1 } -// SearchApprovals indicates an expected call of SearchApprovals. -func (mr *MockStoreMockRecorder) SearchApprovals(ctx, u, s, from, to, page, perPage interface{}) *gomock.Call { +// ListUsers indicates an expected call of ListUsers. +func (mr *MockStoreMockRecorder) ListUsers(ctx, login, page, perPage interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchApprovals", reflect.TypeOf((*MockStore)(nil).SearchApprovals), ctx, u, s, from, to, page, perPage) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListUsers", reflect.TypeOf((*MockStore)(nil).ListUsers), ctx, login, page, perPage) } // SearchDeployments mocks base method. @@ -859,6 +829,21 @@ func (mr *MockStoreMockRecorder) SearchDeployments(ctx, u, s, owned, from, to, p return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchDeployments", reflect.TypeOf((*MockStore)(nil).SearchDeployments), ctx, u, s, owned, from, to, page, perPage) } +// SearchReviews mocks base method. +func (m *MockStore) SearchReviews(ctx context.Context, u *ent.User) ([]*ent.Review, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SearchReviews", ctx, u) + ret0, _ := ret[0].([]*ent.Review) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SearchReviews indicates an expected call of SearchReviews. +func (mr *MockStoreMockRecorder) SearchReviews(ctx, u interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SearchReviews", reflect.TypeOf((*MockStore)(nil).SearchReviews), ctx, u) +} + // SyncDeploymentStatus mocks base method. func (m *MockStore) SyncDeploymentStatus(ctx context.Context, ds *ent.DeploymentStatus) (*ent.DeploymentStatus, error) { m.ctrl.T.Helper() @@ -889,21 +874,6 @@ func (mr *MockStoreMockRecorder) SyncRepo(ctx, r interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SyncRepo", reflect.TypeOf((*MockStore)(nil).SyncRepo), ctx, r) } -// UpdateApproval mocks base method. -func (m *MockStore) UpdateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateApproval", ctx, a) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// UpdateApproval indicates an expected call of UpdateApproval. -func (mr *MockStoreMockRecorder) UpdateApproval(ctx, a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateApproval", reflect.TypeOf((*MockStore)(nil).UpdateApproval), ctx, a) -} - // UpdateChatUser mocks base method. func (m *MockStore) UpdateChatUser(ctx context.Context, cu *ent.ChatUser) (*ent.ChatUser, error) { m.ctrl.T.Helper() @@ -994,6 +964,21 @@ func (mr *MockStoreMockRecorder) UpdateRepo(ctx, r interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRepo", reflect.TypeOf((*MockStore)(nil).UpdateRepo), ctx, r) } +// UpdateReview mocks base method. +func (m *MockStore) UpdateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateReview", ctx, rv) + ret0, _ := ret[0].(*ent.Review) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateReview indicates an expected call of UpdateReview. +func (mr *MockStoreMockRecorder) UpdateReview(ctx, rv interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateReview", reflect.TypeOf((*MockStore)(nil).UpdateReview), ctx, rv) +} + // UpdateUser mocks base method. func (m *MockStore) UpdateUser(ctx context.Context, u *ent.User) (*ent.User, error) { m.ctrl.T.Helper() diff --git a/internal/interactor/review.go b/internal/interactor/review.go new file mode 100644 index 00000000..2a85f644 --- /dev/null +++ b/internal/interactor/review.go @@ -0,0 +1,34 @@ +package interactor + +import ( + "context" + + "github.com/gitploy-io/gitploy/ent" + "github.com/gitploy-io/gitploy/ent/event" + "go.uber.org/zap" +) + +func (i *Interactor) requestReviewByLogin(ctx context.Context, d *ent.Deployment, login string) (*ent.Review, error) { + u, err := i.Store.FindUserByLogin(ctx, login) + if err != nil { + return nil, err + } + + rv, err := i.Store.CreateReview(ctx, &ent.Review{ + DeploymentID: d.ID, + UserID: u.ID, + }) + if err != nil { + return nil, err + } + + if _, err := i.Store.CreateEvent(ctx, &ent.Event{ + Kind: event.KindReview, + Type: event.TypeCreated, + ReviewID: rv.ID, + }); err != nil { + i.log.Error("Failed to create the event.", zap.Error(err)) + } + + return rv, nil +} diff --git a/internal/pkg/store/approval.go b/internal/pkg/store/approval.go deleted file mode 100644 index 1a8532f1..00000000 --- a/internal/pkg/store/approval.go +++ /dev/null @@ -1,149 +0,0 @@ -package store - -import ( - "context" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" - "github.com/gitploy-io/gitploy/ent/predicate" - "github.com/gitploy-io/gitploy/pkg/e" -) - -func (s *Store) SearchApprovals(ctx context.Context, u *ent.User, ss []approval.Status, from time.Time, to time.Time, page, perPage int) ([]*ent.Approval, error) { - statusIn := func(ss []approval.Status) predicate.Approval { - if len(ss) == 0 { - // if not status were provided, - // it always make this predicate truly. - return func(s *sql.Selector) {} - } - - return approval.StatusIn(ss...) - } - - return s.c.Approval. - Query(). - Where( - approval.And( - approval.UserID(u.ID), - statusIn(ss), - approval.CreatedAtGTE(from), - approval.CreatedAtLT(to), - ), - ). - WithUser(). - WithDeployment(func(dq *ent.DeploymentQuery) { - dq. - WithRepo(). - WithUser() - }). - Order(ent.Desc(approval.FieldCreatedAt)). - Offset(offset(page, perPage)). - Limit(perPage). - All(ctx) -} - -func (s *Store) ListApprovals(ctx context.Context, d *ent.Deployment) ([]*ent.Approval, error) { - return s.c.Approval. - Query(). - Where( - approval.DeploymentIDEQ(d.ID), - ). - WithUser(). - WithDeployment(func(dq *ent.DeploymentQuery) { - dq. - WithRepo(). - WithUser() - }). - All(ctx) -} - -func (s *Store) FindApprovalByID(ctx context.Context, id int) (*ent.Approval, error) { - ap, err := s.c.Approval. - Query(). - Where( - approval.IDEQ(id), - ). - WithUser(). - WithDeployment(func(dq *ent.DeploymentQuery) { - dq. - WithRepo(). - WithUser() - }). - First(ctx) - if ent.IsNotFound(err) { - return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The approval is not found.", err) - } else if err != nil { - return nil, e.NewError(e.ErrorCodeInternalError, err) - } - - return ap, nil -} - -func (s *Store) FindApprovalOfUser(ctx context.Context, d *ent.Deployment, u *ent.User) (*ent.Approval, error) { - ap, err := s.c.Approval. - Query(). - Where( - approval.And( - approval.UserIDEQ(u.ID), - approval.DeploymentIDEQ(d.ID), - ), - ). - WithUser(). - WithDeployment(func(dq *ent.DeploymentQuery) { - dq. - WithRepo(). - WithUser() - }). - First(ctx) - if ent.IsNotFound(err) { - return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The user's approval is not found.", err) - } else if err != nil { - return nil, e.NewError(e.ErrorCodeInternalError, err) - } - - return ap, nil -} - -func (s *Store) CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { - ap, err := s.c.Approval. - Create(). - SetUserID(a.UserID). - SetDeploymentID(a.DeploymentID). - Save(ctx) - if ent.IsValidationError(err) { - return nil, e.NewErrorWithMessage( - e.ErrorCodeUnprocessableEntity, - fmt.Sprintf("Failed to create a approval. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name), - err) - } else if err != nil { - return nil, e.NewError(e.ErrorCodeInternalError, err) - } - - return ap, nil -} - -func (s *Store) UpdateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { - ap, err := s.c.Approval. - UpdateOne(a). - SetStatus(a.Status). - Save(ctx) - if ent.IsValidationError(err) { - return nil, e.NewErrorWithMessage( - e.ErrorCodeUnprocessableEntity, - fmt.Sprintf("Failed to update the approval. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name), - err) - } else if err != nil { - return nil, e.NewError(e.ErrorCodeInternalError, err) - } - - return ap, nil -} - -func (s *Store) DeleteApproval(ctx context.Context, a *ent.Approval) error { - return s.c.Approval. - DeleteOne(a). - Exec(ctx) -} diff --git a/internal/pkg/store/approval_test.go b/internal/pkg/store/approval_test.go deleted file mode 100644 index 45a41f0c..00000000 --- a/internal/pkg/store/approval_test.go +++ /dev/null @@ -1,140 +0,0 @@ -package store - -import ( - "context" - "testing" - "time" - - "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" - "github.com/gitploy-io/gitploy/ent/enttest" - "github.com/gitploy-io/gitploy/ent/migrate" - "github.com/gitploy-io/gitploy/pkg/e" -) - -func TestStore_SearchApprovals(t *testing.T) { - client := enttest.Open(t, - "sqlite3", - "file:ent?mode=memory&cache=shared&_fk=1", - enttest.WithMigrateOptions(migrate.WithForeignKeys(false)), - ) - defer client.Close() - - ctx := context.Background() - - const ( - u1 = 1 - d1 = 1 - d2 = 2 - d3 = 3 - ) - - client.Approval. - Create(). - SetStatus(approval.StatusApproved). - SetUserID(u1). - SetDeploymentID(d1). - SaveX(ctx) - - client.Approval. - Create(). - SetStatus(approval.StatusPending). - SetUserID(u1). - SetDeploymentID(d2). - SaveX(ctx) - - client.Approval. - Create(). - SetStatus(approval.StatusPending). - SetUserID(u1). - SetDeploymentID(d3). - SaveX(ctx) - - t.Run("u1 searchs requested approvals of the deployment.", func(t *testing.T) { - const ( - owned = false - page = 1 - perPage = 30 - ) - - store := NewStore(client) - - res, err := store.SearchApprovals(ctx, - &ent.User{ID: u1}, - []approval.Status{}, - time.Now().Add(-time.Minute), - time.Now(), - page, - perPage, - ) - if err != nil { - t.Fatalf("SearchApprovals return an error: %s", err) - t.FailNow() - } - - expected := 3 - if len(res) != expected { - t.Fatalf("SearchApprovals = %v, wanted %v", res, expected) - t.FailNow() - } - }) - -} - -func TestStore_UpdateApproval(t *testing.T) { - t.Run("Return unprocessable_entity error when the status is invalid.", func(t *testing.T) { - ctx := context.Background() - - client := enttest.Open(t, - "sqlite3", - "file:ent?mode=memory&cache=shared&_fk=1", - enttest.WithMigrateOptions(migrate.WithForeignKeys(false)), - ) - defer client.Close() - - a := client.Approval. - Create(). - SetUserID(1). - SetDeploymentID(1). - SaveX(ctx) - - store := NewStore(client) - - t.Log("Update the approval with the invalid value.") - a.Status = approval.Status("VALUE") - _, err := store.UpdateApproval(ctx, a) - if !e.HasErrorCode(err, e.ErrorCodeUnprocessableEntity) { - t.Fatalf("UpdateApproval return error = %v, wanted ErrorCodeUnprocessableEntity", err) - } - }) - - t.Run("Return the updated approval.", func(t *testing.T) { - ctx := context.Background() - - client := enttest.Open(t, - "sqlite3", - "file:ent?mode=memory&cache=shared&_fk=1", - enttest.WithMigrateOptions(migrate.WithForeignKeys(false)), - ) - defer client.Close() - - a := client.Approval. - Create(). - SetUserID(1). - SetDeploymentID(1). - SaveX(ctx) - - store := NewStore(client) - - t.Log("Update the approval ") - a.Status = approval.StatusApproved - a, err := store.UpdateApproval(ctx, a) - if err != nil { - t.Fatalf("UpdateApproval returns an error: %v", err) - } - - if a.Status != approval.StatusApproved { - t.Fatalf("UpdateApproval status = %v, wanted %v", a.Status, approval.StatusApproved) - } - }) -} diff --git a/internal/pkg/store/deployment.go b/internal/pkg/store/deployment.go index 20244dec..4c03ed08 100644 --- a/internal/pkg/store/deployment.go +++ b/internal/pkg/store/deployment.go @@ -244,8 +244,6 @@ func (s *Store) CreateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D SetHTMLURL(d.HTMLURL). SetProductionEnvironment(d.ProductionEnvironment). SetIsRollback(d.IsRollback). - SetIsApprovalEnabled(d.IsApprovalEnabled). - SetRequiredApprovalCount(d.RequiredApprovalCount). SetStatus(d.Status). SetUserID(d.UserID). SetRepoID(d.RepoID). @@ -279,8 +277,6 @@ func (s *Store) UpdateDeployment(ctx context.Context, d *ent.Deployment) (*ent.D SetSha(d.Sha). SetHTMLURL(d.HTMLURL). SetIsRollback(d.IsRollback). - SetIsApprovalEnabled(d.IsApprovalEnabled). - SetRequiredApprovalCount(d.RequiredApprovalCount). SetStatus(d.Status). Save(ctx) if ent.IsValidationError(err) { diff --git a/internal/pkg/store/event.go b/internal/pkg/store/event.go index 783dcc2b..13c38e7f 100644 --- a/internal/pkg/store/event.go +++ b/internal/pkg/store/event.go @@ -10,10 +10,10 @@ import ( "github.com/gitploy-io/gitploy/ent/notificationrecord" ) -// ListEventsGreaterThanTime returns all events for deployment and approval +// ListEventsGreaterThanTime returns all events for deployment and review // that are greater than the time. // -// It processes eager loading, especially, Approval loads a repository of deployment. +// It processes eager loading, especially, review loads a repository of deployment. func (s *Store) ListEventsGreaterThanTime(ctx context.Context, t time.Time) ([]*ent.Event, error) { const limit = 100 @@ -22,8 +22,14 @@ func (s *Store) ListEventsGreaterThanTime(ctx context.Context, t time.Time) ([]* Where( event.CreatedAtGT(t), ). - WithApproval(func(aq *ent.ApprovalQuery) { - aq. + WithDeployment(func(dq *ent.DeploymentQuery) { + dq. + WithUser(). + WithRepo(). + WithDeploymentStatuses() + }). + WithReview(func(rq *ent.ReviewQuery) { + rq. WithUser(). WithDeployment(func(dq *ent.DeploymentQuery) { dq. @@ -31,12 +37,6 @@ func (s *Store) ListEventsGreaterThanTime(ctx context.Context, t time.Time) ([]* WithRepo() }) }). - WithDeployment(func(dq *ent.DeploymentQuery) { - dq. - WithUser(). - WithRepo(). - WithDeploymentStatuses() - }). Limit(limit). All(ctx) } @@ -51,8 +51,8 @@ func (s *Store) CreateEvent(ctx context.Context, e *ent.Event) (*ent.Event, erro qry = qry.SetDeletedID(e.DeletedID) } else if e.Kind == event.KindDeployment { qry = qry.SetDeploymentID(e.DeploymentID) - } else if e.Kind == event.KindApproval { - qry = qry.SetApprovalID(e.ApprovalID) + } else if e.Kind == event.KindReview { + qry = qry.SetReviewID(e.ReviewID) } return qry.Save(ctx) diff --git a/internal/pkg/store/event_test.go b/internal/pkg/store/event_test.go index ee5f6abb..437de115 100644 --- a/internal/pkg/store/event_test.go +++ b/internal/pkg/store/event_test.go @@ -23,7 +23,7 @@ func TestStore_CreateEvent(t *testing.T) { s := NewStore(client) e, err := s.CreateEvent(ctx, &ent.Event{ - Kind: event.KindApproval, + Kind: event.KindReview, Type: event.TypeDeleted, DeletedID: 1, }) diff --git a/internal/pkg/store/review.go b/internal/pkg/store/review.go new file mode 100644 index 00000000..4f106009 --- /dev/null +++ b/internal/pkg/store/review.go @@ -0,0 +1,126 @@ +package store + +import ( + "context" + "fmt" + + "github.com/gitploy-io/gitploy/ent" + "github.com/gitploy-io/gitploy/ent/deployment" + "github.com/gitploy-io/gitploy/ent/review" + "github.com/gitploy-io/gitploy/pkg/e" +) + +func (s *Store) SearchReviews(ctx context.Context, u *ent.User) ([]*ent.Review, error) { + rvs, err := s.c.Review. + Query(). + Where( + review.And( + review.UserID(u.ID), + review.HasDeploymentWith(deployment.StatusEQ(deployment.StatusWaiting)), + review.StatusEQ(review.StatusPending), + ), + ). + WithUser(). + WithDeployment(func(dq *ent.DeploymentQuery) { + dq. + WithRepo(). + WithUser() + }). + Order(ent.Desc(review.FieldCreatedAt)). + All(ctx) + if err != nil { + return nil, e.NewError(e.ErrorCodeInternalError, err) + } + + return rvs, nil +} + +func (s *Store) ListReviews(ctx context.Context, d *ent.Deployment) ([]*ent.Review, error) { + rvs, err := s.c.Review. + Query(). + Where( + review.DeploymentIDEQ(d.ID), + ). + WithUser(). + WithDeployment(). + All(ctx) + if err != nil { + return nil, e.NewError(e.ErrorCodeInternalError, err) + } + + return rvs, nil +} + +func (s *Store) FindReviewByID(ctx context.Context, id int) (*ent.Review, error) { + rv, err := s.c.Review. + Query(). + Where( + review.IDEQ(id), + ). + WithUser(). + WithDeployment(). + Only(ctx) + if ent.IsNotFound(err) { + return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The review is not found.", err) + } else if err != nil { + return nil, e.NewError(e.ErrorCodeInternalError, err) + } + + return rv, nil +} + +func (s *Store) FindReviewOfUser(ctx context.Context, u *ent.User, d *ent.Deployment) (*ent.Review, error) { + rv, err := s.c.Review. + Query(). + Where( + review.DeploymentIDEQ(d.ID), + review.UserIDEQ(u.ID), + ). + WithUser(). + WithDeployment(). + Only(ctx) + if ent.IsNotFound(err) { + return nil, e.NewErrorWithMessage(e.ErrorCodeNotFound, "The review is not found.", err) + } else if err != nil { + return nil, e.NewError(e.ErrorCodeInternalError, err) + } + + return rv, nil +} + +func (s *Store) CreateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) { + rv, err := s.c.Review. + Create(). + SetDeploymentID(rv.DeploymentID). + SetUserID(rv.UserID). + Save(ctx) + if ent.IsValidationError(err) { + return nil, e.NewErrorWithMessage( + e.ErrorCodeUnprocessableEntity, + fmt.Sprintf("Failed to create a review. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name), + err, + ) + } else if err != nil { + return nil, e.NewError(e.ErrorCodeInternalError, err) + } + + return s.FindReviewByID(ctx, rv.ID) +} + +func (s *Store) UpdateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) { + rv, err := s.c.Review. + UpdateOne(rv). + SetStatus(rv.Status). + Save(ctx) + if ent.IsValidationError(err) { + return nil, e.NewErrorWithMessage( + e.ErrorCodeUnprocessableEntity, + fmt.Sprintf("Failed to update the review. The value of \"%s\" field is invalid.", err.(*ent.ValidationError).Name), + err, + ) + } else if err != nil { + return nil, e.NewError(e.ErrorCodeInternalError, err) + } + + return s.FindReviewByID(ctx, rv.ID) +} diff --git a/internal/server/api/v1/repos/approval.go b/internal/server/api/v1/repos/approval.go deleted file mode 100644 index db2dbabd..00000000 --- a/internal/server/api/v1/repos/approval.go +++ /dev/null @@ -1,317 +0,0 @@ -// Copyright 2021 Gitploy.IO Inc. All rights reserved. -// Use of this source code is governed by the Gitploy Non-Commercial License -// that can be found in the LICENSE file. - -// +build !oss - -package repos - -import ( - "net/http" - "strconv" - - "github.com/gin-gonic/gin" - "github.com/gin-gonic/gin/binding" - "go.uber.org/zap" - - "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" - "github.com/gitploy-io/gitploy/ent/event" - gb "github.com/gitploy-io/gitploy/internal/server/global" - "github.com/gitploy-io/gitploy/pkg/e" -) - -type ( - approvalPostPayload struct { - UserID int64 `json:"user_id"` - } - - approvalPatchPayload struct { - Status string `json:"status"` - } -) - -func (r *Repo) ListApprovals(c *gin.Context) { - ctx := c.Request.Context() - - var ( - number = c.Param("number") - ) - - vr, _ := c.Get(KeyRepo) - re := vr.(*ent.Repo) - - d, err := r.i.FindDeploymentOfRepoByNumber(ctx, re, atoi(number)) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the deployment.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - as, err := r.i.ListApprovals(ctx, d) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to list approvals.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - gb.Response(c, http.StatusOK, as) -} - -func (r *Repo) GetApproval(c *gin.Context) { - ctx := c.Request.Context() - - var ( - aid = c.Param("aid") - ) - - ap, err := r.i.FindApprovalByID(ctx, atoi(aid)) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the approval.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - gb.Response(c, http.StatusOK, ap) -} - -func (r *Repo) GetMyApproval(c *gin.Context) { - ctx := c.Request.Context() - - var ( - number int - err error - ) - - if number, err = strconv.Atoi(c.Param("number")); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "The number must be number.", nil), - ) - return - } - - vu, _ := c.Get(gb.KeyUser) - u := vu.(*ent.User) - - vr, _ := c.Get(KeyRepo) - re := vr.(*ent.Repo) - - d, err := r.i.FindDeploymentOfRepoByNumber(ctx, re, number) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the deployment.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - a, err := r.i.FindApprovalOfUser(ctx, d, u) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the user's approval.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - gb.Response(c, http.StatusOK, a) -} - -func (r *Repo) CreateApproval(c *gin.Context) { - ctx := c.Request.Context() - - var ( - number int - err error - ) - - if number, err = strconv.Atoi(c.Param("number")); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "The number must be number.", nil), - ) - return - } - - p := &approvalPostPayload{} - if err := c.ShouldBindBodyWith(p, binding.JSON); err != nil { - r.log.Warn("failed to bind the payload.", zap.Error(err)) - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "It has failed to bind the playload.", nil), - ) - return - } - - vr, _ := c.Get(KeyRepo) - re := vr.(*ent.Repo) - - d, err := r.i.FindDeploymentOfRepoByNumber(ctx, re, number) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the deployment.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - // TODO: Migrate the business logic into the interactor. - user, err := r.i.FindUserByID(ctx, p.UserID) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the user.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - _, err = r.i.FindPermOfRepo(ctx, re, user) - if e.HasErrorCode(err, e.ErrorCodeNotFound) { - r.log.Warn("The approver has no permission for the repository.", zap.Error(err)) - // Override the HTTP status. - gb.ResponseWithStatusAndError(c, http.StatusUnprocessableEntity, err) - return - } else if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the perm of approver.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - if d.Edges.User != nil && user.ID == d.Edges.User.ID { - r.log.Warn("Failed to create a new approval.", zap.Error(err)) - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeUnprocessableEntity, "The deployer can not be the approver.", nil), - ) - return - } - - ap, err := r.i.CreateApproval(ctx, &ent.Approval{ - UserID: user.ID, - DeploymentID: d.ID, - }) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to create a new approval.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - if _, err := r.i.CreateEvent(ctx, &ent.Event{ - Kind: event.KindApproval, - Type: event.TypeCreated, - ApprovalID: ap.ID, - }); err != nil { - r.log.Error("Failed to create the event.", zap.Error(err)) - } - - // Get the approval with edges - if ae, _ := r.i.FindApprovalByID(ctx, ap.ID); ae != nil { - ap = ae - } - - gb.Response(c, http.StatusCreated, ap) -} - -func (r *Repo) UpdateMyApproval(c *gin.Context) { - ctx := c.Request.Context() - - var ( - number int - err error - ) - - if number, err = strconv.Atoi(c.Param("number")); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "The number must be number.", nil), - ) - return - } - - p := &approvalPatchPayload{} - if err := c.ShouldBindBodyWith(p, binding.JSON); err != nil { - r.log.Warn("failed to bind the payload.", zap.Error(err)) - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "It has failed to bind the payload.", nil), - ) - return - } - - vu, _ := c.Get(gb.KeyUser) - u := vu.(*ent.User) - - vr, _ := c.Get(KeyRepo) - re := vr.(*ent.Repo) - - d, err := r.i.FindDeploymentOfRepoByNumber(ctx, re, number) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the deployment.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - a, err := r.i.FindApprovalOfUser(ctx, d, u) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the user's approval.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - if p.Status != string(a.Status) { - a.Status = approval.Status(p.Status) - if a, err = r.i.UpdateApproval(ctx, a); err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to update the approval.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - if _, err := r.i.CreateEvent(ctx, &ent.Event{ - Kind: event.KindApproval, - Type: event.TypeUpdated, - ApprovalID: a.ID, - }); err != nil { - r.log.Error("Failed to create the event.", zap.Error(err)) - } - } - - // Get the approval with edges - if ae, _ := r.i.FindApprovalOfUser(ctx, d, u); ae != nil { - a = ae - } - - gb.Response(c, http.StatusOK, a) -} - -func (r *Repo) DeleteApproval(c *gin.Context) { - ctx := c.Request.Context() - - var ( - aid int - err error - ) - - if aid, err = strconv.Atoi(c.Param("aid")); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "The number must be number.", nil), - ) - return - } - - ap, err := r.i.FindApprovalByID(ctx, aid) - if err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to find the approval.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - if err := r.i.DeleteApproval(ctx, ap); err != nil { - r.log.Check(gb.GetZapLogLevel(err), "Failed to delete the approval.").Write(zap.Error(err)) - gb.ResponseWithError(c, err) - return - } - - if _, err := r.i.CreateEvent(ctx, &ent.Event{ - Kind: event.KindApproval, - Type: event.TypeDeleted, - DeletedID: aid, - }); err != nil { - r.log.Error("It has failed to create a new event.", zap.Error(err)) - } - - c.Status(http.StatusOK) -} diff --git a/internal/server/api/v1/repos/approval_oss.go b/internal/server/api/v1/repos/approval_oss.go deleted file mode 100644 index c23dcbc8..00000000 --- a/internal/server/api/v1/repos/approval_oss.go +++ /dev/null @@ -1,46 +0,0 @@ -// +build oss - -package repos - -import ( - "net/http" - - "github.com/gin-gonic/gin" - - "github.com/gitploy-io/gitploy/ent" - gb "github.com/gitploy-io/gitploy/internal/server/global" - "github.com/gitploy-io/gitploy/pkg/e" -) - -func (r *Repo) ListApprovals(c *gin.Context) { - gb.Response(c, http.StatusOK, make([]*ent.Approval, 0)) -} - -func (r *Repo) GetApproval(c *gin.Context) { - gb.Response(c, http.StatusNotFound, nil) -} - -func (r *Repo) GetMyApproval(c *gin.Context) { - gb.Response(c, http.StatusNotFound, nil) -} - -func (r *Repo) CreateApproval(c *gin.Context) { - gb.ResponseWithError( - c, - e.NewError(e.ErrorCodeLicenseRequired, nil), - ) -} - -func (r *Repo) UpdateMyApproval(c *gin.Context) { - gb.ResponseWithError( - c, - e.NewError(e.ErrorCodeLicenseRequired, nil), - ) -} - -func (r *Repo) DeleteApproval(c *gin.Context) { - gb.ResponseWithError( - c, - e.NewError(e.ErrorCodeLicenseRequired, nil), - ) -} diff --git a/internal/server/api/v1/repos/approval_test.go b/internal/server/api/v1/repos/approval_test.go deleted file mode 100644 index f3d6ef73..00000000 --- a/internal/server/api/v1/repos/approval_test.go +++ /dev/null @@ -1,215 +0,0 @@ -package repos - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "net/http" - "net/http/httptest" - "testing" - - "github.com/gin-gonic/gin" - "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/internal/server/api/v1/repos/mock" - "github.com/golang/mock/gomock" -) - -var ( - ctx = gomock.Any() - any = gomock.Any() -) - -func TestRepo_CreateApproval(t *testing.T) { - t.Run("Validate to request the approval to the deployer.", func(t *testing.T) { - input := struct { - number int - payload *approvalPostPayload - }{ - number: 7, - payload: &approvalPostPayload{ - UserID: 4, - }, - } - - ctrl := gomock.NewController(t) - m := mock.NewMockInteractor(ctrl) - - t.Log("MOCK - Find the deployment by ID.") - m. - EXPECT(). - FindDeploymentOfRepoByNumber(ctx, any, input.number). - Return(&ent.Deployment{ - ID: input.number, - Edges: ent.DeploymentEdges{ - User: &ent.User{ - ID: input.payload.UserID, - }, - }, - }, nil) - - t.Log("MOCK - Find the user, and check the permission.") - m. - EXPECT(). - FindUserByID(ctx, input.payload.UserID). - Return(&ent.User{ - ID: input.payload.UserID, - }, nil) - - m. - EXPECT(). - FindPermOfRepo(ctx, any, &ent.User{ - ID: input.payload.UserID, - }). - Return(&ent.Perm{}, nil) - - gin.SetMode(gin.ReleaseMode) - - r := NewRepo(RepoConfig{}, m) - router := gin.New() - router.POST("/deployments/:number/approvals", func(c *gin.Context) { - c.Set(KeyRepo, &ent.Repo{}) - }, r.CreateApproval) - - body, _ := json.Marshal(input.payload) - req, _ := http.NewRequest("POST", fmt.Sprintf("/deployments/%d/approvals", input.number), bytes.NewBuffer(body)) - - w := httptest.NewRecorder() - router.ServeHTTP(w, req) - - if w.Code != http.StatusUnprocessableEntity { - t.Fatalf("Code != %d, wanted %d", w.Code, http.StatusOK) - } - }) - - t.Run("Create a new approval.", func(t *testing.T) { - input := struct { - number int - payload *approvalPostPayload - }{ - number: 7, - payload: &approvalPostPayload{ - UserID: 4, - }, - } - - const ( - approvalID = 3 - ) - - ctrl := gomock.NewController(t) - m := mock.NewMockInteractor(ctrl) - - m. - EXPECT(). - FindDeploymentOfRepoByNumber(ctx, any, input.number). - Return(&ent.Deployment{ - ID: input.number, - }, nil) - - // Find the user, and check the permission. - m. - EXPECT(). - FindUserByID(ctx, input.payload.UserID). - Return(&ent.User{ - ID: input.payload.UserID, - }, nil) - - m. - EXPECT(). - FindPermOfRepo(ctx, any, &ent.User{ - ID: input.payload.UserID, - }). - Return(&ent.Perm{}, nil) - - // Create a new approval and publish. - m. - EXPECT(). - CreateApproval(ctx, &ent.Approval{ - DeploymentID: input.number, - UserID: input.payload.UserID, - }). - DoAndReturn(func(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { - a.ID = approvalID - return a, nil - }) - - m. - EXPECT(). - CreateEvent(ctx, any). - Return(&ent.Event{}, nil) - - m. - EXPECT(). - FindApprovalByID(ctx, approvalID). - Return(&ent.Approval{ - ID: approvalID, - DeploymentID: input.number, - UserID: input.payload.UserID, - }, nil) - - gin.SetMode(gin.ReleaseMode) - - r := NewRepo(RepoConfig{}, m) - router := gin.New() - router.POST("/deployments/:number/approvals", func(c *gin.Context) { - c.Set(KeyRepo, &ent.Repo{}) - }, r.CreateApproval) - - body, _ := json.Marshal(input.payload) - req, _ := http.NewRequest("POST", fmt.Sprintf("/deployments/%d/approvals", input.number), bytes.NewBuffer(body)) - - w := httptest.NewRecorder() - router.ServeHTTP(w, req) - - if w.Code != http.StatusCreated { - t.Fatalf("Code != %d, wanted %d", w.Code, http.StatusOK) - } - }) -} - -func TestRepo_DeleteApproval(t *testing.T) { - t.Run("Delete the approval.", func(t *testing.T) { - input := struct { - aid int - }{ - aid: 7, - } - - ctrl := gomock.NewController(t) - m := mock.NewMockInteractor(ctrl) - - t.Log("Find the approval by ID.") - m. - EXPECT(). - FindApprovalByID(gomock.Any(), input.aid). - Return(&ent.Approval{ID: input.aid}, nil) - - t.Log("Delete the approval.") - m. - EXPECT(). - DeleteApproval(gomock.Any(), gomock.AssignableToTypeOf(&ent.Approval{})). - Return(nil) - - t.Log("Create a deleted event.") - m. - EXPECT(). - CreateEvent(gomock.Any(), gomock.AssignableToTypeOf(&ent.Event{})). - Return(&ent.Event{ID: 1}, nil) - - gin.SetMode(gin.ReleaseMode) - - r := NewRepo(RepoConfig{}, m) - router := gin.New() - router.DELETE("/deployments/:number/approvals/:aid", r.DeleteApproval) - - req, _ := http.NewRequest("DELETE", fmt.Sprintf("/deployments/1/approvals/%d", input.aid), nil) - - w := httptest.NewRecorder() - router.ServeHTTP(w, req) - - if w.Code != http.StatusOK { - t.Fatalf("Code != %d, wanted %d", w.Code, http.StatusOK) - } - }) -} diff --git a/internal/server/api/v1/repos/deployment.go b/internal/server/api/v1/repos/deployment.go index 9696fc29..901634e9 100644 --- a/internal/server/api/v1/repos/deployment.go +++ b/internal/server/api/v1/repos/deployment.go @@ -131,6 +131,7 @@ func (r *Repo) CreateDeployment(c *gin.Context) { return } + // TODO: Migrate the event logic into the interactor. if _, err := r.i.CreateEvent(ctx, &ent.Event{ Kind: event.KindDeployment, Type: event.TypeCreated, diff --git a/internal/server/api/v1/repos/interface.go b/internal/server/api/v1/repos/interface.go index 22bbe48c..c1d281a5 100644 --- a/internal/server/api/v1/repos/interface.go +++ b/internal/server/api/v1/repos/interface.go @@ -32,12 +32,9 @@ type ( DeployToRemote(ctx context.Context, u *ent.User, r *ent.Repo, d *ent.Deployment, env *vo.Env) (*ent.Deployment, error) GetConfig(ctx context.Context, u *ent.User, r *ent.Repo) (*vo.Config, error) - ListApprovals(ctx context.Context, d *ent.Deployment) ([]*ent.Approval, error) - FindApprovalByID(ctx context.Context, id int) (*ent.Approval, error) - FindApprovalOfUser(ctx context.Context, d *ent.Deployment, u *ent.User) (*ent.Approval, error) - CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) - UpdateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) - DeleteApproval(ctx context.Context, a *ent.Approval) error + ListReviews(ctx context.Context, d *ent.Deployment) ([]*ent.Review, error) + FindReviewOfUser(ctx context.Context, u *ent.User, d *ent.Deployment) (*ent.Review, error) + UpdateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) ListLocksOfRepo(ctx context.Context, r *ent.Repo) ([]*ent.Lock, error) HasLockOfRepoForEnv(ctx context.Context, r *ent.Repo, env string) (bool, error) diff --git a/internal/server/api/v1/repos/mock/interactor.go b/internal/server/api/v1/repos/mock/interactor.go index 3778dd9a..9bc3df33 100644 --- a/internal/server/api/v1/repos/mock/interactor.go +++ b/internal/server/api/v1/repos/mock/interactor.go @@ -67,21 +67,6 @@ func (mr *MockInteractorMockRecorder) CompareCommits(ctx, u, r, base, head, page return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CompareCommits", reflect.TypeOf((*MockInteractor)(nil).CompareCommits), ctx, u, r, base, head, page, perPage) } -// CreateApproval mocks base method. -func (m *MockInteractor) CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateApproval", ctx, a) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CreateApproval indicates an expected call of CreateApproval. -func (mr *MockInteractorMockRecorder) CreateApproval(ctx, a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateApproval", reflect.TypeOf((*MockInteractor)(nil).CreateApproval), ctx, a) -} - // CreateEvent mocks base method. func (m *MockInteractor) CreateEvent(ctx context.Context, e *ent.Event) (*ent.Event, error) { m.ctrl.T.Helper() @@ -127,20 +112,6 @@ func (mr *MockInteractorMockRecorder) DeactivateRepo(ctx, u, r interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeactivateRepo", reflect.TypeOf((*MockInteractor)(nil).DeactivateRepo), ctx, u, r) } -// DeleteApproval mocks base method. -func (m *MockInteractor) DeleteApproval(ctx context.Context, a *ent.Approval) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DeleteApproval", ctx, a) - ret0, _ := ret[0].(error) - return ret0 -} - -// DeleteApproval indicates an expected call of DeleteApproval. -func (mr *MockInteractorMockRecorder) DeleteApproval(ctx, a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteApproval", reflect.TypeOf((*MockInteractor)(nil).DeleteApproval), ctx, a) -} - // DeleteLock mocks base method. func (m *MockInteractor) DeleteLock(ctx context.Context, l *ent.Lock) error { m.ctrl.T.Helper() @@ -185,36 +156,6 @@ func (mr *MockInteractorMockRecorder) DeployToRemote(ctx, u, r, d, env interface return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeployToRemote", reflect.TypeOf((*MockInteractor)(nil).DeployToRemote), ctx, u, r, d, env) } -// FindApprovalByID mocks base method. -func (m *MockInteractor) FindApprovalByID(ctx context.Context, id int) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindApprovalByID", ctx, id) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindApprovalByID indicates an expected call of FindApprovalByID. -func (mr *MockInteractorMockRecorder) FindApprovalByID(ctx, id interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindApprovalByID", reflect.TypeOf((*MockInteractor)(nil).FindApprovalByID), ctx, id) -} - -// FindApprovalOfUser mocks base method. -func (m *MockInteractor) FindApprovalOfUser(ctx context.Context, d *ent.Deployment, u *ent.User) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FindApprovalOfUser", ctx, d, u) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// FindApprovalOfUser indicates an expected call of FindApprovalOfUser. -func (mr *MockInteractorMockRecorder) FindApprovalOfUser(ctx, d, u interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindApprovalOfUser", reflect.TypeOf((*MockInteractor)(nil).FindApprovalOfUser), ctx, d, u) -} - // FindDeploymentByID mocks base method. func (m *MockInteractor) FindDeploymentByID(ctx context.Context, id int) (*ent.Deployment, error) { m.ctrl.T.Helper() @@ -320,6 +261,21 @@ func (mr *MockInteractorMockRecorder) FindRepoOfUserByNamespaceName(ctx, u, name return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindRepoOfUserByNamespaceName", reflect.TypeOf((*MockInteractor)(nil).FindRepoOfUserByNamespaceName), ctx, u, namespace, name) } +// FindReviewOfUser mocks base method. +func (m *MockInteractor) FindReviewOfUser(ctx context.Context, u *ent.User, d *ent.Deployment) (*ent.Review, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FindReviewOfUser", ctx, u, d) + ret0, _ := ret[0].(*ent.Review) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// FindReviewOfUser indicates an expected call of FindReviewOfUser. +func (mr *MockInteractorMockRecorder) FindReviewOfUser(ctx, u, d interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindReviewOfUser", reflect.TypeOf((*MockInteractor)(nil).FindReviewOfUser), ctx, u, d) +} + // FindUserByID mocks base method. func (m *MockInteractor) FindUserByID(ctx context.Context, id int64) (*ent.User, error) { m.ctrl.T.Helper() @@ -424,21 +380,6 @@ func (mr *MockInteractorMockRecorder) IsApproved(ctx, d interface{}) *gomock.Cal return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsApproved", reflect.TypeOf((*MockInteractor)(nil).IsApproved), ctx, d) } -// ListApprovals mocks base method. -func (m *MockInteractor) ListApprovals(ctx context.Context, d *ent.Deployment) ([]*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListApprovals", ctx, d) - ret0, _ := ret[0].([]*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ListApprovals indicates an expected call of ListApprovals. -func (mr *MockInteractorMockRecorder) ListApprovals(ctx, d interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListApprovals", reflect.TypeOf((*MockInteractor)(nil).ListApprovals), ctx, d) -} - // ListBranches mocks base method. func (m *MockInteractor) ListBranches(ctx context.Context, u *ent.User, r *ent.Repo, page, perPage int) ([]*vo.Branch, error) { m.ctrl.T.Helper() @@ -544,34 +485,34 @@ func (mr *MockInteractorMockRecorder) ListReposOfUser(ctx, u, q, namespace, name return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListReposOfUser", reflect.TypeOf((*MockInteractor)(nil).ListReposOfUser), ctx, u, q, namespace, name, sorted, page, perPage) } -// ListTags mocks base method. -func (m *MockInteractor) ListTags(ctx context.Context, u *ent.User, r *ent.Repo, page, perPage int) ([]*vo.Tag, error) { +// ListReviews mocks base method. +func (m *MockInteractor) ListReviews(ctx context.Context, d *ent.Deployment) ([]*ent.Review, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ListTags", ctx, u, r, page, perPage) - ret0, _ := ret[0].([]*vo.Tag) + ret := m.ctrl.Call(m, "ListReviews", ctx, d) + ret0, _ := ret[0].([]*ent.Review) ret1, _ := ret[1].(error) return ret0, ret1 } -// ListTags indicates an expected call of ListTags. -func (mr *MockInteractorMockRecorder) ListTags(ctx, u, r, page, perPage interface{}) *gomock.Call { +// ListReviews indicates an expected call of ListReviews. +func (mr *MockInteractorMockRecorder) ListReviews(ctx, d interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTags", reflect.TypeOf((*MockInteractor)(nil).ListTags), ctx, u, r, page, perPage) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListReviews", reflect.TypeOf((*MockInteractor)(nil).ListReviews), ctx, d) } -// UpdateApproval mocks base method. -func (m *MockInteractor) UpdateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { +// ListTags mocks base method. +func (m *MockInteractor) ListTags(ctx context.Context, u *ent.User, r *ent.Repo, page, perPage int) ([]*vo.Tag, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateApproval", ctx, a) - ret0, _ := ret[0].(*ent.Approval) + ret := m.ctrl.Call(m, "ListTags", ctx, u, r, page, perPage) + ret0, _ := ret[0].([]*vo.Tag) ret1, _ := ret[1].(error) return ret0, ret1 } -// UpdateApproval indicates an expected call of UpdateApproval. -func (mr *MockInteractorMockRecorder) UpdateApproval(ctx, a interface{}) *gomock.Call { +// ListTags indicates an expected call of ListTags. +func (mr *MockInteractorMockRecorder) ListTags(ctx, u, r, page, perPage interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateApproval", reflect.TypeOf((*MockInteractor)(nil).UpdateApproval), ctx, a) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTags", reflect.TypeOf((*MockInteractor)(nil).ListTags), ctx, u, r, page, perPage) } // UpdateLock mocks base method. @@ -603,3 +544,18 @@ func (mr *MockInteractorMockRecorder) UpdateRepo(ctx, r interface{}) *gomock.Cal mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRepo", reflect.TypeOf((*MockInteractor)(nil).UpdateRepo), ctx, r) } + +// UpdateReview mocks base method. +func (m *MockInteractor) UpdateReview(ctx context.Context, rv *ent.Review) (*ent.Review, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateReview", ctx, rv) + ret0, _ := ret[0].(*ent.Review) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateReview indicates an expected call of UpdateReview. +func (mr *MockInteractorMockRecorder) UpdateReview(ctx, rv interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateReview", reflect.TypeOf((*MockInteractor)(nil).UpdateReview), ctx, rv) +} diff --git a/internal/server/api/v1/repos/review.go b/internal/server/api/v1/repos/review.go new file mode 100644 index 00000000..fe4a844f --- /dev/null +++ b/internal/server/api/v1/repos/review.go @@ -0,0 +1,172 @@ +// Copyright 2021 Gitploy.IO Inc. All rights reserved. +// Use of this source code is governed by the Gitploy Non-Commercial License +// that can be found in the LICENSE file. + +// +build !oss + +package repos + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" + "go.uber.org/zap" + + "github.com/gitploy-io/gitploy/ent" + "github.com/gitploy-io/gitploy/ent/event" + "github.com/gitploy-io/gitploy/ent/review" + gb "github.com/gitploy-io/gitploy/internal/server/global" + "github.com/gitploy-io/gitploy/pkg/e" +) + +type ( + reviewPatchPayload struct { + Status string `json:"status"` + } +) + +func (r *Repo) ListReviews(c *gin.Context) { + ctx := c.Request.Context() + + var ( + number int + err error + ) + + if number, err = strconv.Atoi(c.Param("number")); err != nil { + r.log.Warn("The number of deployment must be number.") + gb.ResponseWithError( + c, + e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "The number of deployment must be number.", err), + ) + return + } + + vr, _ := c.Get(KeyRepo) + re := vr.(*ent.Repo) + + d, err := r.i.FindDeploymentOfRepoByNumber(ctx, re, number) + if err != nil { + r.log.Check(gb.GetZapLogLevel(err), "Failed to find the deployment.").Write(zap.Error(err)) + gb.ResponseWithError(c, err) + return + } + + rvs, err := r.i.ListReviews(ctx, d) + if err != nil { + r.log.Check(gb.GetZapLogLevel(err), "Failed to list reviews.").Write(zap.Error(err)) + gb.ResponseWithError(c, err) + return + } + + gb.Response(c, http.StatusOK, rvs) +} + +func (r *Repo) GetUserReview(c *gin.Context) { + ctx := c.Request.Context() + + var ( + number int + err error + ) + + if number, err = strconv.Atoi(c.Param("number")); err != nil { + r.log.Warn("The number of deployment must be number.") + gb.ResponseWithError( + c, + e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "The number of deployemnt must be number.", err), + ) + return + } + + vu, _ := c.Get(gb.KeyUser) + u := vu.(*ent.User) + + vr, _ := c.Get(KeyRepo) + re := vr.(*ent.Repo) + + d, err := r.i.FindDeploymentOfRepoByNumber(ctx, re, number) + if err != nil { + r.log.Check(gb.GetZapLogLevel(err), "Failed to find the deployment.").Write(zap.Error(err)) + gb.ResponseWithError(c, err) + return + } + + rv, err := r.i.FindReviewOfUser(ctx, u, d) + if err != nil { + r.log.Check(gb.GetZapLogLevel(err), "Failed to find the user's review.").Write(zap.Error(err)) + gb.ResponseWithError(c, err) + return + } + + gb.Response(c, http.StatusOK, rv) +} + +func (r *Repo) UpdateUserReview(c *gin.Context) { + ctx := c.Request.Context() + + var ( + number int + err error + ) + + if number, err = strconv.Atoi(c.Param("number")); err != nil { + r.log.Warn("The number of deployment must be number.") + gb.ResponseWithError( + c, + e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "The number of deployment must be number.", err), + ) + return + } + + p := &reviewPatchPayload{} + if err := c.ShouldBindBodyWith(p, binding.JSON); err != nil { + r.log.Warn("Failed to bind the payload.", zap.Error(err)) + gb.ResponseWithError( + c, + e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "It has failed to bind the payload.", nil), + ) + return + } + + vu, _ := c.Get(gb.KeyUser) + u := vu.(*ent.User) + + vr, _ := c.Get(KeyRepo) + re := vr.(*ent.Repo) + + d, err := r.i.FindDeploymentOfRepoByNumber(ctx, re, number) + if err != nil { + r.log.Check(gb.GetZapLogLevel(err), "Failed to find the deployment.").Write(zap.Error(err)) + gb.ResponseWithError(c, err) + return + } + + rv, err := r.i.FindReviewOfUser(ctx, u, d) + if err != nil { + r.log.Check(gb.GetZapLogLevel(err), "Failed to find the user's review.").Write(zap.Error(err)) + gb.ResponseWithError(c, err) + return + } + + if p.Status != string(rv.Status) { + rv.Status = review.Status(p.Status) + if rv, err = r.i.UpdateReview(ctx, rv); err != nil { + r.log.Check(gb.GetZapLogLevel(err), "Failed to update the review.").Write(zap.Error(err)) + gb.ResponseWithError(c, err) + return + } + + if _, err := r.i.CreateEvent(ctx, &ent.Event{ + Kind: event.KindReview, + Type: event.TypeUpdated, + ReviewID: rv.ID, + }); err != nil { + r.log.Error("Failed to create the event.", zap.Error(err)) + } + } + + gb.Response(c, http.StatusOK, rv) +} diff --git a/internal/server/api/v1/repos/comment_oss.go b/internal/server/api/v1/repos/review_oss.go similarity index 63% rename from internal/server/api/v1/repos/comment_oss.go rename to internal/server/api/v1/repos/review_oss.go index b7ae275c..9d24ad57 100644 --- a/internal/server/api/v1/repos/comment_oss.go +++ b/internal/server/api/v1/repos/review_oss.go @@ -12,15 +12,15 @@ import ( "github.com/gitploy-io/gitploy/pkg/e" ) -func (r *Repo) ListComments(c *gin.Context) { - gb.Response(c, http.StatusOK, make([]*ent.Comment, 0)) +func (r *Repo) ListReviews(c *gin.Context) { + gb.Response(c, http.StatusOK, make([]*ent.Review, 0)) } -func (r *Repo) GetComment(c *gin.Context) { +func (r *Repo) GetUserReview(c *gin.Context) { gb.Response(c, http.StatusNotFound, nil) } -func (r *Repo) CreateComment(c *gin.Context) { +func (r *Repo) UpdateUserReview(c *gin.Context) { gb.ResponseWithError( c, e.NewError(e.ErrorCodeLicenseRequired, nil), diff --git a/internal/server/api/v1/search/interface.go b/internal/server/api/v1/search/interface.go index 3acbfa30..20bcca4e 100644 --- a/internal/server/api/v1/search/interface.go +++ b/internal/server/api/v1/search/interface.go @@ -5,13 +5,12 @@ import ( "time" "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" ) type ( Interactor interface { SearchDeployments(ctx context.Context, u *ent.User, s []deployment.Status, owned bool, from time.Time, to time.Time, page, perPage int) ([]*ent.Deployment, error) - SearchApprovals(ctx context.Context, u *ent.User, s []approval.Status, from time.Time, to time.Time, page, perPage int) ([]*ent.Approval, error) + SearchReviews(ctx context.Context, u *ent.User) ([]*ent.Review, error) } ) diff --git a/internal/server/api/v1/search/search.go b/internal/server/api/v1/search/search.go index 8070c7fe..58ea95c1 100644 --- a/internal/server/api/v1/search/search.go +++ b/internal/server/api/v1/search/search.go @@ -10,7 +10,6 @@ import ( "go.uber.org/zap" "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" gb "github.com/gitploy-io/gitploy/internal/server/global" "github.com/gitploy-io/gitploy/pkg/e" @@ -120,78 +119,22 @@ func (s *Search) SearchDeployments(c *gin.Context) { gb.Response(c, http.StatusOK, ds) } -func (s *Search) SearchApprovals(c *gin.Context) { +func (s *Search) SearchAssignedReviews(c *gin.Context) { ctx := c.Request.Context() var ( - statuses = c.DefaultQuery("statuses", "") - from = c.DefaultQuery("from", time.Now().Add(-activeDuration).Format(time.RFC3339)) - to = c.DefaultQuery("to", time.Now().Format(time.RFC3339)) - page = c.DefaultQuery("page", "1") - perPage = c.DefaultQuery("per_page", "30") - ) - - var ( - ss = make([]approval.Status, 0) - f time.Time - t time.Time - p int - pp int + rvs []*ent.Review err error ) - // Validate query parameters. - for _, st := range strings.Split(statuses, ",") { - if st != "" { - ss = append(ss, approval.Status(st)) - } - } - - if f, err = time.Parse(time.RFC3339, from); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "Invalid format of \"from\" parameter.", err), - ) - return - } - - if t, err = time.Parse(time.RFC3339, to); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "Invalid format of \"to\" parameter.", err), - ) - return - } - - if p, err = strconv.Atoi(page); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "Invalid format of \"page\" parameter.", err), - ) - return - } - - if pp, err = strconv.Atoi(perPage); err != nil { - gb.ResponseWithError( - c, - e.NewErrorWithMessage(e.ErrorCodeInvalidRequest, "Invalid format of \"per_page\" parameter.", err), - ) - return - } - - // Search deployments with parameters. - var ( - ds []*ent.Approval - ) - v, _ := c.Get(gb.KeyUser) u := v.(*ent.User) - if ds, err = s.i.SearchApprovals(ctx, u, ss, f.UTC(), t.UTC(), p, pp); err != nil { - s.log.Check(gb.GetZapLogLevel(err), "Failed to search deployments.").Write(zap.Error(err)) + if rvs, err = s.i.SearchReviews(ctx, u); err != nil { + s.log.Check(gb.GetZapLogLevel(err), "Failed to search reviews.").Write(zap.Error(err)) gb.ResponseWithError(c, err) return } - gb.Response(c, http.StatusOK, ds) + gb.Response(c, http.StatusOK, rvs) } diff --git a/internal/server/api/v1/stream/events.go b/internal/server/api/v1/stream/events.go index 681daf4b..9ba2873f 100644 --- a/internal/server/api/v1/stream/events.go +++ b/internal/server/api/v1/stream/events.go @@ -21,7 +21,7 @@ import ( gb "github.com/gitploy-io/gitploy/internal/server/global" ) -// GetEvents streams events of deployment, or approval. +// GetEvents streams events of deployment, or review. func (s *Stream) GetEvents(c *gin.Context) { ctx := c.Request.Context() @@ -109,13 +109,13 @@ func (s *Stream) hasPermForEvent(ctx context.Context, u *ent.User, e *ent.Event) return true, nil } - if e.Kind == event.KindApproval { - a, err := s.i.FindApprovalByID(ctx, e.ApprovalID) + if e.Kind == event.KindReview { + rv, err := s.i.FindReviewByID(ctx, e.ReviewID) if err != nil { return false, err } - d, err := s.i.FindDeploymentByID(ctx, a.DeploymentID) + d, err := s.i.FindDeploymentByID(ctx, rv.DeploymentID) if err != nil { return false, err } @@ -129,7 +129,7 @@ func (s *Stream) hasPermForEvent(ctx context.Context, u *ent.User, e *ent.Event) return true, nil } - return false, fmt.Errorf("The type of event is not \"deployment\" or \"approval\".") + return false, fmt.Errorf("The type of event is not \"deployment\" or \"review\".") } func randstr() string { diff --git a/internal/server/api/v1/stream/interface.go b/internal/server/api/v1/stream/interface.go index 08212c9a..5f10c05e 100644 --- a/internal/server/api/v1/stream/interface.go +++ b/internal/server/api/v1/stream/interface.go @@ -11,7 +11,7 @@ type ( SubscribeEvent(fn func(e *ent.Event)) error UnsubscribeEvent(fn func(e *ent.Event)) error FindDeploymentByID(ctx context.Context, id int) (*ent.Deployment, error) - FindApprovalByID(ctx context.Context, id int) (*ent.Approval, error) + FindReviewByID(ctx context.Context, id int) (*ent.Review, error) FindPermOfRepo(ctx context.Context, r *ent.Repo, u *ent.User) (*ent.Perm, error) } ) diff --git a/internal/server/router.go b/internal/server/router.go index 1c86321a..2b292776 100644 --- a/internal/server/router.go +++ b/internal/server/router.go @@ -93,8 +93,8 @@ func NewRouter(c *RouterConfig) *gin.Engine { r := gin.New() r.Use(cors.New(cors.Config{ - // AllowOrigins: []string{"http://localhost:3000"}, - AllowAllOrigins: true, + AllowOrigins: []string{"http://localhost:3000"}, + // AllowAllOrigins: true, AllowCredentials: true, AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"}, AllowHeaders: []string{"Origin", "Authorization", "Accept", "Content-Length", "Content-Type"}, @@ -147,12 +147,9 @@ func NewRouter(c *RouterConfig) *gin.Engine { repov1.PATCH("/:namespace/:name/deployments/:number", rm.RepoWritePerm(), r.UpdateDeployment) repov1.GET("/:namespace/:name/deployments/:number/changes", rm.RepoReadPerm(), r.ListDeploymentChanges) repov1.POST("/:namespace/:name/deployments/:number/rollback", rm.RepoWritePerm(), r.RollbackDeployment) - repov1.GET("/:namespace/:name/deployments/:number/approvals", rm.RepoReadPerm(), r.ListApprovals) - repov1.POST("/:namespace/:name/deployments/:number/approvals", rm.RepoReadPerm(), r.CreateApproval) - repov1.GET("/:namespace/:name/deployments/:number/approval", rm.RepoReadPerm(), r.GetMyApproval) - repov1.PATCH("/:namespace/:name/deployments/:number/approval", rm.RepoReadPerm(), r.UpdateMyApproval) - repov1.GET("/:namespace/:name/approvals/:aid", rm.RepoReadPerm(), r.GetApproval) - repov1.DELETE("/:namespace/:name/approvals/:aid", rm.RepoReadPerm(), r.DeleteApproval) + repov1.GET("/:namespace/:name/deployments/:number/reviews", rm.RepoReadPerm(), r.ListReviews) + repov1.GET("/:namespace/:name/deployments/:number/review", rm.RepoReadPerm(), r.GetUserReview) + repov1.PATCH("/:namespace/:name/deployments/:number/review", rm.RepoReadPerm(), r.UpdateUserReview) repov1.GET("/:namespace/:name/locks", rm.RepoReadPerm(), r.ListLocks) repov1.POST("/:namespace/:name/locks", rm.RepoWritePerm(), r.CreateLock) repov1.PATCH("/:namespace/:name/locks/:lockID", rm.RepoWritePerm(), r.UpdateLock) @@ -183,7 +180,7 @@ func NewRouter(c *RouterConfig) *gin.Engine { { s := search.NewSearch(c.Interactor) searchv1.GET("/deployments", s.SearchDeployments) - searchv1.GET("/approvals", s.SearchApprovals) + searchv1.GET("/reviews", s.SearchAssignedReviews) } licensev1 := v1.Group("/license") diff --git a/internal/server/slack/deploy.go b/internal/server/slack/deploy.go index 674358b4..7d1bc9de 100644 --- a/internal/server/slack/deploy.go +++ b/internal/server/slack/deploy.go @@ -316,33 +316,6 @@ func (s *Slack) interactDeploy(c *gin.Context) { s.log.Error("It has failed to create the event.", zap.Error(err)) } - if env.IsApprovalEabled() { - for _, id := range sm.ApproverIDs { - i, err := strconv.ParseInt(id, 10, 64) - if err != nil { - s.log.Error("It has failed to parse the ID of approval.", zap.Error(err)) - continue - } - - a, err := s.i.CreateApproval(ctx, &ent.Approval{ - UserID: i, - DeploymentID: d.ID, - }) - if err != nil { - s.log.Error("It has failed to create a new approval.", zap.Error(err)) - continue - } - - if _, err := s.i.CreateEvent(ctx, &ent.Event{ - Kind: event.KindDeployment, - Type: event.TypeCreated, - ApprovalID: a.ID, - }); err != nil { - s.log.Error("It has failed to create the event.", zap.Error(err)) - } - } - } - c.Status(http.StatusOK) } diff --git a/internal/server/slack/interface.go b/internal/server/slack/interface.go index 4afd5405..dd9ec5eb 100644 --- a/internal/server/slack/interface.go +++ b/internal/server/slack/interface.go @@ -32,8 +32,6 @@ type ( Deploy(ctx context.Context, u *ent.User, re *ent.Repo, d *ent.Deployment, env *vo.Env) (*ent.Deployment, error) GetConfig(ctx context.Context, u *ent.User, r *ent.Repo) (*vo.Config, error) - CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) - ListLocksOfRepo(ctx context.Context, r *ent.Repo) ([]*ent.Lock, error) FindLockOfRepoByEnv(ctx context.Context, r *ent.Repo, env string) (*ent.Lock, error) HasLockOfRepoForEnv(ctx context.Context, r *ent.Repo, env string) (bool, error) diff --git a/internal/server/slack/mock/interactor.go b/internal/server/slack/mock/interactor.go index 8b1c1923..627a0353 100644 --- a/internal/server/slack/mock/interactor.go +++ b/internal/server/slack/mock/interactor.go @@ -50,21 +50,6 @@ func (mr *MockInteractorMockRecorder) CheckNotificationRecordOfEvent(ctx, e inte return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CheckNotificationRecordOfEvent", reflect.TypeOf((*MockInteractor)(nil).CheckNotificationRecordOfEvent), ctx, e) } -// CreateApproval mocks base method. -func (m *MockInteractor) CreateApproval(ctx context.Context, a *ent.Approval) (*ent.Approval, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateApproval", ctx, a) - ret0, _ := ret[0].(*ent.Approval) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// CreateApproval indicates an expected call of CreateApproval. -func (mr *MockInteractorMockRecorder) CreateApproval(ctx, a interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateApproval", reflect.TypeOf((*MockInteractor)(nil).CreateApproval), ctx, a) -} - // CreateCallback mocks base method. func (m *MockInteractor) CreateCallback(ctx context.Context, cb *ent.Callback) (*ent.Callback, error) { m.ctrl.T.Helper() diff --git a/internal/server/slack/notification.go b/internal/server/slack/notification.go index d9fde411..c2f4ecda 100644 --- a/internal/server/slack/notification.go +++ b/internal/server/slack/notification.go @@ -8,9 +8,9 @@ import ( "go.uber.org/zap" "github.com/gitploy-io/gitploy/ent" - "github.com/gitploy-io/gitploy/ent/approval" "github.com/gitploy-io/gitploy/ent/deployment" "github.com/gitploy-io/gitploy/ent/event" + "github.com/gitploy-io/gitploy/ent/review" ) const ( @@ -30,8 +30,8 @@ func (s *Slack) Notify(ctx context.Context, e *ent.Event) { s.notifyDeploymentEvent(ctx, e) } - if e.Kind == event.KindApproval { - s.notifyApprovalEvent(ctx, e) + if e.Kind == event.KindReview { + s.notifyReviewEvent(ctx, e) } } @@ -82,18 +82,18 @@ func (s *Slack) notifyDeploymentEvent(ctx context.Context, e *ent.Event) { } } -func (s *Slack) notifyApprovalEvent(ctx context.Context, e *ent.Event) { +func (s *Slack) notifyReviewEvent(ctx context.Context, e *ent.Event) { var ( - a *ent.Approval + r *ent.Review d *ent.Deployment ) - if a = e.Edges.Approval; a == nil { - s.log.Error("The eager loading of approval has failed.") + if r = e.Edges.Review; r == nil { + s.log.Error("The eager loading of review has failed.") return } - if d = a.Edges.Deployment; d == nil { + if d = r.Edges.Deployment; d == nil { s.log.Error("The eager loading of deployment has failed.") return } @@ -101,13 +101,13 @@ func (s *Slack) notifyApprovalEvent(ctx context.Context, e *ent.Event) { if e.Type == event.TypeCreated { option := slack.MsgOptionAttachments(slack.Attachment{ Color: colorPurple, - Pretext: "*Approval Requested*", - Text: fmt.Sprintf("%s has requested the approval for the deployment <%s|#%d> of `%s`.", d.Edges.User.Login, s.buildDeploymentLink(d.Edges.Repo, d), d.Number, d.Edges.Repo.GetFullName()), + Pretext: "*Review Requested*", + Text: fmt.Sprintf("%s requested the review for the deployment <%s|#%d> of `%s`.", d.Edges.User.Login, s.buildDeploymentLink(d.Edges.Repo, d), d.Number, d.Edges.Repo.GetFullName()), }) - recipient, err := s.i.FindUserByID(ctx, a.Edges.User.ID) + recipient, err := s.i.FindUserByID(ctx, r.Edges.User.ID) if err != nil { - s.log.Error("It has failed to find the recipient of the approval.", zap.Error(err)) + s.log.Error("It has failed to find the recipient of the review.", zap.Error(err)) return } if recipient.Edges.ChatUser == nil { @@ -124,14 +124,14 @@ func (s *Slack) notifyApprovalEvent(ctx context.Context, e *ent.Event) { if e.Type == event.TypeUpdated { option := slack.MsgOptionAttachments(slack.Attachment{ - Color: mapApprovalStatusToColor(a.Status), - Pretext: "*Approval Responded*", - Text: fmt.Sprintf("%s has *%s* for the deployment <%s|#%d> of `%s`.", a.Edges.User.Login, a.Status, s.buildDeploymentLink(d.Edges.Repo, d), d.Number, d.Edges.Repo.GetFullName()), + Color: mapReviewStatusToColor(r.Status), + Pretext: "*Review Responded*", + Text: fmt.Sprintf("%s *%s* the deployment <%s|#%d> of `%s`.", r.Edges.User.Login, r.Status, s.buildDeploymentLink(d.Edges.Repo, d), d.Number, d.Edges.Repo.GetFullName()), }) requester, err := s.i.FindUserByID(ctx, d.Edges.User.ID) if err != nil { - s.log.Error("It has failed to find the requester of the approval.", zap.Error(err)) + s.log.Error("It has failed to find the requester of the review.", zap.Error(err)) return } if requester.Edges.ChatUser == nil { @@ -168,13 +168,13 @@ func mapDeploymentStatusToColor(status deployment.Status) string { } } -func mapApprovalStatusToColor(status approval.Status) string { +func mapReviewStatusToColor(status review.Status) string { switch status { - case approval.StatusPending: + case review.StatusPending: return colorGray - case approval.StatusApproved: + case review.StatusApproved: return colorGreen - case approval.StatusDeclined: + case review.StatusRejected: return colorRed default: return colorGray diff --git a/internal/server/slack/rollback.go b/internal/server/slack/rollback.go index 2848e22d..9b29dc3e 100644 --- a/internal/server/slack/rollback.go +++ b/internal/server/slack/rollback.go @@ -254,33 +254,6 @@ func (s *Slack) interactRollback(c *gin.Context) { s.log.Error("It has failed to create the event.", zap.Error(err)) } - if env.IsApprovalEabled() { - for _, id := range sm.ApproverIDs { - i, err := strconv.ParseInt(id, 10, 64) - if err != nil { - s.log.Error("It has failed to parse the ID of approver.", zap.Error(err)) - continue - } - - a, err := s.i.CreateApproval(ctx, &ent.Approval{ - UserID: i, - DeploymentID: d.ID, - }) - if err != nil { - s.log.Error("It has failed to create a new approval.", zap.Error(err)) - continue - } - - if _, err := s.i.CreateEvent(ctx, &ent.Event{ - Kind: event.KindDeployment, - Type: event.TypeCreated, - ApprovalID: a.ID, - }); err != nil { - s.log.Error("It has failed to create the event.", zap.Error(err)) - } - } - } - c.Status(http.StatusOK) } diff --git a/openapi/v1.yaml b/openapi/v1.yaml index 88dfc822..a6f38197 100644 --- a/openapi/v1.yaml +++ b/openapi/v1.yaml @@ -736,11 +736,11 @@ paths: $ref: '#/components/responses/422UnprocessableEntity' '500': $ref: '#/components/responses/500InternalError' - /repos/{namespace}/{name}/deployments/{number}/approvals: + /repos/{namespace}/{name}/deployments/{number}/reviews: get: tags: - Repo - summary: List approvals for the deployment. + summary: List reviews of the deployment. parameters: - in: path name: namespace @@ -760,11 +760,11 @@ paths: description: The deployment number. responses: '200': - description: List of approval + description: List of reviews. content: application/json: schema: - $ref: '#/components/schemas/Approvals' + $ref: '#/components/schemas/Reviews' '401': $ref: '#/components/responses/401Unauthorized' '402': @@ -773,61 +773,11 @@ paths: $ref: '#/components/responses/403Forbidden' '500': $ref: '#/components/responses/500InternalError' - post: - tags: - - Repo - summary: Create a new approval. - parameters: - - in: path - name: namespace - required: true - schema: - type: string - - in: path - name: name - required: true - schema: - type: string - - in: path - name: number - required: true - schema: - type: integer - description: The deployment number. - requestBody: - content: - application/json: - schema: - type: object - properties: - user_id: - type: string - required: - - user_id - responses: - '201': - description: Approval created. - content: - application/json: - schema: - $ref: '#/components/schemas/Approval' - '401': - $ref: '#/components/responses/401Unauthorized' - '402': - $ref: '#/components/responses/402PaymentRequired' - '403': - $ref: '#/components/responses/403Forbidden' - '404': - $ref: '#/components/responses/404NotFound' - '422': - $ref: '#/components/responses/422UnprocessableEntity' - '500': - $ref: '#/components/responses/500InternalError' - /repos/{namespace}/{name}/deployments/{number}/approval: + /repos/{namespace}/{name}/deployments/{number}/review: get: tags: - Repo - summary: Get the approval of user for the deployment. + summary: Get the review of the user. parameters: - in: path name: namespace @@ -847,25 +797,25 @@ paths: description: The deployment number. responses: '200': - description: Approval + description: Return the review. content: application/json: schema: - $ref: '#/components/schemas/Approval' + $ref: '#/components/schemas/Review' '401': $ref: '#/components/responses/401Unauthorized' '402': $ref: '#/components/responses/402PaymentRequired' '403': $ref: '#/components/responses/403Forbidden' - '404': + '404': $ref: '#/components/responses/404NotFound' '500': $ref: '#/components/responses/500InternalError' patch: tags: - Repo - summary: Approve (or Decline) for the approval. + summary: Update the review of the user if it exist. parameters: - in: path name: namespace @@ -891,98 +841,18 @@ paths: properties: status: type: string + enum: + - approved + - rejected required: - status responses: '200': - description: Approval - content: - application/json: - schema: - $ref: '#/components/schemas/Approval' - '400': - $ref: '#/components/responses/400BadRequest' - '401': - $ref: '#/components/responses/401Unauthorized' - '402': - $ref: '#/components/responses/402PaymentRequired' - '403': - $ref: '#/components/responses/403Forbidden' - '404': - $ref: '#/components/responses/404NotFound' - '500': - $ref: '#/components/responses/500InternalError' - # Only permitted users can access to Approval API. - # To be under repository protects to access without permissions. - /repos/{namespace}/{name}/approvals/{aid}: - get: - tags: - - Repo - summary: Get the approval. - parameters: - - in: path - name: namespace - required: true - schema: - type: string - - in: path - name: name - required: true - schema: - type: string - - in: path - name: aid - required: true - schema: - type: number - description: The apporval id. - responses: - '200': - description: Approval + description: Return the review. content: application/json: schema: - $ref: '#/components/schemas/Approval' - '401': - $ref: '#/components/responses/401Unauthorized' - '402': - $ref: '#/components/responses/402PaymentRequired' - '403': - $ref: '#/components/responses/403Forbidden' - '404': - $ref: '#/components/responses/404NotFound' - '500': - $ref: '#/components/responses/500InternalError' - delete: - tags: - - Repo - summary: Delete the approval. - parameters: - - in: path - name: namespace - required: true - schema: - type: string - - in: path - name: name - required: true - schema: - type: string - - in: path - name: number - required: true - schema: - type: integer - description: The deployment number. - - in: path - name: aid - required: true - schema: - type: number - description: The apporval id. - responses: - '200': - description: Approval deleted + $ref: '#/components/schemas/Review' '401': $ref: '#/components/responses/401Unauthorized' '402': @@ -991,6 +861,8 @@ paths: $ref: '#/components/responses/403Forbidden' '404': $ref: '#/components/responses/404NotFound' + '422': + $ref: '#/components/responses/422UnprocessableEntity' '500': $ref: '#/components/responses/500InternalError' /repos/{namespace}/{name}/locks: @@ -1427,45 +1299,11 @@ paths: $ref: '#/components/responses/401Unauthorized' '500': $ref: '#/components/responses/500InternalError' - /search/approvals: + /search/reviews: get: tags: - Search - summary: Search assigned approvals. - parameters: - - in: query - name: statuses - required: false - schema: - type: string - description: > - Status list comma separated. - - in: query - name: from - required: false - schema: - type: string - format: date-time - description: Begin of created_at - - in: query - name: to - required: false - schema: - type: string - format: date-time - description: End of created_at - - in: query - name: page - schema: - type: integer - default: 1 - description: The page number - - in: query - name: per_page - schema: - type: integer - default: 30 - description: The number per page + summary: Search assigned reviews. responses: '200': description: Returns deployments which matches to conditions. @@ -1488,7 +1326,7 @@ paths: summary: Subscribes streaming event responses: '200': - description: Returns events for deployments and approvals + description: Returns events for deployments and reviews content: text/event-stream: schema: @@ -1522,7 +1360,7 @@ paths: type: string enum: - deployment - - approval + - review type: type: string enum: @@ -1539,8 +1377,8 @@ paths: properties: deployment: $ref: '#/components/schemas/Deployment' - approval: - $ref: '#/components/schemas/Approval' + review: + $ref: '#/components/schemas/Review' /sync: post: tags: @@ -1800,10 +1638,6 @@ components: type: boolean is_rollback: type: boolean - is_approval_enabled: - type: boolean - required_approval_count: - type: number created_at: type: string updated_at: @@ -1827,8 +1661,6 @@ components: - status - production_environment - is_rollback - - is_approval_enabled - - required_approval_count - created_at - updated_at DeploymentStatus: @@ -1903,16 +1735,18 @@ components: type: string production_environment: type: boolean - approval: + review: type: object properties: enabled: type: boolean - required_count: - type: number + reviewers: + type: array + items: + type: string required: - enabled - - required_count + - reviewers required: - name - task @@ -1920,11 +1754,11 @@ components: - auto_merge - payload - production_environment - Approvals: + Reviews: type: array items: - $ref: '#/components/schemas/Approval' - Approval: + $ref: '#/components/schemas/Review' + Review: type: object properties: id: @@ -1933,7 +1767,7 @@ components: type: string enum: - pending - - declined + - rejected - approved created_at: type: string diff --git a/pkg/e/code.go b/pkg/e/code.go index f96a4795..419b9217 100644 --- a/pkg/e/code.go +++ b/pkg/e/code.go @@ -16,7 +16,7 @@ const ( // ErrorCodeDeploymentLocked is when the environment is locked. ErrorCodeDeploymentLocked ErrorCode = "deployment_locked" // ErrorCodeDeploymentUnapproved is when the deployment is not approved. - ErrorCodeDeploymentUnapproved ErrorCode = "deployment_unapproved" + ErrorCodeDeploymentNotApproved ErrorCode = "deployment_not_approved" // ErrorCodeDeploymentUndeployable is that the merge conflict occurs or a commit status has failed. ErrorCodeDeploymentUndeployable ErrorCode = "deployment_undeployable" diff --git a/pkg/e/trans.go b/pkg/e/trans.go index d1b42a85..411f6f47 100644 --- a/pkg/e/trans.go +++ b/pkg/e/trans.go @@ -7,7 +7,7 @@ var messages = map[ErrorCode]string{ ErrorCodeDeploymentConflict: "The conflict occurs, please retry.", ErrorCodeDeploymentInvalid: "The validation has failed.", ErrorCodeDeploymentLocked: "The environment is locked.", - ErrorCodeDeploymentUnapproved: "The deployment is not approved", + ErrorCodeDeploymentNotApproved: "The deployment is not approved", ErrorCodeDeploymentUndeployable: "There is merge conflict or a commit status check failed.", ErrorCodeLicenseDecode: "Decoding the license is failed.", ErrorCodeLicenseRequired: "The license is required.", @@ -32,7 +32,7 @@ var httpCodes = map[ErrorCode]int{ ErrorCodeDeploymentConflict: http.StatusUnprocessableEntity, ErrorCodeDeploymentInvalid: http.StatusUnprocessableEntity, ErrorCodeDeploymentLocked: http.StatusUnprocessableEntity, - ErrorCodeDeploymentUnapproved: http.StatusUnprocessableEntity, + ErrorCodeDeploymentNotApproved: http.StatusUnprocessableEntity, ErrorCodeDeploymentUndeployable: http.StatusUnprocessableEntity, ErrorCodeLicenseDecode: http.StatusUnprocessableEntity, ErrorCodeLicenseRequired: http.StatusPaymentRequired, diff --git a/ui/src/apis/approval.ts b/ui/src/apis/approval.ts deleted file mode 100644 index bac496be..00000000 --- a/ui/src/apis/approval.ts +++ /dev/null @@ -1,199 +0,0 @@ -import { StatusCodes } from 'http-status-codes' - -import { instance, headers } from './setting' -import { _fetch } from "./_base" -import { UserData, mapDataToUser } from "./user" -import { DeploymentData, mapDataToDeployment } from "./deployment" -import { - User, - Deployment, - Approval, - ApprovalStatus, - HttpNotFoundError, - HttpUnprocessableEntityError - } from '../models' - -export interface ApprovalData { - id: number, - status: string - created_at: string - updated_at: string - edges: { - user: UserData, - deployment: DeploymentData - } -} - -// eslint-disable-next-line -export const mapDataToApproval = (data: ApprovalData): Approval => { - let user: User | null = null - let deployment: Deployment | null = null - - if ("user" in data.edges) { - user = mapDataToUser(data.edges.user) - } - - if ("deployment" in data.edges) { - deployment = mapDataToDeployment(data.edges.deployment) - } - - return { - id: data.id, - status: mapDataToApprovalStatus(data.status), - createdAt: new Date(data.created_at), - updatedAt: new Date(data.updated_at), - user, - deployment - } -} - -const mapDataToApprovalStatus = (status: string): ApprovalStatus => { - switch (status) { - case "pending": - return ApprovalStatus.Pending - case "approved": - return ApprovalStatus.Approved - case "declined": - return ApprovalStatus.Declined - default: - return ApprovalStatus.Pending - } -} - -function mapApprovalStatusToString(status: ApprovalStatus): string { - switch (status) { - case ApprovalStatus.Pending: - return "pending" - case ApprovalStatus.Approved: - return "approved" - case ApprovalStatus.Declined: - return "declined" - default: - return "pending" - } -} - -export const searchApprovals = async (statuses: ApprovalStatus[], from?: Date, to?: Date, page = 1, perPage = 30): Promise => { - const ss: string[] = [] - statuses.forEach((status) => { - ss.push(mapApprovalStatusToString(status)) - }) - - const fromParam = (from)? `from=${from.toISOString()}` : "" - const toParam = (to)? `to=${to.toISOString()}` : "" - - const approvals: Approval[] = await _fetch(`${instance}/api/v1/search/approvals?statuses=${ss.join(",")}&${fromParam}&${toParam}&page=${page}&per_page=${perPage}`, { - credentials: "same-origin", - headers, - }) - .then(res => res.json()) - .then(data => data.map((d:any): Approval => mapDataToApproval(d))) - - return approvals -} - -export const listApprovals = async (namespace: string, name: string, number: number): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approvals`, { - credentials: "same-origin", - headers, - }) - - if (res.status === StatusCodes.NOT_FOUND) { - throw new HttpNotFoundError("There is no such a deployment.") - } - - const approvals: Approval[] = await res.json() - .then(data => data.map((d:any): Approval => mapDataToApproval(d))) - - return approvals -} - -export const createApproval = async (namespace: string, name: string, number: number, userId: number): Promise => { - const body = { - user_id: userId - } - const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approvals`, { - credentials: "same-origin", - headers, - method: "POST", - body: JSON.stringify(body), - }) - - if (res.status === StatusCodes.UNPROCESSABLE_ENTITY) { - const message = await res.json().then(data => data.message) - throw new HttpUnprocessableEntityError(message) - } - - const approval: Approval = await res.json() - .then(data => mapDataToApproval(data)) - - return approval -} - -export const deleteApproval = async (namespace: string, name: string, id: number): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/approvals/${id}`, { - credentials: "same-origin", - headers, - method: "DELETE", - }) - - if (res.status === StatusCodes.NOT_FOUND) { - const message = await res.json().then(data => data.message) - throw new HttpUnprocessableEntityError(message) - } -} - -export const getMyApproval = async (namespace: string, name: string, number: number): Promise => { - const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, { - credentials: "same-origin", - headers, - }) - - if (res.status === StatusCodes.NOT_FOUND) { - throw new HttpNotFoundError("There is no requested approval.") - } - - const approval = await res.json() - .then(data => mapDataToApproval(data)) - return approval -} - -export const setApprovalApproved = async (namespace: string, name: string, number: number): Promise => { - const body = { - status: ApprovalStatus.Approved.toString(), - } - const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, { - credentials: "same-origin", - headers, - method: "PATCH", - body: JSON.stringify(body), - }) - - if (res.status === StatusCodes.NOT_FOUND) { - throw new HttpNotFoundError("There is no requested approval.") - } - - const approval = await res.json() - .then(data => mapDataToApproval(data)) - return approval -} - -export const setApprovalDeclined = async (namespace: string, name: string, number: number): Promise => { - const body = { - status: ApprovalStatus.Declined.toString(), - } - const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/approval`, { - credentials: "same-origin", - headers, - method: "PATCH", - body: JSON.stringify(body), - }) - - if (res.status === StatusCodes.NOT_FOUND) { - throw new HttpNotFoundError("There is no requested approval.") - } - - const approval = await res.json() - .then(data => mapDataToApproval(data)) - return approval -} \ No newline at end of file diff --git a/ui/src/apis/config.ts b/ui/src/apis/config.ts index 2eb431f7..6510a166 100644 --- a/ui/src/apis/config.ts +++ b/ui/src/apis/config.ts @@ -2,7 +2,7 @@ import { StatusCodes } from 'http-status-codes' import { instance, headers } from './setting' import { _fetch } from "./_base" -import { Config, Env, EnvApproval, HttpNotFoundError } from '../models' +import { Config, Env, HttpNotFoundError } from '../models' interface ConfigData { envs: EnvData[] @@ -11,27 +11,20 @@ interface ConfigData { interface EnvData { name: string required_contexts?: string[] - approval?: { + review?: { enabled: boolean - required_count: number + reviewers: string[] } } const mapDataToConfig = (data: ConfigData): Config => { const envs: Env[] = data.envs.map((e: EnvData) => { - let approval: EnvApproval | undefined - - if (e.approval) { - approval = { - enabled: e.approval.enabled, - required_count: e.approval.required_count, - } - } + const { review } = e return { name: e.name, requiredContexts: e.required_contexts, - approval + review, } }) diff --git a/ui/src/apis/deployment.ts b/ui/src/apis/deployment.ts index c95e1f41..0216da42 100644 --- a/ui/src/apis/deployment.ts +++ b/ui/src/apis/deployment.ts @@ -28,8 +28,6 @@ export interface DeploymentData { status: string uid: number is_rollback: boolean - is_approval_enabled: boolean - required_approval_count: number auto_deploy: boolean created_at: string updated_at: string @@ -77,8 +75,6 @@ export const mapDataToDeployment = (data: DeploymentData): Deployment => { status: mapDeploymentStatusEnum(data.status), uid: data.uid, isRollback: data.is_rollback, - isApprovalEanbled: data.is_approval_enabled, - requiredApprovalCount: data.required_approval_count, createdAt: new Date(data.created_at), updatedAt: new Date(data.updated_at), deployer, diff --git a/ui/src/apis/events.ts b/ui/src/apis/events.ts index ce2c68bd..4737c8c8 100644 --- a/ui/src/apis/events.ts +++ b/ui/src/apis/events.ts @@ -1,8 +1,8 @@ import { instance } from './setting' import { DeploymentData, mapDataToDeployment } from "./deployment" -import { ApprovalData, mapDataToApproval } from "./approval" -import { Deployment, Approval, Event, EventKindEnum, EventTypeEnum } from "../models" +import { ReviewData, mapDataToReview } from "./review" +import { Deployment, Review, Event, EventKindEnum, EventTypeEnum } from "../models" interface EventData { id: number @@ -11,7 +11,7 @@ interface EventData { deleted_id: number edges: { deployment?: DeploymentData - approval?: ApprovalData + review?: ReviewData } } @@ -19,14 +19,14 @@ const mapDataToEvent = (data: EventData): Event => { let kind: EventKindEnum let type: EventTypeEnum let deployment: Deployment | undefined - let approval: Approval | undefined + let review: Review | undefined switch (data.kind) { case "deployment": kind = EventKindEnum.Deployment break - case "approval": - kind = EventKindEnum.Approval + case "review": + kind = EventKindEnum.Review break default: kind = EventKindEnum.Deployment @@ -50,8 +50,8 @@ const mapDataToEvent = (data: EventData): Event => { deployment = mapDataToDeployment(data.edges.deployment) } - if (data.edges.approval) { - approval = mapDataToApproval(data.edges.approval) + if (data.edges.review) { + review = mapDataToReview(data.edges.review) } return { @@ -60,7 +60,7 @@ const mapDataToEvent = (data: EventData): Event => { type, deletedId: data.deleted_id, deployment, - approval + review } } diff --git a/ui/src/apis/index.ts b/ui/src/apis/index.ts index b961c367..e3e49b5a 100644 --- a/ui/src/apis/index.ts +++ b/ui/src/apis/index.ts @@ -24,15 +24,13 @@ import { listBranches, getBranch } from './branch' import { listTags, getTag } from './tag' import { listUsers, updateUser, deleteUser, getMe, getRateLimit } from "./user" import { checkSlack } from "./chat" -import { - searchApprovals, - listApprovals, - getMyApproval, - createApproval, - deleteApproval, - setApprovalApproved, - setApprovalDeclined -} from "./approval" +import { + searchReviews, + listReviews, + getUserReview, + approveReview, + rejectReview, +} from "./review" import { listLocks, lock, @@ -73,13 +71,11 @@ export { getMe, getRateLimit, checkSlack, - searchApprovals, - listApprovals, - createApproval, - deleteApproval, - getMyApproval, - setApprovalApproved, - setApprovalDeclined, + searchReviews, + listReviews, + getUserReview, + approveReview, + rejectReview, listLocks, lock, unlock, diff --git a/ui/src/apis/review.ts b/ui/src/apis/review.ts new file mode 100644 index 00000000..d66326af --- /dev/null +++ b/ui/src/apis/review.ts @@ -0,0 +1,141 @@ +import { StatusCodes } from 'http-status-codes' + +import { instance, headers } from './setting' +import { _fetch } from "./_base" +import { UserData, mapDataToUser } from "./user" +import { DeploymentData, mapDataToDeployment } from "./deployment" +import { + User, + Deployment, + Review, + ReviewStatusEnum, + HttpNotFoundError, + } from '../models' + +export interface ReviewData { + id: number, + status: string + created_at: string + updated_at: string + edges: { + user: UserData, + deployment: DeploymentData + } +} + +// eslint-disable-next-line +export const mapDataToReview = (data: ReviewData): Review => { + let user: User | undefined + let deployment: Deployment | undefined + + if ("user" in data.edges) { + user = mapDataToUser(data.edges.user) + } + + if ("deployment" in data.edges) { + deployment = mapDataToDeployment(data.edges.deployment) + } + + return { + id: data.id, + status: mapDataToReviewStatus(data.status), + createdAt: new Date(data.created_at), + updatedAt: new Date(data.updated_at), + user, + deployment + } +} + +const mapDataToReviewStatus = (status: string): ReviewStatusEnum => { + switch (status) { + case "pending": + return ReviewStatusEnum.Pending + case "approved": + return ReviewStatusEnum.Approved + case "rejected": + return ReviewStatusEnum.Rejected + default: + return ReviewStatusEnum.Pending + } +} + +export const searchReviews = async (): Promise => { + const reviews: Review[] = await _fetch(`${instance}/api/v1/search/reviews`, { + credentials: "same-origin", + headers, + }) + .then(res => res.json()) + .then(data => data.map((d:any): Review => mapDataToReview(d))) + + return reviews +} + +export const listReviews = async (namespace: string, name: string, number: number): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/reviews`, { + credentials: "same-origin", + headers, + }) + + const reviews: Review[] = await res.json() + .then(data => data.map((d:any): Review => mapDataToReview(d))) + + return reviews +} + +export const getUserReview = async (namespace: string, name: string, number: number): Promise => { + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/review`, { + credentials: "same-origin", + headers, + }) + + if (res.status === StatusCodes.NOT_FOUND) { + const { message } = await res.json() + throw new HttpNotFoundError(message) + } + + const review = await res.json() + .then(data => mapDataToReview(data)) + return review +} + +export const approveReview = async (namespace: string, name: string, number: number): Promise => { + const body = { + status: "approved", + } + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/review`, { + credentials: "same-origin", + headers, + method: "PATCH", + body: JSON.stringify(body), + }) + + if (res.status === StatusCodes.NOT_FOUND) { + const { message } = await res.json() + throw new HttpNotFoundError(message) + } + + const review = await res.json() + .then(data => mapDataToReview(data)) + return review +} + +export const rejectReview = async (namespace: string, name: string, number: number): Promise => { + const body = { + status: "rejected", + } + const res = await _fetch(`${instance}/api/v1/repos/${namespace}/${name}/deployments/${number}/review`, { + credentials: "same-origin", + headers, + method: "PATCH", + body: JSON.stringify(body), + }) + + if (res.status === StatusCodes.NOT_FOUND) { + const { message } = await res.json() + throw new HttpNotFoundError(message) + } + + const review = await res.json() + .then(data => mapDataToReview(data)) + return review +} \ No newline at end of file diff --git a/ui/src/components/ApproversSelector/ApprovalList.tsx b/ui/src/components/ApproversSelector/ApprovalList.tsx deleted file mode 100644 index cb799ec8..00000000 --- a/ui/src/components/ApproversSelector/ApprovalList.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { Avatar } from "antd" -import { CheckOutlined, CloseOutlined } from "@ant-design/icons" - -import { Approval, ApprovalStatus } from "../../models" - -export interface ApprovalListProps { - approvals: Approval[] -} - -export default function ApprovalList(props: ApprovalListProps): JSX.Element { - return ( -
- {props.approvals.map((a, idx) => { - const user = a.user - const avatar = (user !== null)? - {user.login} : - U - const icon = mapApprovalStatusToIcon(a.status) - - return ( -
- {icon}  - {avatar} -
) - })} -
- ) -} - -function mapApprovalStatusToIcon(status: ApprovalStatus): JSX.Element { - switch (status) { - case ApprovalStatus.Pending: - return - case ApprovalStatus.Approved: - return - case ApprovalStatus.Declined: - return - default: - return - } -} \ No newline at end of file diff --git a/ui/src/components/ApproversSelector/ApproversSearch.tsx b/ui/src/components/ApproversSelector/ApproversSearch.tsx deleted file mode 100644 index b355bc34..00000000 --- a/ui/src/components/ApproversSelector/ApproversSearch.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import React from "react" -import { Select, SelectProps, Avatar, Spin } from "antd" -import { CheckOutlined } from "@ant-design/icons" -import debounce from "lodash.debounce" - -import { User } from "../../models" - -export interface ApproversSelectProps extends SelectProps{ - approvers: User[] - candidates: User[] - // The type of parameter have to be string - // because candidates could be dynamically changed with search. - onSelectCandidate(id: string): void - onSearchCandidates(login: string): void -} - -export default function ApproversSelect(props: ApproversSelectProps): JSX.Element { - const [ searching, setSearching ] = React.useState(false) - - // Clone Select props only - // https://stackoverflow.com/questions/34698905/how-can-i-clone-a-javascript-object-except-for-one-key - const {candidates, onSelectCandidate, onSearchCandidates, ...selectProps} = props // eslint-disable-line - - // debounce search action. - const onSearch = debounce((login: string) => { - setSearching(true) - setTimeout(() => { - setSearching(false) - }, 500); - - props.onSearchCandidates(login) - }, 800) - - - return ( - - ) -} \ No newline at end of file diff --git a/ui/src/components/ApproversSelector/index.tsx b/ui/src/components/ApproversSelector/index.tsx deleted file mode 100644 index 616c0c23..00000000 --- a/ui/src/components/ApproversSelector/index.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { Typography } from "antd" - -import ApproversSearch, { ApproversSelectProps } from "./ApproversSearch" -import ApprovalList, { ApprovalListProps } from "./ApprovalList" - -const { Text } = Typography - -interface ApproversSelectorProps extends ApproversSelectProps, ApprovalListProps { -} - -export default function ApproversSelector(props: ApproversSelectorProps): JSX.Element { - return ( -
-
- Approvers -
-
- -
-
- {(props.approvals.length !== 0) ? - : - No approvers } -
-
- ) -} \ No newline at end of file diff --git a/ui/src/components/DeployConfirm.tsx b/ui/src/components/DeployConfirm.tsx index 9cb88292..14d6507f 100644 --- a/ui/src/components/DeployConfirm.tsx +++ b/ui/src/components/DeployConfirm.tsx @@ -80,14 +80,6 @@ export default function DeployConfirm(props: DeployConfirmProps): JSX.Element { > {moment(props.deployment.createdAt).format("YYYY-MM-DD HH:mm:ss")} - {(props.deployment.isApprovalEanbled) ? - - {props.deployment.requiredApprovalCount} - : - null } - - - - + }> - + ) diff --git a/ui/src/components/ReviewList.tsx b/ui/src/components/ReviewList.tsx new file mode 100644 index 00000000..86a2455c --- /dev/null +++ b/ui/src/components/ReviewList.tsx @@ -0,0 +1,48 @@ +import { Typography } from "antd" +import { CheckOutlined, CloseOutlined } from "@ant-design/icons" + +import { Review, ReviewStatusEnum } from "../models" +import UserAvatar from "./UserAvatar" + +const { Text } = Typography + + +export interface ReviewListProps { + reviews: Review[] +} + +export default function ReviewList(props: ReviewListProps): JSX.Element { + return ( +
+
+ Reviewers +
+
+ {(props.reviews.length !== 0) ? +
+ {props.reviews.map((r, idx) => { + return ( +
+ {mapReviewStatusToIcon(r.status)}  +
+ ) + })} +
: + No approvers } +
+
+ ) +} + +function mapReviewStatusToIcon(status: ReviewStatusEnum): JSX.Element { + switch (status) { + case ReviewStatusEnum.Pending: + return + case ReviewStatusEnum.Approved: + return + case ReviewStatusEnum.Rejected: + return + default: + return + } +} \ No newline at end of file diff --git a/ui/src/components/RollbackForm.tsx b/ui/src/components/RollbackForm.tsx index e827a1a0..a92834fa 100644 --- a/ui/src/components/RollbackForm.tsx +++ b/ui/src/components/RollbackForm.tsx @@ -1,8 +1,7 @@ import { Form, Select, Button, Avatar } from 'antd' import moment from 'moment' -import { User, Deployment, Env } from "../models" -import ApproversSelect from "./ApproversSelect" +import { Deployment, Env } from "../models" import DeploymentRefCode from './DeploymentRefCode' interface RollbackFormProps { @@ -12,11 +11,6 @@ interface RollbackFormProps { onSelectDeployment(deployment: Deployment): void onClickRollback(): void deploying: boolean - approvalEnabled: boolean - candidates: User[] - onSelectCandidate(candidate: User): void - onDeselectCandidate(candidate: User): void - onSearchCandidates(login: string): void } export default function RollbackForm(props: RollbackFormProps): JSX.Element { @@ -93,17 +87,6 @@ export default function RollbackForm(props: RollbackFormProps): JSX.Element { })}
- - -