Class: GithubWorkflow::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/github_workflow/cli.rb

Instance Method Summary collapse

Instance Method Details

#create_and_startObject



85
86
87
88
# File 'lib/github_workflow/cli.rb', line 85

def create_and_start
  ensure_github_config_present
  create_issue
end

#create_prObject



26
27
28
29
30
# File 'lib/github_workflow/cli.rb', line 26

def create_pr
  ensure_github_config_present
  ensure_origin_exists
  convert_issue_to_pr
end

#infoObject



67
68
69
70
71
# File 'lib/github_workflow/cli.rb', line 67

def info
  ensure_github_config_present
  response = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_number_from_branch}?access_token=#{oauth_token}").body)
  puts response["body"]
end

#openObject



75
76
77
78
79
# File 'lib/github_workflow/cli.rb', line 75

def open
  ensure_github_config_present
  response = JSON.parse(github_client.get("repos/#{user_and_repo}/issues/#{issue_number_from_branch}?access_token=#{oauth_token}").body)
  `/usr/bin/open -a "/Applications/Google Chrome.app" '#{response["html_url"]}'`
end

#push_and_prObject



34
35
36
37
38
# File 'lib/github_workflow/cli.rb', line 34

def push_and_pr
  ensure_github_config_present
  push_and_set_upstream
  convert_issue_to_pr
end

#startObject



17
18
19
20
21
22
# File 'lib/github_workflow/cli.rb', line 17

def start
  ensure_github_config_present
  checkout_master
  rebase_master
  create_branch
end

#statusObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/github_workflow/cli.rb', line 42

def status
  ensure_github_config_present
  ensure_origin_exists
  response = JSON.parse(github_client.get("repos/#{user_and_repo}/statuses/#{current_branch}?access_token=#{oauth_token}").body)

  if response.empty?
    alert "No statuses yet.  Have you pushed your branch?"
  else
    table = Terminal::Table.new(style: { width: 80 }) do |table_rows|
      table_rows << %w(CI Status Description)
      table_rows << :separator

      response.map { |status| status["context"] }.uniq.map do |status|
        response.select { |st| st["context"] == status }.sort_by { |st| st["updated_at"] }.last
      end.each do |status|
        table_rows << %w(context state description).map { |key| status[key] }
      end
    end

    puts table
  end
end