Skip to content

Commit 1c88a47

Browse files
authored
Prevent exceeding 72 character limit (#1138)
* Prevent manifest from exceeding 72 character limit * Add test
1 parent 1a0c45f commit 1c88a47

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

internal/artifacts/manifest.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ func setManifestDesc(source dir.IModule, ep dir.ITargetArtifacts, targetPathGett
6969
return genManifest(ep.GetManifestPath(), entries)
7070
}
7171

72+
func wouldEntryExceedCharLimitAfterMerge(existing entry, newEntryName string) bool {
73+
lines := strings.Split(existing.EntryName, "\n")
74+
lastLine := lines[len(lines)-1]
75+
if len(lines) == 1 {
76+
lastLine = existing.EntryType + ": " + lastLine
77+
}
78+
newChars := ", " + newEntryName
79+
return len(lastLine)+len(newChars) > 72
80+
}
81+
7282
func mergeDuplicateEntries(entries []entry) []entry {
7383
// Several MTA-Module entries can point to the same path. In that case, their names should in the same entry, comma-separated.
7484
mergedEntries := make([]entry, 0)
@@ -83,15 +93,23 @@ func mergeDuplicateEntries(entries []entry) []entry {
8393
for index, entry := range entries {
8494
if entry.EntryType == moduleEntry {
8595
if existing, ok := modules[entry.EntryPath]; ok {
86-
existing.EntryName += ", " + entry.EntryName
96+
if wouldEntryExceedCharLimitAfterMerge(existing, entry.EntryName) {
97+
existing.EntryName += "\n , " + entry.EntryName
98+
} else {
99+
existing.EntryName += ", " + entry.EntryName
100+
}
87101
modules[entry.EntryPath] = existing
88102
} else {
89103
modules[entry.EntryPath] = entries[index]
90104
pathsOrder = append(pathsOrder, entry.EntryPath)
91105
}
92106
} else if entry.EntryType == requiredEntry {
93107
if existing, ok := required[entry.EntryPath]; ok {
94-
existing.EntryName += ", " + entry.EntryName
108+
if wouldEntryExceedCharLimitAfterMerge(existing, entry.EntryName) {
109+
existing.EntryName += "\n , " + entry.EntryName
110+
} else {
111+
existing.EntryName += ", " + entry.EntryName
112+
}
95113
required[entry.EntryPath] = existing
96114
} else {
97115
required[entry.EntryPath] = entries[index]

internal/artifacts/manifest_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,27 @@ bad config
410410
{EntryName: "e1", EntryPath: "a", EntryType: resourceEntry, ContentType: "t1"},
411411
},
412412
),
413+
Entry("merges module entries with the same path and does not exceed 72 character limit", []entry{
414+
{EntryName: "entry1", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
415+
{EntryName: "entry2", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
416+
{EntryName: "entry3", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
417+
{EntryName: "entry4", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
418+
{EntryName: "entry5", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
419+
{EntryName: "entry6", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
420+
{EntryName: "entry7", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
421+
{EntryName: "entry8", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
422+
{EntryName: "entry9", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
423+
{EntryName: "entry10", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
424+
{EntryName: "entry11", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
425+
{EntryName: "entry12", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
426+
{EntryName: "entry13", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
427+
{EntryName: "entry14", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
428+
{EntryName: "entry15", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
429+
{EntryName: "entry16", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
430+
}, []entry{
431+
{EntryName: "entry1, entry2, entry3, entry4, entry5, entry6, entry7\n , entry8, entry9, entry10, entry11, entry12, entry13, entry14, entry15\n , entry16", EntryPath: "a", EntryType: moduleEntry, ContentType: "t"},
432+
},
433+
),
413434
)
414435

415436
var _ = Describe("getContentType", func() {

0 commit comments

Comments
 (0)