barkeep-client 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/barkeep CHANGED
@@ -4,16 +4,17 @@ require "rubygems"
4
4
  require "dedent"
5
5
  require "yaml"
6
6
 
7
- require "barkeep/commit"
8
7
  require "barkeep/configuration"
9
- require "barkeep/unapproved"
10
8
  require "barkeep/version"
11
9
 
12
10
  COMMANDS = {
13
11
  "commit" => "Get information about a particular commit.",
14
- "unapproved" => "Find unapproved commits from a list or commit range."
12
+ "unapproved" => "Find unapproved commits from a list or commit range.",
13
+ "view" => "View a barkeep commit page in your browser."
15
14
  }
16
15
 
16
+ COMMANDS.keys.each { |command| require "barkeep/#{command}" }
17
+
17
18
  def usage(exit_status)
18
19
  puts <<-EOS.dedent
19
20
  Usage:
@@ -9,7 +9,7 @@ require "barkeep/constants"
9
9
  module BarkeepClient
10
10
  module Commands
11
11
  def self.commit(configuration)
12
- options = Trollop::options do
12
+ options = Trollop.options do
13
13
  banner <<-EOS.dedent
14
14
  Barkeep's 'commit' command shows information about a particular commit given its SHA.
15
15
 
@@ -20,21 +20,13 @@ module BarkeepClient
20
20
  to specify a particular repository, and [options] can include:
21
21
  EOS
22
22
  end
23
- Trollop::die "must provide a commit sha" unless ARGV.size == 1
23
+ Trollop.die "must provide a commit sha" unless ARGV.size == 1
24
24
 
25
- commit = ARGV[0]
26
- repo, sha = case commit
27
- when %r{^[^/]+/#{SHA_REGEX}$} # foo/abc123
28
- commit.split "/"
29
- when /^#{SHA_REGEX}$/ # abc123
30
- repo = File.basename(`git rev-parse --show-toplevel`).strip
31
- if repo.empty?
32
- Trollop::die "need to be in a git repo or specify a repository (e.g. myrepo/abc123)"
33
- end
34
- [repo, commit]
35
- else
36
- Trollop::die "#{commit} is an invalid commit specification"
37
- end
25
+ begin
26
+ repo, sha = Commands.parse_commit(ARGV[0])
27
+ rescue RuntimeError => e
28
+ Trollop.die e.message
29
+ end
38
30
 
39
31
  begin
40
32
  result = BarkeepClient.commits(configuration, repo, [sha])[sha]
@@ -45,6 +37,21 @@ module BarkeepClient
45
37
 
46
38
  result.each { |key, value| puts " #{key.rjust(result.keys.map(&:size).max)}: #{value}" }
47
39
  end
40
+
41
+ def self.parse_commit(commit_specification)
42
+ case commit_specification
43
+ when %r{^[^/]+/#{SHA_REGEX}$} # foo/abc123
44
+ commit_specification.split "/"
45
+ when /^#{SHA_REGEX}$/ # abc123
46
+ repo = File.basename(`git rev-parse --show-toplevel`).strip
47
+ if repo.empty?
48
+ raise "need to be in a git repo or specify a repository (e.g. myrepo/abc123)"
49
+ end
50
+ [repo, commit_specification]
51
+ else
52
+ raise "#{commit_specification} is an invalid commit specification"
53
+ end
54
+ end
48
55
  end
49
56
 
50
57
  # Core method for calling Barkeep's commit API call.
@@ -53,7 +60,11 @@ module BarkeepClient
53
60
  result = {}
54
61
  shas.each do |sha|
55
62
  uri = URI.parse(File.join(configuration["barkeep_server"], "/api/commits/#{repo}/#{sha}"))
56
- response = Net::HTTP.get_response uri
63
+ begin
64
+ response = Net::HTTP.get_response uri
65
+ rescue SocketError
66
+ raise "Cannot connect to the Barkeep server."
67
+ end
57
68
  if response.code.to_i != 200
58
69
  error = JSON.parse(response.body)["message"] rescue nil
59
70
  raise error ? "Error: #{error}" : "Unspecified server error."
@@ -9,7 +9,7 @@ require "barkeep/constants"
9
9
  module BarkeepClient
10
10
  module Commands
11
11
  def self.unapproved(configuration)
12
- options = Trollop::options do
12
+ options = Trollop.options do
13
13
  banner <<-EOS.dedent
14
14
  Barkeep's 'unapproved' command shows information about a particular commit. It MUST be run from a git
15
15
  repository of the same name as the repository on the server.
@@ -26,11 +26,11 @@ module BarkeepClient
26
26
  [options] can include:
27
27
  EOS
28
28
  end
29
- Trollop::die "must provide a commit range" if ARGV.empty?
29
+ Trollop.die "must provide a commit range" if ARGV.empty?
30
30
 
31
31
  repo = File.basename(`git rev-parse --show-toplevel`).strip
32
32
  if repo.empty?
33
- Trollop::die "need to be in a git repo"
33
+ Trollop.die "need to be in a git repo"
34
34
  end
35
35
 
36
36
  commit_range = ARGV.map { |arg| "'#{arg}'" }.join(" ")
@@ -1,3 +1,3 @@
1
1
  module BarkeepClient
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -0,0 +1,45 @@
1
+ require "trollop"
2
+ require "dedent"
3
+
4
+ require "barkeep/commit"
5
+
6
+ module BarkeepClient
7
+ module Commands
8
+ def self.view(configuration)
9
+ options = Trollop.options do
10
+ banner <<-EOS.dedent
11
+ Barkeep's 'view' command opens the Barkeep commit page for a commit.
12
+
13
+ Usage:
14
+ $ barkeep view [options] <commit>
15
+ where <commit> is specified as a (partial) SHA-1 hash (for the current repo) or as, for example,
16
+ myrepo/d29a4a0fa
17
+ to specify a particular repository, and [options] can include:
18
+ EOS
19
+ end
20
+ Trollop.die "must provide a commit sha" unless ARGV.size == 1
21
+
22
+ begin
23
+ repo, sha = Commands.parse_commit(ARGV[0])
24
+ rescue RuntimeError => e
25
+ Trollop.die e.message
26
+ end
27
+
28
+ begin
29
+ result = BarkeepClient.commits(configuration, repo, [sha])[sha]
30
+ rescue RuntimeError => e
31
+ puts e.message
32
+ exit 1
33
+ end
34
+
35
+ # Try xdg-open (linux) open (mac os). Otherwise throw an error.
36
+ open_command = ["xdg-open", "open"].reject { |c| `which #{c}`.empty? }.first
37
+ unless open_command
38
+ puts "No application available to open a url (tried 'xdg-open' and 'open')."
39
+ exit 1
40
+ end
41
+
42
+ puts `#{open_command} #{result["link"]}`
43
+ end
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barkeep-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-19 00:00:00.000000000Z
12
+ date: 2011-12-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
16
- requirement: &70356271100060 !ruby/object:Gem::Requirement
16
+ requirement: &70185491808140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.16.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70356271100060
24
+ version_requirements: *70185491808140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: dedent
27
- requirement: &70356271098120 !ruby/object:Gem::Requirement
27
+ requirement: &70185491806960 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.0.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70356271098120
35
+ version_requirements: *70185491806960
36
36
  description: A command-line client for Barkeep's REST API.
37
37
  email:
38
38
  - caleb@ooyala.com
@@ -55,6 +55,7 @@ files:
55
55
  - lib/barkeep/constants.rb
56
56
  - lib/barkeep/unapproved.rb
57
57
  - lib/barkeep/version.rb
58
+ - lib/barkeep/view.rb
58
59
  homepage: https://github.com/ooyala/barkeep
59
60
  licenses: []
60
61
  post_install_message: