@@ -11,6 +11,8 @@ import kotlinx.coroutines.Dispatchers
1111import kotlinx.coroutines.async
1212import kotlinx.coroutines.awaitAll
1313import kotlinx.coroutines.runBlocking
14+ import okhttp3.OkHttpClient
15+ import okhttp3.Request
1416import org.openrewrite.config.CategoryDescriptor
1517import org.openrewrite.config.DeclarativeRecipe
1618import org.openrewrite.config.Environment
@@ -681,6 +683,59 @@ class RecipeMarkdownGenerator : Runnable {
681683 return changedRecipes
682684 }
683685
686+ private fun getLatestStableVersion (): String? {
687+ val client = OkHttpClient ()
688+ val request = Request .Builder ()
689+ .url(" https://api.github.com/repos/moderneinc/moderne-cli-releases/releases/latest" )
690+ .build()
691+
692+ return try {
693+ client.newCall(request).execute().use { response ->
694+ if (response.isSuccessful) {
695+ val responseBody = response.body?.string() ? : return null
696+ val mapper = ObjectMapper ()
697+ val json = mapper.readTree(responseBody)
698+ json.get(" tag_name" )?.asText()
699+ } else {
700+ System .err.println (" Failed to get latest version from GitHub: ${response.code} " )
701+ null
702+ }
703+ }
704+ } catch (e: Exception ) {
705+ System .err.println (" Failed to get latest version from GitHub: ${e.message} " )
706+ null
707+ }
708+ }
709+
710+ private fun getLatestStagingVersion (): String? {
711+ val client = OkHttpClient ()
712+ val request = Request .Builder ()
713+ .url(" https://api.github.com/repos/moderneinc/moderne-cli-releases/releases" )
714+ .build()
715+
716+ return try {
717+ client.newCall(request).execute().use { response ->
718+ if (response.isSuccessful) {
719+ val responseBody = response.body?.string() ? : return null
720+ val mapper = ObjectMapper ()
721+ val releases = mapper.readTree(responseBody)
722+ // These are in order from newest to oldest
723+ if (releases.isArray && releases.size() > 0 ) {
724+ releases[0 ].get(" tag_name" )?.asText()
725+ } else {
726+ null
727+ }
728+ } else {
729+ System .err.println (" Failed to fetch latest staging version: ${response.code} " )
730+ null
731+ }
732+ }
733+ } catch (e: Exception ) {
734+ System .err.println (" Failed to fetch latest staging version: ${e.message} " )
735+ null
736+ }
737+ }
738+
684739 private fun buildChangelog (
685740 newArtifacts : TreeSet <String >,
686741 removedArtifacts : TreeSet <String >,
@@ -693,6 +748,10 @@ class RecipeMarkdownGenerator : Runnable {
693748 // Get the date to label the changelog
694749 val formatted = getDateFormattedYYYYMMDD()
695750
751+ // Get the latest staging and stable versions of the CLI
752+ val stagingVersion = getLatestStagingVersion()
753+ val stableVersion = getLatestStableVersion()
754+
696755 val changelog: File = if (deployType == " release" ) {
697756 File (" src/main/resources/${rewriteBomVersion.replace(' .' , ' -' )} -Release.md" )
698757 } else {
@@ -724,6 +783,16 @@ class RecipeMarkdownGenerator : Runnable {
724783 changelog.appendText(" \n\n :::info" )
725784 changelog.appendText(" \n This changelog only shows what recipes have been added, removed, or changed. OpenRewrite may do releases that do not include these types of changes. To see these changes, please go to the [releases page](https://github.com/openrewrite/rewrite/releases)." )
726785 changelog.appendText(" \n :::\n\n " )
786+
787+ changelog.appendText(" ## Corresponding CLI version\n\n " )
788+
789+ if (stableVersion != null ) {
790+ changelog.appendText(" * Stable CLI version `${stableVersion} `\n " )
791+ }
792+
793+ if (stagingVersion != null ) {
794+ changelog.appendText(" * Staging CLI version: `${stagingVersion} `\n\n " )
795+ }
727796 }
728797
729798 // An example of what the changelog could look like after the below statements can be found here:
0 commit comments