UpdateProjectVariables updates a project's variables and runs reconcile on the deployments.
(ctx context.Context, project *database.Project, environment string, vars map[string]string, unsetVars []string, userID string)
| 258 | |
| 259 | // UpdateProjectVariables updates a project's variables and runs reconcile on the deployments. |
| 260 | func (s *Service) UpdateProjectVariables(ctx context.Context, project *database.Project, environment string, vars map[string]string, unsetVars []string, userID string) error { |
| 261 | if len(vars) == 0 && len(unsetVars) == 0 { |
| 262 | return nil |
| 263 | } |
| 264 | txCtx, tx, err := s.DB.NewTx(ctx, false) |
| 265 | if err != nil { |
| 266 | return err |
| 267 | } |
| 268 | defer func() { |
| 269 | _ = tx.Rollback() |
| 270 | }() |
| 271 | |
| 272 | // Upsert variables |
| 273 | if len(vars) > 0 { |
| 274 | _, err = s.DB.UpsertProjectVariable(txCtx, project.ID, environment, vars, userID) |
| 275 | if err != nil { |
| 276 | return err |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | // Delete unset variables |
| 281 | if len(unsetVars) > 0 { |
| 282 | err = s.DB.DeleteProjectVariables(txCtx, project.ID, environment, unsetVars) |
| 283 | if err != nil { |
| 284 | return err |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // Commit transaction |
| 289 | err = tx.Commit() |
| 290 | if err != nil { |
| 291 | return err |
| 292 | } |
| 293 | |
| 294 | // Update deployments |
| 295 | s.Logger.Info("update project variables: updating deployments", observability.ZapCtx(ctx)) |
| 296 | |
| 297 | err = s.UpdateDeploymentsForProject(ctx, project) |
| 298 | if err != nil { |
| 299 | return err |
| 300 | } |
| 301 | |
| 302 | return nil |
| 303 | } |
| 304 | |
| 305 | // UpdateOrgDeploymentAnnotations iterates over projects of the given org and |
| 306 | // updates annotations of corresponding deployments with the new organization name |
nothing calls this directly
no test coverage detected