@@ -126,7 +126,11 @@ func UpdateDependabotConfig(dependabotConfig string) (*UpdateDependabotConfigRes
126126 if updateDependabotConfigRequest .Content == "" {
127127 return response , nil
128128 }
129- newContent , changed , err := updateSubtractiveFields (response .FinalOutput , updateDependabotConfigRequest .Ecosystems )
129+ subtractiveIndent , err := getIndentation (string (inputConfigFile ))
130+ if err != nil {
131+ return nil , fmt .Errorf ("failed to get indentation: %v" , err )
132+ }
133+ newContent , changed , err := updateSubtractiveFields (response .FinalOutput , updateDependabotConfigRequest .Ecosystems , subtractiveIndent - 1 )
130134 if err != nil {
131135 return nil , fmt .Errorf ("failed to apply subtractive update: %v" , err )
132136 }
@@ -197,7 +201,7 @@ func UpdateDependabotConfig(dependabotConfig string) (*UpdateDependabotConfigRes
197201// updateSubtractiveFields finds each ecosystem entry in the existing YAML config by
198202// PackageEcosystem + Directory, then updates only the non-empty fields from the request,
199203// leaving every other field of that entry unchanged.
200- func updateSubtractiveFields (content string , ecosystems []Ecosystem ) (string , bool , error ) {
204+ func updateSubtractiveFields (content string , ecosystems []Ecosystem , indent int ) (string , bool , error ) {
201205 var cfg Config
202206 if err := yaml .Unmarshal ([]byte (content ), & cfg ); err != nil {
203207 return "" , false , fmt .Errorf ("failed to parse yaml: %w" , err )
@@ -317,7 +321,7 @@ func updateSubtractiveFields(content string, ecosystems []Ecosystem) (string, bo
317321
318322 var buf bytes.Buffer
319323 enc := yaml .NewEncoder (& buf )
320- enc .SetIndent (2 )
324+ enc .SetIndent (indent )
321325 if err := enc .Encode (& cfg ); err != nil {
322326 return "" , false , fmt .Errorf ("failed to marshal yaml: %w" , err )
323327 }
0 commit comments