Class: GitHelper::GitLabMergeRequest
- Inherits:
-
Object
- Object
- GitHelper::GitLabMergeRequest
- Defined in:
- lib/git_helper/merge_request.rb
Instance Attribute Summary collapse
-
#base_branch ⇒ Object
Returns the value of attribute base_branch.
-
#highline ⇒ Object
Returns the value of attribute highline.
-
#local_branch ⇒ Object
Returns the value of attribute local_branch.
-
#local_code ⇒ Object
Returns the value of attribute local_code.
-
#local_project ⇒ Object
Returns the value of attribute local_project.
-
#new_mr_title ⇒ Object
Returns the value of attribute new_mr_title.
Instance Method Summary collapse
-
#create(options) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
-
#initialize(options) ⇒ GitLabMergeRequest
constructor
A new instance of GitLabMergeRequest.
-
#merge ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(options) ⇒ GitLabMergeRequest
Returns a new instance of GitLabMergeRequest.
7 8 9 10 11 12 |
# File 'lib/git_helper/merge_request.rb', line 7 def initialize() @local_project = [:local_project] @local_branch = [:local_branch] @local_code = [:local_code] @highline = [:highline] end |
Instance Attribute Details
#base_branch ⇒ Object
Returns the value of attribute base_branch.
5 6 7 |
# File 'lib/git_helper/merge_request.rb', line 5 def base_branch @base_branch end |
#highline ⇒ Object
Returns the value of attribute highline.
5 6 7 |
# File 'lib/git_helper/merge_request.rb', line 5 def highline @highline end |
#local_branch ⇒ Object
Returns the value of attribute local_branch.
5 6 7 |
# File 'lib/git_helper/merge_request.rb', line 5 def local_branch @local_branch end |
#local_code ⇒ Object
Returns the value of attribute local_code.
5 6 7 |
# File 'lib/git_helper/merge_request.rb', line 5 def local_code @local_code end |
#local_project ⇒ Object
Returns the value of attribute local_project.
5 6 7 |
# File 'lib/git_helper/merge_request.rb', line 5 def local_project @local_project end |
#new_mr_title ⇒ Object
Returns the value of attribute new_mr_title.
5 6 7 |
# File 'lib/git_helper/merge_request.rb', line 5 def new_mr_title @new_mr_title end |
Instance Method Details
#create(options) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
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 |
# File 'lib/git_helper/merge_request.rb', line 16 def create() @base_branch = [:base_branch] @new_mr_title = [:new_title] = { source_branch: local_branch, target_branch: base_branch, squash: squash_merge_request, remove_source_branch: remove_source_branch, description: new_mr_body, title: new_mr_title } puts "Creating merge request: #{new_mr_title}" mr = gitlab_client.create_merge_request(local_project, ) raise StandardError, mr. if mr.diff_refs.nil? || mr.web_url.nil? if mr.diff_refs['base_sha'] == mr.diff_refs['head_sha'] puts "Merge request was created, but no commits have been pushed to GitLab: #{mr.web_url}" else puts "Merge request successfully created: #{mr.web_url}" end rescue StandardError => e puts 'Could not create merge request:' if e..include?('Another open merge request already exists') puts ' A merge request already exists for this branch' else puts " #{e.message}" end end |
#merge ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/git_helper/merge_request.rb', line 53 def merge mr_id = { should_remove_source_branch: existing_mr.should_remove_source_branch || existing_mr.force_remove_source_branch, squash: existing_mr.squash, squash_commit_message: existing_mr.title } puts "Merging merge request: #{mr_id}" merge = gitlab_client.accept_merge_request(local_project, mr_id, ) if merge.merge_commit_sha.nil? [:squash] = true merge = gitlab_client.accept_merge_request(local_project, mr_id, ) end raise StandardError, merge. if merge.merge_commit_sha.nil? puts "Merge request successfully merged: #{merge.merge_commit_sha}" rescue StandardError => e puts 'Could not merge merge request:' if e..include?('404 Not found') puts ' Could not a locate a merge request to merge with given ID' elsif e..include?('405 Method Not Allowed') puts ' The merge request is not mergeable' else puts " #{e.message}" end end |