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

throw an error during inspec check if the version is not correct #1832

Merged
merged 1 commit into from
May 18, 2017

Conversation

chris-rock
Copy link
Contributor

This ensures that inspec check fails if a non-semver version is used in inspec.yml

@chris-rock chris-rock added in progress Type: Enhancement Improves an existing feature and removed in progress labels May 18, 2017
@chris-rock chris-rock requested a review from adamleff May 18, 2017 12:23

# if version is set, ensure it is correct
if !params[:version].nil? && !valid_version?(params[:version])
errors.push("Version need to be in SemVer format in #{ref}")
Copy link
Contributor

Choose a reason for hiding this comment

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

needs here?

Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

Two quick/small changes and then I'm good. :)

if !params[:version].nil? && !valid_version?(params[:version])
errors.push("Version need to be in SemVer format in #{ref}")
end

%w{ title summary maintainer copyright }.each do |field|
next unless params[field.to_sym].nil?
warnings.push("Missing profile #{field} in #{ref}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the inspec check output will provide the filename that generated the warning:

✖  /Users/aleff/profiles/test1/inspec.yml:0:0: Version need to be in SemVer format in inspec.yml

... I propose can just change this to "Version needs to be in SemVer format" to avoid the duplicate "inspec.yml" output

def valid_version?(value)
Semverse::Version.new(value)
true
rescue Semverse::InvalidVersionFormat => _ex
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're not using the exception object, we can remove the => _ex from here.

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
@adamleff adamleff merged commit 6c53188 into master May 18, 2017
@adamleff adamleff deleted the chris-rock/version-error branch May 18, 2017 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants