Module: BarkeepClient::Commands
- Defined in:
- lib/barkeep/view.rb,
lib/barkeep/commit.rb,
lib/barkeep/unapproved.rb
Class Method Summary collapse
- .commit(configuration) ⇒ Object
- .parse_commit(commit_specification) ⇒ Object
- .unapproved(configuration) ⇒ Object
- .view(configuration) ⇒ Object
Class Method Details
.commit(configuration) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/barkeep/commit.rb', line 11 def self.commit(configuration) = Trollop. do " Barkeep's 'commit' command shows information about a particular commit given its SHA.\n\n Usage:\n $ barkeep commit [options] <commit>\n where <commit> is specified as a (partial) SHA-1 hash (for the current repo) or as, for example,\n myrepo/d29a4a0fa\n to specify a particular repository, and [options] can include:\n EOS\n end\n Trollop.die \"must provide a commit sha\" unless ARGV.size == 1\n\n begin\n repo, sha = Commands.parse_commit(ARGV[0])\n rescue RuntimeError => e\n Trollop.die e.message\n end\n\n begin\n result = BarkeepClient.commits(configuration, repo, [sha]).values[0]\n rescue RuntimeError => e\n puts e.message\n exit 1\n end\n\n result.each { |key, value| puts \" \#{key.rjust(result.keys.map(&:size).max)}: \#{value}\" }\nend\n".dedent |
.parse_commit(commit_specification) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/barkeep/commit.rb', line 41 def self.parse_commit(commit_specification) case commit_specification when %r{^[^/]+/#{SHA_REGEX}$} # foo/abc123 commit_specification.split "/" when /^#{SHA_REGEX}$/ # abc123 repo = File.basename(`git rev-parse --show-toplevel`).strip if repo.empty? raise "need to be in a git repo or specify a repository (e.g. myrepo/abc123)" end [repo, commit_specification] else raise "#{commit_specification} is an invalid commit specification" end end |
.unapproved(configuration) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/barkeep/unapproved.rb', line 10 def self.unapproved(configuration) = Trollop. do " Barkeep's 'unapproved' command shows information about a particular commit. It MUST be run from a git\n repository of the same name as the repository on the server.\n\n Usage:\n $ barkeep unapproved [options] <commit-range>\n where <commit-range> is a commit range specified using git's range syntax (see `man gitrevisions`).\n For example:\n\n $ barkeep unapproved abc123\n $ barkeep unapproved ^abc123 def456\n $ barkeep unapproved abc123..def456\n\n [options] can include:\n EOS\n end\n Trollop.die \"must provide a commit range\" if ARGV.empty?\n\n repo = File.basename(`git rev-parse --show-toplevel`).strip\n if repo.empty?\n Trollop.die \"need to be in a git repo\"\n end\n\n commit_range = ARGV.map { |arg| \"'\#{arg}'\" }.join(\" \")\n commits_string = `git log --format='%H' \#{commit_range}`\n exit(1) unless $?.to_i.zero?\n commits = commits_string.split(\"\\n\").map(&:strip)\n\n if commits.empty?\n puts \"No commits in range.\"\n exit 0\n elsif commits.size > 1000\n puts \"Warning: \#{commits.size} commits in range. Lookup could be very slow. Proceed? [yN]\"\n unless STDIN.gets.downcase.strip =~ /^y(es)?/\n puts \"Aborting.\"\n exit 0\n end\n end\n\n begin\n commit_data = BarkeepClient.commits(configuration, repo, commits, [\"approved\"])\n rescue RuntimeError => e\n puts e.message\n exit 1\n end\n\n unapproved_commits = {}\n\n commit_data.each do |sha, commit|\n next if commit[\"approved\"]\n author_name = `git log --format='%an' \#{sha} -n 1`\n unapproved_commits[sha] = author_name\n end\n\n if unapproved_commits.empty?\n puts \"\#{commits.size} approved commit(s) and no unapproved commits in the given range.\"\n else\n puts \"\#{commits.size - unapproved_commits.size} approved commit(s) and \" <<\n \"\#{unapproved_commits.size} unapproved commit(s) in the given range.\"\n puts \"Unapproved:\"\n unapproved_commits.each { |sha, author| puts \"\#{sha} \#{author}\" }\n exit 1\n end\nend\n".dedent |
.view(configuration) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/barkeep/view.rb', line 8 def self.view(configuration) = Trollop. do " Barkeep's 'view' command opens the Barkeep commit page for a commit.\n\n Usage:\n $ barkeep view [options] <commit>\n where <commit> is specified as a (partial) SHA-1 hash (for the current repo) or as, for example,\n myrepo/d29a4a0fa\n to specify a particular repository, and [options] can include:\n EOS\n end\n Trollop.die \"must provide a commit sha\" unless ARGV.size == 1\n\n begin\n repo, sha = Commands.parse_commit(ARGV[0])\n rescue RuntimeError => e\n Trollop.die e.message\n end\n\n begin\n result = BarkeepClient.commits(configuration, repo, [sha]).values[0]\n rescue RuntimeError => e\n puts e.message\n exit 1\n end\n\n # Try xdg-open (linux) open (mac os). Otherwise throw an error.\n open_command = [\"xdg-open\", \"open\"].reject { |c| `which \#{c}`.empty? }.first\n unless open_command\n puts \"No application available to open a url (tried 'xdg-open' and 'open').\"\n exit 1\n end\n\n puts `\#{open_command} \#{result[\"link\"]}`\nend\n".dedent |