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

Configurable lookup of version to bump #159

Merged
merged 6 commits into from
Mar 6, 2023
Merged

Configurable lookup of version to bump #159

merged 6 commits into from
Mar 6, 2023

Conversation

mikkoziel
Copy link
Contributor

Added search-pattern to config. Fixes #61

app/src/main/kotlin/org/virtuslab/bazelsteward/app/App.kt Outdated Show resolved Hide resolved
app/src/main/kotlin/org/virtuslab/bazelsteward/app/App.kt Outdated Show resolved Hide resolved
}

class FilteredByKind<T : DependencyFilter>(private val configs: List<T>, private val libraryId: LibraryId) {
fun find(predicate: (T) -> Boolean): T? {
fun forKind(kind: DependencyKind<*>): FilteredByKind<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to have forKind method, nor findAll

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

val filter = applier.forKind(kind)
val patternSearch = filter.findAllNotNull { kind }
return patternSearch
.flatMap { it.pathPatterns }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should concat anything here. It would not allow to override specific search path for a library if anything is defined for kind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


private fun resolveForKind(kind: DependencyKind<*>): List<PathPattern> {
val filter = applier.forKind(kind)
val patternSearch = filter.findAllNotNull { kind }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method takes a getter, it is supposed to look for a SearchPatternConfig that has some property that is not null. You are just passing here some not null value, i.e. filter.findAllNotNull { searchPatternConfig -> kind } which is equivalent to just taking all values, because kind is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

- regex:.*\/WORKSPACE[.\w]*
- "**/*.bzl"
- kinds:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such definition would never be picked up, because the preceding catches this kind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -28,7 +28,9 @@ data class App(
val gitHostClient: GitHostClient,
val appConfig: AppConfig,
val repoConfig: RepoConfig,
val updateRulesProvider: UpdateRulesProvider
val updateRulesProvider: UpdateRulesProvider,
val searchPatternProvider: SearchPatternProvider,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

fun find(predicate: (T) -> Boolean): T? {
class FilteredByKind<T : DependencyFilter>(
private val configs: List<T>,
private val libraryId: LibraryId?,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remved

val filteredConfigs = configs.filter { predicate(it) }
return filteredConfigs.firstOrNull { it.dependencies.any { f -> f.test(libraryId) } }
return libraryId?.let { filteredConfigs.firstOrNull { it.dependencies.any { f -> f.test(libraryId) } } }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original implementation seemed fine. libraryId is always defined and filtering by kind already happened in forLibrary method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


fun resolveForLibrary(library: Library): List<PathPattern> {
val filter = applier.forLibrary(library)
return filter.findNotNull { library }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this code makes no sense. This method accepts a function Config -> Any?. It will filter for any Configs that have some property as not null. If you pass a function like (config) -> ALWAYS_NOT_NULL VALUE, you just take the first element unconditionally, and this is what you do.

I gave you the exact code, why you took it and modified to be wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

fun resolveForLibrary(library: Library): List<PathPattern> {
val filter = applier.forLibrary(library)
return filter.findNotNull { library }
.let { it?.pathPatterns }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

such code can be replaced with ?.pathPatterns, no need for let. Also this line is not needed. You should find a value with notNull pathPatterns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

import org.virtuslab.bazelsteward.core.common.TextFile
import org.virtuslab.bazelsteward.core.library.Library

class UpdateSuggestionsMapper(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said, it can't be UpdateSuggestionsMapper, because it doesn't even import UpdateSuggestion now. It finds text files for library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed name

return RepoConfigParser().parse(javaClass.classLoader.getResource(resourceName)!!.readText())
}

fun loadTextFileFromResources(javaClass: Class<Any>, fileName: String): TextFile {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be better to use Class<*> everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,58 @@
package org.virtuslab.bazelsteward.common
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that your 2 new files with test utils should not live in the app source directory (src/main). They should be in (src/test). You can place them in subpackage like org.virtuslab.bazelsteward.testing and create a separate bazel target for it. It should be a library target with testonly = True and tests should depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable lookup of version to bump
2 participants