Skip to content

Commit ce74888

Browse files
authored
Limit changelog size by entry count instead of total size (#4167)
Previous attempt capped the changelog length by markdown, but the limit may be exceeded when rendered as HTML The HTML renderer doesn't make it easy to stop rendering once we hit a certain size, so limit by entry count instead
1 parent fca45a8 commit ce74888

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

buildSrc/src/main/kotlin/software/aws/toolkits/gradle/changelog/JetBrainsWriter.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import java.lang.Math.min
1313

1414
class JetBrainsWriter(private val changeNotesFile: File, repoUrl: String? = null) : ChangeLogWriter(repoUrl) {
1515
private val sb = StringBuilder()
16-
private var isMaxLength = false
16+
private var entryCount = 0
1717

1818
override fun append(entry: String) {
19-
if (isMaxLength) return
20-
19+
// if there are too many entries, we fail validation:
2120
// Invalid plugin descriptor 'plugin.xml'. The value of the '<change-notes>' parameter is too long. Its length is 65573 which is more than maximum 65535 characters long.
22-
if ((sb.length + entry.length) > 65000) {
23-
isMaxLength = true
21+
// HtmlRenderer is not that flexible, so do the simple thing instead of trying to backtrack and maximize the size of the bundled changelog
22+
if (entryCount > 10) return
23+
if (++entryCount > 10) {
2424
// language=Markdown
2525
repoUrl?.let {
2626
sb.append("""

buildSrc/src/test/kotlin/software/aws/toolkits/gradle/changelog/JetBrainsWriterTest.kt

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,31 +166,61 @@ class JetBrainsWriterTest {
166166
val file = folder.newFile()
167167
val sut = JetBrainsWriter(file, "https://github.com/org/repo")
168168

169-
sut.writeEntry(
170-
renderEntry(
171-
ReleaseEntry(
172-
LocalDate.of(2017, 2, 1),
173-
"2.0.0-preview-3",
174-
listOf(Entry(ChangeType.FEATURE, "Third feature"))
175-
)
176-
)
177-
)
178-
sut.writeEntry(
179-
renderEntry(
180-
ReleaseEntry(
181-
LocalDate.of(2017, 1, 3),
182-
"2.0.0-preview-2",
183-
generateSequence { Entry(ChangeType.BUGFIX, "Some bugfix") }.take(10000).toList()
169+
repeat(1000) {
170+
sut.writeEntry(
171+
renderEntry(
172+
ReleaseEntry(
173+
LocalDate.of(2017 + it, 2, 1),
174+
"2.0.0-preview-$it",
175+
listOf(Entry(ChangeType.FEATURE, "Feature $it"))
176+
)
184177
)
185178
)
186-
)
179+
}
180+
187181
sut.close()
188182

189183
assertThat(file.readText().trim()).isEqualToIgnoringWhitespace(
190184
"""
191-
<h3><em>2.0.0-preview-3</em> (2017-02-01)</h3>
185+
<h3><em>2.0.0-preview-0</em> (2017-02-01)</h3>
186+
<ul>
187+
<li><strong>(Feature)</strong> Feature 0</li>
188+
</ul>
189+
<h3><em>2.0.0-preview-1</em> (2018-02-01)</h3>
190+
<ul>
191+
<li><strong>(Feature)</strong> Feature 1</li>
192+
</ul>
193+
<h3><em>2.0.0-preview-2</em> (2019-02-01)</h3>
194+
<ul>
195+
<li><strong>(Feature)</strong> Feature 2</li>
196+
</ul>
197+
<h3><em>2.0.0-preview-3</em> (2020-02-01)</h3>
198+
<ul>
199+
<li><strong>(Feature)</strong> Feature 3</li>
200+
</ul>
201+
<h3><em>2.0.0-preview-4</em> (2021-02-01)</h3>
202+
<ul>
203+
<li><strong>(Feature)</strong> Feature 4</li>
204+
</ul>
205+
<h3><em>2.0.0-preview-5</em> (2022-02-01)</h3>
206+
<ul>
207+
<li><strong>(Feature)</strong> Feature 5</li>
208+
</ul>
209+
<h3><em>2.0.0-preview-6</em> (2023-02-01)</h3>
210+
<ul>
211+
<li><strong>(Feature)</strong> Feature 6</li>
212+
</ul>
213+
<h3><em>2.0.0-preview-7</em> (2024-02-01)</h3>
214+
<ul>
215+
<li><strong>(Feature)</strong> Feature 7</li>
216+
</ul>
217+
<h3><em>2.0.0-preview-8</em> (2025-02-01)</h3>
218+
<ul>
219+
<li><strong>(Feature)</strong> Feature 8</li>
220+
</ul>
221+
<h3><em>2.0.0-preview-9</em> (2026-02-01)</h3>
192222
<ul>
193-
<li><strong>(Feature)</strong> Third feature</li>
223+
<li><strong>(Feature)</strong> Feature 9</li>
194224
</ul>
195225
<hr />
196226
<p>Full plugin changelog available on <a href="https://github.com/org/repo/blob/main/CHANGELOG.md">GitHub</a></p>

0 commit comments

Comments
 (0)