// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/buildbarn/bb-portal/ent/gen/ent/bazelinvocation"
	"github.com/buildbarn/bb-portal/ent/gen/ent/predicate"
	"github.com/buildbarn/bb-portal/ent/gen/ent/sourcecontrol"
)

// SourceControlUpdate is the builder for updating SourceControl entities.
type SourceControlUpdate struct {
	config
	hooks    []Hook
	mutation *SourceControlMutation
}

// Where appends a list predicates to the SourceControlUpdate builder.
func (scu *SourceControlUpdate) Where(ps ...predicate.SourceControl) *SourceControlUpdate {
	scu.mutation.Where(ps...)
	return scu
}

// SetRepoURL sets the "repo_url" field.
func (scu *SourceControlUpdate) SetRepoURL(s string) *SourceControlUpdate {
	scu.mutation.SetRepoURL(s)
	return scu
}

// SetNillableRepoURL sets the "repo_url" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableRepoURL(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetRepoURL(*s)
	}
	return scu
}

// ClearRepoURL clears the value of the "repo_url" field.
func (scu *SourceControlUpdate) ClearRepoURL() *SourceControlUpdate {
	scu.mutation.ClearRepoURL()
	return scu
}

// SetBranch sets the "branch" field.
func (scu *SourceControlUpdate) SetBranch(s string) *SourceControlUpdate {
	scu.mutation.SetBranch(s)
	return scu
}

// SetNillableBranch sets the "branch" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableBranch(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetBranch(*s)
	}
	return scu
}

// ClearBranch clears the value of the "branch" field.
func (scu *SourceControlUpdate) ClearBranch() *SourceControlUpdate {
	scu.mutation.ClearBranch()
	return scu
}

// SetCommitSha sets the "commit_sha" field.
func (scu *SourceControlUpdate) SetCommitSha(s string) *SourceControlUpdate {
	scu.mutation.SetCommitSha(s)
	return scu
}

// SetNillableCommitSha sets the "commit_sha" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableCommitSha(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetCommitSha(*s)
	}
	return scu
}

// ClearCommitSha clears the value of the "commit_sha" field.
func (scu *SourceControlUpdate) ClearCommitSha() *SourceControlUpdate {
	scu.mutation.ClearCommitSha()
	return scu
}

// SetActor sets the "actor" field.
func (scu *SourceControlUpdate) SetActor(s string) *SourceControlUpdate {
	scu.mutation.SetActor(s)
	return scu
}

// SetNillableActor sets the "actor" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableActor(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetActor(*s)
	}
	return scu
}

// ClearActor clears the value of the "actor" field.
func (scu *SourceControlUpdate) ClearActor() *SourceControlUpdate {
	scu.mutation.ClearActor()
	return scu
}

// SetRefs sets the "refs" field.
func (scu *SourceControlUpdate) SetRefs(s string) *SourceControlUpdate {
	scu.mutation.SetRefs(s)
	return scu
}

// SetNillableRefs sets the "refs" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableRefs(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetRefs(*s)
	}
	return scu
}

// ClearRefs clears the value of the "refs" field.
func (scu *SourceControlUpdate) ClearRefs() *SourceControlUpdate {
	scu.mutation.ClearRefs()
	return scu
}

// SetRunID sets the "run_id" field.
func (scu *SourceControlUpdate) SetRunID(s string) *SourceControlUpdate {
	scu.mutation.SetRunID(s)
	return scu
}

// SetNillableRunID sets the "run_id" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableRunID(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetRunID(*s)
	}
	return scu
}

// ClearRunID clears the value of the "run_id" field.
func (scu *SourceControlUpdate) ClearRunID() *SourceControlUpdate {
	scu.mutation.ClearRunID()
	return scu
}

// SetWorkflow sets the "workflow" field.
func (scu *SourceControlUpdate) SetWorkflow(s string) *SourceControlUpdate {
	scu.mutation.SetWorkflow(s)
	return scu
}

// SetNillableWorkflow sets the "workflow" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableWorkflow(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetWorkflow(*s)
	}
	return scu
}

// ClearWorkflow clears the value of the "workflow" field.
func (scu *SourceControlUpdate) ClearWorkflow() *SourceControlUpdate {
	scu.mutation.ClearWorkflow()
	return scu
}

