Class: Rosette::Core::Validators::CommitValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/rosette/core/validators/commit_validator.rb

Overview

Validates the existence of a commit.

Examples:

v = CommitValidator.new
v.valid?('73cd130a42017d794ffa86ef0d255541d518a7b3', 'my_repo', config)# => true


v.valid?('non-existent-ref', 'my_repo', config)# => false


v.messages  # => ["Unable to find commit 'non-existent-ref'."]

Direct Known Subclasses

CommitsValidator

Instance Attribute Summary

Attributes inherited from Validator

#options

Instance Method Summary collapse

Methods inherited from Validator

#initialize, #messages

Constructor Details

This class inherits a constructor from Rosette::Core::Validators::Validator

Instance Method Details

#valid?(commit_str, repo_name, configuration) ⇒ Boolean

Returns true if the commit is valid, false otherwise. Also returns false if repo_name isn't a valid repo configured in configuration.

Parameters:

  • commit_str (String)

    The commit to validate.

  • repo_name (String)

    The repo to look for commit_str in.

  • configuration (Configurator)

    The Rosette configuration to use.

Returns:

  • (Boolean)

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rosette/core/validators/commit_validator.rb', line 26

def valid?(commit_str, repo_name, configuration)
  if repo_config = configuration.get_repo(repo_name)
    if commit_str
      commit = repo_config.repo.get_rev_commit(commit_str)
      validate_commit(commit)
    else
      messages << "Nil commit passed."
      false
    end
  else
    messages << "Unable to find repo #{repo_name}."
    false
  end
rescue Java::OrgEclipseJgitErrors::MissingObjectException, Java::JavaLang::IllegalArgumentException
  messages << "Unable to find commit '#{commit_str}'."
  false
end