Module: Rebaser

Defined in:
lib/rebaser.rb,
lib/rebaser/parser.rb,
lib/rebaser/rebaser.rb,
lib/rebaser/version.rb,
lib/rebaser/open_branch_fetcher.rb

Defined Under Namespace

Classes: OpenBranchFetcher, Parser, Rebaser

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.execute(options) ⇒ Object



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
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rebaser.rb', line 9

def self.execute(options)
  puts 'Rebaser'
  puts 'Wanna grow up to be'
  puts '♫  Be a rebaser  ♫'
  puts "\n"
  puts 'Fetching branches...'

  unless options[:username]
    options[:username] = Ask.input "Github username"
  end

  unless options[:password]
    puts "Github password:"
    options[:password] = STDIN.noecho(&:gets).chomp
  end

  unless options[:remote]
    options[:remote] = Ask.input "Where should I fetch branches from (in the form of `timminkov/rebaser`"
  end

  unless options[:token]
    if Ask.confirm "Need to enter a 2 factor authentication code?"
      options[:token] = Ask.input "2 factor code"
    end
  end

  unless options[:rebase_branch]
    options[:rebase_branch] = Ask.input "Please enter the branch to rebase onto", default: 'master'
  end

  branches = OpenBranchFetcher.new(
    username: options[:username],
    password: options[:password],
    token: options[:token],
    remote: options[:remote],
    rebase_branch: options[:rebase_branch],
  ).fetch

  puts "\n\nHere's what I'll be rebasing today:\n"
  puts branches
  puts "\nI'll rebase these branches onto #{options[:rebase_branch]}."
  puts "I'll only rebase if the pull request is opened against the target branch."
  puts "If I run into merge conflicts, I'll skip that branch."
  puts "This can be dangerous as I will be force pushing."
  continue = Ask.confirm "Are you sure you want to continue?", default: false

  return unless continue

  remote = Ask.input "Please enter the remote name to push to", default: 'origin'

  rebaser = Rebaser.new(branches, options[:rebase_branch], remote)
  rebaser.begin

  puts "\nAll done!"
  puts "#{rebaser.successful_rebases.size} branches successfully rebased and pushed."
  puts "#{rebaser.failed_rebases.size} branches failed to rebase."
end