Class: HubMerge::Executable

Inherits:
Object
  • Object
show all
Defined in:
lib/hubmerge.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Executable

Returns a new instance of Executable.



14
15
16
17
18
19
20
# File 'lib/hubmerge.rb', line 14

def initialize(opts = {})
  # Overrides only used in tests
  @spinner = opts[:spinner] || Spinner.new
  @prompts = opts[:prompts] || Prompts
  @github_client = opts[:github_client]
  @merger = opts[:merger] || Merger
end

Instance Method Details

#run(env, argv) ⇒ Object



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
# File 'lib/hubmerge.rb', line 22

def run(env, argv)
  check_or_prompt_github_token(env)
  opts = Options.parse(argv)

  if opts[:show_version]
    @prompts.say(HubMerge::VERSION)
    return 0
  end

  query = check_or_prompt_search_query(opts)
  prs = search_pull_requests(query)
  if prs.empty?
    @prompts.say("No pull requests found. Maybe try refining your search query?")
    return 1
  end

  prs_to_merge = if opts[:merge_without_confirmation]
    prs
  else
    @prompts.pull_requests_to_merge(prs)
  end

  if prs_to_merge.empty?
    @prompts.say("No pull requests selected, aborting")
    return 1
  else
    merge_pull_requests(prs_to_merge, opts)
    return 0
  end
end