UpdateProject updates a project and any impacted deployments. It runs a reconcile if deployment parameters (like branch or variables) have been changed and reconcileDeployment is set.
(ctx context.Context, oldProj *database.Project, opts *database.UpdateProjectOptions)
| 179 | // UpdateProject updates a project and any impacted deployments. |
| 180 | // It runs a reconcile if deployment parameters (like branch or variables) have been changed and reconcileDeployment is set. |
| 181 | func (s *Service) UpdateProject(ctx context.Context, oldProj *database.Project, opts *database.UpdateProjectOptions) (*database.Project, error) { |
| 182 | // check if there is an existing dev deployment for the new primary branch |
| 183 | depls, err := s.DB.FindDeploymentsForProject(ctx, oldProj.ID, "", opts.PrimaryBranch) |
| 184 | if err != nil { |
| 185 | return nil, err |
| 186 | } |
| 187 | for _, d := range depls { |
| 188 | if d.Environment != "prod" { |
| 189 | return nil, fmt.Errorf("cannot change primary branch to %q as there is an existing non-production deployment for this branch. Delete that deployment first", opts.PrimaryBranch) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | proj, err := s.DB.UpdateProject(ctx, oldProj.ID, opts) |
| 194 | if err != nil { |
| 195 | return nil, err |
| 196 | } |
| 197 | |
| 198 | impactsDeployments := (oldProj.ProdVersion != opts.ProdVersion) || |
| 199 | (oldProj.ProdSlots != opts.ProdSlots) || |
| 200 | (oldProj.Name != opts.Name) || |
| 201 | (oldProj.Subpath != opts.Subpath) || |
| 202 | (oldProj.PrimaryBranch != opts.PrimaryBranch) || |
| 203 | !reflect.DeepEqual(oldProj.Annotations, opts.Annotations) || |
| 204 | !reflect.DeepEqual(oldProj.GitRemote, opts.GitRemote) || |
| 205 | !reflect.DeepEqual(oldProj.GithubInstallationID, opts.GithubInstallationID) || |
| 206 | !reflect.DeepEqual(oldProj.ArchiveAssetID, opts.ArchiveAssetID) || |
| 207 | !reflect.DeepEqual(oldProj.OverrideDiskGB, opts.OverrideDiskGB) |
| 208 | |
| 209 | if !impactsDeployments { |
| 210 | return proj, nil |
| 211 | } |
| 212 | |
| 213 | s.Logger.Info("update project: updating deployments", observability.ZapCtx(ctx)) |
| 214 | |
| 215 | // if there is an existing prod deployment for the new branch then update the project use that as its primary deployment |
| 216 | if oldProj.PrimaryBranch != opts.PrimaryBranch { |
| 217 | for _, d := range depls { |
| 218 | if d.Environment != "prod" { |
| 219 | continue |
| 220 | } |
| 221 | proj, err = s.DB.UpdateProject(ctx, proj.ID, &database.UpdateProjectOptions{ |
| 222 | Name: proj.Name, |
| 223 | Description: proj.Description, |
| 224 | Public: proj.Public, |
| 225 | DirectoryName: proj.DirectoryName, |
| 226 | Provisioner: proj.Provisioner, |
| 227 | ArchiveAssetID: proj.ArchiveAssetID, |
| 228 | GitRemote: proj.GitRemote, |
| 229 | GithubInstallationID: proj.GithubInstallationID, |
| 230 | GithubRepoID: proj.GithubRepoID, |
| 231 | ManagedGitRepoID: proj.ManagedGitRepoID, |
| 232 | ProdVersion: proj.ProdVersion, |
| 233 | PrimaryBranch: proj.PrimaryBranch, |
| 234 | Subpath: proj.Subpath, |
| 235 | PrimaryDeploymentID: &d.ID, |
| 236 | ProdSlots: proj.ProdSlots, |
| 237 | ProdTTLSeconds: proj.ProdTTLSeconds, |
| 238 | DevSlots: proj.DevSlots, |
nothing calls this directly
no test coverage detected