diff --git a/app/src/main/kotlin/org/virtuslab/bazelsteward/app/PullRequestSuggester.kt b/app/src/main/kotlin/org/virtuslab/bazelsteward/app/PullRequestSuggester.kt index eba284e5..54bd3de9 100644 --- a/app/src/main/kotlin/org/virtuslab/bazelsteward/app/PullRequestSuggester.kt +++ b/app/src/main/kotlin/org/virtuslab/bazelsteward/app/PullRequestSuggester.kt @@ -34,7 +34,13 @@ class PullRequestSuggester(private val provider: PullRequestConfigProvider) { if (group != null) { listOf(suggestForGroup(group, updates)) } else { - updates.map { suggestForLibrary(it) } + updates.groupBy { it.suggestion.currentLibrary.id.name }.map { (group, updates) -> + if (updates.size == 1) { + suggestForLibrary(updates.single()) + } else { + suggestForGroupedLibrary(GroupId(group), updates) + } + } } } } @@ -55,9 +61,17 @@ class PullRequestSuggester(private val provider: PullRequestConfigProvider) { ) } + private fun suggestForGroupedLibrary(group: GroupId, updates: List): PullRequestSuggestion { + return suggest( + config = provider.resolveForLibrary(updates.first().suggestion.currentLibrary), + libraryId = group, + updates = updates, + ) + } + private fun suggest(config: PullRequestConfig, libraryId: LibraryId, updates: List): PullRequestSuggestion { fun resolveVersion(f: (UpdateSuggestion) -> Version): Version { - return updates.map { f(it.suggestion) }.distinct().singleOrNull() ?: SimpleVersion("mixed") + return updates.map { f(it.suggestion) }.distinctBy { it.value }.singleOrNull() ?: SimpleVersion("mixed") } val versionFrom = resolveVersion { it.currentLibrary.version } diff --git a/app/src/main/kotlin/org/virtuslab/bazelsteward/app/provider/PullRequestConfigProvider.kt b/app/src/main/kotlin/org/virtuslab/bazelsteward/app/provider/PullRequestConfigProvider.kt index 6212a96f..394b5463 100644 --- a/app/src/main/kotlin/org/virtuslab/bazelsteward/app/provider/PullRequestConfigProvider.kt +++ b/app/src/main/kotlin/org/virtuslab/bazelsteward/app/provider/PullRequestConfigProvider.kt @@ -10,18 +10,18 @@ class PullRequestConfigProvider( private val configs: List, dependencyKinds: List>, ) { - private val applier = DependencyFilterApplier(configs, dependencyKinds) + private val filter = DependencyFilterApplier(configs, dependencyKinds) fun resolveGroup(library: Library): GroupId? { - return applier.forLibrary(library).findNotNullOrDefault(null) { it.groupId } + return filter.forLibrary(library).findNotNullOrDefault(null) { it.groupId } } fun resolveForGroup(groupId: GroupId): PullRequestConfig { - return resolveFromFilter(applier.forPredicate { it.groupId == groupId }) + return resolveFromFilter(filter.forPredicate { it.groupId == groupId }) } fun resolveForLibrary(library: Library): PullRequestConfig { - return resolveFromFilter(applier.forLibrary(library)) + return resolveFromFilter(filter.forLibrary(library)) } private fun resolveFromFilter(filter: DependencyFilterApplier.Filtered): PullRequestConfig {