// SetAction sets the "action" field.
func (scu *SourceControlUpdate) SetAction(s string) *SourceControlUpdate {
	scu.mutation.SetAction(s)
	return scu
}

// SetNillableAction sets the "action" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableAction(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetAction(*s)
	}
	return scu
}

// ClearAction clears the value of the "action" field.
func (scu *SourceControlUpdate) ClearAction() *SourceControlUpdate {
	scu.mutation.ClearAction()
	return scu
}

// SetWorkspace sets the "workspace" field.
func (scu *SourceControlUpdate) SetWorkspace(s string) *SourceControlUpdate {
	scu.mutation.SetWorkspace(s)
	return scu
}

// SetNillableWorkspace sets the "workspace" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableWorkspace(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetWorkspace(*s)
	}
	return scu
}

// ClearWorkspace clears the value of the "workspace" field.
func (scu *SourceControlUpdate) ClearWorkspace() *SourceControlUpdate {
	scu.mutation.ClearWorkspace()
	return scu
}

// SetEventName sets the "event_name" field.
func (scu *SourceControlUpdate) SetEventName(s string) *SourceControlUpdate {
	scu.mutation.SetEventName(s)
	return scu
}

// SetNillableEventName sets the "event_name" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableEventName(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetEventName(*s)
	}
	return scu
}

// ClearEventName clears the value of the "event_name" field.
func (scu *SourceControlUpdate) ClearEventName() *SourceControlUpdate {
	scu.mutation.ClearEventName()
	return scu
}

// SetJob sets the "job" field.
func (scu *SourceControlUpdate) SetJob(s string) *SourceControlUpdate {
	scu.mutation.SetJob(s)
	return scu
}

// SetNillableJob sets the "job" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableJob(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetJob(*s)
	}
	return scu
}

// ClearJob clears the value of the "job" field.
func (scu *SourceControlUpdate) ClearJob() *SourceControlUpdate {
	scu.mutation.ClearJob()
	return scu
}

// SetRunnerName sets the "runner_name" field.
func (scu *SourceControlUpdate) SetRunnerName(s string) *SourceControlUpdate {
	scu.mutation.SetRunnerName(s)
	return scu
}

// SetNillableRunnerName sets the "runner_name" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableRunnerName(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetRunnerName(*s)
	}
	return scu
}

// ClearRunnerName clears the value of the "runner_name" field.
func (scu *SourceControlUpdate) ClearRunnerName() *SourceControlUpdate {
	scu.mutation.ClearRunnerName()
	return scu
}

// SetRunnerArch sets the "runner_arch" field.
func (scu *SourceControlUpdate) SetRunnerArch(s string) *SourceControlUpdate {
	scu.mutation.SetRunnerArch(s)
	return scu
}

// SetNillableRunnerArch sets the "runner_arch" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableRunnerArch(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetRunnerArch(*s)
	}
	return scu
}

// ClearRunnerArch clears the value of the "runner_arch" field.
func (scu *SourceControlUpdate) ClearRunnerArch() *SourceControlUpdate {
	scu.mutation.ClearRunnerArch()
	return scu
}

// SetRunnerOs sets the "runner_os" field.
func (scu *SourceControlUpdate) SetRunnerOs(s string) *SourceControlUpdate {
	scu.mutation.SetRunnerOs(s)
	return scu
}

// SetNillableRunnerOs sets the "runner_os" field if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableRunnerOs(s *string) *SourceControlUpdate {
	if s != nil {
		scu.SetRunnerOs(*s)
	}
	return scu
}

// ClearRunnerOs clears the value of the "runner_os" field.
func (scu *SourceControlUpdate) ClearRunnerOs() *SourceControlUpdate {
	scu.mutation.ClearRunnerOs()
	return scu
}

// SetBazelInvocationID sets the "bazel_invocation" edge to the BazelInvocation entity by ID.
func (scu *SourceControlUpdate) SetBazelInvocationID(id int) *SourceControlUpdate {
	scu.mutation.SetBazelInvocationID(id)
	return scu
}

// SetNillableBazelInvocationID sets the "bazel_invocation" edge to the BazelInvocation entity by ID if the given value is not nil.
func (scu *SourceControlUpdate) SetNillableBazelInvocationID(id *int) *SourceControlUpdate {
	if id != nil {
		scu = scu.SetBazelInvocationID(*id)
	}
	return scu
}

