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.
-
#cli ⇒ Object
Returns the value of attribute cli.
-
#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
-
#initialize(options) ⇒ GitLabMergeRequest
constructor
A new instance of GitLabMergeRequest.
- #merge ⇒ Object
Constructor Details
#initialize(options) ⇒ GitLabMergeRequest
Returns a new instance of GitLabMergeRequest.
5 6 7 8 9 10 |
# File 'lib/git_helper/merge_request.rb', line 5 def initialize() @local_project = [:local_project] @local_branch = [:local_branch] @local_code = [:local_code] @cli = [:cli] end |
Instance Attribute Details
#base_branch ⇒ Object
Returns the value of attribute base_branch.
3 4 5 |
# File 'lib/git_helper/merge_request.rb', line 3 def base_branch @base_branch end |
#cli ⇒ Object
Returns the value of attribute cli.
3 4 5 |
# File 'lib/git_helper/merge_request.rb', line 3 def cli @cli end |
#local_branch ⇒ Object
Returns the value of attribute local_branch.
3 4 5 |
# File 'lib/git_helper/merge_request.rb', line 3 def local_branch @local_branch end |
#local_code ⇒ Object
Returns the value of attribute local_code.
3 4 5 |
# File 'lib/git_helper/merge_request.rb', line 3 def local_code @local_code end |
#local_project ⇒ Object
Returns the value of attribute local_project.
3 4 5 |
# File 'lib/git_helper/merge_request.rb', line 3 def local_project @local_project end |
#new_mr_title ⇒ Object
Returns the value of attribute new_mr_title.
3 4 5 |
# File 'lib/git_helper/merge_request.rb', line 3 def new_mr_title @new_mr_title end |
Instance Method Details
#create(options) ⇒ Object
12 13 14 15 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 |
# File 'lib/git_helper/merge_request.rb', line 12 def create() @base_branch = [:base_branch] @new_mr_title = [:new_title] begin = { source_branch: local_branch, target_branch: base_branch, squash: squash_merge_request, remove_source_branch: remove_source_branch, description: new_mr_body } puts "Creating merge request: #{new_mr_title}" mr = gitlab_client.create_merge_request(local_project, new_mr_title, ) 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 Gitlab::Error::Conflict => e puts 'Could not create merge request:' puts ' A merge request already exists for this branch' rescue Exception => e puts 'Could not create merge request:' puts e. end end |
#merge ⇒ Object
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/git_helper/merge_request.rb', line 42 def merge begin 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 if merge.merge_commit_sha.nil? puts 'Could not merge merge request:' puts " #{merge.merge_error}" else puts "Merge request successfully merged: #{merge.merge_commit_sha}" end rescue Gitlab::Error::MethodNotAllowed => e puts 'Could not merge merge request:' puts ' The merge request is not mergeable' rescue Gitlab::Error::NotFound => e puts 'Could not merge merge request:' puts " Could not a locate a merge request to merge with ID #{mr_id}" rescue Exception => e puts 'Could not merge merge request:' puts e. end end |