Class: GithubFlowCli::PrCommands

Inherits:
Thor
  • Object
show all
Defined in:
lib/commands/pr.rb

Instance Method Summary collapse

Instance Method Details

#allObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/commands/pr.rb', line 8

def all
  # TODO: before filer
  unless Local.repo
    puts "not valid outside of a github repo."
    exit(4)
  end
  pull_requests = API.pull_requests(Local.repo)
  unless pull_requests.empty?
    puts pull_requests.map { |p| "#{Local.repo ? '' : i.repository.name}##{p.number} (#{p.assignee&.login || "NONE"}): #{p.title}" }
  end
end

#create(title = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/commands/pr.rb', line 21

def create(title = nil)
  # TODO: before filer
  unless Local.repo
    puts "not valid outside of a github repo."
    exit(4)
  end
  puts API.create_pr(title: title).html_url
rescue Octokit::UnprocessableEntity => ex
  case ex.message
  when /no commits between .*? and/i
    puts "No commits between base and head, stop creating PR..."
  when /already exists/
    puts "PR already exists."
    pr_number = Config.pr_branch_map.find {|_, v| v == Local.git.current_branch }.first
    puts API.pull_request(Local.repo, pr_number).html_url
  when /missing_field/
    puts "issue info lost, please provide the title"
  else
    raise
  end
end