barkeep-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ barkeep-client (0.0.2)
5
+ dedent (~> 0.0.2)
6
+ trollop (~> 1.16.2)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ dedent (0.0.2)
12
+ trollop (1.16.2)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ barkeep-client!
@@ -1,13 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
2
3
 
3
4
  Gem::Specification.new do |s|
4
5
  s.name = "barkeep-client"
5
- s.version = "0.0.2"
6
+ s.version = "0.0.3"
6
7
  s.authors = ["Caleb Spare"]
7
8
  s.email = ["caleb@ooyala.com"]
8
- s.homepage = ""
9
- s.summary = %q{Who is the barkeep?}
10
- s.description = %q{Who is the barkeep?}
9
+ s.homepage = "https://github.com/ooyala/barkeep"
10
+ s.summary = %q{Barkeep command-line client}
11
+ s.description = %q{A command-line client for Barkeep's REST API.}
11
12
 
12
13
  s.rubyforge_project = "barkeep-client"
13
14
 
@@ -16,7 +17,6 @@ Gem::Specification.new do |s|
16
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
18
  s.require_paths = ["lib"]
18
19
 
19
- # specify any dependencies here; for example:
20
- # s.add_development_dependency "rspec"
21
- # s.add_runtime_dependency "rest-client"
20
+ s.add_dependency "trollop", "~> 1.16.2"
21
+ s.add_dependency "dedent", "~> 0.0.2"
22
22
  end
data/bin/barkeep CHANGED
@@ -1,12 +1,53 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- puts <<-'EOS'
4
- _ _ _ _ _ _ ___
5
- | | (_) | | | | | | | | |__ \
6
- __ _| |__ ___ _ ___ | |_| |__ ___ | |__ __ _ _ __| | _____ ___ _ __ ) |
7
- \ \ /\ / / '_ \ / _ \ | / __| | __| '_ \ / _ \ | '_ \ / _` | '__| |/ / _ \/ _ \ '_ \ / /
8
- \ V V /| | | | (_) | | \__ \ | |_| | | | __/ | |_) | (_| | | | < __/ __/ |_) |_|
9
- \_/\_/ |_| |_|\___/ |_|___/ \__|_| |_|\___| |_.__/ \__,_|_| |_|\_\___|\___| .__/(_)
10
- | |
11
- |_|
12
- EOS
3
+ require "rubygems"
4
+ require "dedent"
5
+ require "yaml"
6
+
7
+ require "barkeep/commit"
8
+ require "barkeep/unapproved"
9
+
10
+ CONFIG_FILE = File.join(ENV["HOME"], ".barkeeprc")
11
+
12
+ COMMANDS = {
13
+ "commit" => "Get information about a particular commit.",
14
+ "unapproved" => "Find unapproved commits from a list or commit range."
15
+ }
16
+
17
+ sub_command = ARGV.shift
18
+ unless COMMANDS.include? sub_command
19
+ puts sub_command ? "Error: unrecognized command '#{sub_command}'" : "Error: must provide command."
20
+ puts <<-EOS.dedent
21
+
22
+ Usage:
23
+ $ barkeep <command> [args]
24
+ where <command> is one of:
25
+ EOS
26
+ COMMANDS.each { |command, purpose| puts " #{command.rjust(COMMANDS.keys.map(&:size).max)} | #{purpose}" }
27
+ puts <<-EOS.dedent
28
+
29
+ Type 'barkeep <command> --help' for more information about a particular command."
30
+ EOS
31
+ exit 1
32
+ end
33
+
34
+ # Load in configuration from ~/.barkeeprc.
35
+ begin
36
+ configuration = YAML.load_file CONFIG_FILE
37
+ rescue
38
+ puts <<-EOS.dedent
39
+ Error: #{CONFIG_FILE} must exist to specify barkeep server information, and it must be a valid YAML file.
40
+ EOS
41
+ exit 1
42
+ end
43
+
44
+ # Check the configuration
45
+ REQUIRED_KEYS = %w[barkeep_server]
46
+ unless REQUIRED_KEYS.each { |key| configuration.include? key }
47
+ puts "Error: each of the following configuration keys are required in your #{CONFIG_FILE}:"
48
+ REQUIRED_KEYS.each { |key| puts " #{key}" }
49
+ exit 1
50
+ end
51
+
52
+ # Delegate to the trollop parsing + client logic that lives in the appropriate subcommand file.
53
+ BarkeepClient.send sub_command.to_sym, configuration
@@ -0,0 +1,47 @@
1
+ require "rubygems"
2
+ require "trollop"
3
+ require "dedent"
4
+ require "net/http"
5
+ require "json"
6
+
7
+ require "barkeep/constants"
8
+
9
+ module BarkeepClient
10
+ def self.commit(configuration)
11
+ options = Trollop::options do
12
+ banner <<-EOS.dedent
13
+ Barkeep's 'commit' command shows information about a particular commit.
14
+
15
+ Usage:
16
+ $ barkeep commit [options] <commit>
17
+ where <commit> is specified as a (partial) SHA-1 hash (for the current repo) or as, for example,
18
+ myrepo/d29a4a0fa
19
+ to specify a particular repository, and [options] can include:
20
+ EOS
21
+ end
22
+ Trollop::die "must provide a commit sha" unless ARGV.size == 1
23
+
24
+ commit = ARGV[0]
25
+ repo, sha = case commit
26
+ when %r{^[^/]+/#{SHA_REGEX}$} # foo/abc123
27
+ commit.split "/"
28
+ when /^#{SHA_REGEX}$/ # abc123
29
+ repo = File.basename(`git rev-parse --show-toplevel`).strip
30
+ if repo.empty?
31
+ Trollop::die "need to be in a git repo or specify a repository (e.g. myrepo/abc123)"
32
+ end
33
+ [repo, commit]
34
+ else
35
+ Trollop::die "#{commit} is an invalid commit specification"
36
+ end
37
+ uri = URI.parse(File.join(configuration["barkeep_server"], "/api/commits/#{repo}/#{sha}"))
38
+ result = Net::HTTP.get_response uri
39
+ if result.code.to_i != 200
40
+ error = JSON.parse(result.body)["message"] rescue nil
41
+ puts error ? "Error: #{error}" : "Unspecified server error."
42
+ exit 1
43
+ end
44
+ info = JSON.parse(result.body)
45
+ info.each { |key, value| puts " #{key.rjust(info.keys.map(&:size).max)}: #{value}" }
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module BarkeepClient
2
+ SHA_REGEX = /[0-9a-fA-F]+/
3
+ end
@@ -0,0 +1,81 @@
1
+ require "rubygems"
2
+ require "trollop"
3
+ require "dedent"
4
+ require "net/http"
5
+ require "json"
6
+
7
+ require "barkeep/constants"
8
+
9
+ module BarkeepClient
10
+ def self.unapproved(configuration)
11
+ options = Trollop::options do
12
+ banner <<-EOS.dedent
13
+ Barkeep's 'unapproved' command shows information about a particular commit. It MUST be run from a git
14
+ repository of the same name as the repository on the server.
15
+
16
+ Usage:
17
+ $ barkeep unapproved [options] <commit-range>
18
+ where <commit-range> is a single git SHA or a commit range specified using git's '..' syntax.
19
+ For example:
20
+
21
+ $ barkeep unapproved abc123
22
+ $ barkeep unapproved abc123..def456
23
+
24
+ [options] can include:
25
+ EOS
26
+ opt :stop_on_unapproved, "Stop and print a message on the first unapproved commit."
27
+ end
28
+ Trollop::die "must provide a commit range" unless ARGV.size == 1
29
+
30
+ repo = File.basename(`git rev-parse --show-toplevel`).strip
31
+ if repo.empty?
32
+ Trollop::die "need to be in a git repo"
33
+ end
34
+
35
+ commit_range = ARGV[0]
36
+ case commit_range
37
+ when /^#{SHA_REGEX}$/
38
+ commits_string = `git rev-parse #{commit_range}`
39
+ when /^#{SHA_REGEX}\.\.(#{SHA_REGEX})?$/, /^\.\.#{SHA_REGEX}$/
40
+ commits_string = `git log --format='%H' #{commit_range}`
41
+ else
42
+ Trollop::die "#{commit_range} is an invalid commit range specification"
43
+ end
44
+ exit(1) unless $?.to_i.zero?
45
+ commits = commits_string.split("\n").map(&:strip)
46
+
47
+ if commits.empty?
48
+ puts "No commits in range."
49
+ exit 0
50
+ end
51
+
52
+ unapproved_commits = {}
53
+ commits.each do |sha|
54
+ uri = URI.parse(File.join(configuration["barkeep_server"], "/api/commits/#{repo}/#{sha}"))
55
+ result = Net::HTTP.get_response uri
56
+ if result.code.to_i != 200
57
+ error = JSON.parse(result.body)["message"] rescue nil
58
+ puts error ? "Error: #{error}" : "Unspecified server error."
59
+ exit 1
60
+ end
61
+ info = JSON.parse(result.body)
62
+ next if info["approved"]
63
+ author_name = `git log --format='%an' #{sha} -n 1`
64
+ if options[:stop_on_unapproved]
65
+ puts "Found unapproved commit #{sha} by #{author_name}"
66
+ exit 1
67
+ end
68
+ unapproved_commits[sha] = author_name
69
+ end
70
+
71
+ if unapproved_commits.empty?
72
+ puts "#{commits.size} approved commit(s) and no unapproved commits in the given range."
73
+ else
74
+ puts "#{commits.size - unapproved_commits.size} approved commit(s) and " <<
75
+ "#{unapproved_commits.size} unapproved commit(s) in the given range."
76
+ puts "Unapproved:"
77
+ unapproved_commits.each { |sha, author| puts "#{sha} #{author}" }
78
+ exit 1
79
+ end
80
+ end
81
+ end
metadata CHANGED
@@ -1,53 +1,109 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: barkeep-client
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Caleb Spare
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2011-12-08 00:00:00.000000000Z
13
- dependencies: []
14
- description: Who is the barkeep?
15
- email:
17
+
18
+ date: 2011-12-08 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: trollop
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 83
30
+ segments:
31
+ - 1
32
+ - 16
33
+ - 2
34
+ version: 1.16.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: dedent
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 27
46
+ segments:
47
+ - 0
48
+ - 0
49
+ - 2
50
+ version: 0.0.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: A command-line client for Barkeep's REST API.
54
+ email:
16
55
  - caleb@ooyala.com
17
- executables:
56
+ executables:
18
57
  - barkeep
19
58
  extensions: []
59
+
20
60
  extra_rdoc_files: []
21
- files:
61
+
62
+ files:
22
63
  - .gitignore
23
64
  - .rbenv-version
24
65
  - Gemfile
66
+ - Gemfile.lock
25
67
  - README.md
26
68
  - Rakefile
27
69
  - barkeep_client.gemspec
28
70
  - bin/barkeep
29
- homepage: ''
71
+ - lib/barkeep/commit.rb
72
+ - lib/barkeep/constants.rb
73
+ - lib/barkeep/unapproved.rb
74
+ has_rdoc: true
75
+ homepage: https://github.com/ooyala/barkeep
30
76
  licenses: []
77
+
31
78
  post_install_message:
32
79
  rdoc_options: []
33
- require_paths:
80
+
81
+ require_paths:
34
82
  - lib
35
- required_ruby_version: !ruby/object:Gem::Requirement
83
+ required_ruby_version: !ruby/object:Gem::Requirement
36
84
  none: false
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
93
  none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
47
101
  requirements: []
102
+
48
103
  rubyforge_project: barkeep-client
49
- rubygems_version: 1.8.10
104
+ rubygems_version: 1.6.2
50
105
  signing_key:
51
106
  specification_version: 3
52
- summary: Who is the barkeep?
107
+ summary: Barkeep command-line client
53
108
  test_files: []
109
+