Skip to content

Commit eeed572

Browse files
author
Tharanishwaran
committed
improve logic flow in updateComponentsSheet function
Signed-off-by: Tharanishwaran <[email protected]>
1 parent fcddaf0 commit eeed572

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

registry/spreadsheet_update.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,26 +202,30 @@ func updateModelsSheet(srv *sheets.Service, cred, sheetId string, values []*Mode
202202
}
203203

204204
func updateComponentsSheet(srv *sheets.Service, cred, sheetId string, values []*ComponentCSV, csvPath string) error {
205-
marshalledValues, err := marshalStructToCSValues[ComponentCSV](values)
205+
if len(values) == 0 {
206+
Log.Info("No components to append, skipping update")
207+
return nil
208+
}
209+
210+
marshalledValues, err := marshalStructToCSValues[ComponentCSV](values)
211+
if err != nil {
212+
return err
213+
}
214+
215+
err = appendSheet(srv, cred, sheetId, ComponentsSheetAppendRange, marshalledValues, csvPath)
206216
if err != nil {
207217
return err
208218
}
209219

210-
if len(values) > 0 {
211-
componentNames := make([]string, 0, len(values))
212-
modelName := values[0].Model
213-
for _, comp := range values {
214-
componentNames = append(componentNames, comp.Component)
215-
}
216-
Log.Infof("Appending %d components for model [%s]: %s",
217-
len(values), modelName, strings.Join(componentNames, ", "))
218-
} else {
219-
Log.Info("Appending", len(values), "in the components sheet")
220+
componentNames := make([]string, 0, len(values))
221+
modelName := values[0].Model
222+
for _, comp := range values {
223+
componentNames = append(componentNames, comp.Component)
220224
}
225+
Log.Infof("Successfully appended %d components for model [%s]: %s",
226+
len(values), modelName, strings.Join(componentNames, ", "))
221227

222-
err = appendSheet(srv, cred, sheetId, ComponentsSheetAppendRange, marshalledValues, csvPath)
223-
224-
return err
228+
return nil
225229
}
226230

227231
func appendSheet(srv *sheets.Service, cred, sheetId, appendRange string, values [][]interface{}, csvPaths ...string) error {

0 commit comments

Comments
 (0)