From 32df5254ec99fdd4db3b156dfeedc8b637ef60f4 Mon Sep 17 00:00:00 2001 From: yokowu <18836617@qq.com> Date: Tue, 26 May 2026 18:01:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20github=20webhook=20=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=A4=B1=E8=B4=A5=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/biz/git/handler/v1/webhook_github.go | 34 +- backend/biz/task/repo/gittask.go | 47 +- backend/biz/task/usecase/gittask.go | 4 +- backend/config/config.go | 7 + backend/db/client.go | 215 ++- backend/db/ent.go | 2 + backend/db/gittask.go | 248 ++++ backend/db/gittask/gittask.go | 160 +++ backend/db/gittask/where.go | 800 +++++++++++ backend/db/gittask_create.go | 1306 ++++++++++++++++++ backend/db/gittask_delete.go | 88 ++ backend/db/gittask_query.go | 657 +++++++++ backend/db/gittask_update.go | 858 ++++++++++++ backend/db/hook/hook.go | 12 + backend/db/intercept/intercept.go | 30 + backend/db/migrate/schema.go | 34 + backend/db/mutation.go | 1219 +++++++++++++++- backend/db/page.go | 14 + backend/db/predicate/predicate.go | 3 + backend/db/runtime/runtime.go | 11 + backend/db/task.go | 31 +- backend/db/task/task.go | 23 + backend/db/task/where.go | 23 + backend/db/task_create.go | 36 + backend/db/task_query.go | 72 +- backend/db/task_update.go | 109 ++ backend/db/tx.go | 3 + backend/domain/gittask.go | 2 +- backend/ent/schema/gittask.go | 47 + backend/ent/schema/task.go | 1 + backend/pkg/entx/taskhook.go | 1 + backend/pkg/logger/logger.go | 11 +- backend/pkg/logger/logger_test.go | 32 + 33 files changed, 6073 insertions(+), 67 deletions(-) create mode 100644 backend/db/gittask.go create mode 100644 backend/db/gittask/gittask.go create mode 100644 backend/db/gittask/where.go create mode 100644 backend/db/gittask_create.go create mode 100644 backend/db/gittask_delete.go create mode 100644 backend/db/gittask_query.go create mode 100644 backend/db/gittask_update.go create mode 100644 backend/ent/schema/gittask.go create mode 100644 backend/pkg/logger/logger_test.go diff --git a/backend/biz/git/handler/v1/webhook_github.go b/backend/biz/git/handler/v1/webhook_github.go index 92d3a892..fe74ad94 100644 --- a/backend/biz/git/handler/v1/webhook_github.go +++ b/backend/biz/git/handler/v1/webhook_github.go @@ -30,6 +30,7 @@ type GithubWebhookHandler struct { logger *slog.Logger redis *redis.Client gitbotUsecase domain.GitBotUsecase + pubhost domain.PublicHostUsecase gitTaskUsecase domain.GitTaskUsecase } @@ -41,6 +42,7 @@ func NewGithubWebhookHandler(i *do.Injector) (*GithubWebhookHandler, error) { redis: do.MustInvoke[*redis.Client](i), gitbotUsecase: do.MustInvoke[domain.GitBotUsecase](i), gitTaskUsecase: do.MustInvoke[domain.GitTaskUsecase](i), + pubhost: do.MustInvoke[domain.PublicHostUsecase](i), } w := do.MustInvoke[*web.Web](i) @@ -76,6 +78,7 @@ func (h *GithubWebhookHandler) Webhook(c *web.Context) error { } event := c.Request().Header.Get("X-Github-Event") + h.logger.With("bot", bot.ID, "body", string(body), "event", event).DebugContext(c.Request().Context(), "github webhook") if event == "pull_request" { h.handlePullRequest(ctx, bot, body) } @@ -132,21 +135,34 @@ func (h *GithubWebhookHandler) handlePullRequest(ctx context.Context, bot *domai return } + host, err := h.pubhost.PickHost(ctx) + if err != nil { + h.logger.With("error", err).ErrorContext(ctx, "failed to pick host") + return + } + branch := pr.Head.Ref repo := pr.Head.Repo - h.gitTaskUsecase.Create(ctx, domain.CreateGitTaskReq{ - HostID: bot.Host.ID, + if _, err := h.gitTaskUsecase.Create(ctx, domain.CreateGitTaskReq{ + HostID: host.ID, ImageID: uuid.MustParse(h.cfg.Task.ImageID), Prompt: pr.HTMLURL, Git: taskflow.Git{Token: bot.Token}, Subject: domain.Subject{ - ID: fmt.Sprintf("%d", pr.ID), Type: "PullRequest", - Title: pr.Title, URL: pr.HTMLURL, Number: pr.Number, + ID: fmt.Sprintf("%d", pr.ID), + Type: "PullRequest", + Title: pr.Title, + URL: pr.HTMLURL, + Number: pr.Number, }, Repo: domain.Repo{ - ID: fmt.Sprintf("%d", repo.ID), Name: repo.Name, - FullName: repo.FullName, URL: repo.HTMLURL, - Desc: repo.Description, IsPrivate: repo.Private, Branch: &branch, + ID: fmt.Sprintf("%d", repo.ID), + Name: repo.Name, + FullName: repo.FullName, + URL: repo.HTMLURL, + Desc: repo.Description, + IsPrivate: repo.Private, + Branch: &branch, }, Platform: consts.GitPlatformGithub, User: domain.User{Name: pr.User.Login, AvatarURL: pr.User.AvatarURL, Email: pr.User.Email}, @@ -154,7 +170,9 @@ func (h *GithubWebhookHandler) handlePullRequest(ctx context.Context, bot *domai Time: time.Now(), Env: map[string]string{"GITHUB_TOKEN": bot.Token}, Bot: bot, - }) + }); err != nil { + h.logger.With("error", err).ErrorContext(ctx, "failed to create git task") + } } // --- 公共工具函数 --- diff --git a/backend/biz/task/repo/gittask.go b/backend/biz/task/repo/gittask.go index adf43977..561d0762 100644 --- a/backend/biz/task/repo/gittask.go +++ b/backend/biz/task/repo/gittask.go @@ -13,7 +13,6 @@ import ( "github.com/chaitin/MonkeyCode/backend/consts" "github.com/chaitin/MonkeyCode/backend/db" "github.com/chaitin/MonkeyCode/backend/db/host" - "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/model" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/chaitin/MonkeyCode/backend/domain" @@ -60,7 +59,7 @@ func (g *GitTaskRepo) upsertUser(ctx context.Context, tx *db.Tx, u *domain.User) } // Create implements domain.GitTaskRepoInterface. -func (g *GitTaskRepo) Create(ctx context.Context, req domain.CreateGitTaskReq, fn func(user *db.User, t *db.Task, m *db.Model, i *db.Image) (*taskflow.VirtualMachine, error)) (*db.Task, error) { +func (g *GitTaskRepo) Create(ctx context.Context, req domain.CreateGitTaskReq, fn func(user *db.User, t *db.Task, m *db.Model) (*taskflow.VirtualMachine, error)) (*db.Task, error) { var res *db.Task err := entx.WithTx2(ctx, g.db, func(tx *db.Tx) error { h, err := tx.Host.Query().Where(host.ID(req.HostID)).First(ctx) @@ -68,19 +67,17 @@ func (g *GitTaskRepo) Create(ctx context.Context, req domain.CreateGitTaskReq, f return fmt.Errorf("host not found: %w", err) } - // 查找 review 模型 - ms, err := tx.Model.Query(). - Where(model.Remark("review")). - Where(model.HasUserWith(user.Role(consts.UserRoleAdmin))). - All(ctx) - if err != nil || len(ms) == 0 { - return fmt.Errorf("review model not found") - } - m := ms[0] - - img, err := tx.Image.Query().Where(image.ID(req.ImageID)).First(ctx) + mid, err := uuid.Parse(g.cfg.ReviewAgent.ModelID) if err != nil { - return fmt.Errorf("image not found: %w", err) + return fmt.Errorf("failed to parse model id: %w", err) + } + + // 查找 review 模型 + m, err := tx.Model.Query(). + Where(model.ID(mid)). + First(ctx) + if err != nil { + return fmt.Errorf("review model not found") } u, err := g.upsertUser(ctx, tx, &req.User) @@ -101,26 +98,26 @@ func (g *GitTaskRepo) Create(ctx context.Context, req domain.CreateGitTaskReq, f SetContent(req.Prompt). SetUserID(u.ID). SetStatus(consts.TaskStatusPending). + SetLogStore(consts.LogStoreClickHouse). Save(ctx) if err != nil { return err } - // 创建 ProjectTask 关联 - pt, err := tx.ProjectTask.Create(). - SetImageID(img.ID). - SetModelID(m.ID). + // 创建 GitTask 关联 + if err := tx.GitTask.Create(). SetTaskID(tk.ID). - SetRepoURL(req.Repo.URL). - SetBranch(branch). - SetCliName(consts.CliNameClaude). - Save(ctx) - if err != nil { + SetGithubInstallationID(req.GithubInstallationID). + SetSubjectID(req.Subject.ID). + SetSubjectNumber(req.Subject.Number). + SetSubjectTitle(req.Subject.Title). + SetSubjectType(req.Subject.Type). + SetSubjectURL(req.Subject.URL). + Exec(ctx); err != nil { return err } - _ = pt - vm, err := fn(u, tk, m, img) + vm, err := fn(u, tk, m) if err != nil { return err } diff --git a/backend/biz/task/usecase/gittask.go b/backend/biz/task/usecase/gittask.go index f2936f4c..38046a8c 100644 --- a/backend/biz/task/usecase/gittask.go +++ b/backend/biz/task/usecase/gittask.go @@ -55,7 +55,7 @@ func (g *GitTaskUsecase) Create(ctx context.Context, req domain.CreateGitTaskReq req.Env = make(map[string]string) } - tk, err := g.repo.Create(ctx, req, func(u *db.User, t *db.Task, m *db.Model, img *db.Image) (*taskflow.VirtualMachine, error) { + tk, err := g.repo.Create(ctx, req, func(u *db.User, t *db.Task, m *db.Model) (*taskflow.VirtualMachine, error) { branch := "master" if req.Repo.Branch != nil { branch = *req.Repo.Branch @@ -72,7 +72,7 @@ func (g *GitTaskUsecase) Create(ctx context.Context, req domain.CreateGitTaskReq Branch: branch, Token: req.Git.Token, }, - ImageURL: img.Name, + ImageURL: g.cfg.ReviewAgent.Image, TaskID: t.ID, LLM: taskflow.LLMProviderReq{ Provider: taskflow.LlmProviderOpenAI, diff --git a/backend/config/config.go b/backend/config/config.go index 9f40c163..9f4db39f 100644 --- a/backend/config/config.go +++ b/backend/config/config.go @@ -74,6 +74,13 @@ type Config struct { // 语音识别配置(阿里云 NLS) NLS NLS `mapstructure:"nls"` + + ReviewAgent ReviewAgent `mapstructure:"review_agent"` +} + +type ReviewAgent struct { + ModelID string `mapstructure:"model_id"` + Image string `mapstructure:"image"` } // NLS 阿里云语音识别配置 diff --git a/backend/db/client.go b/backend/db/client.go index df3535b5..eaa61680 100644 --- a/backend/db/client.go +++ b/backend/db/client.go @@ -21,6 +21,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/gitbottask" "github.com/chaitin/MonkeyCode/backend/db/gitbotuser" "github.com/chaitin/MonkeyCode/backend/db/gitidentity" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/host" "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/mcptool" @@ -74,6 +75,8 @@ type Client struct { GitBotUser *GitBotUserClient // GitIdentity is the client for interacting with the GitIdentity builders. GitIdentity *GitIdentityClient + // GitTask is the client for interacting with the GitTask builders. + GitTask *GitTaskClient // Host is the client for interacting with the Host builders. Host *HostClient // Image is the client for interacting with the Image builders. @@ -158,6 +161,7 @@ func (c *Client) init() { c.GitBotTask = NewGitBotTaskClient(c.config) c.GitBotUser = NewGitBotUserClient(c.config) c.GitIdentity = NewGitIdentityClient(c.config) + c.GitTask = NewGitTaskClient(c.config) c.Host = NewHostClient(c.config) c.Image = NewImageClient(c.config) c.MCPTool = NewMCPToolClient(c.config) @@ -289,6 +293,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { GitBotTask: NewGitBotTaskClient(cfg), GitBotUser: NewGitBotUserClient(cfg), GitIdentity: NewGitIdentityClient(cfg), + GitTask: NewGitTaskClient(cfg), Host: NewHostClient(cfg), Image: NewImageClient(cfg), MCPTool: NewMCPToolClient(cfg), @@ -347,6 +352,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) GitBotTask: NewGitBotTaskClient(cfg), GitBotUser: NewGitBotUserClient(cfg), GitIdentity: NewGitIdentityClient(cfg), + GitTask: NewGitTaskClient(cfg), Host: NewHostClient(cfg), Image: NewImageClient(cfg), MCPTool: NewMCPToolClient(cfg), @@ -410,14 +416,15 @@ func (c *Client) Close() error { // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ - c.Audit, c.GitBot, c.GitBotTask, c.GitBotUser, c.GitIdentity, c.Host, c.Image, - c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model, c.ModelApiKey, - c.ModelPricing, c.NotifyChannel, c.NotifySendLog, c.NotifySubscription, - c.Project, c.ProjectCollaborator, c.ProjectGitBot, c.ProjectIssue, - c.ProjectIssueComment, c.ProjectTask, c.Task, c.TaskModelSwitch, - c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup, c.TeamGroupHost, - c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel, c.TeamHost, c.TeamImage, - c.TeamMember, c.TeamModel, c.User, c.UserIdentity, c.VirtualMachine, + c.Audit, c.GitBot, c.GitBotTask, c.GitBotUser, c.GitIdentity, c.GitTask, c.Host, + c.Image, c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model, + c.ModelApiKey, c.ModelPricing, c.NotifyChannel, c.NotifySendLog, + c.NotifySubscription, c.Project, c.ProjectCollaborator, c.ProjectGitBot, + c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Task, + c.TaskModelSwitch, c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup, + c.TeamGroupHost, c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel, + c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, c.User, c.UserIdentity, + c.VirtualMachine, } { n.Use(hooks...) } @@ -427,14 +434,15 @@ func (c *Client) Use(hooks ...Hook) { // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ - c.Audit, c.GitBot, c.GitBotTask, c.GitBotUser, c.GitIdentity, c.Host, c.Image, - c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model, c.ModelApiKey, - c.ModelPricing, c.NotifyChannel, c.NotifySendLog, c.NotifySubscription, - c.Project, c.ProjectCollaborator, c.ProjectGitBot, c.ProjectIssue, - c.ProjectIssueComment, c.ProjectTask, c.Task, c.TaskModelSwitch, - c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup, c.TeamGroupHost, - c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel, c.TeamHost, c.TeamImage, - c.TeamMember, c.TeamModel, c.User, c.UserIdentity, c.VirtualMachine, + c.Audit, c.GitBot, c.GitBotTask, c.GitBotUser, c.GitIdentity, c.GitTask, c.Host, + c.Image, c.MCPTool, c.MCPUpstream, c.MCPUserToolSetting, c.Model, + c.ModelApiKey, c.ModelPricing, c.NotifyChannel, c.NotifySendLog, + c.NotifySubscription, c.Project, c.ProjectCollaborator, c.ProjectGitBot, + c.ProjectIssue, c.ProjectIssueComment, c.ProjectTask, c.Task, + c.TaskModelSwitch, c.TaskUsageStat, c.TaskVirtualMachine, c.Team, c.TeamGroup, + c.TeamGroupHost, c.TeamGroupImage, c.TeamGroupMember, c.TeamGroupModel, + c.TeamHost, c.TeamImage, c.TeamMember, c.TeamModel, c.User, c.UserIdentity, + c.VirtualMachine, } { n.Intercept(interceptors...) } @@ -453,6 +461,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.GitBotUser.mutate(ctx, m) case *GitIdentityMutation: return c.GitIdentity.mutate(ctx, m) + case *GitTaskMutation: + return c.GitTask.mutate(ctx, m) case *HostMutation: return c.Host.mutate(ctx, m) case *ImageMutation: @@ -1435,6 +1445,155 @@ func (c *GitIdentityClient) mutate(ctx context.Context, m *GitIdentityMutation) } } +// GitTaskClient is a client for the GitTask schema. +type GitTaskClient struct { + config +} + +// NewGitTaskClient returns a client for the GitTask from the given config. +func NewGitTaskClient(c config) *GitTaskClient { + return &GitTaskClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `gittask.Hooks(f(g(h())))`. +func (c *GitTaskClient) Use(hooks ...Hook) { + c.hooks.GitTask = append(c.hooks.GitTask, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `gittask.Intercept(f(g(h())))`. +func (c *GitTaskClient) Intercept(interceptors ...Interceptor) { + c.inters.GitTask = append(c.inters.GitTask, interceptors...) +} + +// Create returns a builder for creating a GitTask entity. +func (c *GitTaskClient) Create() *GitTaskCreate { + mutation := newGitTaskMutation(c.config, OpCreate) + return &GitTaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of GitTask entities. +func (c *GitTaskClient) CreateBulk(builders ...*GitTaskCreate) *GitTaskCreateBulk { + return &GitTaskCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GitTaskClient) MapCreateBulk(slice any, setFunc func(*GitTaskCreate, int)) *GitTaskCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GitTaskCreateBulk{err: fmt.Errorf("calling to GitTaskClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GitTaskCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GitTaskCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for GitTask. +func (c *GitTaskClient) Update() *GitTaskUpdate { + mutation := newGitTaskMutation(c.config, OpUpdate) + return &GitTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *GitTaskClient) UpdateOne(_m *GitTask) *GitTaskUpdateOne { + mutation := newGitTaskMutation(c.config, OpUpdateOne, withGitTask(_m)) + return &GitTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *GitTaskClient) UpdateOneID(id uuid.UUID) *GitTaskUpdateOne { + mutation := newGitTaskMutation(c.config, OpUpdateOne, withGitTaskID(id)) + return &GitTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for GitTask. +func (c *GitTaskClient) Delete() *GitTaskDelete { + mutation := newGitTaskMutation(c.config, OpDelete) + return &GitTaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *GitTaskClient) DeleteOne(_m *GitTask) *GitTaskDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *GitTaskClient) DeleteOneID(id uuid.UUID) *GitTaskDeleteOne { + builder := c.Delete().Where(gittask.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &GitTaskDeleteOne{builder} +} + +// Query returns a query builder for GitTask. +func (c *GitTaskClient) Query() *GitTaskQuery { + return &GitTaskQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeGitTask}, + inters: c.Interceptors(), + } +} + +// Get returns a GitTask entity by its id. +func (c *GitTaskClient) Get(ctx context.Context, id uuid.UUID) (*GitTask, error) { + return c.Query().Where(gittask.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *GitTaskClient) GetX(ctx context.Context, id uuid.UUID) *GitTask { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryTask queries the task edge of a GitTask. +func (c *GitTaskClient) QueryTask(_m *GitTask) *TaskQuery { + query := (&TaskClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(gittask.Table, gittask.FieldID, id), + sqlgraph.To(task.Table, task.FieldID), + sqlgraph.Edge(sqlgraph.O2O, true, gittask.TaskTable, gittask.TaskColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *GitTaskClient) Hooks() []Hook { + return c.hooks.GitTask +} + +// Interceptors returns the client interceptors. +func (c *GitTaskClient) Interceptors() []Interceptor { + return c.inters.GitTask +} + +func (c *GitTaskClient) mutate(ctx context.Context, m *GitTaskMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GitTaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GitTaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GitTaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GitTaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("db: unknown GitTask mutation op: %q", m.Op()) + } +} + // HostClient is a client for the Host schema. type HostClient struct { config @@ -4756,6 +4915,22 @@ func (c *TaskClient) QueryProjectTasks(_m *Task) *ProjectTaskQuery { return query } +// QueryGitTasks queries the git_tasks edge of a Task. +func (c *TaskClient) QueryGitTasks(_m *Task) *GitTaskQuery { + query := (&GitTaskClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(task.Table, task.FieldID, id), + sqlgraph.To(gittask.Table, gittask.FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, task.GitTasksTable, task.GitTasksColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + // QueryUser queries the user edge of a Task. func (c *TaskClient) QueryUser(_m *Task) *UserQuery { query := (&UserClient{config: c.config}).Query() @@ -8060,8 +8235,8 @@ func (c *VirtualMachineClient) mutate(ctx context.Context, m *VirtualMachineMuta // hooks and interceptors per client, for fast access. type ( hooks struct { - Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, Host, Image, MCPTool, - MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing, + Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, GitTask, Host, Image, + MCPTool, MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing, NotifyChannel, NotifySendLog, NotifySubscription, Project, ProjectCollaborator, ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Task, TaskModelSwitch, TaskUsageStat, TaskVirtualMachine, Team, TeamGroup, @@ -8069,8 +8244,8 @@ type ( TeamImage, TeamMember, TeamModel, User, UserIdentity, VirtualMachine []ent.Hook } inters struct { - Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, Host, Image, MCPTool, - MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing, + Audit, GitBot, GitBotTask, GitBotUser, GitIdentity, GitTask, Host, Image, + MCPTool, MCPUpstream, MCPUserToolSetting, Model, ModelApiKey, ModelPricing, NotifyChannel, NotifySendLog, NotifySubscription, Project, ProjectCollaborator, ProjectGitBot, ProjectIssue, ProjectIssueComment, ProjectTask, Task, TaskModelSwitch, TaskUsageStat, TaskVirtualMachine, Team, TeamGroup, diff --git a/backend/db/ent.go b/backend/db/ent.go index ec0cf8e5..0d83033d 100644 --- a/backend/db/ent.go +++ b/backend/db/ent.go @@ -17,6 +17,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/gitbottask" "github.com/chaitin/MonkeyCode/backend/db/gitbotuser" "github.com/chaitin/MonkeyCode/backend/db/gitidentity" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/host" "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/mcptool" @@ -116,6 +117,7 @@ func checkColumn(t, c string) error { gitbottask.Table: gitbottask.ValidColumn, gitbotuser.Table: gitbotuser.ValidColumn, gitidentity.Table: gitidentity.ValidColumn, + gittask.Table: gittask.ValidColumn, host.Table: host.ValidColumn, image.Table: image.ValidColumn, mcptool.Table: mcptool.ValidColumn, diff --git a/backend/db/gittask.go b/backend/db/gittask.go new file mode 100644 index 00000000..de043b55 --- /dev/null +++ b/backend/db/gittask.go @@ -0,0 +1,248 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/chaitin/MonkeyCode/backend/db/gittask" + "github.com/chaitin/MonkeyCode/backend/db/task" + "github.com/google/uuid" +) + +// GitTask is the model entity for the GitTask schema. +type GitTask struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // TaskID holds the value of the "task_id" field. + TaskID uuid.UUID `json:"task_id,omitempty"` + // RepoID holds the value of the "repo_id" field. + RepoID uuid.UUID `json:"repo_id,omitempty"` + // SubjectType holds the value of the "subject_type" field. + SubjectType string `json:"subject_type,omitempty"` + // SubjectID holds the value of the "subject_id" field. + SubjectID string `json:"subject_id,omitempty"` + // SubjectNumber holds the value of the "subject_number" field. + SubjectNumber int `json:"subject_number,omitempty"` + // SubjectURL holds the value of the "subject_url" field. + SubjectURL string `json:"subject_url,omitempty"` + // SubjectTitle holds the value of the "subject_title" field. + SubjectTitle string `json:"subject_title,omitempty"` + // PromptID holds the value of the "prompt_id" field. + PromptID string `json:"prompt_id,omitempty"` + // ShowURL holds the value of the "show_url" field. + ShowURL string `json:"show_url,omitempty"` + // GithubInstallationID holds the value of the "github_installation_id" field. + GithubInstallationID int64 `json:"github_installation_id,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the GitTaskQuery when eager-loading is set. + Edges GitTaskEdges `json:"edges"` + selectValues sql.SelectValues +} + +// GitTaskEdges holds the relations/edges for other nodes in the graph. +type GitTaskEdges struct { + // Task holds the value of the task edge. + Task *Task `json:"task,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// TaskOrErr returns the Task value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e GitTaskEdges) TaskOrErr() (*Task, error) { + if e.Task != nil { + return e.Task, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: task.Label} + } + return nil, &NotLoadedError{edge: "task"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*GitTask) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case gittask.FieldSubjectNumber, gittask.FieldGithubInstallationID: + values[i] = new(sql.NullInt64) + case gittask.FieldSubjectType, gittask.FieldSubjectID, gittask.FieldSubjectURL, gittask.FieldSubjectTitle, gittask.FieldPromptID, gittask.FieldShowURL: + values[i] = new(sql.NullString) + case gittask.FieldCreatedAt: + values[i] = new(sql.NullTime) + case gittask.FieldID, gittask.FieldTaskID, gittask.FieldRepoID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the GitTask fields. +func (_m *GitTask) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case gittask.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + _m.ID = *value + } + case gittask.FieldTaskID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field task_id", values[i]) + } else if value != nil { + _m.TaskID = *value + } + case gittask.FieldRepoID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field repo_id", values[i]) + } else if value != nil { + _m.RepoID = *value + } + case gittask.FieldSubjectType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field subject_type", values[i]) + } else if value.Valid { + _m.SubjectType = value.String + } + case gittask.FieldSubjectID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field subject_id", values[i]) + } else if value.Valid { + _m.SubjectID = value.String + } + case gittask.FieldSubjectNumber: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field subject_number", values[i]) + } else if value.Valid { + _m.SubjectNumber = int(value.Int64) + } + case gittask.FieldSubjectURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field subject_url", values[i]) + } else if value.Valid { + _m.SubjectURL = value.String + } + case gittask.FieldSubjectTitle: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field subject_title", values[i]) + } else if value.Valid { + _m.SubjectTitle = value.String + } + case gittask.FieldPromptID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field prompt_id", values[i]) + } else if value.Valid { + _m.PromptID = value.String + } + case gittask.FieldShowURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field show_url", values[i]) + } else if value.Valid { + _m.ShowURL = value.String + } + case gittask.FieldGithubInstallationID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field github_installation_id", values[i]) + } else if value.Valid { + _m.GithubInstallationID = value.Int64 + } + case gittask.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 { + _m.CreatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the GitTask. +// This includes values selected through modifiers, order, etc. +func (_m *GitTask) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// QueryTask queries the "task" edge of the GitTask entity. +func (_m *GitTask) QueryTask() *TaskQuery { + return NewGitTaskClient(_m.config).QueryTask(_m) +} + +// Update returns a builder for updating this GitTask. +// Note that you need to call GitTask.Unwrap() before calling this method if this GitTask +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *GitTask) Update() *GitTaskUpdateOne { + return NewGitTaskClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the GitTask 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 (_m *GitTask) Unwrap() *GitTask { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("db: GitTask is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *GitTask) String() string { + var builder strings.Builder + builder.WriteString("GitTask(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("task_id=") + builder.WriteString(fmt.Sprintf("%v", _m.TaskID)) + builder.WriteString(", ") + builder.WriteString("repo_id=") + builder.WriteString(fmt.Sprintf("%v", _m.RepoID)) + builder.WriteString(", ") + builder.WriteString("subject_type=") + builder.WriteString(_m.SubjectType) + builder.WriteString(", ") + builder.WriteString("subject_id=") + builder.WriteString(_m.SubjectID) + builder.WriteString(", ") + builder.WriteString("subject_number=") + builder.WriteString(fmt.Sprintf("%v", _m.SubjectNumber)) + builder.WriteString(", ") + builder.WriteString("subject_url=") + builder.WriteString(_m.SubjectURL) + builder.WriteString(", ") + builder.WriteString("subject_title=") + builder.WriteString(_m.SubjectTitle) + builder.WriteString(", ") + builder.WriteString("prompt_id=") + builder.WriteString(_m.PromptID) + builder.WriteString(", ") + builder.WriteString("show_url=") + builder.WriteString(_m.ShowURL) + builder.WriteString(", ") + builder.WriteString("github_installation_id=") + builder.WriteString(fmt.Sprintf("%v", _m.GithubInstallationID)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// GitTasks is a parsable slice of GitTask. +type GitTasks []*GitTask diff --git a/backend/db/gittask/gittask.go b/backend/db/gittask/gittask.go new file mode 100644 index 00000000..59923c1f --- /dev/null +++ b/backend/db/gittask/gittask.go @@ -0,0 +1,160 @@ +// Code generated by ent, DO NOT EDIT. + +package gittask + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the gittask type in the database. + Label = "git_task" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldTaskID holds the string denoting the task_id field in the database. + FieldTaskID = "task_id" + // FieldRepoID holds the string denoting the repo_id field in the database. + FieldRepoID = "repo_id" + // FieldSubjectType holds the string denoting the subject_type field in the database. + FieldSubjectType = "subject_type" + // FieldSubjectID holds the string denoting the subject_id field in the database. + FieldSubjectID = "subject_id" + // FieldSubjectNumber holds the string denoting the subject_number field in the database. + FieldSubjectNumber = "subject_number" + // FieldSubjectURL holds the string denoting the subject_url field in the database. + FieldSubjectURL = "subject_url" + // FieldSubjectTitle holds the string denoting the subject_title field in the database. + FieldSubjectTitle = "subject_title" + // FieldPromptID holds the string denoting the prompt_id field in the database. + FieldPromptID = "prompt_id" + // FieldShowURL holds the string denoting the show_url field in the database. + FieldShowURL = "show_url" + // FieldGithubInstallationID holds the string denoting the github_installation_id field in the database. + FieldGithubInstallationID = "github_installation_id" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // EdgeTask holds the string denoting the task edge name in mutations. + EdgeTask = "task" + // Table holds the table name of the gittask in the database. + Table = "git_tasks" + // TaskTable is the table that holds the task relation/edge. + TaskTable = "git_tasks" + // TaskInverseTable is the table name for the Task entity. + // It exists in this package in order to avoid circular dependency with the "task" package. + TaskInverseTable = "tasks" + // TaskColumn is the table column denoting the task relation/edge. + TaskColumn = "task_id" +) + +// Columns holds all SQL columns for gittask fields. +var Columns = []string{ + FieldID, + FieldTaskID, + FieldRepoID, + FieldSubjectType, + FieldSubjectID, + FieldSubjectNumber, + FieldSubjectURL, + FieldSubjectTitle, + FieldPromptID, + FieldShowURL, + FieldGithubInstallationID, + FieldCreatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // SubjectTypeValidator is a validator for the "subject_type" field. It is called by the builders before save. + SubjectTypeValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the GitTask queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByTaskID orders the results by the task_id field. +func ByTaskID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTaskID, opts...).ToFunc() +} + +// ByRepoID orders the results by the repo_id field. +func ByRepoID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRepoID, opts...).ToFunc() +} + +// BySubjectType orders the results by the subject_type field. +func BySubjectType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubjectType, opts...).ToFunc() +} + +// BySubjectID orders the results by the subject_id field. +func BySubjectID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubjectID, opts...).ToFunc() +} + +// BySubjectNumber orders the results by the subject_number field. +func BySubjectNumber(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubjectNumber, opts...).ToFunc() +} + +// BySubjectURL orders the results by the subject_url field. +func BySubjectURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubjectURL, opts...).ToFunc() +} + +// BySubjectTitle orders the results by the subject_title field. +func BySubjectTitle(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSubjectTitle, opts...).ToFunc() +} + +// ByPromptID orders the results by the prompt_id field. +func ByPromptID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPromptID, opts...).ToFunc() +} + +// ByShowURL orders the results by the show_url field. +func ByShowURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldShowURL, opts...).ToFunc() +} + +// ByGithubInstallationID orders the results by the github_installation_id field. +func ByGithubInstallationID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldGithubInstallationID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByTaskField orders the results by task field. +func ByTaskField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTaskStep(), sql.OrderByField(field, opts...)) + } +} +func newTaskStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TaskInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, true, TaskTable, TaskColumn), + ) +} diff --git a/backend/db/gittask/where.go b/backend/db/gittask/where.go new file mode 100644 index 00000000..0194e190 --- /dev/null +++ b/backend/db/gittask/where.go @@ -0,0 +1,800 @@ +// Code generated by ent, DO NOT EDIT. + +package gittask + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/google/uuid" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldID, id)) +} + +// TaskID applies equality check predicate on the "task_id" field. It's identical to TaskIDEQ. +func TaskID(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldTaskID, v)) +} + +// RepoID applies equality check predicate on the "repo_id" field. It's identical to RepoIDEQ. +func RepoID(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldRepoID, v)) +} + +// SubjectType applies equality check predicate on the "subject_type" field. It's identical to SubjectTypeEQ. +func SubjectType(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectType, v)) +} + +// SubjectID applies equality check predicate on the "subject_id" field. It's identical to SubjectIDEQ. +func SubjectID(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectID, v)) +} + +// SubjectNumber applies equality check predicate on the "subject_number" field. It's identical to SubjectNumberEQ. +func SubjectNumber(v int) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectNumber, v)) +} + +// SubjectURL applies equality check predicate on the "subject_url" field. It's identical to SubjectURLEQ. +func SubjectURL(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectURL, v)) +} + +// SubjectTitle applies equality check predicate on the "subject_title" field. It's identical to SubjectTitleEQ. +func SubjectTitle(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectTitle, v)) +} + +// PromptID applies equality check predicate on the "prompt_id" field. It's identical to PromptIDEQ. +func PromptID(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldPromptID, v)) +} + +// ShowURL applies equality check predicate on the "show_url" field. It's identical to ShowURLEQ. +func ShowURL(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldShowURL, v)) +} + +// GithubInstallationID applies equality check predicate on the "github_installation_id" field. It's identical to GithubInstallationIDEQ. +func GithubInstallationID(v int64) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldGithubInstallationID, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldCreatedAt, v)) +} + +// TaskIDEQ applies the EQ predicate on the "task_id" field. +func TaskIDEQ(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldTaskID, v)) +} + +// TaskIDNEQ applies the NEQ predicate on the "task_id" field. +func TaskIDNEQ(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldTaskID, v)) +} + +// TaskIDIn applies the In predicate on the "task_id" field. +func TaskIDIn(vs ...uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldTaskID, vs...)) +} + +// TaskIDNotIn applies the NotIn predicate on the "task_id" field. +func TaskIDNotIn(vs ...uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldTaskID, vs...)) +} + +// RepoIDEQ applies the EQ predicate on the "repo_id" field. +func RepoIDEQ(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldRepoID, v)) +} + +// RepoIDNEQ applies the NEQ predicate on the "repo_id" field. +func RepoIDNEQ(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldRepoID, v)) +} + +// RepoIDIn applies the In predicate on the "repo_id" field. +func RepoIDIn(vs ...uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldRepoID, vs...)) +} + +// RepoIDNotIn applies the NotIn predicate on the "repo_id" field. +func RepoIDNotIn(vs ...uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldRepoID, vs...)) +} + +// RepoIDGT applies the GT predicate on the "repo_id" field. +func RepoIDGT(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldRepoID, v)) +} + +// RepoIDGTE applies the GTE predicate on the "repo_id" field. +func RepoIDGTE(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldRepoID, v)) +} + +// RepoIDLT applies the LT predicate on the "repo_id" field. +func RepoIDLT(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldRepoID, v)) +} + +// RepoIDLTE applies the LTE predicate on the "repo_id" field. +func RepoIDLTE(v uuid.UUID) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldRepoID, v)) +} + +// RepoIDIsNil applies the IsNil predicate on the "repo_id" field. +func RepoIDIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldRepoID)) +} + +// RepoIDNotNil applies the NotNil predicate on the "repo_id" field. +func RepoIDNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldRepoID)) +} + +// SubjectTypeEQ applies the EQ predicate on the "subject_type" field. +func SubjectTypeEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectType, v)) +} + +// SubjectTypeNEQ applies the NEQ predicate on the "subject_type" field. +func SubjectTypeNEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldSubjectType, v)) +} + +// SubjectTypeIn applies the In predicate on the "subject_type" field. +func SubjectTypeIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldSubjectType, vs...)) +} + +// SubjectTypeNotIn applies the NotIn predicate on the "subject_type" field. +func SubjectTypeNotIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldSubjectType, vs...)) +} + +// SubjectTypeGT applies the GT predicate on the "subject_type" field. +func SubjectTypeGT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldSubjectType, v)) +} + +// SubjectTypeGTE applies the GTE predicate on the "subject_type" field. +func SubjectTypeGTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldSubjectType, v)) +} + +// SubjectTypeLT applies the LT predicate on the "subject_type" field. +func SubjectTypeLT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldSubjectType, v)) +} + +// SubjectTypeLTE applies the LTE predicate on the "subject_type" field. +func SubjectTypeLTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldSubjectType, v)) +} + +// SubjectTypeContains applies the Contains predicate on the "subject_type" field. +func SubjectTypeContains(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContains(FieldSubjectType, v)) +} + +// SubjectTypeHasPrefix applies the HasPrefix predicate on the "subject_type" field. +func SubjectTypeHasPrefix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasPrefix(FieldSubjectType, v)) +} + +// SubjectTypeHasSuffix applies the HasSuffix predicate on the "subject_type" field. +func SubjectTypeHasSuffix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasSuffix(FieldSubjectType, v)) +} + +// SubjectTypeEqualFold applies the EqualFold predicate on the "subject_type" field. +func SubjectTypeEqualFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEqualFold(FieldSubjectType, v)) +} + +// SubjectTypeContainsFold applies the ContainsFold predicate on the "subject_type" field. +func SubjectTypeContainsFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContainsFold(FieldSubjectType, v)) +} + +// SubjectIDEQ applies the EQ predicate on the "subject_id" field. +func SubjectIDEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectID, v)) +} + +// SubjectIDNEQ applies the NEQ predicate on the "subject_id" field. +func SubjectIDNEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldSubjectID, v)) +} + +// SubjectIDIn applies the In predicate on the "subject_id" field. +func SubjectIDIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldSubjectID, vs...)) +} + +// SubjectIDNotIn applies the NotIn predicate on the "subject_id" field. +func SubjectIDNotIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldSubjectID, vs...)) +} + +// SubjectIDGT applies the GT predicate on the "subject_id" field. +func SubjectIDGT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldSubjectID, v)) +} + +// SubjectIDGTE applies the GTE predicate on the "subject_id" field. +func SubjectIDGTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldSubjectID, v)) +} + +// SubjectIDLT applies the LT predicate on the "subject_id" field. +func SubjectIDLT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldSubjectID, v)) +} + +// SubjectIDLTE applies the LTE predicate on the "subject_id" field. +func SubjectIDLTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldSubjectID, v)) +} + +// SubjectIDContains applies the Contains predicate on the "subject_id" field. +func SubjectIDContains(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContains(FieldSubjectID, v)) +} + +// SubjectIDHasPrefix applies the HasPrefix predicate on the "subject_id" field. +func SubjectIDHasPrefix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasPrefix(FieldSubjectID, v)) +} + +// SubjectIDHasSuffix applies the HasSuffix predicate on the "subject_id" field. +func SubjectIDHasSuffix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasSuffix(FieldSubjectID, v)) +} + +// SubjectIDIsNil applies the IsNil predicate on the "subject_id" field. +func SubjectIDIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldSubjectID)) +} + +// SubjectIDNotNil applies the NotNil predicate on the "subject_id" field. +func SubjectIDNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldSubjectID)) +} + +// SubjectIDEqualFold applies the EqualFold predicate on the "subject_id" field. +func SubjectIDEqualFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEqualFold(FieldSubjectID, v)) +} + +// SubjectIDContainsFold applies the ContainsFold predicate on the "subject_id" field. +func SubjectIDContainsFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContainsFold(FieldSubjectID, v)) +} + +// SubjectNumberEQ applies the EQ predicate on the "subject_number" field. +func SubjectNumberEQ(v int) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectNumber, v)) +} + +// SubjectNumberNEQ applies the NEQ predicate on the "subject_number" field. +func SubjectNumberNEQ(v int) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldSubjectNumber, v)) +} + +// SubjectNumberIn applies the In predicate on the "subject_number" field. +func SubjectNumberIn(vs ...int) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldSubjectNumber, vs...)) +} + +// SubjectNumberNotIn applies the NotIn predicate on the "subject_number" field. +func SubjectNumberNotIn(vs ...int) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldSubjectNumber, vs...)) +} + +// SubjectNumberGT applies the GT predicate on the "subject_number" field. +func SubjectNumberGT(v int) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldSubjectNumber, v)) +} + +// SubjectNumberGTE applies the GTE predicate on the "subject_number" field. +func SubjectNumberGTE(v int) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldSubjectNumber, v)) +} + +// SubjectNumberLT applies the LT predicate on the "subject_number" field. +func SubjectNumberLT(v int) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldSubjectNumber, v)) +} + +// SubjectNumberLTE applies the LTE predicate on the "subject_number" field. +func SubjectNumberLTE(v int) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldSubjectNumber, v)) +} + +// SubjectNumberIsNil applies the IsNil predicate on the "subject_number" field. +func SubjectNumberIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldSubjectNumber)) +} + +// SubjectNumberNotNil applies the NotNil predicate on the "subject_number" field. +func SubjectNumberNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldSubjectNumber)) +} + +// SubjectURLEQ applies the EQ predicate on the "subject_url" field. +func SubjectURLEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectURL, v)) +} + +// SubjectURLNEQ applies the NEQ predicate on the "subject_url" field. +func SubjectURLNEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldSubjectURL, v)) +} + +// SubjectURLIn applies the In predicate on the "subject_url" field. +func SubjectURLIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldSubjectURL, vs...)) +} + +// SubjectURLNotIn applies the NotIn predicate on the "subject_url" field. +func SubjectURLNotIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldSubjectURL, vs...)) +} + +// SubjectURLGT applies the GT predicate on the "subject_url" field. +func SubjectURLGT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldSubjectURL, v)) +} + +// SubjectURLGTE applies the GTE predicate on the "subject_url" field. +func SubjectURLGTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldSubjectURL, v)) +} + +// SubjectURLLT applies the LT predicate on the "subject_url" field. +func SubjectURLLT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldSubjectURL, v)) +} + +// SubjectURLLTE applies the LTE predicate on the "subject_url" field. +func SubjectURLLTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldSubjectURL, v)) +} + +// SubjectURLContains applies the Contains predicate on the "subject_url" field. +func SubjectURLContains(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContains(FieldSubjectURL, v)) +} + +// SubjectURLHasPrefix applies the HasPrefix predicate on the "subject_url" field. +func SubjectURLHasPrefix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasPrefix(FieldSubjectURL, v)) +} + +// SubjectURLHasSuffix applies the HasSuffix predicate on the "subject_url" field. +func SubjectURLHasSuffix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasSuffix(FieldSubjectURL, v)) +} + +// SubjectURLIsNil applies the IsNil predicate on the "subject_url" field. +func SubjectURLIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldSubjectURL)) +} + +// SubjectURLNotNil applies the NotNil predicate on the "subject_url" field. +func SubjectURLNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldSubjectURL)) +} + +// SubjectURLEqualFold applies the EqualFold predicate on the "subject_url" field. +func SubjectURLEqualFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEqualFold(FieldSubjectURL, v)) +} + +// SubjectURLContainsFold applies the ContainsFold predicate on the "subject_url" field. +func SubjectURLContainsFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContainsFold(FieldSubjectURL, v)) +} + +// SubjectTitleEQ applies the EQ predicate on the "subject_title" field. +func SubjectTitleEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldSubjectTitle, v)) +} + +// SubjectTitleNEQ applies the NEQ predicate on the "subject_title" field. +func SubjectTitleNEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldSubjectTitle, v)) +} + +// SubjectTitleIn applies the In predicate on the "subject_title" field. +func SubjectTitleIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldSubjectTitle, vs...)) +} + +// SubjectTitleNotIn applies the NotIn predicate on the "subject_title" field. +func SubjectTitleNotIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldSubjectTitle, vs...)) +} + +// SubjectTitleGT applies the GT predicate on the "subject_title" field. +func SubjectTitleGT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldSubjectTitle, v)) +} + +// SubjectTitleGTE applies the GTE predicate on the "subject_title" field. +func SubjectTitleGTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldSubjectTitle, v)) +} + +// SubjectTitleLT applies the LT predicate on the "subject_title" field. +func SubjectTitleLT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldSubjectTitle, v)) +} + +// SubjectTitleLTE applies the LTE predicate on the "subject_title" field. +func SubjectTitleLTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldSubjectTitle, v)) +} + +// SubjectTitleContains applies the Contains predicate on the "subject_title" field. +func SubjectTitleContains(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContains(FieldSubjectTitle, v)) +} + +// SubjectTitleHasPrefix applies the HasPrefix predicate on the "subject_title" field. +func SubjectTitleHasPrefix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasPrefix(FieldSubjectTitle, v)) +} + +// SubjectTitleHasSuffix applies the HasSuffix predicate on the "subject_title" field. +func SubjectTitleHasSuffix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasSuffix(FieldSubjectTitle, v)) +} + +// SubjectTitleIsNil applies the IsNil predicate on the "subject_title" field. +func SubjectTitleIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldSubjectTitle)) +} + +// SubjectTitleNotNil applies the NotNil predicate on the "subject_title" field. +func SubjectTitleNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldSubjectTitle)) +} + +// SubjectTitleEqualFold applies the EqualFold predicate on the "subject_title" field. +func SubjectTitleEqualFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEqualFold(FieldSubjectTitle, v)) +} + +// SubjectTitleContainsFold applies the ContainsFold predicate on the "subject_title" field. +func SubjectTitleContainsFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContainsFold(FieldSubjectTitle, v)) +} + +// PromptIDEQ applies the EQ predicate on the "prompt_id" field. +func PromptIDEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldPromptID, v)) +} + +// PromptIDNEQ applies the NEQ predicate on the "prompt_id" field. +func PromptIDNEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldPromptID, v)) +} + +// PromptIDIn applies the In predicate on the "prompt_id" field. +func PromptIDIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldPromptID, vs...)) +} + +// PromptIDNotIn applies the NotIn predicate on the "prompt_id" field. +func PromptIDNotIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldPromptID, vs...)) +} + +// PromptIDGT applies the GT predicate on the "prompt_id" field. +func PromptIDGT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldPromptID, v)) +} + +// PromptIDGTE applies the GTE predicate on the "prompt_id" field. +func PromptIDGTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldPromptID, v)) +} + +// PromptIDLT applies the LT predicate on the "prompt_id" field. +func PromptIDLT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldPromptID, v)) +} + +// PromptIDLTE applies the LTE predicate on the "prompt_id" field. +func PromptIDLTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldPromptID, v)) +} + +// PromptIDContains applies the Contains predicate on the "prompt_id" field. +func PromptIDContains(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContains(FieldPromptID, v)) +} + +// PromptIDHasPrefix applies the HasPrefix predicate on the "prompt_id" field. +func PromptIDHasPrefix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasPrefix(FieldPromptID, v)) +} + +// PromptIDHasSuffix applies the HasSuffix predicate on the "prompt_id" field. +func PromptIDHasSuffix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasSuffix(FieldPromptID, v)) +} + +// PromptIDIsNil applies the IsNil predicate on the "prompt_id" field. +func PromptIDIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldPromptID)) +} + +// PromptIDNotNil applies the NotNil predicate on the "prompt_id" field. +func PromptIDNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldPromptID)) +} + +// PromptIDEqualFold applies the EqualFold predicate on the "prompt_id" field. +func PromptIDEqualFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEqualFold(FieldPromptID, v)) +} + +// PromptIDContainsFold applies the ContainsFold predicate on the "prompt_id" field. +func PromptIDContainsFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContainsFold(FieldPromptID, v)) +} + +// ShowURLEQ applies the EQ predicate on the "show_url" field. +func ShowURLEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldShowURL, v)) +} + +// ShowURLNEQ applies the NEQ predicate on the "show_url" field. +func ShowURLNEQ(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldShowURL, v)) +} + +// ShowURLIn applies the In predicate on the "show_url" field. +func ShowURLIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldShowURL, vs...)) +} + +// ShowURLNotIn applies the NotIn predicate on the "show_url" field. +func ShowURLNotIn(vs ...string) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldShowURL, vs...)) +} + +// ShowURLGT applies the GT predicate on the "show_url" field. +func ShowURLGT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldShowURL, v)) +} + +// ShowURLGTE applies the GTE predicate on the "show_url" field. +func ShowURLGTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldShowURL, v)) +} + +// ShowURLLT applies the LT predicate on the "show_url" field. +func ShowURLLT(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldShowURL, v)) +} + +// ShowURLLTE applies the LTE predicate on the "show_url" field. +func ShowURLLTE(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldShowURL, v)) +} + +// ShowURLContains applies the Contains predicate on the "show_url" field. +func ShowURLContains(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContains(FieldShowURL, v)) +} + +// ShowURLHasPrefix applies the HasPrefix predicate on the "show_url" field. +func ShowURLHasPrefix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasPrefix(FieldShowURL, v)) +} + +// ShowURLHasSuffix applies the HasSuffix predicate on the "show_url" field. +func ShowURLHasSuffix(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldHasSuffix(FieldShowURL, v)) +} + +// ShowURLIsNil applies the IsNil predicate on the "show_url" field. +func ShowURLIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldShowURL)) +} + +// ShowURLNotNil applies the NotNil predicate on the "show_url" field. +func ShowURLNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldShowURL)) +} + +// ShowURLEqualFold applies the EqualFold predicate on the "show_url" field. +func ShowURLEqualFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldEqualFold(FieldShowURL, v)) +} + +// ShowURLContainsFold applies the ContainsFold predicate on the "show_url" field. +func ShowURLContainsFold(v string) predicate.GitTask { + return predicate.GitTask(sql.FieldContainsFold(FieldShowURL, v)) +} + +// GithubInstallationIDEQ applies the EQ predicate on the "github_installation_id" field. +func GithubInstallationIDEQ(v int64) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldGithubInstallationID, v)) +} + +// GithubInstallationIDNEQ applies the NEQ predicate on the "github_installation_id" field. +func GithubInstallationIDNEQ(v int64) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldGithubInstallationID, v)) +} + +// GithubInstallationIDIn applies the In predicate on the "github_installation_id" field. +func GithubInstallationIDIn(vs ...int64) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldGithubInstallationID, vs...)) +} + +// GithubInstallationIDNotIn applies the NotIn predicate on the "github_installation_id" field. +func GithubInstallationIDNotIn(vs ...int64) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldGithubInstallationID, vs...)) +} + +// GithubInstallationIDGT applies the GT predicate on the "github_installation_id" field. +func GithubInstallationIDGT(v int64) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldGithubInstallationID, v)) +} + +// GithubInstallationIDGTE applies the GTE predicate on the "github_installation_id" field. +func GithubInstallationIDGTE(v int64) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldGithubInstallationID, v)) +} + +// GithubInstallationIDLT applies the LT predicate on the "github_installation_id" field. +func GithubInstallationIDLT(v int64) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldGithubInstallationID, v)) +} + +// GithubInstallationIDLTE applies the LTE predicate on the "github_installation_id" field. +func GithubInstallationIDLTE(v int64) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldGithubInstallationID, v)) +} + +// GithubInstallationIDIsNil applies the IsNil predicate on the "github_installation_id" field. +func GithubInstallationIDIsNil() predicate.GitTask { + return predicate.GitTask(sql.FieldIsNull(FieldGithubInstallationID)) +} + +// GithubInstallationIDNotNil applies the NotNil predicate on the "github_installation_id" field. +func GithubInstallationIDNotNil() predicate.GitTask { + return predicate.GitTask(sql.FieldNotNull(FieldGithubInstallationID)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.GitTask { + return predicate.GitTask(sql.FieldLTE(FieldCreatedAt, v)) +} + +// HasTask applies the HasEdge predicate on the "task" edge. +func HasTask() predicate.GitTask { + return predicate.GitTask(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2O, true, TaskTable, TaskColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasTaskWith applies the HasEdge predicate on the "task" edge with a given conditions (other predicates). +func HasTaskWith(preds ...predicate.Task) predicate.GitTask { + return predicate.GitTask(func(s *sql.Selector) { + step := newTaskStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.GitTask) predicate.GitTask { + return predicate.GitTask(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.GitTask) predicate.GitTask { + return predicate.GitTask(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.GitTask) predicate.GitTask { + return predicate.GitTask(sql.NotPredicates(p)) +} diff --git a/backend/db/gittask_create.go b/backend/db/gittask_create.go new file mode 100644 index 00000000..a96f9cea --- /dev/null +++ b/backend/db/gittask_create.go @@ -0,0 +1,1306 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/gittask" + "github.com/chaitin/MonkeyCode/backend/db/task" + "github.com/google/uuid" +) + +// GitTaskCreate is the builder for creating a GitTask entity. +type GitTaskCreate struct { + config + mutation *GitTaskMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetTaskID sets the "task_id" field. +func (_c *GitTaskCreate) SetTaskID(v uuid.UUID) *GitTaskCreate { + _c.mutation.SetTaskID(v) + return _c +} + +// SetRepoID sets the "repo_id" field. +func (_c *GitTaskCreate) SetRepoID(v uuid.UUID) *GitTaskCreate { + _c.mutation.SetRepoID(v) + return _c +} + +// SetNillableRepoID sets the "repo_id" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableRepoID(v *uuid.UUID) *GitTaskCreate { + if v != nil { + _c.SetRepoID(*v) + } + return _c +} + +// SetSubjectType sets the "subject_type" field. +func (_c *GitTaskCreate) SetSubjectType(v string) *GitTaskCreate { + _c.mutation.SetSubjectType(v) + return _c +} + +// SetSubjectID sets the "subject_id" field. +func (_c *GitTaskCreate) SetSubjectID(v string) *GitTaskCreate { + _c.mutation.SetSubjectID(v) + return _c +} + +// SetNillableSubjectID sets the "subject_id" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableSubjectID(v *string) *GitTaskCreate { + if v != nil { + _c.SetSubjectID(*v) + } + return _c +} + +// SetSubjectNumber sets the "subject_number" field. +func (_c *GitTaskCreate) SetSubjectNumber(v int) *GitTaskCreate { + _c.mutation.SetSubjectNumber(v) + return _c +} + +// SetNillableSubjectNumber sets the "subject_number" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableSubjectNumber(v *int) *GitTaskCreate { + if v != nil { + _c.SetSubjectNumber(*v) + } + return _c +} + +// SetSubjectURL sets the "subject_url" field. +func (_c *GitTaskCreate) SetSubjectURL(v string) *GitTaskCreate { + _c.mutation.SetSubjectURL(v) + return _c +} + +// SetNillableSubjectURL sets the "subject_url" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableSubjectURL(v *string) *GitTaskCreate { + if v != nil { + _c.SetSubjectURL(*v) + } + return _c +} + +// SetSubjectTitle sets the "subject_title" field. +func (_c *GitTaskCreate) SetSubjectTitle(v string) *GitTaskCreate { + _c.mutation.SetSubjectTitle(v) + return _c +} + +// SetNillableSubjectTitle sets the "subject_title" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableSubjectTitle(v *string) *GitTaskCreate { + if v != nil { + _c.SetSubjectTitle(*v) + } + return _c +} + +// SetPromptID sets the "prompt_id" field. +func (_c *GitTaskCreate) SetPromptID(v string) *GitTaskCreate { + _c.mutation.SetPromptID(v) + return _c +} + +// SetNillablePromptID sets the "prompt_id" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillablePromptID(v *string) *GitTaskCreate { + if v != nil { + _c.SetPromptID(*v) + } + return _c +} + +// SetShowURL sets the "show_url" field. +func (_c *GitTaskCreate) SetShowURL(v string) *GitTaskCreate { + _c.mutation.SetShowURL(v) + return _c +} + +// SetNillableShowURL sets the "show_url" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableShowURL(v *string) *GitTaskCreate { + if v != nil { + _c.SetShowURL(*v) + } + return _c +} + +// SetGithubInstallationID sets the "github_installation_id" field. +func (_c *GitTaskCreate) SetGithubInstallationID(v int64) *GitTaskCreate { + _c.mutation.SetGithubInstallationID(v) + return _c +} + +// SetNillableGithubInstallationID sets the "github_installation_id" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableGithubInstallationID(v *int64) *GitTaskCreate { + if v != nil { + _c.SetGithubInstallationID(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *GitTaskCreate) SetCreatedAt(v time.Time) *GitTaskCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *GitTaskCreate) SetNillableCreatedAt(v *time.Time) *GitTaskCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *GitTaskCreate) SetID(v uuid.UUID) *GitTaskCreate { + _c.mutation.SetID(v) + return _c +} + +// SetTask sets the "task" edge to the Task entity. +func (_c *GitTaskCreate) SetTask(v *Task) *GitTaskCreate { + return _c.SetTaskID(v.ID) +} + +// Mutation returns the GitTaskMutation object of the builder. +func (_c *GitTaskCreate) Mutation() *GitTaskMutation { + return _c.mutation +} + +// Save creates the GitTask in the database. +func (_c *GitTaskCreate) Save(ctx context.Context) (*GitTask, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *GitTaskCreate) SaveX(ctx context.Context) *GitTask { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *GitTaskCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *GitTaskCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *GitTaskCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := gittask.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *GitTaskCreate) check() error { + if _, ok := _c.mutation.TaskID(); !ok { + return &ValidationError{Name: "task_id", err: errors.New(`db: missing required field "GitTask.task_id"`)} + } + if _, ok := _c.mutation.SubjectType(); !ok { + return &ValidationError{Name: "subject_type", err: errors.New(`db: missing required field "GitTask.subject_type"`)} + } + if v, ok := _c.mutation.SubjectType(); ok { + if err := gittask.SubjectTypeValidator(v); err != nil { + return &ValidationError{Name: "subject_type", err: fmt.Errorf(`db: validator failed for field "GitTask.subject_type": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`db: missing required field "GitTask.created_at"`)} + } + if len(_c.mutation.TaskIDs()) == 0 { + return &ValidationError{Name: "task", err: errors.New(`db: missing required edge "GitTask.task"`)} + } + return nil +} + +func (_c *GitTaskCreate) sqlSave(ctx context.Context) (*GitTask, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *GitTaskCreate) createSpec() (*GitTask, *sqlgraph.CreateSpec) { + var ( + _node = &GitTask{config: _c.config} + _spec = sqlgraph.NewCreateSpec(gittask.Table, sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID)) + ) + _spec.OnConflict = _c.conflict + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := _c.mutation.RepoID(); ok { + _spec.SetField(gittask.FieldRepoID, field.TypeUUID, value) + _node.RepoID = value + } + if value, ok := _c.mutation.SubjectType(); ok { + _spec.SetField(gittask.FieldSubjectType, field.TypeString, value) + _node.SubjectType = value + } + if value, ok := _c.mutation.SubjectID(); ok { + _spec.SetField(gittask.FieldSubjectID, field.TypeString, value) + _node.SubjectID = value + } + if value, ok := _c.mutation.SubjectNumber(); ok { + _spec.SetField(gittask.FieldSubjectNumber, field.TypeInt, value) + _node.SubjectNumber = value + } + if value, ok := _c.mutation.SubjectURL(); ok { + _spec.SetField(gittask.FieldSubjectURL, field.TypeString, value) + _node.SubjectURL = value + } + if value, ok := _c.mutation.SubjectTitle(); ok { + _spec.SetField(gittask.FieldSubjectTitle, field.TypeString, value) + _node.SubjectTitle = value + } + if value, ok := _c.mutation.PromptID(); ok { + _spec.SetField(gittask.FieldPromptID, field.TypeString, value) + _node.PromptID = value + } + if value, ok := _c.mutation.ShowURL(); ok { + _spec.SetField(gittask.FieldShowURL, field.TypeString, value) + _node.ShowURL = value + } + if value, ok := _c.mutation.GithubInstallationID(); ok { + _spec.SetField(gittask.FieldGithubInstallationID, field.TypeInt64, value) + _node.GithubInstallationID = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(gittask.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if nodes := _c.mutation.TaskIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: true, + Table: gittask.TaskTable, + Columns: []string{gittask.TaskColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.TaskID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.GitTask.Create(). +// SetTaskID(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.GitTaskUpsert) { +// SetTaskID(v+v). +// }). +// Exec(ctx) +func (_c *GitTaskCreate) OnConflict(opts ...sql.ConflictOption) *GitTaskUpsertOne { + _c.conflict = opts + return &GitTaskUpsertOne{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.GitTask.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *GitTaskCreate) OnConflictColumns(columns ...string) *GitTaskUpsertOne { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &GitTaskUpsertOne{ + create: _c, + } +} + +type ( + // GitTaskUpsertOne is the builder for "upsert"-ing + // one GitTask node. + GitTaskUpsertOne struct { + create *GitTaskCreate + } + + // GitTaskUpsert is the "OnConflict" setter. + GitTaskUpsert struct { + *sql.UpdateSet + } +) + +// SetTaskID sets the "task_id" field. +func (u *GitTaskUpsert) SetTaskID(v uuid.UUID) *GitTaskUpsert { + u.Set(gittask.FieldTaskID, v) + return u +} + +// UpdateTaskID sets the "task_id" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateTaskID() *GitTaskUpsert { + u.SetExcluded(gittask.FieldTaskID) + return u +} + +// SetRepoID sets the "repo_id" field. +func (u *GitTaskUpsert) SetRepoID(v uuid.UUID) *GitTaskUpsert { + u.Set(gittask.FieldRepoID, v) + return u +} + +// UpdateRepoID sets the "repo_id" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateRepoID() *GitTaskUpsert { + u.SetExcluded(gittask.FieldRepoID) + return u +} + +// ClearRepoID clears the value of the "repo_id" field. +func (u *GitTaskUpsert) ClearRepoID() *GitTaskUpsert { + u.SetNull(gittask.FieldRepoID) + return u +} + +// SetSubjectType sets the "subject_type" field. +func (u *GitTaskUpsert) SetSubjectType(v string) *GitTaskUpsert { + u.Set(gittask.FieldSubjectType, v) + return u +} + +// UpdateSubjectType sets the "subject_type" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateSubjectType() *GitTaskUpsert { + u.SetExcluded(gittask.FieldSubjectType) + return u +} + +// SetSubjectID sets the "subject_id" field. +func (u *GitTaskUpsert) SetSubjectID(v string) *GitTaskUpsert { + u.Set(gittask.FieldSubjectID, v) + return u +} + +// UpdateSubjectID sets the "subject_id" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateSubjectID() *GitTaskUpsert { + u.SetExcluded(gittask.FieldSubjectID) + return u +} + +// ClearSubjectID clears the value of the "subject_id" field. +func (u *GitTaskUpsert) ClearSubjectID() *GitTaskUpsert { + u.SetNull(gittask.FieldSubjectID) + return u +} + +// SetSubjectNumber sets the "subject_number" field. +func (u *GitTaskUpsert) SetSubjectNumber(v int) *GitTaskUpsert { + u.Set(gittask.FieldSubjectNumber, v) + return u +} + +// UpdateSubjectNumber sets the "subject_number" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateSubjectNumber() *GitTaskUpsert { + u.SetExcluded(gittask.FieldSubjectNumber) + return u +} + +// AddSubjectNumber adds v to the "subject_number" field. +func (u *GitTaskUpsert) AddSubjectNumber(v int) *GitTaskUpsert { + u.Add(gittask.FieldSubjectNumber, v) + return u +} + +// ClearSubjectNumber clears the value of the "subject_number" field. +func (u *GitTaskUpsert) ClearSubjectNumber() *GitTaskUpsert { + u.SetNull(gittask.FieldSubjectNumber) + return u +} + +// SetSubjectURL sets the "subject_url" field. +func (u *GitTaskUpsert) SetSubjectURL(v string) *GitTaskUpsert { + u.Set(gittask.FieldSubjectURL, v) + return u +} + +// UpdateSubjectURL sets the "subject_url" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateSubjectURL() *GitTaskUpsert { + u.SetExcluded(gittask.FieldSubjectURL) + return u +} + +// ClearSubjectURL clears the value of the "subject_url" field. +func (u *GitTaskUpsert) ClearSubjectURL() *GitTaskUpsert { + u.SetNull(gittask.FieldSubjectURL) + return u +} + +// SetSubjectTitle sets the "subject_title" field. +func (u *GitTaskUpsert) SetSubjectTitle(v string) *GitTaskUpsert { + u.Set(gittask.FieldSubjectTitle, v) + return u +} + +// UpdateSubjectTitle sets the "subject_title" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateSubjectTitle() *GitTaskUpsert { + u.SetExcluded(gittask.FieldSubjectTitle) + return u +} + +// ClearSubjectTitle clears the value of the "subject_title" field. +func (u *GitTaskUpsert) ClearSubjectTitle() *GitTaskUpsert { + u.SetNull(gittask.FieldSubjectTitle) + return u +} + +// SetPromptID sets the "prompt_id" field. +func (u *GitTaskUpsert) SetPromptID(v string) *GitTaskUpsert { + u.Set(gittask.FieldPromptID, v) + return u +} + +// UpdatePromptID sets the "prompt_id" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdatePromptID() *GitTaskUpsert { + u.SetExcluded(gittask.FieldPromptID) + return u +} + +// ClearPromptID clears the value of the "prompt_id" field. +func (u *GitTaskUpsert) ClearPromptID() *GitTaskUpsert { + u.SetNull(gittask.FieldPromptID) + return u +} + +// SetShowURL sets the "show_url" field. +func (u *GitTaskUpsert) SetShowURL(v string) *GitTaskUpsert { + u.Set(gittask.FieldShowURL, v) + return u +} + +// UpdateShowURL sets the "show_url" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateShowURL() *GitTaskUpsert { + u.SetExcluded(gittask.FieldShowURL) + return u +} + +// ClearShowURL clears the value of the "show_url" field. +func (u *GitTaskUpsert) ClearShowURL() *GitTaskUpsert { + u.SetNull(gittask.FieldShowURL) + return u +} + +// SetGithubInstallationID sets the "github_installation_id" field. +func (u *GitTaskUpsert) SetGithubInstallationID(v int64) *GitTaskUpsert { + u.Set(gittask.FieldGithubInstallationID, v) + return u +} + +// UpdateGithubInstallationID sets the "github_installation_id" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateGithubInstallationID() *GitTaskUpsert { + u.SetExcluded(gittask.FieldGithubInstallationID) + return u +} + +// AddGithubInstallationID adds v to the "github_installation_id" field. +func (u *GitTaskUpsert) AddGithubInstallationID(v int64) *GitTaskUpsert { + u.Add(gittask.FieldGithubInstallationID, v) + return u +} + +// ClearGithubInstallationID clears the value of the "github_installation_id" field. +func (u *GitTaskUpsert) ClearGithubInstallationID() *GitTaskUpsert { + u.SetNull(gittask.FieldGithubInstallationID) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *GitTaskUpsert) SetCreatedAt(v time.Time) *GitTaskUpsert { + u.Set(gittask.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *GitTaskUpsert) UpdateCreatedAt() *GitTaskUpsert { + u.SetExcluded(gittask.FieldCreatedAt) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// Using this option is equivalent to using: +// +// client.GitTask.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(gittask.FieldID) +// }), +// ). +// Exec(ctx) +func (u *GitTaskUpsertOne) UpdateNewValues() *GitTaskUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + if _, exists := u.create.mutation.ID(); exists { + s.SetIgnore(gittask.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.GitTask.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *GitTaskUpsertOne) Ignore() *GitTaskUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *GitTaskUpsertOne) DoNothing() *GitTaskUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the GitTaskCreate.OnConflict +// documentation for more info. +func (u *GitTaskUpsertOne) Update(set func(*GitTaskUpsert)) *GitTaskUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&GitTaskUpsert{UpdateSet: update}) + })) + return u +} + +// SetTaskID sets the "task_id" field. +func (u *GitTaskUpsertOne) SetTaskID(v uuid.UUID) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetTaskID(v) + }) +} + +// UpdateTaskID sets the "task_id" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateTaskID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateTaskID() + }) +} + +// SetRepoID sets the "repo_id" field. +func (u *GitTaskUpsertOne) SetRepoID(v uuid.UUID) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetRepoID(v) + }) +} + +// UpdateRepoID sets the "repo_id" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateRepoID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateRepoID() + }) +} + +// ClearRepoID clears the value of the "repo_id" field. +func (u *GitTaskUpsertOne) ClearRepoID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearRepoID() + }) +} + +// SetSubjectType sets the "subject_type" field. +func (u *GitTaskUpsertOne) SetSubjectType(v string) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectType(v) + }) +} + +// UpdateSubjectType sets the "subject_type" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateSubjectType() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectType() + }) +} + +// SetSubjectID sets the "subject_id" field. +func (u *GitTaskUpsertOne) SetSubjectID(v string) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectID(v) + }) +} + +// UpdateSubjectID sets the "subject_id" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateSubjectID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectID() + }) +} + +// ClearSubjectID clears the value of the "subject_id" field. +func (u *GitTaskUpsertOne) ClearSubjectID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectID() + }) +} + +// SetSubjectNumber sets the "subject_number" field. +func (u *GitTaskUpsertOne) SetSubjectNumber(v int) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectNumber(v) + }) +} + +// AddSubjectNumber adds v to the "subject_number" field. +func (u *GitTaskUpsertOne) AddSubjectNumber(v int) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.AddSubjectNumber(v) + }) +} + +// UpdateSubjectNumber sets the "subject_number" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateSubjectNumber() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectNumber() + }) +} + +// ClearSubjectNumber clears the value of the "subject_number" field. +func (u *GitTaskUpsertOne) ClearSubjectNumber() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectNumber() + }) +} + +// SetSubjectURL sets the "subject_url" field. +func (u *GitTaskUpsertOne) SetSubjectURL(v string) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectURL(v) + }) +} + +// UpdateSubjectURL sets the "subject_url" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateSubjectURL() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectURL() + }) +} + +// ClearSubjectURL clears the value of the "subject_url" field. +func (u *GitTaskUpsertOne) ClearSubjectURL() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectURL() + }) +} + +// SetSubjectTitle sets the "subject_title" field. +func (u *GitTaskUpsertOne) SetSubjectTitle(v string) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectTitle(v) + }) +} + +// UpdateSubjectTitle sets the "subject_title" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateSubjectTitle() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectTitle() + }) +} + +// ClearSubjectTitle clears the value of the "subject_title" field. +func (u *GitTaskUpsertOne) ClearSubjectTitle() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectTitle() + }) +} + +// SetPromptID sets the "prompt_id" field. +func (u *GitTaskUpsertOne) SetPromptID(v string) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetPromptID(v) + }) +} + +// UpdatePromptID sets the "prompt_id" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdatePromptID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdatePromptID() + }) +} + +// ClearPromptID clears the value of the "prompt_id" field. +func (u *GitTaskUpsertOne) ClearPromptID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearPromptID() + }) +} + +// SetShowURL sets the "show_url" field. +func (u *GitTaskUpsertOne) SetShowURL(v string) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetShowURL(v) + }) +} + +// UpdateShowURL sets the "show_url" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateShowURL() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateShowURL() + }) +} + +// ClearShowURL clears the value of the "show_url" field. +func (u *GitTaskUpsertOne) ClearShowURL() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearShowURL() + }) +} + +// SetGithubInstallationID sets the "github_installation_id" field. +func (u *GitTaskUpsertOne) SetGithubInstallationID(v int64) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetGithubInstallationID(v) + }) +} + +// AddGithubInstallationID adds v to the "github_installation_id" field. +func (u *GitTaskUpsertOne) AddGithubInstallationID(v int64) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.AddGithubInstallationID(v) + }) +} + +// UpdateGithubInstallationID sets the "github_installation_id" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateGithubInstallationID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateGithubInstallationID() + }) +} + +// ClearGithubInstallationID clears the value of the "github_installation_id" field. +func (u *GitTaskUpsertOne) ClearGithubInstallationID() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.ClearGithubInstallationID() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *GitTaskUpsertOne) SetCreatedAt(v time.Time) *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *GitTaskUpsertOne) UpdateCreatedAt() *GitTaskUpsertOne { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *GitTaskUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for GitTaskCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *GitTaskUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *GitTaskUpsertOne) ID(ctx context.Context) (id uuid.UUID, err error) { + if u.create.driver.Dialect() == dialect.MySQL { + // In case of "ON CONFLICT", there is no way to get back non-numeric ID + // fields from the database since MySQL does not support the RETURNING clause. + return id, errors.New("db: GitTaskUpsertOne.ID is not supported by MySQL driver. Use GitTaskUpsertOne.Exec instead") + } + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *GitTaskUpsertOne) IDX(ctx context.Context) uuid.UUID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// GitTaskCreateBulk is the builder for creating many GitTask entities in bulk. +type GitTaskCreateBulk struct { + config + err error + builders []*GitTaskCreate + conflict []sql.ConflictOption +} + +// Save creates the GitTask entities in the database. +func (_c *GitTaskCreateBulk) Save(ctx context.Context) ([]*GitTask, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*GitTask, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*GitTaskMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = _c.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *GitTaskCreateBulk) SaveX(ctx context.Context) []*GitTask { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *GitTaskCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *GitTaskCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.GitTask.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.GitTaskUpsert) { +// SetTaskID(v+v). +// }). +// Exec(ctx) +func (_c *GitTaskCreateBulk) OnConflict(opts ...sql.ConflictOption) *GitTaskUpsertBulk { + _c.conflict = opts + return &GitTaskUpsertBulk{ + create: _c, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.GitTask.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (_c *GitTaskCreateBulk) OnConflictColumns(columns ...string) *GitTaskUpsertBulk { + _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) + return &GitTaskUpsertBulk{ + create: _c, + } +} + +// GitTaskUpsertBulk is the builder for "upsert"-ing +// a bulk of GitTask nodes. +type GitTaskUpsertBulk struct { + create *GitTaskCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.GitTask.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(gittask.FieldID) +// }), +// ). +// Exec(ctx) +func (u *GitTaskUpsertBulk) UpdateNewValues() *GitTaskUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + for _, b := range u.create.builders { + if _, exists := b.mutation.ID(); exists { + s.SetIgnore(gittask.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.GitTask.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *GitTaskUpsertBulk) Ignore() *GitTaskUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *GitTaskUpsertBulk) DoNothing() *GitTaskUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the GitTaskCreateBulk.OnConflict +// documentation for more info. +func (u *GitTaskUpsertBulk) Update(set func(*GitTaskUpsert)) *GitTaskUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&GitTaskUpsert{UpdateSet: update}) + })) + return u +} + +// SetTaskID sets the "task_id" field. +func (u *GitTaskUpsertBulk) SetTaskID(v uuid.UUID) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetTaskID(v) + }) +} + +// UpdateTaskID sets the "task_id" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateTaskID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateTaskID() + }) +} + +// SetRepoID sets the "repo_id" field. +func (u *GitTaskUpsertBulk) SetRepoID(v uuid.UUID) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetRepoID(v) + }) +} + +// UpdateRepoID sets the "repo_id" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateRepoID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateRepoID() + }) +} + +// ClearRepoID clears the value of the "repo_id" field. +func (u *GitTaskUpsertBulk) ClearRepoID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearRepoID() + }) +} + +// SetSubjectType sets the "subject_type" field. +func (u *GitTaskUpsertBulk) SetSubjectType(v string) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectType(v) + }) +} + +// UpdateSubjectType sets the "subject_type" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateSubjectType() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectType() + }) +} + +// SetSubjectID sets the "subject_id" field. +func (u *GitTaskUpsertBulk) SetSubjectID(v string) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectID(v) + }) +} + +// UpdateSubjectID sets the "subject_id" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateSubjectID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectID() + }) +} + +// ClearSubjectID clears the value of the "subject_id" field. +func (u *GitTaskUpsertBulk) ClearSubjectID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectID() + }) +} + +// SetSubjectNumber sets the "subject_number" field. +func (u *GitTaskUpsertBulk) SetSubjectNumber(v int) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectNumber(v) + }) +} + +// AddSubjectNumber adds v to the "subject_number" field. +func (u *GitTaskUpsertBulk) AddSubjectNumber(v int) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.AddSubjectNumber(v) + }) +} + +// UpdateSubjectNumber sets the "subject_number" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateSubjectNumber() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectNumber() + }) +} + +// ClearSubjectNumber clears the value of the "subject_number" field. +func (u *GitTaskUpsertBulk) ClearSubjectNumber() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectNumber() + }) +} + +// SetSubjectURL sets the "subject_url" field. +func (u *GitTaskUpsertBulk) SetSubjectURL(v string) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectURL(v) + }) +} + +// UpdateSubjectURL sets the "subject_url" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateSubjectURL() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectURL() + }) +} + +// ClearSubjectURL clears the value of the "subject_url" field. +func (u *GitTaskUpsertBulk) ClearSubjectURL() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectURL() + }) +} + +// SetSubjectTitle sets the "subject_title" field. +func (u *GitTaskUpsertBulk) SetSubjectTitle(v string) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetSubjectTitle(v) + }) +} + +// UpdateSubjectTitle sets the "subject_title" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateSubjectTitle() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateSubjectTitle() + }) +} + +// ClearSubjectTitle clears the value of the "subject_title" field. +func (u *GitTaskUpsertBulk) ClearSubjectTitle() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearSubjectTitle() + }) +} + +// SetPromptID sets the "prompt_id" field. +func (u *GitTaskUpsertBulk) SetPromptID(v string) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetPromptID(v) + }) +} + +// UpdatePromptID sets the "prompt_id" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdatePromptID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdatePromptID() + }) +} + +// ClearPromptID clears the value of the "prompt_id" field. +func (u *GitTaskUpsertBulk) ClearPromptID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearPromptID() + }) +} + +// SetShowURL sets the "show_url" field. +func (u *GitTaskUpsertBulk) SetShowURL(v string) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetShowURL(v) + }) +} + +// UpdateShowURL sets the "show_url" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateShowURL() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateShowURL() + }) +} + +// ClearShowURL clears the value of the "show_url" field. +func (u *GitTaskUpsertBulk) ClearShowURL() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearShowURL() + }) +} + +// SetGithubInstallationID sets the "github_installation_id" field. +func (u *GitTaskUpsertBulk) SetGithubInstallationID(v int64) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetGithubInstallationID(v) + }) +} + +// AddGithubInstallationID adds v to the "github_installation_id" field. +func (u *GitTaskUpsertBulk) AddGithubInstallationID(v int64) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.AddGithubInstallationID(v) + }) +} + +// UpdateGithubInstallationID sets the "github_installation_id" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateGithubInstallationID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateGithubInstallationID() + }) +} + +// ClearGithubInstallationID clears the value of the "github_installation_id" field. +func (u *GitTaskUpsertBulk) ClearGithubInstallationID() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.ClearGithubInstallationID() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *GitTaskUpsertBulk) SetCreatedAt(v time.Time) *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *GitTaskUpsertBulk) UpdateCreatedAt() *GitTaskUpsertBulk { + return u.Update(func(s *GitTaskUpsert) { + s.UpdateCreatedAt() + }) +} + +// Exec executes the query. +func (u *GitTaskUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("db: OnConflict was set for builder %d. Set it on the GitTaskCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("db: missing options for GitTaskCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *GitTaskUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/gittask_delete.go b/backend/db/gittask_delete.go new file mode 100644 index 00000000..d7126719 --- /dev/null +++ b/backend/db/gittask_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/gittask" + "github.com/chaitin/MonkeyCode/backend/db/predicate" +) + +// GitTaskDelete is the builder for deleting a GitTask entity. +type GitTaskDelete struct { + config + hooks []Hook + mutation *GitTaskMutation +} + +// Where appends a list predicates to the GitTaskDelete builder. +func (_d *GitTaskDelete) Where(ps ...predicate.GitTask) *GitTaskDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *GitTaskDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *GitTaskDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *GitTaskDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(gittask.Table, sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// GitTaskDeleteOne is the builder for deleting a single GitTask entity. +type GitTaskDeleteOne struct { + _d *GitTaskDelete +} + +// Where appends a list predicates to the GitTaskDelete builder. +func (_d *GitTaskDeleteOne) Where(ps ...predicate.GitTask) *GitTaskDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *GitTaskDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{gittask.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *GitTaskDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/backend/db/gittask_query.go b/backend/db/gittask_query.go new file mode 100644 index 00000000..10e262ad --- /dev/null +++ b/backend/db/gittask_query.go @@ -0,0 +1,657 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/gittask" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/task" + "github.com/google/uuid" +) + +// GitTaskQuery is the builder for querying GitTask entities. +type GitTaskQuery struct { + config + ctx *QueryContext + order []gittask.OrderOption + inters []Interceptor + predicates []predicate.GitTask + withTask *TaskQuery + modifiers []func(*sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the GitTaskQuery builder. +func (_q *GitTaskQuery) Where(ps ...predicate.GitTask) *GitTaskQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *GitTaskQuery) Limit(limit int) *GitTaskQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *GitTaskQuery) Offset(offset int) *GitTaskQuery { + _q.ctx.Offset = &offset + return _q +} + +// 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 (_q *GitTaskQuery) Unique(unique bool) *GitTaskQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *GitTaskQuery) Order(o ...gittask.OrderOption) *GitTaskQuery { + _q.order = append(_q.order, o...) + return _q +} + +// QueryTask chains the current query on the "task" edge. +func (_q *GitTaskQuery) QueryTask() *TaskQuery { + query := (&TaskClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(gittask.Table, gittask.FieldID, selector), + sqlgraph.To(task.Table, task.FieldID), + sqlgraph.Edge(sqlgraph.O2O, true, gittask.TaskTable, gittask.TaskColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first GitTask entity from the query. +// Returns a *NotFoundError when no GitTask was found. +func (_q *GitTaskQuery) First(ctx context.Context) (*GitTask, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{gittask.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *GitTaskQuery) FirstX(ctx context.Context) *GitTask { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first GitTask ID from the query. +// Returns a *NotFoundError when no GitTask ID was found. +func (_q *GitTaskQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{gittask.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *GitTaskQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single GitTask entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one GitTask entity is found. +// Returns a *NotFoundError when no GitTask entities are found. +func (_q *GitTaskQuery) Only(ctx context.Context) (*GitTask, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{gittask.Label} + default: + return nil, &NotSingularError{gittask.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *GitTaskQuery) OnlyX(ctx context.Context) *GitTask { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only GitTask ID in the query. +// Returns a *NotSingularError when more than one GitTask ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *GitTaskQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{gittask.Label} + default: + err = &NotSingularError{gittask.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *GitTaskQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of GitTasks. +func (_q *GitTaskQuery) All(ctx context.Context) ([]*GitTask, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*GitTask, *GitTaskQuery]() + return withInterceptors[[]*GitTask](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *GitTaskQuery) AllX(ctx context.Context) []*GitTask { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of GitTask IDs. +func (_q *GitTaskQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(gittask.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *GitTaskQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *GitTaskQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*GitTaskQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *GitTaskQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *GitTaskQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("db: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *GitTaskQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the GitTaskQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *GitTaskQuery) Clone() *GitTaskQuery { + if _q == nil { + return nil + } + return &GitTaskQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]gittask.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.GitTask{}, _q.predicates...), + withTask: _q.withTask.Clone(), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + modifiers: append([]func(*sql.Selector){}, _q.modifiers...), + } +} + +// WithTask tells the query-builder to eager-load the nodes that are connected to +// the "task" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *GitTaskQuery) WithTask(opts ...func(*TaskQuery)) *GitTaskQuery { + query := (&TaskClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withTask = query + return _q +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// TaskID uuid.UUID `json:"task_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.GitTask.Query(). +// GroupBy(gittask.FieldTaskID). +// Aggregate(db.Count()). +// Scan(ctx, &v) +func (_q *GitTaskQuery) GroupBy(field string, fields ...string) *GitTaskGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &GitTaskGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = gittask.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// TaskID uuid.UUID `json:"task_id,omitempty"` +// } +// +// client.GitTask.Query(). +// Select(gittask.FieldTaskID). +// Scan(ctx, &v) +func (_q *GitTaskQuery) Select(fields ...string) *GitTaskSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &GitTaskSelect{GitTaskQuery: _q} + sbuild.label = gittask.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a GitTaskSelect configured with the given aggregations. +func (_q *GitTaskQuery) Aggregate(fns ...AggregateFunc) *GitTaskSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *GitTaskQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("db: uninitialized interceptor (forgotten import db/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !gittask.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *GitTaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GitTask, error) { + var ( + nodes = []*GitTask{} + _spec = _q.querySpec() + loadedTypes = [1]bool{ + _q.withTask != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*GitTask).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &GitTask{config: _q.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := _q.withTask; query != nil { + if err := _q.loadTask(ctx, query, nodes, nil, + func(n *GitTask, e *Task) { n.Edges.Task = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (_q *GitTaskQuery) loadTask(ctx context.Context, query *TaskQuery, nodes []*GitTask, init func(*GitTask), assign func(*GitTask, *Task)) error { + ids := make([]uuid.UUID, 0, len(nodes)) + nodeids := make(map[uuid.UUID][]*GitTask) + for i := range nodes { + fk := nodes[i].TaskID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(task.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "task_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (_q *GitTaskQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *GitTaskQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(gittask.Table, gittask.Columns, sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, gittask.FieldID) + for i := range fields { + if fields[i] != gittask.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if _q.withTask != nil { + _spec.Node.AddColumnOnce(gittask.FieldTaskID) + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *GitTaskQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(gittask.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = gittask.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, m := range _q.modifiers { + m(selector) + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.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 := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return 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 (_q *GitTaskQuery) ForUpdate(opts ...sql.LockOption) *GitTaskQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return _q +} + +// 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 (_q *GitTaskQuery) ForShare(opts ...sql.LockOption) *GitTaskQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_q *GitTaskQuery) Modify(modifiers ...func(s *sql.Selector)) *GitTaskSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// GitTaskGroupBy is the group-by builder for GitTask entities. +type GitTaskGroupBy struct { + selector + build *GitTaskQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *GitTaskGroupBy) Aggregate(fns ...AggregateFunc) *GitTaskGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *GitTaskGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*GitTaskQuery, *GitTaskGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *GitTaskGroupBy) sqlScan(ctx context.Context, root *GitTaskQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// GitTaskSelect is the builder for selecting fields of GitTask entities. +type GitTaskSelect struct { + *GitTaskQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *GitTaskSelect) Aggregate(fns ...AggregateFunc) *GitTaskSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *GitTaskSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*GitTaskQuery, *GitTaskSelect](ctx, _s.GitTaskQuery, _s, _s.inters, v) +} + +func (_s *GitTaskSelect) sqlScan(ctx context.Context, root *GitTaskQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_s *GitTaskSelect) Modify(modifiers ...func(s *sql.Selector)) *GitTaskSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/backend/db/gittask_update.go b/backend/db/gittask_update.go new file mode 100644 index 00000000..fc8e8548 --- /dev/null +++ b/backend/db/gittask_update.go @@ -0,0 +1,858 @@ +// Code generated by ent, DO NOT EDIT. + +package db + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/chaitin/MonkeyCode/backend/db/gittask" + "github.com/chaitin/MonkeyCode/backend/db/predicate" + "github.com/chaitin/MonkeyCode/backend/db/task" + "github.com/google/uuid" +) + +// GitTaskUpdate is the builder for updating GitTask entities. +type GitTaskUpdate struct { + config + hooks []Hook + mutation *GitTaskMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the GitTaskUpdate builder. +func (_u *GitTaskUpdate) Where(ps ...predicate.GitTask) *GitTaskUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetTaskID sets the "task_id" field. +func (_u *GitTaskUpdate) SetTaskID(v uuid.UUID) *GitTaskUpdate { + _u.mutation.SetTaskID(v) + return _u +} + +// SetNillableTaskID sets the "task_id" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableTaskID(v *uuid.UUID) *GitTaskUpdate { + if v != nil { + _u.SetTaskID(*v) + } + return _u +} + +// SetRepoID sets the "repo_id" field. +func (_u *GitTaskUpdate) SetRepoID(v uuid.UUID) *GitTaskUpdate { + _u.mutation.SetRepoID(v) + return _u +} + +// SetNillableRepoID sets the "repo_id" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableRepoID(v *uuid.UUID) *GitTaskUpdate { + if v != nil { + _u.SetRepoID(*v) + } + return _u +} + +// ClearRepoID clears the value of the "repo_id" field. +func (_u *GitTaskUpdate) ClearRepoID() *GitTaskUpdate { + _u.mutation.ClearRepoID() + return _u +} + +// SetSubjectType sets the "subject_type" field. +func (_u *GitTaskUpdate) SetSubjectType(v string) *GitTaskUpdate { + _u.mutation.SetSubjectType(v) + return _u +} + +// SetNillableSubjectType sets the "subject_type" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableSubjectType(v *string) *GitTaskUpdate { + if v != nil { + _u.SetSubjectType(*v) + } + return _u +} + +// SetSubjectID sets the "subject_id" field. +func (_u *GitTaskUpdate) SetSubjectID(v string) *GitTaskUpdate { + _u.mutation.SetSubjectID(v) + return _u +} + +// SetNillableSubjectID sets the "subject_id" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableSubjectID(v *string) *GitTaskUpdate { + if v != nil { + _u.SetSubjectID(*v) + } + return _u +} + +// ClearSubjectID clears the value of the "subject_id" field. +func (_u *GitTaskUpdate) ClearSubjectID() *GitTaskUpdate { + _u.mutation.ClearSubjectID() + return _u +} + +// SetSubjectNumber sets the "subject_number" field. +func (_u *GitTaskUpdate) SetSubjectNumber(v int) *GitTaskUpdate { + _u.mutation.ResetSubjectNumber() + _u.mutation.SetSubjectNumber(v) + return _u +} + +// SetNillableSubjectNumber sets the "subject_number" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableSubjectNumber(v *int) *GitTaskUpdate { + if v != nil { + _u.SetSubjectNumber(*v) + } + return _u +} + +// AddSubjectNumber adds value to the "subject_number" field. +func (_u *GitTaskUpdate) AddSubjectNumber(v int) *GitTaskUpdate { + _u.mutation.AddSubjectNumber(v) + return _u +} + +// ClearSubjectNumber clears the value of the "subject_number" field. +func (_u *GitTaskUpdate) ClearSubjectNumber() *GitTaskUpdate { + _u.mutation.ClearSubjectNumber() + return _u +} + +// SetSubjectURL sets the "subject_url" field. +func (_u *GitTaskUpdate) SetSubjectURL(v string) *GitTaskUpdate { + _u.mutation.SetSubjectURL(v) + return _u +} + +// SetNillableSubjectURL sets the "subject_url" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableSubjectURL(v *string) *GitTaskUpdate { + if v != nil { + _u.SetSubjectURL(*v) + } + return _u +} + +// ClearSubjectURL clears the value of the "subject_url" field. +func (_u *GitTaskUpdate) ClearSubjectURL() *GitTaskUpdate { + _u.mutation.ClearSubjectURL() + return _u +} + +// SetSubjectTitle sets the "subject_title" field. +func (_u *GitTaskUpdate) SetSubjectTitle(v string) *GitTaskUpdate { + _u.mutation.SetSubjectTitle(v) + return _u +} + +// SetNillableSubjectTitle sets the "subject_title" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableSubjectTitle(v *string) *GitTaskUpdate { + if v != nil { + _u.SetSubjectTitle(*v) + } + return _u +} + +// ClearSubjectTitle clears the value of the "subject_title" field. +func (_u *GitTaskUpdate) ClearSubjectTitle() *GitTaskUpdate { + _u.mutation.ClearSubjectTitle() + return _u +} + +// SetPromptID sets the "prompt_id" field. +func (_u *GitTaskUpdate) SetPromptID(v string) *GitTaskUpdate { + _u.mutation.SetPromptID(v) + return _u +} + +// SetNillablePromptID sets the "prompt_id" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillablePromptID(v *string) *GitTaskUpdate { + if v != nil { + _u.SetPromptID(*v) + } + return _u +} + +// ClearPromptID clears the value of the "prompt_id" field. +func (_u *GitTaskUpdate) ClearPromptID() *GitTaskUpdate { + _u.mutation.ClearPromptID() + return _u +} + +// SetShowURL sets the "show_url" field. +func (_u *GitTaskUpdate) SetShowURL(v string) *GitTaskUpdate { + _u.mutation.SetShowURL(v) + return _u +} + +// SetNillableShowURL sets the "show_url" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableShowURL(v *string) *GitTaskUpdate { + if v != nil { + _u.SetShowURL(*v) + } + return _u +} + +// ClearShowURL clears the value of the "show_url" field. +func (_u *GitTaskUpdate) ClearShowURL() *GitTaskUpdate { + _u.mutation.ClearShowURL() + return _u +} + +// SetGithubInstallationID sets the "github_installation_id" field. +func (_u *GitTaskUpdate) SetGithubInstallationID(v int64) *GitTaskUpdate { + _u.mutation.ResetGithubInstallationID() + _u.mutation.SetGithubInstallationID(v) + return _u +} + +// SetNillableGithubInstallationID sets the "github_installation_id" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableGithubInstallationID(v *int64) *GitTaskUpdate { + if v != nil { + _u.SetGithubInstallationID(*v) + } + return _u +} + +// AddGithubInstallationID adds value to the "github_installation_id" field. +func (_u *GitTaskUpdate) AddGithubInstallationID(v int64) *GitTaskUpdate { + _u.mutation.AddGithubInstallationID(v) + return _u +} + +// ClearGithubInstallationID clears the value of the "github_installation_id" field. +func (_u *GitTaskUpdate) ClearGithubInstallationID() *GitTaskUpdate { + _u.mutation.ClearGithubInstallationID() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *GitTaskUpdate) SetCreatedAt(v time.Time) *GitTaskUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *GitTaskUpdate) SetNillableCreatedAt(v *time.Time) *GitTaskUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetTask sets the "task" edge to the Task entity. +func (_u *GitTaskUpdate) SetTask(v *Task) *GitTaskUpdate { + return _u.SetTaskID(v.ID) +} + +// Mutation returns the GitTaskMutation object of the builder. +func (_u *GitTaskUpdate) Mutation() *GitTaskMutation { + return _u.mutation +} + +// ClearTask clears the "task" edge to the Task entity. +func (_u *GitTaskUpdate) ClearTask() *GitTaskUpdate { + _u.mutation.ClearTask() + return _u +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *GitTaskUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *GitTaskUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *GitTaskUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *GitTaskUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *GitTaskUpdate) check() error { + if v, ok := _u.mutation.SubjectType(); ok { + if err := gittask.SubjectTypeValidator(v); err != nil { + return &ValidationError{Name: "subject_type", err: fmt.Errorf(`db: validator failed for field "GitTask.subject_type": %w`, err)} + } + } + if _u.mutation.TaskCleared() && len(_u.mutation.TaskIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "GitTask.task"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *GitTaskUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GitTaskUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *GitTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(gittask.Table, gittask.Columns, sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.RepoID(); ok { + _spec.SetField(gittask.FieldRepoID, field.TypeUUID, value) + } + if _u.mutation.RepoIDCleared() { + _spec.ClearField(gittask.FieldRepoID, field.TypeUUID) + } + if value, ok := _u.mutation.SubjectType(); ok { + _spec.SetField(gittask.FieldSubjectType, field.TypeString, value) + } + if value, ok := _u.mutation.SubjectID(); ok { + _spec.SetField(gittask.FieldSubjectID, field.TypeString, value) + } + if _u.mutation.SubjectIDCleared() { + _spec.ClearField(gittask.FieldSubjectID, field.TypeString) + } + if value, ok := _u.mutation.SubjectNumber(); ok { + _spec.SetField(gittask.FieldSubjectNumber, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedSubjectNumber(); ok { + _spec.AddField(gittask.FieldSubjectNumber, field.TypeInt, value) + } + if _u.mutation.SubjectNumberCleared() { + _spec.ClearField(gittask.FieldSubjectNumber, field.TypeInt) + } + if value, ok := _u.mutation.SubjectURL(); ok { + _spec.SetField(gittask.FieldSubjectURL, field.TypeString, value) + } + if _u.mutation.SubjectURLCleared() { + _spec.ClearField(gittask.FieldSubjectURL, field.TypeString) + } + if value, ok := _u.mutation.SubjectTitle(); ok { + _spec.SetField(gittask.FieldSubjectTitle, field.TypeString, value) + } + if _u.mutation.SubjectTitleCleared() { + _spec.ClearField(gittask.FieldSubjectTitle, field.TypeString) + } + if value, ok := _u.mutation.PromptID(); ok { + _spec.SetField(gittask.FieldPromptID, field.TypeString, value) + } + if _u.mutation.PromptIDCleared() { + _spec.ClearField(gittask.FieldPromptID, field.TypeString) + } + if value, ok := _u.mutation.ShowURL(); ok { + _spec.SetField(gittask.FieldShowURL, field.TypeString, value) + } + if _u.mutation.ShowURLCleared() { + _spec.ClearField(gittask.FieldShowURL, field.TypeString) + } + if value, ok := _u.mutation.GithubInstallationID(); ok { + _spec.SetField(gittask.FieldGithubInstallationID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedGithubInstallationID(); ok { + _spec.AddField(gittask.FieldGithubInstallationID, field.TypeInt64, value) + } + if _u.mutation.GithubInstallationIDCleared() { + _spec.ClearField(gittask.FieldGithubInstallationID, field.TypeInt64) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(gittask.FieldCreatedAt, field.TypeTime, value) + } + if _u.mutation.TaskCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: true, + Table: gittask.TaskTable, + Columns: []string{gittask.TaskColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TaskIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: true, + Table: gittask.TaskTable, + Columns: []string{gittask.TaskColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{gittask.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// GitTaskUpdateOne is the builder for updating a single GitTask entity. +type GitTaskUpdateOne struct { + config + fields []string + hooks []Hook + mutation *GitTaskMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetTaskID sets the "task_id" field. +func (_u *GitTaskUpdateOne) SetTaskID(v uuid.UUID) *GitTaskUpdateOne { + _u.mutation.SetTaskID(v) + return _u +} + +// SetNillableTaskID sets the "task_id" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableTaskID(v *uuid.UUID) *GitTaskUpdateOne { + if v != nil { + _u.SetTaskID(*v) + } + return _u +} + +// SetRepoID sets the "repo_id" field. +func (_u *GitTaskUpdateOne) SetRepoID(v uuid.UUID) *GitTaskUpdateOne { + _u.mutation.SetRepoID(v) + return _u +} + +// SetNillableRepoID sets the "repo_id" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableRepoID(v *uuid.UUID) *GitTaskUpdateOne { + if v != nil { + _u.SetRepoID(*v) + } + return _u +} + +// ClearRepoID clears the value of the "repo_id" field. +func (_u *GitTaskUpdateOne) ClearRepoID() *GitTaskUpdateOne { + _u.mutation.ClearRepoID() + return _u +} + +// SetSubjectType sets the "subject_type" field. +func (_u *GitTaskUpdateOne) SetSubjectType(v string) *GitTaskUpdateOne { + _u.mutation.SetSubjectType(v) + return _u +} + +// SetNillableSubjectType sets the "subject_type" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableSubjectType(v *string) *GitTaskUpdateOne { + if v != nil { + _u.SetSubjectType(*v) + } + return _u +} + +// SetSubjectID sets the "subject_id" field. +func (_u *GitTaskUpdateOne) SetSubjectID(v string) *GitTaskUpdateOne { + _u.mutation.SetSubjectID(v) + return _u +} + +// SetNillableSubjectID sets the "subject_id" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableSubjectID(v *string) *GitTaskUpdateOne { + if v != nil { + _u.SetSubjectID(*v) + } + return _u +} + +// ClearSubjectID clears the value of the "subject_id" field. +func (_u *GitTaskUpdateOne) ClearSubjectID() *GitTaskUpdateOne { + _u.mutation.ClearSubjectID() + return _u +} + +// SetSubjectNumber sets the "subject_number" field. +func (_u *GitTaskUpdateOne) SetSubjectNumber(v int) *GitTaskUpdateOne { + _u.mutation.ResetSubjectNumber() + _u.mutation.SetSubjectNumber(v) + return _u +} + +// SetNillableSubjectNumber sets the "subject_number" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableSubjectNumber(v *int) *GitTaskUpdateOne { + if v != nil { + _u.SetSubjectNumber(*v) + } + return _u +} + +// AddSubjectNumber adds value to the "subject_number" field. +func (_u *GitTaskUpdateOne) AddSubjectNumber(v int) *GitTaskUpdateOne { + _u.mutation.AddSubjectNumber(v) + return _u +} + +// ClearSubjectNumber clears the value of the "subject_number" field. +func (_u *GitTaskUpdateOne) ClearSubjectNumber() *GitTaskUpdateOne { + _u.mutation.ClearSubjectNumber() + return _u +} + +// SetSubjectURL sets the "subject_url" field. +func (_u *GitTaskUpdateOne) SetSubjectURL(v string) *GitTaskUpdateOne { + _u.mutation.SetSubjectURL(v) + return _u +} + +// SetNillableSubjectURL sets the "subject_url" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableSubjectURL(v *string) *GitTaskUpdateOne { + if v != nil { + _u.SetSubjectURL(*v) + } + return _u +} + +// ClearSubjectURL clears the value of the "subject_url" field. +func (_u *GitTaskUpdateOne) ClearSubjectURL() *GitTaskUpdateOne { + _u.mutation.ClearSubjectURL() + return _u +} + +// SetSubjectTitle sets the "subject_title" field. +func (_u *GitTaskUpdateOne) SetSubjectTitle(v string) *GitTaskUpdateOne { + _u.mutation.SetSubjectTitle(v) + return _u +} + +// SetNillableSubjectTitle sets the "subject_title" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableSubjectTitle(v *string) *GitTaskUpdateOne { + if v != nil { + _u.SetSubjectTitle(*v) + } + return _u +} + +// ClearSubjectTitle clears the value of the "subject_title" field. +func (_u *GitTaskUpdateOne) ClearSubjectTitle() *GitTaskUpdateOne { + _u.mutation.ClearSubjectTitle() + return _u +} + +// SetPromptID sets the "prompt_id" field. +func (_u *GitTaskUpdateOne) SetPromptID(v string) *GitTaskUpdateOne { + _u.mutation.SetPromptID(v) + return _u +} + +// SetNillablePromptID sets the "prompt_id" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillablePromptID(v *string) *GitTaskUpdateOne { + if v != nil { + _u.SetPromptID(*v) + } + return _u +} + +// ClearPromptID clears the value of the "prompt_id" field. +func (_u *GitTaskUpdateOne) ClearPromptID() *GitTaskUpdateOne { + _u.mutation.ClearPromptID() + return _u +} + +// SetShowURL sets the "show_url" field. +func (_u *GitTaskUpdateOne) SetShowURL(v string) *GitTaskUpdateOne { + _u.mutation.SetShowURL(v) + return _u +} + +// SetNillableShowURL sets the "show_url" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableShowURL(v *string) *GitTaskUpdateOne { + if v != nil { + _u.SetShowURL(*v) + } + return _u +} + +// ClearShowURL clears the value of the "show_url" field. +func (_u *GitTaskUpdateOne) ClearShowURL() *GitTaskUpdateOne { + _u.mutation.ClearShowURL() + return _u +} + +// SetGithubInstallationID sets the "github_installation_id" field. +func (_u *GitTaskUpdateOne) SetGithubInstallationID(v int64) *GitTaskUpdateOne { + _u.mutation.ResetGithubInstallationID() + _u.mutation.SetGithubInstallationID(v) + return _u +} + +// SetNillableGithubInstallationID sets the "github_installation_id" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableGithubInstallationID(v *int64) *GitTaskUpdateOne { + if v != nil { + _u.SetGithubInstallationID(*v) + } + return _u +} + +// AddGithubInstallationID adds value to the "github_installation_id" field. +func (_u *GitTaskUpdateOne) AddGithubInstallationID(v int64) *GitTaskUpdateOne { + _u.mutation.AddGithubInstallationID(v) + return _u +} + +// ClearGithubInstallationID clears the value of the "github_installation_id" field. +func (_u *GitTaskUpdateOne) ClearGithubInstallationID() *GitTaskUpdateOne { + _u.mutation.ClearGithubInstallationID() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *GitTaskUpdateOne) SetCreatedAt(v time.Time) *GitTaskUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *GitTaskUpdateOne) SetNillableCreatedAt(v *time.Time) *GitTaskUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetTask sets the "task" edge to the Task entity. +func (_u *GitTaskUpdateOne) SetTask(v *Task) *GitTaskUpdateOne { + return _u.SetTaskID(v.ID) +} + +// Mutation returns the GitTaskMutation object of the builder. +func (_u *GitTaskUpdateOne) Mutation() *GitTaskMutation { + return _u.mutation +} + +// ClearTask clears the "task" edge to the Task entity. +func (_u *GitTaskUpdateOne) ClearTask() *GitTaskUpdateOne { + _u.mutation.ClearTask() + return _u +} + +// Where appends a list predicates to the GitTaskUpdate builder. +func (_u *GitTaskUpdateOne) Where(ps ...predicate.GitTask) *GitTaskUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *GitTaskUpdateOne) Select(field string, fields ...string) *GitTaskUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated GitTask entity. +func (_u *GitTaskUpdateOne) Save(ctx context.Context) (*GitTask, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *GitTaskUpdateOne) SaveX(ctx context.Context) *GitTask { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *GitTaskUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *GitTaskUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *GitTaskUpdateOne) check() error { + if v, ok := _u.mutation.SubjectType(); ok { + if err := gittask.SubjectTypeValidator(v); err != nil { + return &ValidationError{Name: "subject_type", err: fmt.Errorf(`db: validator failed for field "GitTask.subject_type": %w`, err)} + } + } + if _u.mutation.TaskCleared() && len(_u.mutation.TaskIDs()) > 0 { + return errors.New(`db: clearing a required unique edge "GitTask.task"`) + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *GitTaskUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *GitTaskUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *GitTaskUpdateOne) sqlSave(ctx context.Context) (_node *GitTask, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(gittask.Table, gittask.Columns, sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`db: missing "GitTask.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, gittask.FieldID) + for _, f := range fields { + if !gittask.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("db: invalid field %q for query", f)} + } + if f != gittask.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.RepoID(); ok { + _spec.SetField(gittask.FieldRepoID, field.TypeUUID, value) + } + if _u.mutation.RepoIDCleared() { + _spec.ClearField(gittask.FieldRepoID, field.TypeUUID) + } + if value, ok := _u.mutation.SubjectType(); ok { + _spec.SetField(gittask.FieldSubjectType, field.TypeString, value) + } + if value, ok := _u.mutation.SubjectID(); ok { + _spec.SetField(gittask.FieldSubjectID, field.TypeString, value) + } + if _u.mutation.SubjectIDCleared() { + _spec.ClearField(gittask.FieldSubjectID, field.TypeString) + } + if value, ok := _u.mutation.SubjectNumber(); ok { + _spec.SetField(gittask.FieldSubjectNumber, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedSubjectNumber(); ok { + _spec.AddField(gittask.FieldSubjectNumber, field.TypeInt, value) + } + if _u.mutation.SubjectNumberCleared() { + _spec.ClearField(gittask.FieldSubjectNumber, field.TypeInt) + } + if value, ok := _u.mutation.SubjectURL(); ok { + _spec.SetField(gittask.FieldSubjectURL, field.TypeString, value) + } + if _u.mutation.SubjectURLCleared() { + _spec.ClearField(gittask.FieldSubjectURL, field.TypeString) + } + if value, ok := _u.mutation.SubjectTitle(); ok { + _spec.SetField(gittask.FieldSubjectTitle, field.TypeString, value) + } + if _u.mutation.SubjectTitleCleared() { + _spec.ClearField(gittask.FieldSubjectTitle, field.TypeString) + } + if value, ok := _u.mutation.PromptID(); ok { + _spec.SetField(gittask.FieldPromptID, field.TypeString, value) + } + if _u.mutation.PromptIDCleared() { + _spec.ClearField(gittask.FieldPromptID, field.TypeString) + } + if value, ok := _u.mutation.ShowURL(); ok { + _spec.SetField(gittask.FieldShowURL, field.TypeString, value) + } + if _u.mutation.ShowURLCleared() { + _spec.ClearField(gittask.FieldShowURL, field.TypeString) + } + if value, ok := _u.mutation.GithubInstallationID(); ok { + _spec.SetField(gittask.FieldGithubInstallationID, field.TypeInt64, value) + } + if value, ok := _u.mutation.AddedGithubInstallationID(); ok { + _spec.AddField(gittask.FieldGithubInstallationID, field.TypeInt64, value) + } + if _u.mutation.GithubInstallationIDCleared() { + _spec.ClearField(gittask.FieldGithubInstallationID, field.TypeInt64) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(gittask.FieldCreatedAt, field.TypeTime, value) + } + if _u.mutation.TaskCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: true, + Table: gittask.TaskTable, + Columns: []string{gittask.TaskColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.TaskIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: true, + Table: gittask.TaskTable, + Columns: []string{gittask.TaskColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(task.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _spec.AddModifiers(_u.modifiers...) + _node = &GitTask{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{gittask.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/backend/db/hook/hook.go b/backend/db/hook/hook.go index 74107e19..cf0675e1 100644 --- a/backend/db/hook/hook.go +++ b/backend/db/hook/hook.go @@ -69,6 +69,18 @@ func (f GitIdentityFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, e return nil, fmt.Errorf("unexpected mutation type %T. expect *db.GitIdentityMutation", m) } +// The GitTaskFunc type is an adapter to allow the use of ordinary +// function as GitTask mutator. +type GitTaskFunc func(context.Context, *db.GitTaskMutation) (db.Value, error) + +// Mutate calls f(ctx, m). +func (f GitTaskFunc) Mutate(ctx context.Context, m db.Mutation) (db.Value, error) { + if mv, ok := m.(*db.GitTaskMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *db.GitTaskMutation", m) +} + // The HostFunc type is an adapter to allow the use of ordinary // function as Host mutator. type HostFunc func(context.Context, *db.HostMutation) (db.Value, error) diff --git a/backend/db/intercept/intercept.go b/backend/db/intercept/intercept.go index e93485ff..6aba2cdb 100644 --- a/backend/db/intercept/intercept.go +++ b/backend/db/intercept/intercept.go @@ -13,6 +13,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/gitbottask" "github.com/chaitin/MonkeyCode/backend/db/gitbotuser" "github.com/chaitin/MonkeyCode/backend/db/gitidentity" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/host" "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/mcptool" @@ -241,6 +242,33 @@ func (f TraverseGitIdentity) Traverse(ctx context.Context, q db.Query) error { return fmt.Errorf("unexpected query type %T. expect *db.GitIdentityQuery", q) } +// The GitTaskFunc type is an adapter to allow the use of ordinary function as a Querier. +type GitTaskFunc func(context.Context, *db.GitTaskQuery) (db.Value, error) + +// Query calls f(ctx, q). +func (f GitTaskFunc) Query(ctx context.Context, q db.Query) (db.Value, error) { + if q, ok := q.(*db.GitTaskQuery); ok { + return f(ctx, q) + } + return nil, fmt.Errorf("unexpected query type %T. expect *db.GitTaskQuery", q) +} + +// The TraverseGitTask type is an adapter to allow the use of ordinary function as Traverser. +type TraverseGitTask func(context.Context, *db.GitTaskQuery) error + +// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline. +func (f TraverseGitTask) Intercept(next db.Querier) db.Querier { + return next +} + +// Traverse calls f(ctx, q). +func (f TraverseGitTask) Traverse(ctx context.Context, q db.Query) error { + if q, ok := q.(*db.GitTaskQuery); ok { + return f(ctx, q) + } + return fmt.Errorf("unexpected query type %T. expect *db.GitTaskQuery", q) +} + // The HostFunc type is an adapter to allow the use of ordinary function as a Querier. type HostFunc func(context.Context, *db.HostQuery) (db.Value, error) @@ -1172,6 +1200,8 @@ func NewQuery(q db.Query) (Query, error) { return &query[*db.GitBotUserQuery, predicate.GitBotUser, gitbotuser.OrderOption]{typ: db.TypeGitBotUser, tq: q}, nil case *db.GitIdentityQuery: return &query[*db.GitIdentityQuery, predicate.GitIdentity, gitidentity.OrderOption]{typ: db.TypeGitIdentity, tq: q}, nil + case *db.GitTaskQuery: + return &query[*db.GitTaskQuery, predicate.GitTask, gittask.OrderOption]{typ: db.TypeGitTask, tq: q}, nil case *db.HostQuery: return &query[*db.HostQuery, predicate.Host, host.OrderOption]{typ: db.TypeHost, tq: q}, nil case *db.ImageQuery: diff --git a/backend/db/migrate/schema.go b/backend/db/migrate/schema.go index 096fae7c..1827c7b4 100644 --- a/backend/db/migrate/schema.go +++ b/backend/db/migrate/schema.go @@ -152,6 +152,35 @@ var ( }, }, } + // GitTasksColumns holds the columns for the "git_tasks" table. + GitTasksColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "repo_id", Type: field.TypeUUID, Nullable: true}, + {Name: "subject_type", Type: field.TypeString}, + {Name: "subject_id", Type: field.TypeString, Nullable: true}, + {Name: "subject_number", Type: field.TypeInt, Nullable: true}, + {Name: "subject_url", Type: field.TypeString, Nullable: true}, + {Name: "subject_title", Type: field.TypeString, Nullable: true}, + {Name: "prompt_id", Type: field.TypeString, Nullable: true}, + {Name: "show_url", Type: field.TypeString, Nullable: true, Size: 2147483647}, + {Name: "github_installation_id", Type: field.TypeInt64, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "task_id", Type: field.TypeUUID, Unique: true}, + } + // GitTasksTable holds the schema information for the "git_tasks" table. + GitTasksTable = &schema.Table{ + Name: "git_tasks", + Columns: GitTasksColumns, + PrimaryKey: []*schema.Column{GitTasksColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "git_tasks_tasks_git_tasks", + Columns: []*schema.Column{GitTasksColumns[11]}, + RefColumns: []*schema.Column{TasksColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + } // HostsColumns holds the columns for the "hosts" table. HostsColumns = []*schema.Column{ {Name: "id", Type: field.TypeString, Unique: true}, @@ -1325,6 +1354,7 @@ var ( GitBotTasksTable, GitBotUsersTable, GitIdentitiesTable, + GitTasksTable, HostsTable, ImagesTable, McpToolsTable, @@ -1385,6 +1415,10 @@ func init() { GitIdentitiesTable.Annotation = &entsql.Annotation{ Table: "git_identities", } + GitTasksTable.ForeignKeys[0].RefTable = TasksTable + GitTasksTable.Annotation = &entsql.Annotation{ + Table: "git_tasks", + } HostsTable.ForeignKeys[0].RefTable = UsersTable HostsTable.Annotation = &entsql.Annotation{ Table: "hosts", diff --git a/backend/db/mutation.go b/backend/db/mutation.go index f7b10c77..8431acc3 100644 --- a/backend/db/mutation.go +++ b/backend/db/mutation.go @@ -17,6 +17,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/gitbottask" "github.com/chaitin/MonkeyCode/backend/db/gitbotuser" "github.com/chaitin/MonkeyCode/backend/db/gitidentity" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/host" "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/mcptool" @@ -70,6 +71,7 @@ const ( TypeGitBotTask = "GitBotTask" TypeGitBotUser = "GitBotUser" TypeGitIdentity = "GitIdentity" + TypeGitTask = "GitTask" TypeHost = "Host" TypeImage = "Image" TypeMCPTool = "MCPTool" @@ -4674,6 +4676,1158 @@ func (m *GitIdentityMutation) ResetEdge(name string) error { return fmt.Errorf("unknown GitIdentity edge %s", name) } +// GitTaskMutation represents an operation that mutates the GitTask nodes in the graph. +type GitTaskMutation struct { + config + op Op + typ string + id *uuid.UUID + repo_id *uuid.UUID + subject_type *string + subject_id *string + subject_number *int + addsubject_number *int + subject_url *string + subject_title *string + prompt_id *string + show_url *string + github_installation_id *int64 + addgithub_installation_id *int64 + created_at *time.Time + clearedFields map[string]struct{} + task *uuid.UUID + clearedtask bool + done bool + oldValue func(context.Context) (*GitTask, error) + predicates []predicate.GitTask +} + +var _ ent.Mutation = (*GitTaskMutation)(nil) + +// gittaskOption allows management of the mutation configuration using functional options. +type gittaskOption func(*GitTaskMutation) + +// newGitTaskMutation creates new mutation for the GitTask entity. +func newGitTaskMutation(c config, op Op, opts ...gittaskOption) *GitTaskMutation { + m := &GitTaskMutation{ + config: c, + op: op, + typ: TypeGitTask, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withGitTaskID sets the ID field of the mutation. +func withGitTaskID(id uuid.UUID) gittaskOption { + return func(m *GitTaskMutation) { + var ( + err error + once sync.Once + value *GitTask + ) + m.oldValue = func(ctx context.Context) (*GitTask, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().GitTask.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withGitTask sets the old GitTask of the mutation. +func withGitTask(node *GitTask) gittaskOption { + return func(m *GitTaskMutation) { + m.oldValue = func(context.Context) (*GitTask, 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 GitTaskMutation) 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 GitTaskMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("db: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of GitTask entities. +func (m *GitTaskMutation) SetID(id uuid.UUID) { + 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 *GitTaskMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *GitTaskMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().GitTask.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetTaskID sets the "task_id" field. +func (m *GitTaskMutation) SetTaskID(u uuid.UUID) { + m.task = &u +} + +// TaskID returns the value of the "task_id" field in the mutation. +func (m *GitTaskMutation) TaskID() (r uuid.UUID, exists bool) { + v := m.task + if v == nil { + return + } + return *v, true +} + +// OldTaskID returns the old "task_id" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldTaskID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldTaskID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldTaskID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldTaskID: %w", err) + } + return oldValue.TaskID, nil +} + +// ResetTaskID resets all changes to the "task_id" field. +func (m *GitTaskMutation) ResetTaskID() { + m.task = nil +} + +// SetRepoID sets the "repo_id" field. +func (m *GitTaskMutation) SetRepoID(u uuid.UUID) { + m.repo_id = &u +} + +// RepoID returns the value of the "repo_id" field in the mutation. +func (m *GitTaskMutation) RepoID() (r uuid.UUID, exists bool) { + v := m.repo_id + if v == nil { + return + } + return *v, true +} + +// OldRepoID returns the old "repo_id" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldRepoID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRepoID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("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 +} + +// ClearRepoID clears the value of the "repo_id" field. +func (m *GitTaskMutation) ClearRepoID() { + m.repo_id = nil + m.clearedFields[gittask.FieldRepoID] = struct{}{} +} + +// RepoIDCleared returns if the "repo_id" field was cleared in this mutation. +func (m *GitTaskMutation) RepoIDCleared() bool { + _, ok := m.clearedFields[gittask.FieldRepoID] + return ok +} + +// ResetRepoID resets all changes to the "repo_id" field. +func (m *GitTaskMutation) ResetRepoID() { + m.repo_id = nil + delete(m.clearedFields, gittask.FieldRepoID) +} + +// SetSubjectType sets the "subject_type" field. +func (m *GitTaskMutation) SetSubjectType(s string) { + m.subject_type = &s +} + +// SubjectType returns the value of the "subject_type" field in the mutation. +func (m *GitTaskMutation) SubjectType() (r string, exists bool) { + v := m.subject_type + if v == nil { + return + } + return *v, true +} + +// OldSubjectType returns the old "subject_type" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldSubjectType(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubjectType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubjectType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubjectType: %w", err) + } + return oldValue.SubjectType, nil +} + +// ResetSubjectType resets all changes to the "subject_type" field. +func (m *GitTaskMutation) ResetSubjectType() { + m.subject_type = nil +} + +// SetSubjectID sets the "subject_id" field. +func (m *GitTaskMutation) SetSubjectID(s string) { + m.subject_id = &s +} + +// SubjectID returns the value of the "subject_id" field in the mutation. +func (m *GitTaskMutation) SubjectID() (r string, exists bool) { + v := m.subject_id + if v == nil { + return + } + return *v, true +} + +// OldSubjectID returns the old "subject_id" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldSubjectID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubjectID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubjectID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubjectID: %w", err) + } + return oldValue.SubjectID, nil +} + +// ClearSubjectID clears the value of the "subject_id" field. +func (m *GitTaskMutation) ClearSubjectID() { + m.subject_id = nil + m.clearedFields[gittask.FieldSubjectID] = struct{}{} +} + +// SubjectIDCleared returns if the "subject_id" field was cleared in this mutation. +func (m *GitTaskMutation) SubjectIDCleared() bool { + _, ok := m.clearedFields[gittask.FieldSubjectID] + return ok +} + +// ResetSubjectID resets all changes to the "subject_id" field. +func (m *GitTaskMutation) ResetSubjectID() { + m.subject_id = nil + delete(m.clearedFields, gittask.FieldSubjectID) +} + +// SetSubjectNumber sets the "subject_number" field. +func (m *GitTaskMutation) SetSubjectNumber(i int) { + m.subject_number = &i + m.addsubject_number = nil +} + +// SubjectNumber returns the value of the "subject_number" field in the mutation. +func (m *GitTaskMutation) SubjectNumber() (r int, exists bool) { + v := m.subject_number + if v == nil { + return + } + return *v, true +} + +// OldSubjectNumber returns the old "subject_number" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldSubjectNumber(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubjectNumber is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubjectNumber requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubjectNumber: %w", err) + } + return oldValue.SubjectNumber, nil +} + +// AddSubjectNumber adds i to the "subject_number" field. +func (m *GitTaskMutation) AddSubjectNumber(i int) { + if m.addsubject_number != nil { + *m.addsubject_number += i + } else { + m.addsubject_number = &i + } +} + +// AddedSubjectNumber returns the value that was added to the "subject_number" field in this mutation. +func (m *GitTaskMutation) AddedSubjectNumber() (r int, exists bool) { + v := m.addsubject_number + if v == nil { + return + } + return *v, true +} + +// ClearSubjectNumber clears the value of the "subject_number" field. +func (m *GitTaskMutation) ClearSubjectNumber() { + m.subject_number = nil + m.addsubject_number = nil + m.clearedFields[gittask.FieldSubjectNumber] = struct{}{} +} + +// SubjectNumberCleared returns if the "subject_number" field was cleared in this mutation. +func (m *GitTaskMutation) SubjectNumberCleared() bool { + _, ok := m.clearedFields[gittask.FieldSubjectNumber] + return ok +} + +// ResetSubjectNumber resets all changes to the "subject_number" field. +func (m *GitTaskMutation) ResetSubjectNumber() { + m.subject_number = nil + m.addsubject_number = nil + delete(m.clearedFields, gittask.FieldSubjectNumber) +} + +// SetSubjectURL sets the "subject_url" field. +func (m *GitTaskMutation) SetSubjectURL(s string) { + m.subject_url = &s +} + +// SubjectURL returns the value of the "subject_url" field in the mutation. +func (m *GitTaskMutation) SubjectURL() (r string, exists bool) { + v := m.subject_url + if v == nil { + return + } + return *v, true +} + +// OldSubjectURL returns the old "subject_url" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldSubjectURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubjectURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubjectURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubjectURL: %w", err) + } + return oldValue.SubjectURL, nil +} + +// ClearSubjectURL clears the value of the "subject_url" field. +func (m *GitTaskMutation) ClearSubjectURL() { + m.subject_url = nil + m.clearedFields[gittask.FieldSubjectURL] = struct{}{} +} + +// SubjectURLCleared returns if the "subject_url" field was cleared in this mutation. +func (m *GitTaskMutation) SubjectURLCleared() bool { + _, ok := m.clearedFields[gittask.FieldSubjectURL] + return ok +} + +// ResetSubjectURL resets all changes to the "subject_url" field. +func (m *GitTaskMutation) ResetSubjectURL() { + m.subject_url = nil + delete(m.clearedFields, gittask.FieldSubjectURL) +} + +// SetSubjectTitle sets the "subject_title" field. +func (m *GitTaskMutation) SetSubjectTitle(s string) { + m.subject_title = &s +} + +// SubjectTitle returns the value of the "subject_title" field in the mutation. +func (m *GitTaskMutation) SubjectTitle() (r string, exists bool) { + v := m.subject_title + if v == nil { + return + } + return *v, true +} + +// OldSubjectTitle returns the old "subject_title" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldSubjectTitle(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSubjectTitle is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSubjectTitle requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSubjectTitle: %w", err) + } + return oldValue.SubjectTitle, nil +} + +// ClearSubjectTitle clears the value of the "subject_title" field. +func (m *GitTaskMutation) ClearSubjectTitle() { + m.subject_title = nil + m.clearedFields[gittask.FieldSubjectTitle] = struct{}{} +} + +// SubjectTitleCleared returns if the "subject_title" field was cleared in this mutation. +func (m *GitTaskMutation) SubjectTitleCleared() bool { + _, ok := m.clearedFields[gittask.FieldSubjectTitle] + return ok +} + +// ResetSubjectTitle resets all changes to the "subject_title" field. +func (m *GitTaskMutation) ResetSubjectTitle() { + m.subject_title = nil + delete(m.clearedFields, gittask.FieldSubjectTitle) +} + +// SetPromptID sets the "prompt_id" field. +func (m *GitTaskMutation) SetPromptID(s string) { + m.prompt_id = &s +} + +// PromptID returns the value of the "prompt_id" field in the mutation. +func (m *GitTaskMutation) PromptID() (r string, exists bool) { + v := m.prompt_id + if v == nil { + return + } + return *v, true +} + +// OldPromptID returns the old "prompt_id" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldPromptID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPromptID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPromptID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPromptID: %w", err) + } + return oldValue.PromptID, nil +} + +// ClearPromptID clears the value of the "prompt_id" field. +func (m *GitTaskMutation) ClearPromptID() { + m.prompt_id = nil + m.clearedFields[gittask.FieldPromptID] = struct{}{} +} + +// PromptIDCleared returns if the "prompt_id" field was cleared in this mutation. +func (m *GitTaskMutation) PromptIDCleared() bool { + _, ok := m.clearedFields[gittask.FieldPromptID] + return ok +} + +// ResetPromptID resets all changes to the "prompt_id" field. +func (m *GitTaskMutation) ResetPromptID() { + m.prompt_id = nil + delete(m.clearedFields, gittask.FieldPromptID) +} + +// SetShowURL sets the "show_url" field. +func (m *GitTaskMutation) SetShowURL(s string) { + m.show_url = &s +} + +// ShowURL returns the value of the "show_url" field in the mutation. +func (m *GitTaskMutation) ShowURL() (r string, exists bool) { + v := m.show_url + if v == nil { + return + } + return *v, true +} + +// OldShowURL returns the old "show_url" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldShowURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldShowURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldShowURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldShowURL: %w", err) + } + return oldValue.ShowURL, nil +} + +// ClearShowURL clears the value of the "show_url" field. +func (m *GitTaskMutation) ClearShowURL() { + m.show_url = nil + m.clearedFields[gittask.FieldShowURL] = struct{}{} +} + +// ShowURLCleared returns if the "show_url" field was cleared in this mutation. +func (m *GitTaskMutation) ShowURLCleared() bool { + _, ok := m.clearedFields[gittask.FieldShowURL] + return ok +} + +// ResetShowURL resets all changes to the "show_url" field. +func (m *GitTaskMutation) ResetShowURL() { + m.show_url = nil + delete(m.clearedFields, gittask.FieldShowURL) +} + +// SetGithubInstallationID sets the "github_installation_id" field. +func (m *GitTaskMutation) SetGithubInstallationID(i int64) { + m.github_installation_id = &i + m.addgithub_installation_id = nil +} + +// GithubInstallationID returns the value of the "github_installation_id" field in the mutation. +func (m *GitTaskMutation) GithubInstallationID() (r int64, exists bool) { + v := m.github_installation_id + if v == nil { + return + } + return *v, true +} + +// OldGithubInstallationID returns the old "github_installation_id" field's value of the GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldGithubInstallationID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldGithubInstallationID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldGithubInstallationID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGithubInstallationID: %w", err) + } + return oldValue.GithubInstallationID, nil +} + +// AddGithubInstallationID adds i to the "github_installation_id" field. +func (m *GitTaskMutation) AddGithubInstallationID(i int64) { + if m.addgithub_installation_id != nil { + *m.addgithub_installation_id += i + } else { + m.addgithub_installation_id = &i + } +} + +// AddedGithubInstallationID returns the value that was added to the "github_installation_id" field in this mutation. +func (m *GitTaskMutation) AddedGithubInstallationID() (r int64, exists bool) { + v := m.addgithub_installation_id + if v == nil { + return + } + return *v, true +} + +// ClearGithubInstallationID clears the value of the "github_installation_id" field. +func (m *GitTaskMutation) ClearGithubInstallationID() { + m.github_installation_id = nil + m.addgithub_installation_id = nil + m.clearedFields[gittask.FieldGithubInstallationID] = struct{}{} +} + +// GithubInstallationIDCleared returns if the "github_installation_id" field was cleared in this mutation. +func (m *GitTaskMutation) GithubInstallationIDCleared() bool { + _, ok := m.clearedFields[gittask.FieldGithubInstallationID] + return ok +} + +// ResetGithubInstallationID resets all changes to the "github_installation_id" field. +func (m *GitTaskMutation) ResetGithubInstallationID() { + m.github_installation_id = nil + m.addgithub_installation_id = nil + delete(m.clearedFields, gittask.FieldGithubInstallationID) +} + +// SetCreatedAt sets the "created_at" field. +func (m *GitTaskMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *GitTaskMutation) 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 GitTask entity. +// If the GitTask 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 *GitTaskMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("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 *GitTaskMutation) ResetCreatedAt() { + m.created_at = nil +} + +// ClearTask clears the "task" edge to the Task entity. +func (m *GitTaskMutation) ClearTask() { + m.clearedtask = true + m.clearedFields[gittask.FieldTaskID] = struct{}{} +} + +// TaskCleared reports if the "task" edge to the Task entity was cleared. +func (m *GitTaskMutation) TaskCleared() bool { + return m.clearedtask +} + +// TaskIDs returns the "task" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// TaskID instead. It exists only for internal usage by the builders. +func (m *GitTaskMutation) TaskIDs() (ids []uuid.UUID) { + if id := m.task; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetTask resets all changes to the "task" edge. +func (m *GitTaskMutation) ResetTask() { + m.task = nil + m.clearedtask = false +} + +// Where appends a list predicates to the GitTaskMutation builder. +func (m *GitTaskMutation) Where(ps ...predicate.GitTask) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the GitTaskMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *GitTaskMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.GitTask, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *GitTaskMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *GitTaskMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (GitTask). +func (m *GitTaskMutation) 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 *GitTaskMutation) Fields() []string { + fields := make([]string, 0, 11) + if m.task != nil { + fields = append(fields, gittask.FieldTaskID) + } + if m.repo_id != nil { + fields = append(fields, gittask.FieldRepoID) + } + if m.subject_type != nil { + fields = append(fields, gittask.FieldSubjectType) + } + if m.subject_id != nil { + fields = append(fields, gittask.FieldSubjectID) + } + if m.subject_number != nil { + fields = append(fields, gittask.FieldSubjectNumber) + } + if m.subject_url != nil { + fields = append(fields, gittask.FieldSubjectURL) + } + if m.subject_title != nil { + fields = append(fields, gittask.FieldSubjectTitle) + } + if m.prompt_id != nil { + fields = append(fields, gittask.FieldPromptID) + } + if m.show_url != nil { + fields = append(fields, gittask.FieldShowURL) + } + if m.github_installation_id != nil { + fields = append(fields, gittask.FieldGithubInstallationID) + } + if m.created_at != nil { + fields = append(fields, gittask.FieldCreatedAt) + } + 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 *GitTaskMutation) Field(name string) (ent.Value, bool) { + switch name { + case gittask.FieldTaskID: + return m.TaskID() + case gittask.FieldRepoID: + return m.RepoID() + case gittask.FieldSubjectType: + return m.SubjectType() + case gittask.FieldSubjectID: + return m.SubjectID() + case gittask.FieldSubjectNumber: + return m.SubjectNumber() + case gittask.FieldSubjectURL: + return m.SubjectURL() + case gittask.FieldSubjectTitle: + return m.SubjectTitle() + case gittask.FieldPromptID: + return m.PromptID() + case gittask.FieldShowURL: + return m.ShowURL() + case gittask.FieldGithubInstallationID: + return m.GithubInstallationID() + case gittask.FieldCreatedAt: + return m.CreatedAt() + } + 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 *GitTaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case gittask.FieldTaskID: + return m.OldTaskID(ctx) + case gittask.FieldRepoID: + return m.OldRepoID(ctx) + case gittask.FieldSubjectType: + return m.OldSubjectType(ctx) + case gittask.FieldSubjectID: + return m.OldSubjectID(ctx) + case gittask.FieldSubjectNumber: + return m.OldSubjectNumber(ctx) + case gittask.FieldSubjectURL: + return m.OldSubjectURL(ctx) + case gittask.FieldSubjectTitle: + return m.OldSubjectTitle(ctx) + case gittask.FieldPromptID: + return m.OldPromptID(ctx) + case gittask.FieldShowURL: + return m.OldShowURL(ctx) + case gittask.FieldGithubInstallationID: + return m.OldGithubInstallationID(ctx) + case gittask.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown GitTask 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 *GitTaskMutation) SetField(name string, value ent.Value) error { + switch name { + case gittask.FieldTaskID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetTaskID(v) + return nil + case gittask.FieldRepoID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRepoID(v) + return nil + case gittask.FieldSubjectType: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubjectType(v) + return nil + case gittask.FieldSubjectID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubjectID(v) + return nil + case gittask.FieldSubjectNumber: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubjectNumber(v) + return nil + case gittask.FieldSubjectURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubjectURL(v) + return nil + case gittask.FieldSubjectTitle: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSubjectTitle(v) + return nil + case gittask.FieldPromptID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPromptID(v) + return nil + case gittask.FieldShowURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetShowURL(v) + return nil + case gittask.FieldGithubInstallationID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGithubInstallationID(v) + return nil + case gittask.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + } + return fmt.Errorf("unknown GitTask field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *GitTaskMutation) AddedFields() []string { + var fields []string + if m.addsubject_number != nil { + fields = append(fields, gittask.FieldSubjectNumber) + } + if m.addgithub_installation_id != nil { + fields = append(fields, gittask.FieldGithubInstallationID) + } + 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 *GitTaskMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case gittask.FieldSubjectNumber: + return m.AddedSubjectNumber() + case gittask.FieldGithubInstallationID: + return m.AddedGithubInstallationID() + } + 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 *GitTaskMutation) AddField(name string, value ent.Value) error { + switch name { + case gittask.FieldSubjectNumber: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSubjectNumber(v) + return nil + case gittask.FieldGithubInstallationID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddGithubInstallationID(v) + return nil + } + return fmt.Errorf("unknown GitTask numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *GitTaskMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(gittask.FieldRepoID) { + fields = append(fields, gittask.FieldRepoID) + } + if m.FieldCleared(gittask.FieldSubjectID) { + fields = append(fields, gittask.FieldSubjectID) + } + if m.FieldCleared(gittask.FieldSubjectNumber) { + fields = append(fields, gittask.FieldSubjectNumber) + } + if m.FieldCleared(gittask.FieldSubjectURL) { + fields = append(fields, gittask.FieldSubjectURL) + } + if m.FieldCleared(gittask.FieldSubjectTitle) { + fields = append(fields, gittask.FieldSubjectTitle) + } + if m.FieldCleared(gittask.FieldPromptID) { + fields = append(fields, gittask.FieldPromptID) + } + if m.FieldCleared(gittask.FieldShowURL) { + fields = append(fields, gittask.FieldShowURL) + } + if m.FieldCleared(gittask.FieldGithubInstallationID) { + fields = append(fields, gittask.FieldGithubInstallationID) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *GitTaskMutation) 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 *GitTaskMutation) ClearField(name string) error { + switch name { + case gittask.FieldRepoID: + m.ClearRepoID() + return nil + case gittask.FieldSubjectID: + m.ClearSubjectID() + return nil + case gittask.FieldSubjectNumber: + m.ClearSubjectNumber() + return nil + case gittask.FieldSubjectURL: + m.ClearSubjectURL() + return nil + case gittask.FieldSubjectTitle: + m.ClearSubjectTitle() + return nil + case gittask.FieldPromptID: + m.ClearPromptID() + return nil + case gittask.FieldShowURL: + m.ClearShowURL() + return nil + case gittask.FieldGithubInstallationID: + m.ClearGithubInstallationID() + return nil + } + return fmt.Errorf("unknown GitTask 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 *GitTaskMutation) ResetField(name string) error { + switch name { + case gittask.FieldTaskID: + m.ResetTaskID() + return nil + case gittask.FieldRepoID: + m.ResetRepoID() + return nil + case gittask.FieldSubjectType: + m.ResetSubjectType() + return nil + case gittask.FieldSubjectID: + m.ResetSubjectID() + return nil + case gittask.FieldSubjectNumber: + m.ResetSubjectNumber() + return nil + case gittask.FieldSubjectURL: + m.ResetSubjectURL() + return nil + case gittask.FieldSubjectTitle: + m.ResetSubjectTitle() + return nil + case gittask.FieldPromptID: + m.ResetPromptID() + return nil + case gittask.FieldShowURL: + m.ResetShowURL() + return nil + case gittask.FieldGithubInstallationID: + m.ResetGithubInstallationID() + return nil + case gittask.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown GitTask field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *GitTaskMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.task != nil { + edges = append(edges, gittask.EdgeTask) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *GitTaskMutation) AddedIDs(name string) []ent.Value { + switch name { + case gittask.EdgeTask: + if id := m.task; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *GitTaskMutation) 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 *GitTaskMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *GitTaskMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedtask { + edges = append(edges, gittask.EdgeTask) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *GitTaskMutation) EdgeCleared(name string) bool { + switch name { + case gittask.EdgeTask: + return m.clearedtask + } + 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 *GitTaskMutation) ClearEdge(name string) error { + switch name { + case gittask.EdgeTask: + m.ClearTask() + return nil + } + return fmt.Errorf("unknown GitTask 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 *GitTaskMutation) ResetEdge(name string) error { + switch name { + case gittask.EdgeTask: + m.ResetTask() + return nil + } + return fmt.Errorf("unknown GitTask edge %s", name) +} + // HostMutation represents an operation that mutates the Host nodes in the graph. type HostMutation struct { config @@ -23900,6 +25054,8 @@ type TaskMutation struct { project_tasks map[uuid.UUID]struct{} removedproject_tasks map[uuid.UUID]struct{} clearedproject_tasks bool + git_tasks *uuid.UUID + clearedgit_tasks bool user *uuid.UUID cleareduser bool vms map[string]struct{} @@ -24623,6 +25779,45 @@ func (m *TaskMutation) ResetProjectTasks() { m.removedproject_tasks = nil } +// SetGitTasksID sets the "git_tasks" edge to the GitTask entity by id. +func (m *TaskMutation) SetGitTasksID(id uuid.UUID) { + m.git_tasks = &id +} + +// ClearGitTasks clears the "git_tasks" edge to the GitTask entity. +func (m *TaskMutation) ClearGitTasks() { + m.clearedgit_tasks = true +} + +// GitTasksCleared reports if the "git_tasks" edge to the GitTask entity was cleared. +func (m *TaskMutation) GitTasksCleared() bool { + return m.clearedgit_tasks +} + +// GitTasksID returns the "git_tasks" edge ID in the mutation. +func (m *TaskMutation) GitTasksID() (id uuid.UUID, exists bool) { + if m.git_tasks != nil { + return *m.git_tasks, true + } + return +} + +// GitTasksIDs returns the "git_tasks" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// GitTasksID instead. It exists only for internal usage by the builders. +func (m *TaskMutation) GitTasksIDs() (ids []uuid.UUID) { + if id := m.git_tasks; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetGitTasks resets all changes to the "git_tasks" edge. +func (m *TaskMutation) ResetGitTasks() { + m.git_tasks = nil + m.clearedgit_tasks = false +} + // ClearUser clears the "user" edge to the User entity. func (m *TaskMutation) ClearUser() { m.cleareduser = true @@ -25242,10 +26437,13 @@ func (m *TaskMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *TaskMutation) AddedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.project_tasks != nil { edges = append(edges, task.EdgeProjectTasks) } + if m.git_tasks != nil { + edges = append(edges, task.EdgeGitTasks) + } if m.user != nil { edges = append(edges, task.EdgeUser) } @@ -25274,6 +26472,10 @@ func (m *TaskMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids + case task.EdgeGitTasks: + if id := m.git_tasks; id != nil { + return []ent.Value{*id} + } case task.EdgeUser: if id := m.user; id != nil { return []ent.Value{*id} @@ -25308,7 +26510,7 @@ func (m *TaskMutation) AddedIDs(name string) []ent.Value { // RemovedEdges returns all edge names that were removed in this mutation. func (m *TaskMutation) RemovedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.removedproject_tasks != nil { edges = append(edges, task.EdgeProjectTasks) } @@ -25367,10 +26569,13 @@ func (m *TaskMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TaskMutation) ClearedEdges() []string { - edges := make([]string, 0, 6) + edges := make([]string, 0, 7) if m.clearedproject_tasks { edges = append(edges, task.EdgeProjectTasks) } + if m.clearedgit_tasks { + edges = append(edges, task.EdgeGitTasks) + } if m.cleareduser { edges = append(edges, task.EdgeUser) } @@ -25395,6 +26600,8 @@ func (m *TaskMutation) EdgeCleared(name string) bool { switch name { case task.EdgeProjectTasks: return m.clearedproject_tasks + case task.EdgeGitTasks: + return m.clearedgit_tasks case task.EdgeUser: return m.cleareduser case task.EdgeVms: @@ -25413,6 +26620,9 @@ func (m *TaskMutation) EdgeCleared(name string) bool { // if that edge is not defined in the schema. func (m *TaskMutation) ClearEdge(name string) error { switch name { + case task.EdgeGitTasks: + m.ClearGitTasks() + return nil case task.EdgeUser: m.ClearUser() return nil @@ -25427,6 +26637,9 @@ func (m *TaskMutation) ResetEdge(name string) error { case task.EdgeProjectTasks: m.ResetProjectTasks() return nil + case task.EdgeGitTasks: + m.ResetGitTasks() + return nil case task.EdgeUser: m.ResetUser() return nil diff --git a/backend/db/page.go b/backend/db/page.go index f8952aec..d5eed556 100644 --- a/backend/db/page.go +++ b/backend/db/page.go @@ -81,6 +81,20 @@ func (_m *GitIdentityQuery) Page(ctx context.Context, page, size int) ([]*GitIde return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil } +func (_m *GitTaskQuery) Page(ctx context.Context, page, size int) ([]*GitTask, *PageInfo, error) { + cnt, err := _m.Count(ctx) + if err != nil { + return nil, nil, err + } + offset := size * (page - 1) + rs, err := _m.Offset(offset).Limit(size).All(ctx) + if err != nil { + return nil, nil, err + } + has := (page * size) < cnt + return rs, &PageInfo{HasNextPage: has, TotalCount: int64(cnt)}, nil +} + func (_m *HostQuery) Page(ctx context.Context, page, size int) ([]*Host, *PageInfo, error) { cnt, err := _m.Count(ctx) if err != nil { diff --git a/backend/db/predicate/predicate.go b/backend/db/predicate/predicate.go index c85b2439..6764d5bb 100644 --- a/backend/db/predicate/predicate.go +++ b/backend/db/predicate/predicate.go @@ -21,6 +21,9 @@ type GitBotUser func(*sql.Selector) // GitIdentity is the predicate function for gitidentity builders. type GitIdentity func(*sql.Selector) +// GitTask is the predicate function for gittask builders. +type GitTask func(*sql.Selector) + // Host is the predicate function for host builders. type Host func(*sql.Selector) diff --git a/backend/db/runtime/runtime.go b/backend/db/runtime/runtime.go index 47d61f5f..2dbd45a4 100644 --- a/backend/db/runtime/runtime.go +++ b/backend/db/runtime/runtime.go @@ -11,6 +11,7 @@ import ( "github.com/chaitin/MonkeyCode/backend/db/gitbottask" "github.com/chaitin/MonkeyCode/backend/db/gitbotuser" "github.com/chaitin/MonkeyCode/backend/db/gitidentity" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/host" "github.com/chaitin/MonkeyCode/backend/db/image" "github.com/chaitin/MonkeyCode/backend/db/mcptool" @@ -107,6 +108,16 @@ func init() { gitidentity.DefaultUpdatedAt = gitidentityDescUpdatedAt.Default.(func() time.Time) // gitidentity.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. gitidentity.UpdateDefaultUpdatedAt = gitidentityDescUpdatedAt.UpdateDefault.(func() time.Time) + gittaskFields := schema.GitTask{}.Fields() + _ = gittaskFields + // gittaskDescSubjectType is the schema descriptor for subject_type field. + gittaskDescSubjectType := gittaskFields[3].Descriptor() + // gittask.SubjectTypeValidator is a validator for the "subject_type" field. It is called by the builders before save. + gittask.SubjectTypeValidator = gittaskDescSubjectType.Validators[0].(func(string) error) + // gittaskDescCreatedAt is the schema descriptor for created_at field. + gittaskDescCreatedAt := gittaskFields[11].Descriptor() + // gittask.DefaultCreatedAt holds the default value on creation for the created_at field. + gittask.DefaultCreatedAt = gittaskDescCreatedAt.Default.(func() time.Time) hostMixin := schema.Host{}.Mixin() hostMixinHooks0 := hostMixin[0].Hooks() host.Hooks[0] = hostMixinHooks0[0] diff --git a/backend/db/task.go b/backend/db/task.go index 20b42f92..d914969a 100644 --- a/backend/db/task.go +++ b/backend/db/task.go @@ -10,6 +10,7 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/chaitin/MonkeyCode/backend/consts" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/user" "github.com/google/uuid" @@ -56,6 +57,8 @@ type Task struct { type TaskEdges struct { // ProjectTasks holds the value of the project_tasks edge. ProjectTasks []*ProjectTask `json:"project_tasks,omitempty"` + // GitTasks holds the value of the git_tasks edge. + GitTasks *GitTask `json:"git_tasks,omitempty"` // User holds the value of the user edge. User *User `json:"user,omitempty"` // Vms holds the value of the vms edge. @@ -68,7 +71,7 @@ type TaskEdges struct { TaskVms []*TaskVirtualMachine `json:"task_vms,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [6]bool + loadedTypes [7]bool } // ProjectTasksOrErr returns the ProjectTasks value or an error if the edge @@ -80,12 +83,23 @@ func (e TaskEdges) ProjectTasksOrErr() ([]*ProjectTask, error) { return nil, &NotLoadedError{edge: "project_tasks"} } +// GitTasksOrErr returns the GitTasks value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e TaskEdges) GitTasksOrErr() (*GitTask, error) { + if e.GitTasks != nil { + return e.GitTasks, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: gittask.Label} + } + return nil, &NotLoadedError{edge: "git_tasks"} +} + // 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 TaskEdges) UserOrErr() (*User, error) { if e.User != nil { return e.User, nil - } else if e.loadedTypes[1] { + } else if e.loadedTypes[2] { return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} @@ -94,7 +108,7 @@ func (e TaskEdges) UserOrErr() (*User, error) { // VmsOrErr returns the Vms value or an error if the edge // was not loaded in eager-loading. func (e TaskEdges) VmsOrErr() ([]*VirtualMachine, error) { - if e.loadedTypes[2] { + if e.loadedTypes[3] { return e.Vms, nil } return nil, &NotLoadedError{edge: "vms"} @@ -103,7 +117,7 @@ func (e TaskEdges) VmsOrErr() ([]*VirtualMachine, error) { // GitBotTasksOrErr returns the GitBotTasks value or an error if the edge // was not loaded in eager-loading. func (e TaskEdges) GitBotTasksOrErr() ([]*GitBotTask, error) { - if e.loadedTypes[3] { + if e.loadedTypes[4] { return e.GitBotTasks, nil } return nil, &NotLoadedError{edge: "git_bot_tasks"} @@ -112,7 +126,7 @@ func (e TaskEdges) GitBotTasksOrErr() ([]*GitBotTask, error) { // ModelSwitchesOrErr returns the ModelSwitches value or an error if the edge // was not loaded in eager-loading. func (e TaskEdges) ModelSwitchesOrErr() ([]*TaskModelSwitch, error) { - if e.loadedTypes[4] { + if e.loadedTypes[5] { return e.ModelSwitches, nil } return nil, &NotLoadedError{edge: "model_switches"} @@ -121,7 +135,7 @@ func (e TaskEdges) ModelSwitchesOrErr() ([]*TaskModelSwitch, error) { // TaskVmsOrErr returns the TaskVms value or an error if the edge // was not loaded in eager-loading. func (e TaskEdges) TaskVmsOrErr() ([]*TaskVirtualMachine, error) { - if e.loadedTypes[5] { + if e.loadedTypes[6] { return e.TaskVms, nil } return nil, &NotLoadedError{edge: "task_vms"} @@ -256,6 +270,11 @@ func (_m *Task) QueryProjectTasks() *ProjectTaskQuery { return NewTaskClient(_m.config).QueryProjectTasks(_m) } +// QueryGitTasks queries the "git_tasks" edge of the Task entity. +func (_m *Task) QueryGitTasks() *GitTaskQuery { + return NewTaskClient(_m.config).QueryGitTasks(_m) +} + // QueryUser queries the "user" edge of the Task entity. func (_m *Task) QueryUser() *UserQuery { return NewTaskClient(_m.config).QueryUser(_m) diff --git a/backend/db/task/task.go b/backend/db/task/task.go index f1c2b166..e364c60b 100644 --- a/backend/db/task/task.go +++ b/backend/db/task/task.go @@ -43,6 +43,8 @@ const ( FieldCompletedAt = "completed_at" // EdgeProjectTasks holds the string denoting the project_tasks edge name in mutations. EdgeProjectTasks = "project_tasks" + // EdgeGitTasks holds the string denoting the git_tasks edge name in mutations. + EdgeGitTasks = "git_tasks" // EdgeUser holds the string denoting the user edge name in mutations. EdgeUser = "user" // EdgeVms holds the string denoting the vms edge name in mutations. @@ -62,6 +64,13 @@ const ( ProjectTasksInverseTable = "project_tasks" // ProjectTasksColumn is the table column denoting the project_tasks relation/edge. ProjectTasksColumn = "task_id" + // GitTasksTable is the table that holds the git_tasks relation/edge. + GitTasksTable = "git_tasks" + // GitTasksInverseTable is the table name for the GitTask entity. + // It exists in this package in order to avoid circular dependency with the "gittask" package. + GitTasksInverseTable = "git_tasks" + // GitTasksColumn is the table column denoting the git_tasks relation/edge. + GitTasksColumn = "task_id" // UserTable is the table that holds the user relation/edge. UserTable = "tasks" // UserInverseTable is the table name for the User entity. @@ -238,6 +247,13 @@ func ByProjectTasks(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } +// ByGitTasksField orders the results by git_tasks field. +func ByGitTasksField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGitTasksStep(), sql.OrderByField(field, opts...)) + } +} + // ByUserField orders the results by user field. func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { @@ -307,6 +323,13 @@ func newProjectTasksStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, ProjectTasksTable, ProjectTasksColumn), ) } +func newGitTasksStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GitTasksInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, GitTasksTable, GitTasksColumn), + ) +} func newUserStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), diff --git a/backend/db/task/where.go b/backend/db/task/where.go index 17d50d60..b9e1527d 100644 --- a/backend/db/task/where.go +++ b/backend/db/task/where.go @@ -960,6 +960,29 @@ func HasProjectTasksWith(preds ...predicate.ProjectTask) predicate.Task { }) } +// HasGitTasks applies the HasEdge predicate on the "git_tasks" edge. +func HasGitTasks() predicate.Task { + return predicate.Task(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, GitTasksTable, GitTasksColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasGitTasksWith applies the HasEdge predicate on the "git_tasks" edge with a given conditions (other predicates). +func HasGitTasksWith(preds ...predicate.GitTask) predicate.Task { + return predicate.Task(func(s *sql.Selector) { + step := newGitTasksStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + // HasUser applies the HasEdge predicate on the "user" edge. func HasUser() predicate.Task { return predicate.Task(func(s *sql.Selector) { diff --git a/backend/db/task_create.go b/backend/db/task_create.go index ff3cec0e..fe85d847 100644 --- a/backend/db/task_create.go +++ b/backend/db/task_create.go @@ -14,6 +14,7 @@ import ( "entgo.io/ent/schema/field" "github.com/chaitin/MonkeyCode/backend/consts" "github.com/chaitin/MonkeyCode/backend/db/gitbottask" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/projecttask" "github.com/chaitin/MonkeyCode/backend/db/task" "github.com/chaitin/MonkeyCode/backend/db/taskmodelswitch" @@ -202,6 +203,25 @@ func (_c *TaskCreate) AddProjectTasks(v ...*ProjectTask) *TaskCreate { return _c.AddProjectTaskIDs(ids...) } +// SetGitTasksID sets the "git_tasks" edge to the GitTask entity by ID. +func (_c *TaskCreate) SetGitTasksID(id uuid.UUID) *TaskCreate { + _c.mutation.SetGitTasksID(id) + return _c +} + +// SetNillableGitTasksID sets the "git_tasks" edge to the GitTask entity by ID if the given value is not nil. +func (_c *TaskCreate) SetNillableGitTasksID(id *uuid.UUID) *TaskCreate { + if id != nil { + _c = _c.SetGitTasksID(*id) + } + return _c +} + +// SetGitTasks sets the "git_tasks" edge to the GitTask entity. +func (_c *TaskCreate) SetGitTasks(v *GitTask) *TaskCreate { + return _c.SetGitTasksID(v.ID) +} + // SetUser sets the "user" edge to the User entity. func (_c *TaskCreate) SetUser(v *User) *TaskCreate { return _c.SetUserID(v.ID) @@ -459,6 +479,22 @@ func (_c *TaskCreate) createSpec() (*Task, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } + if nodes := _c.mutation.GitTasksIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: task.GitTasksTable, + Columns: []string{task.GitTasksColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } if nodes := _c.mutation.UserIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/backend/db/task_query.go b/backend/db/task_query.go index 4adb986d..c018cefb 100644 --- a/backend/db/task_query.go +++ b/backend/db/task_query.go @@ -14,6 +14,7 @@ import ( "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/chaitin/MonkeyCode/backend/db/gitbottask" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/predicate" "github.com/chaitin/MonkeyCode/backend/db/projecttask" "github.com/chaitin/MonkeyCode/backend/db/task" @@ -32,6 +33,7 @@ type TaskQuery struct { inters []Interceptor predicates []predicate.Task withProjectTasks *ProjectTaskQuery + withGitTasks *GitTaskQuery withUser *UserQuery withVms *VirtualMachineQuery withGitBotTasks *GitBotTaskQuery @@ -96,6 +98,28 @@ func (_q *TaskQuery) QueryProjectTasks() *ProjectTaskQuery { return query } +// QueryGitTasks chains the current query on the "git_tasks" edge. +func (_q *TaskQuery) QueryGitTasks() *GitTaskQuery { + query := (&GitTaskClient{config: _q.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + selector := _q.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(task.Table, task.FieldID, selector), + sqlgraph.To(gittask.Table, gittask.FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, task.GitTasksTable, task.GitTasksColumn), + ) + fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) + return fromU, nil + } + return query +} + // QueryUser chains the current query on the "user" edge. func (_q *TaskQuery) QueryUser() *UserQuery { query := (&UserClient{config: _q.config}).Query() @@ -399,6 +423,7 @@ func (_q *TaskQuery) Clone() *TaskQuery { inters: append([]Interceptor{}, _q.inters...), predicates: append([]predicate.Task{}, _q.predicates...), withProjectTasks: _q.withProjectTasks.Clone(), + withGitTasks: _q.withGitTasks.Clone(), withUser: _q.withUser.Clone(), withVms: _q.withVms.Clone(), withGitBotTasks: _q.withGitBotTasks.Clone(), @@ -422,6 +447,17 @@ func (_q *TaskQuery) WithProjectTasks(opts ...func(*ProjectTaskQuery)) *TaskQuer return _q } +// WithGitTasks tells the query-builder to eager-load the nodes that are connected to +// the "git_tasks" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *TaskQuery) WithGitTasks(opts ...func(*GitTaskQuery)) *TaskQuery { + query := (&GitTaskClient{config: _q.config}).Query() + for _, opt := range opts { + opt(query) + } + _q.withGitTasks = query + return _q +} + // 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 (_q *TaskQuery) WithUser(opts ...func(*UserQuery)) *TaskQuery { @@ -555,8 +591,9 @@ func (_q *TaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Task, e var ( nodes = []*Task{} _spec = _q.querySpec() - loadedTypes = [6]bool{ + loadedTypes = [7]bool{ _q.withProjectTasks != nil, + _q.withGitTasks != nil, _q.withUser != nil, _q.withVms != nil, _q.withGitBotTasks != nil, @@ -592,6 +629,12 @@ func (_q *TaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Task, e return nil, err } } + if query := _q.withGitTasks; query != nil { + if err := _q.loadGitTasks(ctx, query, nodes, nil, + func(n *Task, e *GitTask) { n.Edges.GitTasks = e }); err != nil { + return nil, err + } + } if query := _q.withUser; query != nil { if err := _q.loadUser(ctx, query, nodes, nil, func(n *Task, e *User) { n.Edges.User = e }); err != nil { @@ -659,6 +702,33 @@ func (_q *TaskQuery) loadProjectTasks(ctx context.Context, query *ProjectTaskQue } return nil } +func (_q *TaskQuery) loadGitTasks(ctx context.Context, query *GitTaskQuery, nodes []*Task, init func(*Task), assign func(*Task, *GitTask)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[uuid.UUID]*Task) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(gittask.FieldTaskID) + } + query.Where(predicate.GitTask(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(task.GitTasksColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.TaskID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "task_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} func (_q *TaskQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Task, init func(*Task), assign func(*Task, *User)) error { ids := make([]uuid.UUID, 0, len(nodes)) nodeids := make(map[uuid.UUID][]*Task) diff --git a/backend/db/task_update.go b/backend/db/task_update.go index 67deab93..dec7d759 100644 --- a/backend/db/task_update.go +++ b/backend/db/task_update.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/schema/field" "github.com/chaitin/MonkeyCode/backend/consts" "github.com/chaitin/MonkeyCode/backend/db/gitbottask" + "github.com/chaitin/MonkeyCode/backend/db/gittask" "github.com/chaitin/MonkeyCode/backend/db/predicate" "github.com/chaitin/MonkeyCode/backend/db/projecttask" "github.com/chaitin/MonkeyCode/backend/db/task" @@ -262,6 +263,25 @@ func (_u *TaskUpdate) AddProjectTasks(v ...*ProjectTask) *TaskUpdate { return _u.AddProjectTaskIDs(ids...) } +// SetGitTasksID sets the "git_tasks" edge to the GitTask entity by ID. +func (_u *TaskUpdate) SetGitTasksID(id uuid.UUID) *TaskUpdate { + _u.mutation.SetGitTasksID(id) + return _u +} + +// SetNillableGitTasksID sets the "git_tasks" edge to the GitTask entity by ID if the given value is not nil. +func (_u *TaskUpdate) SetNillableGitTasksID(id *uuid.UUID) *TaskUpdate { + if id != nil { + _u = _u.SetGitTasksID(*id) + } + return _u +} + +// SetGitTasks sets the "git_tasks" edge to the GitTask entity. +func (_u *TaskUpdate) SetGitTasks(v *GitTask) *TaskUpdate { + return _u.SetGitTasksID(v.ID) +} + // SetUser sets the "user" edge to the User entity. func (_u *TaskUpdate) SetUser(v *User) *TaskUpdate { return _u.SetUserID(v.ID) @@ -353,6 +373,12 @@ func (_u *TaskUpdate) RemoveProjectTasks(v ...*ProjectTask) *TaskUpdate { return _u.RemoveProjectTaskIDs(ids...) } +// ClearGitTasks clears the "git_tasks" edge to the GitTask entity. +func (_u *TaskUpdate) ClearGitTasks() *TaskUpdate { + _u.mutation.ClearGitTasks() + return _u +} + // ClearUser clears the "user" edge to the User entity. func (_u *TaskUpdate) ClearUser() *TaskUpdate { _u.mutation.ClearUser() @@ -615,6 +641,35 @@ func (_u *TaskUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.GitTasksCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: task.GitTasksTable, + Columns: []string{task.GitTasksColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GitTasksIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: task.GitTasksTable, + Columns: []string{task.GitTasksColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.UserCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -1083,6 +1138,25 @@ func (_u *TaskUpdateOne) AddProjectTasks(v ...*ProjectTask) *TaskUpdateOne { return _u.AddProjectTaskIDs(ids...) } +// SetGitTasksID sets the "git_tasks" edge to the GitTask entity by ID. +func (_u *TaskUpdateOne) SetGitTasksID(id uuid.UUID) *TaskUpdateOne { + _u.mutation.SetGitTasksID(id) + return _u +} + +// SetNillableGitTasksID sets the "git_tasks" edge to the GitTask entity by ID if the given value is not nil. +func (_u *TaskUpdateOne) SetNillableGitTasksID(id *uuid.UUID) *TaskUpdateOne { + if id != nil { + _u = _u.SetGitTasksID(*id) + } + return _u +} + +// SetGitTasks sets the "git_tasks" edge to the GitTask entity. +func (_u *TaskUpdateOne) SetGitTasks(v *GitTask) *TaskUpdateOne { + return _u.SetGitTasksID(v.ID) +} + // SetUser sets the "user" edge to the User entity. func (_u *TaskUpdateOne) SetUser(v *User) *TaskUpdateOne { return _u.SetUserID(v.ID) @@ -1174,6 +1248,12 @@ func (_u *TaskUpdateOne) RemoveProjectTasks(v ...*ProjectTask) *TaskUpdateOne { return _u.RemoveProjectTaskIDs(ids...) } +// ClearGitTasks clears the "git_tasks" edge to the GitTask entity. +func (_u *TaskUpdateOne) ClearGitTasks() *TaskUpdateOne { + _u.mutation.ClearGitTasks() + return _u +} + // ClearUser clears the "user" edge to the User entity. func (_u *TaskUpdateOne) ClearUser() *TaskUpdateOne { _u.mutation.ClearUser() @@ -1466,6 +1546,35 @@ func (_u *TaskUpdateOne) sqlSave(ctx context.Context) (_node *Task, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } + if _u.mutation.GitTasksCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: task.GitTasksTable, + Columns: []string{task.GitTasksColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := _u.mutation.GitTasksIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2O, + Inverse: false, + Table: task.GitTasksTable, + Columns: []string{task.GitTasksColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(gittask.FieldID, field.TypeUUID), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } if _u.mutation.UserCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/backend/db/tx.go b/backend/db/tx.go index 6d1ed167..ac423775 100644 --- a/backend/db/tx.go +++ b/backend/db/tx.go @@ -24,6 +24,8 @@ type Tx struct { GitBotUser *GitBotUserClient // GitIdentity is the client for interacting with the GitIdentity builders. GitIdentity *GitIdentityClient + // GitTask is the client for interacting with the GitTask builders. + GitTask *GitTaskClient // Host is the client for interacting with the Host builders. Host *HostClient // Image is the client for interacting with the Image builders. @@ -228,6 +230,7 @@ func (tx *Tx) init() { tx.GitBotTask = NewGitBotTaskClient(tx.config) tx.GitBotUser = NewGitBotUserClient(tx.config) tx.GitIdentity = NewGitIdentityClient(tx.config) + tx.GitTask = NewGitTaskClient(tx.config) tx.Host = NewHostClient(tx.config) tx.Image = NewImageClient(tx.config) tx.MCPTool = NewMCPToolClient(tx.config) diff --git a/backend/domain/gittask.go b/backend/domain/gittask.go index 2933a1e0..c3109b3d 100644 --- a/backend/domain/gittask.go +++ b/backend/domain/gittask.go @@ -18,7 +18,7 @@ type GitTaskUsecase interface { // GitTaskRepoInterface GitTask 数据访问接口 type GitTaskRepoInterface interface { - Create(ctx context.Context, req CreateGitTaskReq, fn func(user *db.User, t *db.Task, m *db.Model, i *db.Image) (*taskflow.VirtualMachine, error)) (*db.Task, error) + Create(ctx context.Context, req CreateGitTaskReq, fn func(user *db.User, t *db.Task, m *db.Model) (*taskflow.VirtualMachine, error)) (*db.Task, error) } // CreateGitTaskReq 创建 GitTask 请求 diff --git a/backend/ent/schema/gittask.go b/backend/ent/schema/gittask.go new file mode 100644 index 00000000..f62d16ed --- /dev/null +++ b/backend/ent/schema/gittask.go @@ -0,0 +1,47 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +type GitTask struct { + ent.Schema +} + +func (GitTask) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Table("git_tasks"), + } +} + +// Fields of the GitTask. +func (GitTask) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}), + field.UUID("task_id", uuid.UUID{}), + field.UUID("repo_id", uuid.UUID{}).Optional(), + field.String("subject_type").NotEmpty(), + field.String("subject_id").Optional(), + field.Int("subject_number").Optional(), + field.String("subject_url").Optional(), + field.String("subject_title").Optional(), + field.String("prompt_id").Optional(), + field.Text("show_url").Optional(), + field.Int64("github_installation_id").Optional(), + field.Time("created_at").Default(time.Now), + } +} + +// Edges of the GitTask. +func (GitTask) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("task", Task.Type).Ref("git_tasks").Field("task_id").Unique().Required(), + } +} diff --git a/backend/ent/schema/task.go b/backend/ent/schema/task.go index c26b60e4..ab1621da 100644 --- a/backend/ent/schema/task.go +++ b/backend/ent/schema/task.go @@ -55,6 +55,7 @@ func (Task) Fields() []ent.Field { func (Task) Edges() []ent.Edge { return []ent.Edge{ edge.To("project_tasks", ProjectTask.Type), + edge.To("git_tasks", GitTask.Type).Unique(), edge.From("user", User.Type).Ref("tasks").Field("user_id").Unique().Required(), edge.From("vms", VirtualMachine.Type).Through("task_vms", TaskVirtualMachine.Type).Ref("tasks"), edge.To("git_bot_tasks", GitBotTask.Type), diff --git a/backend/pkg/entx/taskhook.go b/backend/pkg/entx/taskhook.go index 37b83511..ea1a76f5 100644 --- a/backend/pkg/entx/taskhook.go +++ b/backend/pkg/entx/taskhook.go @@ -51,6 +51,7 @@ func TaskConcurrencyHook(next ent.Mutator) ent.Mutator { Where( task.UserIDEQ(userID), task.StatusIn(consts.TaskStatusPending, consts.TaskStatusProcessing), + task.HasProjectTasks(), ). Count(ctx) if err != nil { diff --git a/backend/pkg/logger/logger.go b/backend/pkg/logger/logger.go index bf4d4d74..c43709f1 100644 --- a/backend/pkg/logger/logger.go +++ b/backend/pkg/logger/logger.go @@ -1,6 +1,7 @@ package logger import ( + "fmt" "log/slog" "os" ) @@ -25,12 +26,20 @@ func NewLogger(cfg *Config) *slog.Logger { level.Set(slog.LevelWarn) } base := slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ - Level: level, + Level: level, + ReplaceAttr: replaceAttr, }) handler := &ContextLogger{Handler: base} return slog.New(handler) } +func replaceAttr(_ []string, attr slog.Attr) slog.Attr { + if err, ok := attr.Value.Any().(error); ok && err != nil && err.Error() == "" { + attr.Value = slog.StringValue(fmt.Sprintf("%T", err)) + } + return attr +} + func SetLevel(lv string) { switch lv { case "debug": diff --git a/backend/pkg/logger/logger_test.go b/backend/pkg/logger/logger_test.go new file mode 100644 index 00000000..a8094041 --- /dev/null +++ b/backend/pkg/logger/logger_test.go @@ -0,0 +1,32 @@ +package logger + +import ( + "bytes" + "encoding/json" + "log/slog" + "testing" +) + +type emptyError struct{} + +func (emptyError) Error() string { return "" } + +func TestReplaceAttrKeepsEmptyErrorVisible(t *testing.T) { + var buf bytes.Buffer + l := slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{ + ReplaceAttr: replaceAttr, + })) + + l.Error("failed", "error", emptyError{}) + + var got map[string]any + if err := json.Unmarshal(buf.Bytes(), &got); err != nil { + t.Fatalf("unmarshal log: %v", err) + } + if got["error"] == "" { + t.Fatal("error attr is empty") + } + if got["error"] != "logger.emptyError" { + t.Fatalf("error attr = %v, want logger.emptyError", got["error"]) + } +}