Skip to content

Commit

Permalink
retrieve activity messages when closing repository fails (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Sep 9, 2022
1 parent d28e119 commit 19a8631
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
22 changes: 20 additions & 2 deletions nexus/src/main/kotlin/com/vanniktech/maven/publish/nexus/Nexus.kt
Expand Up @@ -200,8 +200,26 @@ class Nexus(
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")
val properties = try {
val response = service.getRepositoryActivity(repositoryId).execute()
if (response.isSuccessful) {
response.body()?.find { it.name == "close" }
?.events?.find { it.name == "ruleFailed" }
?.properties?.filter { it.name == "failureMessage" }
} else {
emptyList()
}
} catch (_: IOException) {
emptyList()
}

if (properties.isNullOrEmpty()) {
val url = baseUrl.toHttpUrl().newBuilder("/#stagingRepositories").toString()
throw IOException("Closing the repository failed. ${repository.notifications} messages are available on $url")
} else {
val message = properties.joinToString("\n") { it.value }
throw IOException("Closing the repository failed with the following errors:\n$message")
}
}
}
}
Expand Down
Expand Up @@ -28,6 +28,15 @@ internal data class Repository(
val notifications: Int
)

@JsonClass(generateAdapter = true)
internal data class RepositoryEventProperty(val name: String, val value: String)

@JsonClass(generateAdapter = true)
internal data class RepositoryEvent(val name: String, val properties: List<RepositoryEventProperty>)

@JsonClass(generateAdapter = true)
internal data class RepositoryActivity(val name: String, val events: List<RepositoryEvent>)

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

Expand Down
Expand Up @@ -27,6 +27,9 @@ internal interface NexusService {
@GET("staging/repository/{repositoryId}")
fun getRepository(@Path("repositoryId") repositoryId: String): Call<Repository>

@GET("staging/repository/{repositoryId}/activity")
fun getRepositoryActivity(@Path("repositoryId") repositoryId: String): Call<List<RepositoryActivity>>

@POST("staging/bulk/close")
fun closeRepository(@Body input: TransitionRepositoryInput): Call<Unit>

Expand Down

0 comments on commit 19a8631

Please sign in to comment.