Skip to content

Fixes #28766 - add version macro#7361

Merged
lzap merged 1 commit intotheforeman:developfrom
ares:fix/28766
Mar 18, 2020
Merged

Fixes #28766 - add version macro#7361
lzap merged 1 commit intotheforeman:developfrom
ares:fix/28766

Conversation

@ares
Copy link
Member

@ares ares commented Jan 15, 2020

No description provided.

@theforeman-bot
Copy link
Member

Issues: #28766

end

def version(version)
Gem::Version.new(version.to_s)
Copy link
Member Author

Choose a reason for hiding this comment

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

potentially we can rescue from ArgumentError which is raised on malformed string and return Gem::Version.new(0) (nil is discouraged), though that can be misleading in comparisons, e.g. it will always be smaller than any other version

perhaps raising some better rendering error would be best, thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

How difficult would using a proxy object (That we control) be?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not something I'd do in next month :-) do you have some more complicated use of it in mind? Or you don't want to rely on Gem not chaning it's API?

Copy link
Member

Choose a reason for hiding this comment

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

The latter. I fear we‘re introducing technical depth here.

Copy link
Member

Choose a reason for hiding this comment

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

You could do what Puppet has done: a versioncmp function that is basically Gem::Version.new(first) <=> Gem::Version.new(second). That API might be easier to guarantee in the future.

For reference, I know that RPM and Debian version comparisons are slightly more complex and different than semver. Probably good to at least state what it's based on.

Copy link
Member

Choose a reason for hiding this comment

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

What Ewoud says comes to my mind too, the most clean way. Hides the implementation completely.

@ares
Copy link
Member Author

ares commented Jan 16, 2020

I don't think failures are related

@ares
Copy link
Member Author

ares commented Jan 16, 2020

well given it's EOD anyway, let's rerrun to be sure :-) [test foreman] [test katello]
foreman failing tests were on 2.6 postgres only, 6 tests related to audits (nil.changed_attributes)

katello didn't see http_proxies table

@ares
Copy link
Member Author

ares commented Jan 17, 2020

katello still fails the same, but that's unrelated, all the rest is green

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Other than that, I am good. Consider a different name since we might want to use version to return foreman version, probably version_compare or something like that. But I don't insist.

@@ -0,0 +1,3 @@
class Gem::Version::Jail < Safemode::Jail
allow :<, :>, :<=, :>=, :==, :eql?, :prerelease?, :release, :version, :to_s, :bump, :canonical_segments
end
Copy link
Member

Choose a reason for hiding this comment

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

This can go now.

@ares
Copy link
Member Author

ares commented Mar 11, 2020

I updated based on suggestions, only one new macro for version comparison is added and it's name reflects better what it does.

We lost few useful macros this way (:prerelease?, :release, :version,, :bump, :canonical_segments) however I hope this can now get in.

@lzap, community template report needs to be updated afterwards, it relied on version macro. The comparison logic is now included in this new gem_version_compare(first, second) macro

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

How does it deal with nil? Currently I'd say that's undefined (no tests) and perhaps not that relevant, but perhaps you want to make a statement about that.

:number_with_precision,
:number_to_human_size
:number_to_human_size,
:gem_version_compare
Copy link
Member

Choose a reason for hiding this comment

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

I thought we had trailing comma's but looks like we don't here. @mmoll is that a missing rubocop rule?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that should be Style/TrailingCommaInArrayLiteral... I'd need to have a deeper look to find out, if that's a Rubocop bug.

Copy link
Member

@lzap lzap left a comment

Choose a reason for hiding this comment

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

Thank you

@lzap lzap merged commit d0335fb into theforeman:develop Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants