Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect when closing the repository failed #402

Merged
merged 2 commits into from Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt
Expand Up @@ -3,12 +3,13 @@ package com.vanniktech.maven.publish.nexus
import java.io.IOException
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory

class Nexus(
baseUrl: String,
private val baseUrl: String,
private val username: String,
password: String,
) {
Expand Down Expand Up @@ -177,15 +178,22 @@ class Nexus(

Thread.sleep(CLOSE_WAIT_INTERVAL_MILLIS)

try {
val repository = getStagingRepository(repositoryId)
if (repository.type == "closed" && !repository.transitioning) {
break
}
val repository = try {
getStagingRepository(repositoryId)
} catch (e: IOException) {
System.err.println("Exception trying to get repository status: ${e.message}")
null
} catch (e: TimeoutException) {
System.err.println("Exception trying to get repository status: ${e.message}")
null
}

if (repository?.type == "closed" && !repository.transitioning) {
break
}
if (repository?.type == "open" && !repository.transitioning && repository.notifications > 0) {
val url = baseUrl.toHttpUrl().newBuilder("/#stagingRepositories").toString()
throw IOException("Closing the repository failed. ${repository.notifications} messages are available on $url")
}
}
}
Expand Down
Expand Up @@ -21,7 +21,12 @@ internal data class CreatedRepository(val stagedRepositoryId: String)
internal data class CreateRepositoryResponse(val data: CreatedRepository)

@JsonClass(generateAdapter = true)
internal data class Repository(val repositoryId: String, val transitioning: Boolean, val type: String)
internal data class Repository(
val repositoryId: String,
val transitioning: Boolean,
val type: String,
val notifications: Int
)

@JsonClass(generateAdapter = true)
internal data class ProfileRepositoriesResponse(val data: List<Repository>)
Expand Down