Class: Ninny::Commands::PullRequestMerge
- Inherits:
-
Ninny::Command
- Object
- Ninny::Command
- Ninny::Commands::PullRequestMerge
- Defined in:
- lib/ninny/commands/pull_request_merge.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#branch_type ⇒ Object
readonly
Returns the value of attribute branch_type.
-
#options ⇒ Object
Returns the value of attribute options.
-
#pull_request ⇒ Object
Public: Find the pull request.
-
#pull_request_id ⇒ Object
Returns the value of attribute pull_request_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#branch_to_merge_into ⇒ Object
Public: Find the branch.
-
#check_out_branch ⇒ Object
Public: Check out the branch.
-
#comment_about_merge ⇒ Object
Public: Comment that the pull request was merged into the branch.
-
#comment_body ⇒ Object
Public: The content of the comment to post when merged.
- #determine_local_user ⇒ Object
- #execute ⇒ Object
-
#initialize(pull_request_id, options) ⇒ PullRequestMerge
constructor
A new instance of PullRequestMerge.
-
#merge_pull_request ⇒ Object
Public: Merge the pull request’s branch into the checked-out branch.
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, ) @branch_type = [:branch_type] || Ninny::Git::STAGING_PREFIX self.pull_request_id = pull_request_id self. = end |
Instance Attribute Details
#branch_type ⇒ Object (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 |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 8 def @options end |
#pull_request ⇒ Object
Public: Find the pull request
Returns a Ninny::Repository::PullRequest rubocop:disable Lint/DuplicateMethods
78 79 80 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 78 def pull_request @pull_request end |
#pull_request_id ⇒ Object
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 |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 9 def username @username end |
Instance Method Details
#branch_to_merge_into ⇒ Object
Public: Find the branch
Returns a String
86 87 88 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 86 def branch_to_merge_into @branch_to_merge_into ||= Ninny.git.latest_branch_for(branch_type) end |
#check_out_branch ⇒ Object
Public: Check out the branch
44 45 46 47 48 49 50 51 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 44 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 "Could not find a #{branch_type} branch. Please create one or double check it exists. If it " \ 'exists, please do a fresh git pull or git fetch to ensure Ninny can find it.' end |
#comment_about_merge ⇒ Object
Public: Comment that the pull request was merged into the branch
60 61 62 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 60 def comment_about_merge pull_request.write_comment(comment_body) end |
#comment_body ⇒ Object
Public: The content of the comment to post when merged
Returns a String
67 68 69 70 71 72 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 67 def comment_body user = username || determine_local_user body = "Merged into #{branch_to_merge_into}".dup body << " by #{user}" if user body << '.' end |
#determine_local_user ⇒ Object
90 91 92 93 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 90 def determine_local_user local_user_name = `git config user.name`.strip local_user_name.empty? ? nil : local_user_name end |
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 return nil if pull_request_id.nil? check_out_branch merge_pull_request comment_about_merge end |
#merge_pull_request ⇒ Object
Public: Merge the pull request’s branch into the checked-out branch
54 55 56 57 |
# File 'lib/ninny/commands/pull_request_merge.rb', line 54 def merge_pull_request prompt.say "Merging #{pull_request.branch} to #{branch_to_merge_into}." Ninny.git.merge(pull_request.branch) end |