Module: BarkeepClient

Defined in:
lib/barkeep.rb,
lib/barkeep/view.rb,
lib/barkeep/commit.rb,
lib/barkeep/version.rb,
lib/barkeep/constants.rb,
lib/barkeep/unapproved.rb,
lib/barkeep/configuration.rb

Defined Under Namespace

Modules: Commands

Constant Summary collapse

COMMANDS =
{
  "commit" => "Get information about a particular commit.",
  "unapproved" => "Find unapproved commits from a list or commit range.",
  "view" => "View a barkeep commit page in your browser."
}
VERSION =
"0.1.7"
SHA_REGEX =
/[0-9a-fA-F]+/
CONFIG_FILE =
File.join(ENV["HOME"], ".barkeeprc")
REQUIRED_CONFIG_KEYS =
%w[barkeep_server]

Class Method Summary collapse

Class Method Details

.commits(configuration, repo, shas, fields = []) ⇒ Object

Core method for calling Barkeep’s commit API call.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/barkeep/commit.rb', line 58

def self.commits(configuration, repo, shas, fields = [])
  result = {}
  params = { :shas => shas.join(",") }
  params[:fields] = fields.join(",") unless fields.empty?
  begin
    response = RestClient.post "http://#{configuration["barkeep_server"]}/api/commits/#{repo}", params
  rescue SocketError
    raise "Cannot connect to the Barkeep server at http:#{configuration["barkeep_server"]}."
  end
  if response.code != 200
    error = JSON.parse(response.body)["message"] rescue nil
    raise error ? "Error: #{error}" : "Unspecified server error."
  end
  commits = JSON.parse(response.body)
  commits.each do |sha, info|
    commit_data = {}
    info.each do |key, value|
      next if value.nil?
      value = Time.at(value).strftime("%m/%d/%Y %I:%M%p") if key == "approved_at"
      commit_data[key] = value
    end
    result[sha] = commit_data
  end
  result
end

.get_configurationObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/barkeep/configuration.rb', line 9

def self.get_configuration
  begin
    configuration = YAML.load_file CONFIG_FILE
    raise "Bad file" if configuration == false # On empty yaml files or ones with only comments. Lame API
  rescue
    raise <<-EOS.dedent
      Error: #{CONFIG_FILE} must exist to specify barkeep server information,
      and it must be a valid YAML file.
    EOS
  end

  # Check the configuration
  unless REQUIRED_CONFIG_KEYS.all? { |key| configuration.include? key }
    error = "Error: the following configuration keys are required in your #{CONFIG_FILE}: " <<
            REQUIRED_CONFIG_KEYS.join(', ')
    raise error
  end

  # Tweak parameters for backwards compatibility:
  configuration["barkeep_server"].sub! %r{^http://}, ""

  configuration
end