Class: Ninny::Commands::PullRequestMerge

Inherits:
Ninny::Command show all
Defined in:
lib/ninny/commands/pull_request_merge.rb

Direct Known Subclasses

StageUp

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Ninny::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(pull_request_id, options) ⇒ PullRequestMerge

Returns a new instance of PullRequestMerge.



11
12
13
14
15
# File 'lib/ninny/commands/pull_request_merge.rb', line 11

def initialize(pull_request_id, options)
  @branch_type = options[:branch_type] || Ninny::Git::STAGING_PREFIX
  self.pull_request_id = pull_request_id
  self.options = options
end

Instance Attribute Details

#branch_typeObject (readonly)

Returns the value of attribute branch_type.



9
10
11
# File 'lib/ninny/commands/pull_request_merge.rb', line 9

def branch_type
  @branch_type
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/ninny/commands/pull_request_merge.rb', line 8

def options
  @options
end

#pull_requestObject

Public: Find the pull request

Returns a Ninny::Repository::PullRequest rubocop:disable Lint/DuplicateMethods



68
69
70
# File 'lib/ninny/commands/pull_request_merge.rb', line 68

def pull_request
  @pull_request
end

#pull_request_idObject

Returns the value of attribute pull_request_id.



8
9
10
# File 'lib/ninny/commands/pull_request_merge.rb', line 8

def pull_request_id
  @pull_request_id
end

Instance Method Details

#branch_to_merge_intoObject

Public: Find the branch

Returns a String



76
77
78
# File 'lib/ninny/commands/pull_request_merge.rb', line 76

def branch_to_merge_into
  @branch_to_merge_into ||= Ninny.git.latest_branch_for(branch_type)
end

#check_out_branchObject

Public: Check out the branch



37
38
39
40
41
42
43
44
# File 'lib/ninny/commands/pull_request_merge.rb', line 37

def check_out_branch
  prompt.say "Checking out #{branch_to_merge_into}."
  Ninny.git.check_out(branch_to_merge_into, false)
  Ninny.git.track_current_branch
rescue Ninny::Git::NoBranchOfType
  prompt.say "No #{branch_type} branch available. Creating one now."
  CreateDatedBranch.new(branch: branch_type).execute
end

#comment_about_mergeObject

Public: Comment that the pull request was merged into the branch



53
54
55
# File 'lib/ninny/commands/pull_request_merge.rb', line 53

def comment_about_merge
  pull_request.write_comment(comment_body)
end

#comment_bodyObject

Public: The content of the comment to post when merged

Returns a String



60
61
62
# File 'lib/ninny/commands/pull_request_merge.rb', line 60

def comment_body
  "Merged into #{branch_to_merge_into}."
end

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ninny/commands/pull_request_merge.rb', line 17

def execute(*)
  unless pull_request_id
    current = Ninny.repo.current_pull_request
    self.pull_request_id = current.number if current
  end

  self.pull_request_id ||= select_pull_request

  check_out_branch
  merge_pull_request
  comment_about_merge
end

#merge_pull_requestObject

Public: Merge the pull request’s branch into the checked-out branch



47
48
49
50
# File 'lib/ninny/commands/pull_request_merge.rb', line 47

def merge_pull_request
  prompt.say "Merging #{pull_request.branch} to #{branch_to_merge_into}."
  Ninny.git.merge(pull_request.branch)
end