Skip to content

Commit

Permalink
detect when closing the repository failed (#402)
Browse files Browse the repository at this point in the history
* detect when closing the repository failed

* import
  • Loading branch information
gabrielittner committed Sep 4, 2022
1 parent aeed9f3 commit 482502d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
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

0 comments on commit 482502d

Please sign in to comment.