// SetBazelInvocation sets the "bazel_invocation" edge to the BazelInvocation entity.
func (scu *SourceControlUpdate) SetBazelInvocation(b *BazelInvocation) *SourceControlUpdate {
	return scu.SetBazelInvocationID(b.ID)
}

// Mutation returns the SourceControlMutation object of the builder.
func (scu *SourceControlUpdate) Mutation() *SourceControlMutation {
	return scu.mutation
}

// ClearBazelInvocation clears the "bazel_invocation" edge to the BazelInvocation entity.
func (scu *SourceControlUpdate) ClearBazelInvocation() *SourceControlUpdate {
	scu.mutation.ClearBazelInvocation()
	return scu
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (scu *SourceControlUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, scu.sqlSave, scu.mutation, scu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (scu *SourceControlUpdate) SaveX(ctx context.Context) int {
	affected, err := scu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (scu *SourceControlUpdate) Exec(ctx context.Context) error {
	_, err := scu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (scu *SourceControlUpdate) ExecX(ctx context.Context) {
	if err := scu.Exec(ctx); err != nil {
		panic(err)
	}
}

func (scu *SourceControlUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(sourcecontrol.Table, sourcecontrol.Columns, sqlgraph.NewFieldSpec(sourcecontrol.FieldID, field.TypeInt))
	if ps := scu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := scu.mutation.RepoURL(); ok {
		_spec.SetField(sourcecontrol.FieldRepoURL, field.TypeString, value)
	}
	if scu.mutation.RepoURLCleared() {
		_spec.ClearField(sourcecontrol.FieldRepoURL, field.TypeString)
	}
	if value, ok := scu.mutation.Branch(); ok {
		_spec.SetField(sourcecontrol.FieldBranch, field.TypeString, value)
	}
	if scu.mutation.BranchCleared() {
		_spec.ClearField(sourcecontrol.FieldBranch, field.TypeString)
	}
	if value, ok := scu.mutation.CommitSha(); ok {
		_spec.SetField(sourcecontrol.FieldCommitSha, field.TypeString, value)
	}
	if scu.mutation.CommitShaCleared() {
		_spec.ClearField(sourcecontrol.FieldCommitSha, field.TypeString)
	}
	if value, ok := scu.mutation.Actor(); ok {
		_spec.SetField(sourcecontrol.FieldActor, field.TypeString, value)
	}
	if scu.mutation.ActorCleared() {
		_spec.ClearField(sourcecontrol.FieldActor, field.TypeString)
	}
	if value, ok := scu.mutation.Refs(); ok {
		_spec.SetField(sourcecontrol.FieldRefs, field.TypeString, value)
	}
	if scu.mutation.RefsCleared() {
		_spec.ClearField(sourcecontrol.FieldRefs, field.TypeString)
	}
	if value, ok := scu.mutation.RunID(); ok {
		_spec.SetField(sourcecontrol.FieldRunID, field.TypeString, value)
	}
	if scu.mutation.RunIDCleared() {
		_spec.ClearField(sourcecontrol.FieldRunID, field.TypeString)
	}
	if value, ok := scu.mutation.Workflow(); ok {
		_spec.SetField(sourcecontrol.FieldWorkflow, field.TypeString, value)
	}
	if scu.mutation.WorkflowCleared() {
		_spec.ClearField(sourcecontrol.FieldWorkflow, field.TypeString)
	}
	if value, ok := scu.mutation.Action(); ok {
		_spec.SetField(sourcecontrol.FieldAction, field.TypeString, value)
	}
	if scu.mutation.ActionCleared() {
		_spec.ClearField(sourcecontrol.FieldAction, field.TypeString)
	}
	if value, ok := scu.mutation.Workspace(); ok {
		_spec.SetField(sourcecontrol.FieldWorkspace, field.TypeString, value)
	}
	if scu.mutation.WorkspaceCleared() {
		_spec.ClearField(sourcecontrol.FieldWorkspace, field.TypeString)
	}
	if value, ok := scu.mutation.EventName(); ok {
		_spec.SetField(sourcecontrol.FieldEventName, field.TypeString, value)
	}
	if scu.mutation.EventNameCleared() {
		_spec.ClearField(sourcecontrol.FieldEventName, field.TypeString)
	}
	if value, ok := scu.mutation.Job(); ok {
		_spec.SetField(sourcecontrol.FieldJob, field.TypeString, value)
	}
	if scu.mutation.JobCleared() {
		_spec.ClearField(sourcecontrol.FieldJob, field.TypeString)
	}
	if value, ok := scu.mutation.RunnerName(); ok {
		_spec.SetField(sourcecontrol.FieldRunnerName, field.TypeString, value)
	}
	if scu.mutation.RunnerNameCleared() {
		_spec.ClearField(sourcecontrol.FieldRunnerName, field.TypeString)
	}
	if value, ok := scu.mutation.RunnerArch(); ok {
		_spec.SetField(sourcecontrol.FieldRunnerArch, field.TypeString, value)
	}
	if scu.mutation.RunnerArchCleared() {
		_spec.ClearField(sourcecontrol.FieldRunnerArch, field.TypeString)
	}
	if value, ok := scu.mutation.RunnerOs(); ok {
		_spec.SetField(sourcecontrol.FieldRunnerOs, field.TypeString, value)
	}
	if scu.mutation.RunnerOsCleared() {
		_spec.ClearField(sourcecontrol.FieldRunnerOs, field.TypeString)
	}
	if scu.mutation.BazelInvocationCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   sourcecontrol.BazelInvocationTable,
			Columns: []string{sourcecontrol.BazelInvocationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(bazelinvocation.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := scu.mutation.BazelInvocationIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   sourcecontrol.BazelInvocationTable,
			Columns: []string{sourcecontrol.BazelInvocationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(bazelinvocation.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, scu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{sourcecontrol.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	scu.mutation.done = true
	return n, nil
}

// SourceControlUpdateOne is the builder for updating a single SourceControl entity.
type SourceControlUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *SourceControlMutation
}

// SetRepoURL sets the "repo_url" field.
func (scuo *SourceControlUpdateOne) SetRepoURL(s string) *SourceControlUpdateOne {
	scuo.mutation.SetRepoURL(s)
	return scuo
}

// SetNillableRepoURL sets the "repo_url" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableRepoURL(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetRepoURL(*s)
	}
	return scuo
}

// ClearRepoURL clears the value of the "repo_url" field.
func (scuo *SourceControlUpdateOne) ClearRepoURL() *SourceControlUpdateOne {
	scuo.mutation.ClearRepoURL()
	return scuo
}

// SetBranch sets the "branch" field.
func (scuo *SourceControlUpdateOne) SetBranch(s string) *SourceControlUpdateOne {
	scuo.mutation.SetBranch(s)
	return scuo
}

// SetNillableBranch sets the "branch" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableBranch(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetBranch(*s)
	}
	return scuo
}

// ClearBranch clears the value of the "branch" field.
func (scuo *SourceControlUpdateOne) ClearBranch() *SourceControlUpdateOne {
	scuo.mutation.ClearBranch()
	return scuo
}

// SetCommitSha sets the "commit_sha" field.
func (scuo *SourceControlUpdateOne) SetCommitSha(s string) *SourceControlUpdateOne {
	scuo.mutation.SetCommitSha(s)
	return scuo
}

// SetNillableCommitSha sets the "commit_sha" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableCommitSha(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetCommitSha(*s)
	}
	return scuo
}

// ClearCommitSha clears the value of the "commit_sha" field.
func (scuo *SourceControlUpdateOne) ClearCommitSha() *SourceControlUpdateOne {
	scuo.mutation.ClearCommitSha()
	return scuo
}

// SetActor sets the "actor" field.
func (scuo *SourceControlUpdateOne) SetActor(s string) *SourceControlUpdateOne {
	scuo.mutation.SetActor(s)
	return scuo
}

// SetNillableActor sets the "actor" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableActor(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetActor(*s)
	}
	return scuo
}

