Module: BarkeepClient
- Defined in:
- 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
- VERSION =
"0.1.2"
- SHA_REGEX =
/[0-9a-fA-F]+/
- CONFIG_FILE =
File.join(ENV["HOME"], ".barkeeprc")
- REQUIRED_CONFIG_KEYS =
%w[barkeep_server]
Class Method Summary collapse
-
.commits(configuration, repo, shas) ⇒ Object
Core method for calling Barkeep’s commit API call.
- .get_configuration ⇒ Object
Class Method Details
.commits(configuration, repo, shas) ⇒ Object
Core method for calling Barkeep’s commit API call. TODO: Support querying lots of commits at once using the altered API call.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/barkeep/commit.rb', line 52 def self.commits(configuration, repo, shas) result = {} shas.each do |sha| uri = URI.parse(File.join(configuration["barkeep_server"], "/api/commits/#{repo}/#{sha}")) response = Net::HTTP.get_response uri if response.code.to_i != 200 error = JSON.parse(response.body)["message"] rescue nil raise error ? "Error: #{error}" : "Unspecified server error." end info = JSON.parse(response.body) 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_configuration ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 configuration end |