Class: MultiRepo::Helpers::PullRequestBlasterOuter

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_repo/helpers/pull_request_blaster_outer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, base:, head:, script:, dry_run:, message:, title: nil, body: nil, force: false) ⇒ PullRequestBlasterOuter

Returns a new instance of PullRequestBlasterOuter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 7

def initialize(repo, base:, head:, script:, dry_run:, message:, title: nil, body: nil, force: false, **)
  @repo    = repo
  @base    = base
  @head    = head
  @script  = begin
    s = Pathname.new(script).expand_path
    raise "File not found #{s}" unless s.exist?
    s.to_s
  end
  @dry_run = dry_run
  @force   = force

  @source_message = message&.gsub("\\n", "\n")
  @source_title   = title
  @source_body    = body&.gsub("\\n", "\n")
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def base
  @base
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def dry_run
  @dry_run
end

#forceObject (readonly)

Returns the value of attribute force.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def force
  @force
end

#headObject (readonly)

Returns the value of attribute head.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def head
  @head
end

#repoObject (readonly)

Returns the value of attribute repo.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def repo
  @repo
end

#scriptObject (readonly)

Returns the value of attribute script.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def script
  @script
end

#source_bodyObject (readonly)

Returns the value of attribute source_body.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def source_body
  @source_body
end

#source_messageObject (readonly)

Returns the value of attribute source_message.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def source_message
  @source_message
end

#source_titleObject (readonly)

Returns the value of attribute source_title.



5
6
7
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 5

def source_title
  @source_title
end

Instance Method Details

#blastObject



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
66
67
68
69
70
71
72
73
74
75
# File 'lib/multi_repo/helpers/pull_request_blaster_outer.rb', line 24

def blast
  repo.git.fetch

  unless repo.git.remote_branch?("origin", base)
    puts "!! Skipping #{repo.name}: 'origin/#{base}' not found".light_yellow
    return
  end

  repo.git.hard_checkout(head, "origin/#{base}")
  run_script

  result = false
  if !changes_found?
    puts
    puts "!! Skipping #{repo.name}: No changes found".light_yellow
    result = "no changes".light_yellow
  else
    commit_changes
    show_commit
    puts

    if dry_run
      puts "** dry-run: Skipping opening pull request. The pull request would look like:".light_black
      puts
      puts "Pull Request Title:".light_black
      puts title.light_black
      puts
      puts "Pull Request Body:".light_black
      puts body.light_black

      result = "dry run".light_black
    else
      answer =
        if force
          "Y"
        else
          print "Do you want to open a pull request on #{repo.name} with the above changes? (y/N): "
          $stdin.gets.chomp
        end

      if answer.upcase.start_with?("Y")
        fork_repo unless forked?
        push_branch
        result = open_pull_request
      else
        puts "!! Skipping #{repo.name}: User ignored".light_yellow
        result = "ignored".light_yellow
      end
    end
  end
  result
end