// ClearActor clears the value of the "actor" field.
func (scuo *SourceControlUpdateOne) ClearActor() *SourceControlUpdateOne {
	scuo.mutation.ClearActor()
	return scuo
}

// SetRefs sets the "refs" field.
func (scuo *SourceControlUpdateOne) SetRefs(s string) *SourceControlUpdateOne {
	scuo.mutation.SetRefs(s)
	return scuo
}

// SetNillableRefs sets the "refs" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableRefs(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetRefs(*s)
	}
	return scuo
}

// ClearRefs clears the value of the "refs" field.
func (scuo *SourceControlUpdateOne) ClearRefs() *SourceControlUpdateOne {
	scuo.mutation.ClearRefs()
	return scuo
}

// SetRunID sets the "run_id" field.
func (scuo *SourceControlUpdateOne) SetRunID(s string) *SourceControlUpdateOne {
	scuo.mutation.SetRunID(s)
	return scuo
}

// SetNillableRunID sets the "run_id" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableRunID(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetRunID(*s)
	}
	return scuo
}

// ClearRunID clears the value of the "run_id" field.
func (scuo *SourceControlUpdateOne) ClearRunID() *SourceControlUpdateOne {
	scuo.mutation.ClearRunID()
	return scuo
}

// SetWorkflow sets the "workflow" field.
func (scuo *SourceControlUpdateOne) SetWorkflow(s string) *SourceControlUpdateOne {
	scuo.mutation.SetWorkflow(s)
	return scuo
}

