Skip to content

Commit e511bed

Browse files
committed
fix: truncate backstage names to 63 characters
Backstage has a limit on names to 63 characters. Truncate long names to fit this limit.
1 parent 6a65880 commit e511bed

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/backstage/backstage.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path/filepath"
1313
"sort"
14+
"strconv"
1415
"strings"
1516
"time"
1617

@@ -211,7 +212,8 @@ func (c *CatalogInfo) LoadVervetAPIs(root, versions string, pivotDate time.Time,
211212
if _, ok := apiUniqueNames[api.Metadata.Name]; ok {
212213
return fmt.Errorf(`
213214
there are multiple apis named %s, only one will be available on Backstage.
214-
To resolve this error change the Name attribute in one of the spec files`,
215+
To resolve this error change the Name attribute in one of the spec files.
216+
Note names may be truncated to fit the Backstage 63 character limit`,
215217
api.Metadata.Name,
216218
)
217219
}
@@ -271,7 +273,10 @@ func (c *CatalogInfo) vervetAPI(doc *vervet.Document, root string, pivotDate tim
271273
return nil, err
272274
}
273275

274-
name := fmt.Sprintf("%s_%s_%s", toBackstageName(doc.Info.Title), toBackstageName(apiName), version.DateString())
276+
name_suffix := fmt.Sprintf("_%s_%s", toBackstageName(apiName), version.DateString())
277+
// Backstage names can only be a maximum of 63 characters
278+
name_len := 63 - len(name_suffix)
279+
name := fmt.Sprintf("%."+strconv.Itoa(name_len)+"s%s", toBackstageName(doc.Info.Title), name_suffix)
275280
title := doc.Info.Title + " " + version.DateString()
276281
labels := map[string]string{
277282
snykApiVersionDate: version.DateString(),

0 commit comments

Comments
 (0)