Class: Octopolo::PullRequestMerger
- Inherits:
-
Object
- Object
- Octopolo::PullRequestMerger
- Includes:
- CLIWrapper, ConfigWrapper, GitWrapper
- Defined in:
- lib/octopolo/pull_request_merger.rb
Instance Attribute Summary collapse
-
#branch_type ⇒ Object
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.
Attributes included from GitWrapper
Attributes included from CLIWrapper
Attributes included from ConfigWrapper
Class Method Summary collapse
-
.perform(branch_type, pull_request_id, options = {}) ⇒ Object
Public: Create a new branch of the given type for today’s date.
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.
-
#initialize(branch_type, pull_request_id, options = {}) ⇒ PullRequestMerger
constructor
Public: Initialize a new instance of DatedBranchCreator.
-
#merge_pull_request ⇒ Object
Public: Merge the pull request’s branch into the checked-out branch.
-
#perform ⇒ Object
Public: Create the branch and handle related processing.
Constructor Details
#initialize(branch_type, pull_request_id, options = {}) ⇒ PullRequestMerger
Public: Initialize a new instance of DatedBranchCreator
branch_type - Name of the type of branch (e.g., staging or deployable) pull_request_id - The pull request id to use for the merge options - hash of options
- post_comment - whether or not to post a comment on the pull-request
20 21 22 23 24 |
# File 'lib/octopolo/pull_request_merger.rb', line 20 def initialize(branch_type, pull_request_id, ={}) self.branch_type = branch_type self.pull_request_id = pull_request_id self. = end |
Instance Attribute Details
#branch_type ⇒ Object
Returns the value of attribute branch_type.
12 13 14 |
# File 'lib/octopolo/pull_request_merger.rb', line 12 def branch_type @branch_type end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/octopolo/pull_request_merger.rb', line 12 def @options end |
#pull_request ⇒ Object
Public: Find the pull request
Returns a GitHub::PullRequest
93 94 95 |
# File 'lib/octopolo/pull_request_merger.rb', line 93 def pull_request @pull_request end |
#pull_request_id ⇒ Object
Returns the value of attribute pull_request_id.
12 13 14 |
# File 'lib/octopolo/pull_request_merger.rb', line 12 def pull_request_id @pull_request_id end |
Class Method Details
.perform(branch_type, pull_request_id, options = {}) ⇒ Object
Public: Create a new branch of the given type for today’s date
branch_type - Name of the type of branch (e.g., staging or deployable) post_comment - Whether or not to comment on the pull-request
Returns a DatedBranchCreator
32 33 34 35 36 |
# File 'lib/octopolo/pull_request_merger.rb', line 32 def self.perform(branch_type, pull_request_id, ={}) new(branch_type, pull_request_id, ).tap do |creator| creator.perform end end |
Instance Method Details
#branch_to_merge_into ⇒ Object
Public: Find the branch
Returns a String
100 101 102 |
# File 'lib/octopolo/pull_request_merger.rb', line 100 def branch_to_merge_into @branch_to_merge_into ||= git.latest_branch_for(branch_type) end |
#check_out_branch ⇒ Object
Public: Check out the branch
62 63 64 65 66 67 |
# File 'lib/octopolo/pull_request_merger.rb', line 62 def check_out_branch git.check_out branch_to_merge_into rescue Git::NoBranchOfType cli.say "No #{branch_type} branch available. Creating one now." git.check_out DatedBranchCreator.perform(branch_type).branch_name end |
#comment_about_merge ⇒ Object
Public: Comment that the pull request was merged into the branch
75 76 77 |
# File 'lib/octopolo/pull_request_merger.rb', line 75 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
82 83 84 85 86 87 88 |
# File 'lib/octopolo/pull_request_merger.rb', line 82 def comment_body body = "Merged into #{branch_to_merge_into}." if [:user_notifications] body << " /cc #{[:user_notifications].map {|name| "@#{name}"}.join(' ')}" end body end |
#merge_pull_request ⇒ Object
Public: Merge the pull request’s branch into the checked-out branch
70 71 72 |
# File 'lib/octopolo/pull_request_merger.rb', line 70 def merge_pull_request git.merge pull_request.branch end |
#perform ⇒ Object
Public: Create the branch and handle related processing
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/octopolo/pull_request_merger.rb', line 39 def perform git.if_clean do check_out_branch merge_pull_request comment_about_merge end rescue => e case e when GitHub::PullRequest::NotFound cli.say "Unable to find pull request #{pull_request_id}. Please retry with a valid ID." when Git::MergeFailed cli.say "Merge failed. Please identify the source of this merge conflict resolve this conflict in your pull request's branch. NOTE: Merge conflicts resolved in the #{branch_type} branch are NOT used when deploying." when Git::CheckoutFailed cli.say "Checkout of #{branch_to_merge_into} failed. Please contact Infrastructure to determine the cause." when GitHub::PullRequest::CommentFailed cli.say "Unable to write comment. Please navigate to #{pull_request.url} and add the comment, '#{comment_body}'" else cli.say "An unknown error occurred: #{e.inspect}" end raise end |