// SetNillableWorkflow sets the "workflow" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableWorkflow(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetWorkflow(*s)
	}
	return scuo
}

// ClearWorkflow clears the value of the "workflow" field.
func (scuo *SourceControlUpdateOne) ClearWorkflow() *SourceControlUpdateOne {
	scuo.mutation.ClearWorkflow()
	return scuo
}

// SetAction sets the "action" field.
func (scuo *SourceControlUpdateOne) SetAction(s string) *SourceControlUpdateOne {
	scuo.mutation.SetAction(s)
	return scuo
}

// SetNillableAction sets the "action" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableAction(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetAction(*s)
	}
	return scuo
}

// ClearAction clears the value of the "action" field.
func (scuo *SourceControlUpdateOne) ClearAction() *SourceControlUpdateOne {
	scuo.mutation.ClearAction()
	return scuo
}

// SetWorkspace sets the "workspace" field.
func (scuo *SourceControlUpdateOne) SetWorkspace(s string) *SourceControlUpdateOne {
	scuo.mutation.SetWorkspace(s)
	return scuo
}

// SetNillableWorkspace sets the "workspace" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableWorkspace(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetWorkspace(*s)
	}
	return scuo
}

// ClearWorkspace clears the value of the "workspace" field.
func (scuo *SourceControlUpdateOne) ClearWorkspace() *SourceControlUpdateOne {
	scuo.mutation.ClearWorkspace()
	return scuo
}

// SetEventName sets the "event_name" field.
func (scuo *SourceControlUpdateOne) SetEventName(s string) *SourceControlUpdateOne {
	scuo.mutation.SetEventName(s)
	return scuo
}

// SetNillableEventName sets the "event_name" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableEventName(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetEventName(*s)
	}
	return scuo
}

// ClearEventName clears the value of the "event_name" field.
func (scuo *SourceControlUpdateOne) ClearEventName() *SourceControlUpdateOne {
	scuo.mutation.ClearEventName()
	return scuo
}

// SetJob sets the "job" field.
func (scuo *SourceControlUpdateOne) SetJob(s string) *SourceControlUpdateOne {
	scuo.mutation.SetJob(s)
	return scuo
}

// SetNillableJob sets the "job" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableJob(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetJob(*s)
	}
	return scuo
}

// ClearJob clears the value of the "job" field.
func (scuo *SourceControlUpdateOne) ClearJob() *SourceControlUpdateOne {
	scuo.mutation.ClearJob()
	return scuo
}

// SetRunnerName sets the "runner_name" field.
func (scuo *SourceControlUpdateOne) SetRunnerName(s string) *SourceControlUpdateOne {
	scuo.mutation.SetRunnerName(s)
	return scuo
}

// SetNillableRunnerName sets the "runner_name" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableRunnerName(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetRunnerName(*s)
	}
	return scuo
}

// ClearRunnerName clears the value of the "runner_name" field.
func (scuo *SourceControlUpdateOne) ClearRunnerName() *SourceControlUpdateOne {
	scuo.mutation.ClearRunnerName()
	return scuo
}

// SetRunnerArch sets the "runner_arch" field.
func (scuo *SourceControlUpdateOne) SetRunnerArch(s string) *SourceControlUpdateOne {
	scuo.mutation.SetRunnerArch(s)
	return scuo
}

// SetNillableRunnerArch sets the "runner_arch" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableRunnerArch(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetRunnerArch(*s)
	}
	return scuo
}

