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

Regex #30

Merged
merged 8 commits into from
Jan 16, 2023
Merged

Regex #30

merged 8 commits into from
Jan 16, 2023

Conversation

mikkoziel
Copy link
Contributor

Changes in regex of Semantic Version, parsing from string and in comparing two prerelease versions. Added tests

@mikkoziel
Copy link
Contributor Author

Resolves #19

else 0

private fun comparePreReleases(preRelease: String, other: String): Int {
val qualifiers: Map<String, Int> = mapOf(
Pair("alpha", 1),
Copy link
Collaborator

Choose a reason for hiding this comment

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

fyi: you can use "alpha" to 1 syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replace

preRelease.startsWith('a') -> "alpha"
preRelease.startsWith('b') -> "beta"
preRelease.startsWith('m') -> "milestone"
else -> qualifiers.keys.firstOrNull { preRelease.contains(it) }
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it safe to look for it like that? I think that both map and its keys may be unordered so it might not be predictable what results will you get.

Also, shouldn't you first look for the qualifiers in map and then check first letters? (I don't know the specs and it will not change anything now, but if it matters and another qualifier with low priority would be added and it would start with a, b or m it could break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, as maps retain order of the value so results are predictable
And I need to check one thing about qualifiers and trimming of 0's as I noticed one bug in this logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bugs was fixed. Creating issue about trimming null values

else 0

private fun comparePreReleases(preRelease: String, other: String): Int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

preRelease and other are names suggesting that we are dealing with 2 completely different things, while we are dealing with two preRelease components. More common names like
a, b
preRelease1, preRelease2
this, that
first, second

would make it easier to follow

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

} else it
}

return compareQualifiers
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could inline this variable

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

else -> qualifiers[firstQualifier]!!.compareTo(qualifiers[otherQualifier]!!)
}.let {
if (it == 0) {
val preReleaseNoQualifier = getPreReleaseNoQualifier(firstQualifier!!, preRelease)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it safe to !!?

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 as it wasn't safe

}
}

private fun getPreReleaseNoQualifier(qualifier: String, preRelease: String): String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the logic of this function?

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 to better show logic of a function

values[3].toInt(),
values[4],
values[5]
values["majorRegex"]?.value?.toIntOrNull() ?: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to keep group names with suffix "regex" ? To keep it consistent users in the config will have to do it in the same way

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, I missed this part. Please remove the regex suffix.

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 suffix "Regex" from groups

@lukaszwawrzyk lukaszwawrzyk merged commit f7ad4ce into main Jan 16, 2023
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.

3 participants