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

retrieve activity messages when closing repository fails #409

Merged
merged 1 commit into from Sep 9, 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
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