// ClearRunnerArch clears the value of the "runner_arch" field.
func (scuo *SourceControlUpdateOne) ClearRunnerArch() *SourceControlUpdateOne {
	scuo.mutation.ClearRunnerArch()
	return scuo
}

// SetRunnerOs sets the "runner_os" field.
func (scuo *SourceControlUpdateOne) SetRunnerOs(s string) *SourceControlUpdateOne {
	scuo.mutation.SetRunnerOs(s)
	return scuo
}

// SetNillableRunnerOs sets the "runner_os" field if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableRunnerOs(s *string) *SourceControlUpdateOne {
	if s != nil {
		scuo.SetRunnerOs(*s)
	}
	return scuo
}

// ClearRunnerOs clears the value of the "runner_os" field.
func (scuo *SourceControlUpdateOne) ClearRunnerOs() *SourceControlUpdateOne {
	scuo.mutation.ClearRunnerOs()
	return scuo
}

// SetBazelInvocationID sets the "bazel_invocation" edge to the BazelInvocation entity by ID.
func (scuo *SourceControlUpdateOne) SetBazelInvocationID(id int) *SourceControlUpdateOne {
	scuo.mutation.SetBazelInvocationID(id)
	return scuo
}

// SetNillableBazelInvocationID sets the "bazel_invocation" edge to the BazelInvocation entity by ID if the given value is not nil.
func (scuo *SourceControlUpdateOne) SetNillableBazelInvocationID(id *int) *SourceControlUpdateOne {
	if id != nil {
		scuo = scuo.SetBazelInvocationID(*id)
	}
	return scuo
}

// SetBazelInvocation sets the "bazel_invocation" edge to the BazelInvocation entity.
func (scuo *SourceControlUpdateOne) SetBazelInvocation(b *BazelInvocation) *SourceControlUpdateOne {
	return scuo.SetBazelInvocationID(b.ID)
}

// Mutation returns the SourceControlMutation object of the builder.
func (scuo *SourceControlUpdateOne) Mutation() *SourceControlMutation {
	return scuo.mutation
}

// ClearBazelInvocation clears the "bazel_invocation" edge to the BazelInvocation entity.
func (scuo *SourceControlUpdateOne) ClearBazelInvocation() *SourceControlUpdateOne {
	scuo.mutation.ClearBazelInvocation()
	return scuo
}

