Skip to content

Commit

Permalink
[ide starter] Move release filtering to ide starter. Fix for multiple…
Browse files Browse the repository at this point in the history
… same releases with different build number. Tests on release filtering.

GitOrigin-RevId: 2539a455285da2eb268b9bea23fddde7d6c7164a
  • Loading branch information
Nikita-Kudrin authored and intellij-monorepo-bot committed Oct 3, 2023
1 parent ffabd19 commit 6b34dd4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.intellij.ide.starter.junit5

import com.intellij.ide.starter.community.JetBrainsDataServiceClient
import com.intellij.ide.starter.ide.IdeProductProvider
import io.kotest.matchers.collections.shouldHaveSize
import org.junit.jupiter.api.Test
import kotlin.random.Random

class JetBrainsReleaseFilteringTest {
@Test
fun `getting N latest public releases`() {
val numberOfReleases = Random.nextInt(2, 10)
val latestReleases = JetBrainsDataServiceClient.getLatestPublicReleases(productType = IdeProductProvider.IU.productCode,
numberOfReleases = numberOfReleases)
latestReleases.shouldHaveSize(numberOfReleases)
latestReleases.map { it.build }.toSet().shouldHaveSize(numberOfReleases)
}

@Test
fun `filtering only major version of public releases`() {
val numberOfReleases = Random.nextInt(2, 10)
val latestReleases = JetBrainsDataServiceClient.getLatestPublicReleaseVersions(productType = IdeProductProvider.IU.productCode,
numberOfReleases = numberOfReleases)
latestReleases.shouldHaveSize(numberOfReleases)
latestReleases.toSet().shouldHaveSize(numberOfReleases)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,51 @@ import com.intellij.ide.starter.utils.logOutput
import org.apache.http.client.methods.HttpGet


class JetBrainsDataServiceClient {
companion object {
object JetBrainsDataServiceClient {
private const val DATA_SERVICE_URL = "https://data.services.jetbrains.com"

private const val DATA_SERVICE_URL = "https://data.services.jetbrains.com"
fun getReleases(request: ProductInfoRequestParameters): Map<String, List<ReleaseInfo>> {
val getUrlToJbDataServices = "$DATA_SERVICE_URL/products/releases${request.toUriQuery()}"
logOutput("Requesting products by url: $getUrlToJbDataServices")

fun getReleases(request: ProductInfoRequestParameters): Map<String, List<ReleaseInfo>> {
val getUrlToJbDataServices = "$DATA_SERVICE_URL/products/releases${request.toUriQuery()}"
logOutput("Requesting products by url: $getUrlToJbDataServices")
return HttpClient.sendRequest(
HttpGet(getUrlToJbDataServices).apply {
addHeader("Content-Type", "application/json")
addHeader("Accept", "application/json")
}) {
jacksonObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(JavaTimeModule())
.readValue(it.entity.content, object : TypeReference<Map<String, List<ReleaseInfo>>>() {})
}
}

return HttpClient.sendRequest(
HttpGet(getUrlToJbDataServices).apply {
addHeader("Content-Type", "application/json")
addHeader("Accept", "application/json")
}) {
jacksonObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(JavaTimeModule())
.readValue(it.entity.content, object : TypeReference<Map<String, List<ReleaseInfo>>>() {})
fun getLatestPublicReleases(productType: String,
numberOfReleases: Int = Int.MAX_VALUE,
maxReleaseBuild: String? = null): List<ReleaseInfo> {
return getReleases(ProductInfoRequestParameters(productType))
.values
.first()
.let {
if (maxReleaseBuild != null) it.filter { release -> release.build.substringBefore(".").toInt() <= maxReleaseBuild.toInt() } else it
}
}
.take(numberOfReleases)
}

/**
* @param productType What product releases do you need. UI/GO/AI etc.
* @param numberOfReleases How many latest releases do you need. 1/5/10 etc.
* @param maxReleaseBuild What is the newest release you need. 223/222/213 etc
*
* @return List of releases sorted from newest to oldest. 2023.1/2022.3 etc
* */
fun getLatestPublicReleaseVersions(productType: String,
numberOfReleases: Int = Int.MAX_VALUE,
maxReleaseBuild: String? = null): List<String> {
// because there might be multiple releases with the same major version we need to filter it as an additional step
return getLatestPublicReleases(productType, numberOfReleases = Int.MAX_VALUE, maxReleaseBuild)
.map { it.majorVersion }
.toSet()
.take(numberOfReleases)
}
}

0 comments on commit 6b34dd4

Please sign in to comment.