(_ context.Context, name string, param params.UpdateGithubEndpointParams)
| 82 | } |
| 83 | |
| 84 | func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param params.UpdateGithubEndpointParams) (ghEndpoint params.ForgeEndpoint, err error) { |
| 85 | var rowsAffected int64 |
| 86 | defer func() { |
| 87 | if err == nil && rowsAffected > 0 { |
| 88 | s.sendNotify(common.GithubEndpointEntityType, common.UpdateOperation, ghEndpoint) |
| 89 | } |
| 90 | }() |
| 91 | var endpoint GithubEndpoint |
| 92 | err = s.conn.Transaction(func(tx *gorm.DB) error { |
| 93 | if err := tx.Where("name = ? and endpoint_type = ?", name, params.GithubEndpointType).First(&endpoint).Error; err != nil { |
| 94 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 95 | return fmt.Errorf("error github endpoint not found: %w", runnerErrors.ErrNotFound) |
| 96 | } |
| 97 | return fmt.Errorf("error fetching github endpoint: %w", err) |
| 98 | } |
| 99 | |
| 100 | var credsCount int64 |
| 101 | if err := tx.Model(&GithubCredentials{}).Where("endpoint_name = ?", endpoint.Name).Count(&credsCount).Error; err != nil { |
| 102 | if !errors.Is(err, gorm.ErrRecordNotFound) { |
| 103 | return fmt.Errorf("error fetching github credentials: %w", err) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | updates := make(map[string]interface{}) |
| 108 | |
| 109 | if param.APIBaseURL != nil && *param.APIBaseURL != endpoint.APIBaseURL { |
| 110 | updates["api_base_url"] = *param.APIBaseURL |
| 111 | } |
| 112 | |
| 113 | if param.BaseURL != nil && *param.BaseURL != endpoint.BaseURL { |
| 114 | updates["base_url"] = *param.BaseURL |
| 115 | } |
| 116 | |
| 117 | if param.UploadBaseURL != nil && *param.UploadBaseURL != endpoint.UploadBaseURL { |
| 118 | updates["upload_base_url"] = *param.UploadBaseURL |
| 119 | } |
| 120 | |
| 121 | if param.CACertBundle != nil && string(param.CACertBundle) != string(endpoint.CACertBundle) { |
| 122 | updates["ca_cert_bundle"] = param.CACertBundle |
| 123 | } |
| 124 | |
| 125 | if param.Description != nil && *param.Description != endpoint.Description { |
| 126 | updates["description"] = *param.Description |
| 127 | } |
| 128 | |
| 129 | if credsCount > 0 { |
| 130 | if _, hasAPIBaseURL := updates["api_base_url"]; hasAPIBaseURL { |
| 131 | return fmt.Errorf("cannot update endpoint URLs with existing credentials: %w", runnerErrors.ErrBadRequest) |
| 132 | } |
| 133 | if _, hasBaseURL := updates["base_url"]; hasBaseURL { |
| 134 | return fmt.Errorf("cannot update endpoint URLs with existing credentials: %w", runnerErrors.ErrBadRequest) |
| 135 | } |
| 136 | if _, hasUploadBaseURL := updates["upload_base_url"]; hasUploadBaseURL { |
| 137 | return fmt.Errorf("cannot update endpoint URLs with existing credentials: %w", runnerErrors.ErrBadRequest) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if len(updates) > 0 { |
nothing calls this directly
no test coverage detected