// Where appends a list predicates to the SourceControlUpdate builder.
func (scuo *SourceControlUpdateOne) Where(ps ...predicate.SourceControl) *SourceControlUpdateOne {
	scuo.mutation.Where(ps...)
	return scuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (scuo *SourceControlUpdateOne) Select(field string, fields ...string) *SourceControlUpdateOne {
	scuo.fields = append([]string{field}, fields...)
	return scuo
}

// Save executes the query and returns the updated SourceControl entity.
func (scuo *SourceControlUpdateOne) Save(ctx context.Context) (*SourceControl, error) {
	return withHooks(ctx, scuo.sqlSave, scuo.mutation, scuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (scuo *SourceControlUpdateOne) SaveX(ctx context.Context) *SourceControl {
	node, err := scuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (scuo *SourceControlUpdateOne) Exec(ctx context.Context) error {
	_, err := scuo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (scuo *SourceControlUpdateOne) ExecX(ctx context.Context) {
	if err := scuo.Exec(ctx); err != nil {
		panic(err)
	}
}

func (scuo *SourceControlUpdateOne) sqlSave(ctx context.Context) (_node *SourceControl, err error) {
	_spec := sqlgraph.NewUpdateSpec(sourcecontrol.Table, sourcecontrol.Columns, sqlgraph.NewFieldSpec(sourcecontrol.FieldID, field.TypeInt))
	id, ok := scuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SourceControl.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := scuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, sourcecontrol.FieldID)
		for _, f := range fields {
			if !sourcecontrol.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != sourcecontrol.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := scuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := scuo.mutation.RepoURL(); ok {
		_spec.SetField(sourcecontrol.FieldRepoURL, field.TypeString, value)
	}
	if scuo.mutation.RepoURLCleared() {
		_spec.ClearField(sourcecontrol.FieldRepoURL, field.TypeString)
	}
	if value, ok := scuo.mutation.Branch(); ok {
		_spec.SetField(sourcecontrol.FieldBranch, field.TypeString, value)
	}
	if scuo.mutation.BranchCleared() {
		_spec.ClearField(sourcecontrol.FieldBranch, field.TypeString)
	}
	if value, ok := scuo.mutation.CommitSha(); ok {
		_spec.SetField(sourcecontrol.FieldCommitSha, field.TypeString, value)
	}
	if scuo.mutation.CommitShaCleared() {
		_spec.ClearField(sourcecontrol.FieldCommitSha, field.TypeString)
	}
	if value, ok := scuo.mutation.Actor(); ok {
		_spec.SetField(sourcecontrol.FieldActor, field.TypeString, value)
	}
	if scuo.mutation.ActorCleared() {
		_spec.ClearField(sourcecontrol.FieldActor, field.TypeString)
	}
	if value, ok := scuo.mutation.Refs(); ok {
		_spec.SetField(sourcecontrol.FieldRefs, field.TypeString, value)
	}
	if scuo.mutation.RefsCleared() {
		_spec.ClearField(sourcecontrol.FieldRefs, field.TypeString)
	}
	if value, ok := scuo.mutation.RunID(); ok {
		_spec.SetField(sourcecontrol.FieldRunID, field.TypeString, value)
	}
	if scuo.mutation.RunIDCleared() {
		_spec.ClearField(sourcecontrol.FieldRunID, field.TypeString)
	}
	if value, ok := scuo.mutation.Workflow(); ok {
		_spec.SetField(sourcecontrol.FieldWorkflow, field.TypeString, value)
	}
	if scuo.mutation.WorkflowCleared() {
		_spec.ClearField(sourcecontrol.FieldWorkflow, field.TypeString)
	}
	if value, ok := scuo.mutation.Action(); ok {
		_spec.SetField(sourcecontrol.FieldAction, field.TypeString, value)
	}
	if scuo.mutation.ActionCleared() {
		_spec.ClearField(sourcecontrol.FieldAction, field.TypeString)
	}
	if value, ok := scuo.mutation.Workspace(); ok {
		_spec.SetField(sourcecontrol.FieldWorkspace, field.TypeString, value)
	}
	if scuo.mutation.WorkspaceCleared() {
		_spec.ClearField(sourcecontrol.FieldWorkspace, field.TypeString)
	}
	if value, ok := scuo.mutation.EventName(); ok {
		_spec.SetField(sourcecontrol.FieldEventName, field.TypeString, value)
	}
	if scuo.mutation.EventNameCleared() {
		_spec.ClearField(sourcecontrol.FieldEventName, field.TypeString)
	}
	if value, ok := scuo.mutation.Job(); ok {
		_spec.SetField(sourcecontrol.FieldJob, field.TypeString, value)
	}
	if scuo.mutation.JobCleared() {
		_spec.ClearField(sourcecontrol.FieldJob, field.TypeString)
	}
	if value, ok := scuo.mutation.RunnerName(); ok {
		_spec.SetField(sourcecontrol.FieldRunnerName, field.TypeString, value)
	}
	if scuo.mutation.RunnerNameCleared() {
		_spec.ClearField(sourcecontrol.FieldRunnerName, field.TypeString)
	}
	if value, ok := scuo.mutation.RunnerArch(); ok {
		_spec.SetField(sourcecontrol.FieldRunnerArch, field.TypeString, value)
	}
	if scuo.mutation.RunnerArchCleared() {
		_spec.ClearField(sourcecontrol.FieldRunnerArch, field.TypeString)
	}
	if value, ok := scuo.mutation.RunnerOs(); ok {
		_spec.SetField(sourcecontrol.FieldRunnerOs, field.TypeString, value)
	}
	if scuo.mutation.RunnerOsCleared() {
		_spec.ClearField(sourcecontrol.FieldRunnerOs, field.TypeString)
	}
	if scuo.mutation.BazelInvocationCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   sourcecontrol.BazelInvocationTable,
			Columns: []string{sourcecontrol.BazelInvocationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(bazelinvocation.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := scuo.mutation.BazelInvocationIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2O,
			Inverse: true,
			Table:   sourcecontrol.BazelInvocationTable,
			Columns: []string{sourcecontrol.BazelInvocationColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(bazelinvocation.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &SourceControl{config: scuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, scuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{sourcecontrol.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	scuo.mutation.done = true
	return _node, nil
}
