Class: Hull::Command
- Inherits:
-
Object
- Object
- Hull::Command
- Defined in:
- lib/hull/help.rb,
lib/hull/list.rb,
lib/hull/show.rb,
lib/hull/command.rb
Class Method Summary collapse
- .help ⇒ Object
- .list ⇒ Object
- .pull_info(pull) ⇒ Object
- .show(number) ⇒ Object
- .write_comment(comment) ⇒ Object
Class Method Details
.help ⇒ Object
3 4 5 6 7 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/hull/help.rb', line 3 def self.help <<HELP #{help_title('### Setup')} Config Github user name: $ git config github.username <github_username> Config GitHub API key (https://github.com/account/admin): $ git config github.token <api_token> #{help_title('### Usage')} This help doc: $ #{help_hull} #{help_command('help')} List all pull requests for this project: $ #{help_hull} #{help_command('list')} Show details about pull request number <number>: $ #{help_hull} #{help_command('show')} <#{help_number('number')}> #{help_title('### Unimplemented Features')} Check out the contents of pull request number <number> and switch to that branch: $ #{help_hull} <#{help_command('checkout')}|#{help_command('co')}|#{help_command('pull')}> <#{help_number('number')}> Remove contents of pull request <number> that has been checked out: $ #{help_hull} <#{help_command('rm')}|#{help_command('remove')}|#{help_command('delete')}> <#{help_number('number')}> #{help_title('### Why Hull?')} Originally it was called puller, but @natekross pushed a gem with the same name to rubygems.org, literally the day I started working on Hull. #{help_red("\x28\xe2\x95\xaf\xc2\xb0\xe2\x96\xa1\xc2\xb0\xef\xbc\x89\xe2\x95\xaf")}\xef\xb8\xb5\x20\xe2\x94\xbb\xe2\x94\x81\xe2\x94\xbb HELP end |
.list ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hull/list.rb', line 3 def self.list validate_config json = get_json(github_url) if json['error'].to_s != '' return error(json['error']) end pulls = json['pulls'] return if pulls.length == 0 branch_names = pulls.map { |pull| pull['head']['label'].split(/:/) } @repo_len = [ branch_names.map(&:first).map(&:length).max, 15 ].min @branch_len = [ branch_names.map(&:last).map(&:length).max, 30 ].min lines = [ "Number of pull requests: #{pulls.length}" ] pulls.each do |pull| lines << pull_info(pull) end lines.join("\n") end |
.pull_info(pull) ⇒ Object
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 |
# File 'lib/hull/list.rb', line 24 def self.pull_info(pull) number = pull['number'].to_s mergeable = pull['mergeable'] title = pull['title'] created_at = Time.parse(pull['issue_created_at']) repo_name, branch_name = pull['head']['label'].split(/:/) if repo_name == username color = :yellow else if mergeable is_old = repo.branches.map(&:name).any? { |branch| branch =~ /^. *cr\/#{number}/} color = is_old ? :purple : :white else color = :red end end number = pad_left(number, 6) title = pad_right(title, column_size - @repo_len - @branch_len - 10) repo_name = pad_left(repo_name, @repo_len) branch_name = pad_right(branch_name, @branch_len) [ write(number, color), [ write(repo_name, :yellow), branch_name.split(/\//).map do |branch| write(branch, :green) end.join('/'), ].join('/'), title, ].join(' ') end |
.show(number) ⇒ Object
3 4 5 6 7 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 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hull/show.rb', line 3 def self.show(number) validate_config url = github_url(number) begin body = get_json(url) rescue OpenURI::HTTPError return error("Pull request ##{number} might not exist. Try running 'hull list'.") end if body['error'].to_s != '' return error(body['error']) end pull = body["pull"] title = pull["title"] description = pull["body"] discussions = pull["discussion"] comments = discussions.select do |msg| msg["type"] =~ /Comment/ end.map do |msg| = {} [:user] = msg["user"]["login"] [:message] = msg["body"] [:path] = msg["path"] end if pull['merged_at'] merge_status = write('MERGED', :green) elsif pull['mergeable'] merge_status = write('NOT MERGED', :yellow) elsif pull["state"] == "closed" merge_status = write('CLOSED', :red) else merge_status = write('CONFLICT', :red) end lines = [] lines << "Number: #{write(number, :yellow)}" lines << "Title: #{write(title, :purple)}" lines << "Description: #{pad_right(description.gsub(/[\r\n]+/, ' '), column_size - 13)}" lines << "Status: #{merge_status}" if comments.length > 0 lines.push('', 'Comments:') comments.each do |comment| lines << write_comment(comment) end end lines.join("\n") end |
.write_comment(comment) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hull/show.rb', line 56 def self.write_comment(comment) arr = [] remaining_cols = column_size if comment[:path] path = comment[:path].split(/\//).last arr.push('@', write(path, :pink), ' ') remaining_cols -= path.length + 2 end arr.push('<', write(comment[:user], :yellow), '>') remaining_cols -= comment[:user].length + 4 remaining_cols = [ remaining_cols, 30 ].max = pad_right(comment[:message].gsub(/[\r\n]+/, ' '), remaining_cols) arr.push(': ', write(, :white)) arr.join('') end |