Skip to content

Commit 9f3e108

Browse files
committed
fix: Limit dev changelog parsing and display to recent entries
1 parent df23aa6 commit 9f3e108

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

app/src/main/java/app/morphe/manager/domain/bundles/RemotePatchBundle.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class JsonPatchBundle(
379379
val activeEndpoint = resolveBranchUrl(endpoint)
380380
val changelogUrl = api.changelogUrlFromBundleEndpoint(activeEndpoint) ?: return emptyList()
381381
return fetchAndCacheEntries("$uid|$changelogUrl", sinceVersion) {
382-
api.fetchChangelogFromUrl(changelogUrl)
382+
api.fetchChangelogFromUrl(changelogUrl, stopAfterFirstStable = usePrerelease)
383383
}
384384
}
385385

@@ -461,7 +461,9 @@ class APIPatchBundle(
461461

462462
override suspend fun fetchChangelogEntries(sinceVersion: String?): List<ChangelogEntry> {
463463
val branch = if (usePrerelease) BRANCH_DEV else BRANCH_STABLE
464-
return fetchAndCacheEntries("$uid|$branch", sinceVersion) { api.fetchPatchesChangelog(branch) }
464+
return fetchAndCacheEntries("$uid|$branch", sinceVersion) {
465+
api.fetchPatchesChangelog(branch, stopAfterFirstStable = usePrerelease)
466+
}
465467
}
466468

467469
override fun copy(

app/src/main/java/app/morphe/manager/network/api/MorpheAPI.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,17 +421,17 @@ class MorpheAPI(
421421
}
422422

423423
/** Fetches and parses CHANGELOG.md from the first-party patches repository. */
424-
suspend fun fetchPatchesChangelog(branch: String = "main"): List<ChangelogEntry> =
425-
fetchChangelogFromRepo(patchesConfig, branch)
424+
suspend fun fetchPatchesChangelog(branch: String = "main", stopAfterFirstStable: Boolean = false): List<ChangelogEntry> =
425+
fetchChangelogFromRepo(patchesConfig, branch, stopAfterFirstStable = stopAfterFirstStable)
426426

427427
/**
428428
* Fetches and parses CHANGELOG.md from an arbitrary raw URL.
429429
* Used for third-party bundles that follow the Morphe changelog format.
430430
*/
431-
suspend fun fetchChangelogFromUrl(changelogUrl: String): List<ChangelogEntry> {
431+
suspend fun fetchChangelogFromUrl(changelogUrl: String, stopAfterFirstStable: Boolean = false): List<ChangelogEntry> {
432432
Log.d(tag, "fetchChangelogFromUrl: $changelogUrl")
433433
return when (val r = client.request<String> { url(changelogUrl) }) {
434-
is APIResponse.Success -> ChangelogParser.parse(r.data)
434+
is APIResponse.Success -> ChangelogParser.parse(r.data, stopAfterFirstStable)
435435
is APIResponse.Error, is APIResponse.Failure -> {
436436
Log.w(tag, "Failed to fetch changelog from $changelogUrl")
437437
emptyList()
@@ -442,15 +442,16 @@ class MorpheAPI(
442442
private suspend fun fetchChangelogFromRepo(
443443
config: RepoConfig,
444444
branch: String,
445-
path: String = "CHANGELOG.md"
445+
path: String = "CHANGELOG.md",
446+
stopAfterFirstStable: Boolean = false
446447
): List<ChangelogEntry> {
447448
val url = config.rawFileUrl(branch, path)
448449
Log.d(tag, "fetchChangelog: $url")
449450
return when (val r = client.request<String> {
450451
url(url)
451452
header("Cache-Control", "no-cache")
452453
}) {
453-
is APIResponse.Success -> ChangelogParser.parse(r.data)
454+
is APIResponse.Success -> ChangelogParser.parse(r.data, stopAfterFirstStable)
454455
is APIResponse.Error, is APIResponse.Failure -> {
455456
Log.w(tag, "Failed to fetch $path for ${config.name}@$branch")
456457
emptyList()

app/src/main/java/app/morphe/manager/ui/screen/home/SourceManagementDialogs.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ fun BundleChangelogDialog(
11581158
val lastStable = allEntries.firstOrNull { !it.version.contains("-") }
11591159
if (lastStable != null)
11601160
ChangelogParser.entriesNewerThan(allEntries, lastStable.version) + lastStable
1161-
else allEntries
1161+
else allEntries.take(30)
11621162
} else {
11631163
// Stable: from the installed version onwards
11641164
val installed = src.installedVersionSignature

app/src/main/java/app/morphe/manager/util/ChangelogParser.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ object ChangelogParser {
6565
/**
6666
* Parse raw CHANGELOG.md text into a list of [ChangelogEntry], ordered
6767
* newest-first (same order as in the file).
68+
*
69+
* When [stopAfterFirstStable] is true the parser stops as soon as the first
70+
* stable release (no pre-release suffix) has been collected and the next
71+
* heading is encountered, skipping the rest of the file. Useful for dev-branch
72+
* changelogs that accumulate many old entries below the last stable baseline.
6873
*/
69-
fun parse(markdown: String): List<ChangelogEntry> {
74+
fun parse(markdown: String, stopAfterFirstStable: Boolean = false): List<ChangelogEntry> {
7075
val entries = mutableListOf<ChangelogEntry>()
7176
val lines = markdown.lines()
7277

@@ -89,6 +94,10 @@ object ChangelogParser {
8994
val match = VERSION_HEADING.find(line)
9095
if (match != null) {
9196
flush()
97+
if (stopAfterFirstStable && entries.lastOrNull()?.version?.contains("-") == false) {
98+
currentVersion = null
99+
break
100+
}
92101
currentVersion = match.groupValues[1].trim()
93102
currentDate = match.groupValues[2]
94103
currentContent.clear()

0 commit comments

Comments
 (0)