-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch, format and display changelog in the CLI update message (#1950)
* Fetch, format and display changelog in the CLI update message * Refactor changelog fetching and add unit tests
- Loading branch information
Showing
4 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
maestro-cli/src/main/java/maestro/cli/util/ChangeLogUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package maestro.cli.util | ||
|
||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
|
||
typealias ChangeLog = List<String>? | ||
|
||
object ChangeLogUtils { | ||
|
||
fun formatBody(content: String?, version: String): ChangeLog = content | ||
?.split("\n## ")?.map { it.lines() } | ||
?.first { it.first().startsWith(version) } | ||
?.drop(1) | ||
?.map { it.trim().replace("**", "") } | ||
?.map { it.replace("\\[(.*?)]\\(.*?\\)".toRegex(), "$1") } | ||
?.filter { it.isNotEmpty() && it.startsWith("- ") } | ||
|
||
fun fetchContent(): String? { | ||
val request = Request.Builder() | ||
.url("https://raw.githubusercontent.com/mobile-dev-inc/maestro/main/CHANGELOG.md") | ||
.build() | ||
return OkHttpClient().newCall(request).execute().body?.string() | ||
} | ||
|
||
fun print(changelog: ChangeLog): String = | ||
changelog?.let { "\n${it.joinToString("\n")}\n" }.orEmpty() | ||
} |
78 changes: 78 additions & 0 deletions
78
maestro-cli/src/test/kotlin/maestro/cli/util/ChangeLogUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package maestro.cli.util | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import java.io.File | ||
import org.junit.jupiter.api.Test | ||
|
||
class ChangeLogUtilsTest { | ||
|
||
private val changelogFile = File(System.getProperty("user.dir"), "../CHANGELOG.md") | ||
|
||
@Test | ||
fun `test format last version`() { | ||
val content = changelogFile.readText() | ||
|
||
val changelog = ChangeLogUtils.formatBody(content, "1.38.1") | ||
|
||
assertThat(changelog).containsExactly( | ||
"- New commands AI visual testing: assertWithAI and assertNoDefectsWithAI", | ||
"- Enable basic support for Maestro uploads while keeping maestro cloud functioning", | ||
) | ||
} | ||
|
||
@Test | ||
fun `test format link and no paragraph`() { | ||
val content = changelogFile.readText() | ||
|
||
val changelog = ChangeLogUtils.formatBody(content, "1.37.9") | ||
|
||
assertThat(changelog).containsExactly( | ||
"- Revert iOS landscape mode fix (#1916)", | ||
) | ||
} | ||
|
||
@Test | ||
fun `test format no subheader`() { | ||
val content = changelogFile.readText() | ||
|
||
val changelog = ChangeLogUtils.formatBody(content, "1.37.1") | ||
|
||
assertThat(changelog).containsExactly( | ||
"- Fix crash when `flutter` or `xcodebuild` is not installed (#1839)", | ||
) | ||
} | ||
|
||
@Test | ||
fun `test format strong no paragraph and no sublist`() { | ||
val content = changelogFile.readText() | ||
|
||
val changelog = ChangeLogUtils.formatBody(content, "1.37.0") | ||
|
||
assertThat(changelog).containsExactly( | ||
"- Sharding tests for parallel execution on many devices 🎉 (#1732 by Kaan)", | ||
"- Reports in HTML (#1750 by Depa Panjie Purnama)", | ||
"- Homebrew is back!", | ||
"- Current platform exposed in JavaScript (#1747 by Dan Caseley)", | ||
"- Control airplane mode (#1672 by NyCodeGHG)", | ||
"- New `killApp` command (#1727 by Alexandre Favre)", | ||
"- Fix cleaning up retries in iOS driver (#1669)", | ||
"- Fix some commands not respecting custom labels (#1762 by Dan Caseley)", | ||
"- Fix “Protocol family unavailable” when rerunning iOS tests (#1671 by Stanisław Chmiela)", | ||
) | ||
} | ||
|
||
@Test | ||
fun `test print`() { | ||
val content = changelogFile.readText() | ||
val changelog = ChangeLogUtils.formatBody(content, "1.17.1") | ||
|
||
val printed = ChangeLogUtils.print(changelog) | ||
|
||
assertThat(printed).isEqualTo( | ||
"\n" + | ||
"- Tweak: Remove Maestro Studio icon from Mac dock\n" + | ||
"- Tweak: Prefer port 9999 for Maestro Studio app\n" + | ||
"- Fix: Fix Maestro Studio conditional code snippet\n" | ||
) | ||
} | ||
} |