git_helper 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/git_helper/highline_cli.rb +1 -2
- data/lib/git_helper/merge_request.rb +18 -6
- data/lib/git_helper/pull_request.rb +17 -4
- data/lib/git_helper/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d7f6658d90f9abf6f52b670fcd9e09ac4fc5964abbf70d0e88d21c6d3838d598
         | 
| 4 | 
            +
              data.tar.gz: 420511dc29ead38efe88f841b76bb42f1b086b5c76369202056d7856002886ef
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e8ee96f3180249acb8a25a549fa937852ff8a3a836a41d445dd7e5ea9f941f5b00408e174378e7c0b259a137cc96ce0ee3f52f3af7c3156f263e10f3253e1c3d
         | 
| 7 | 
            +
              data.tar.gz: bd1b57e904dcb2a29a2f85688038af87908499240e0b86f0e75c5cebb0ebd6de4e538b25dab598df247ff8a2bc82da665d0a6c57e2c41ac470a47cb20c226a46
         | 
| @@ -12,6 +12,8 @@ module GitHelper | |
| 12 12 | 
             
                    options = {
         | 
| 13 13 | 
             
                      source_branch: local_branch,
         | 
| 14 14 | 
             
                      target_branch: base_branch,
         | 
| 15 | 
            +
                      squash: squash_merge_request,
         | 
| 16 | 
            +
                      remove_source_branch: remove_source_branch,
         | 
| 15 17 | 
             
                      description: new_mr_body
         | 
| 16 18 | 
             
                    }
         | 
| 17 19 |  | 
| @@ -37,12 +39,18 @@ module GitHelper | |
| 37 39 | 
             
                    # Ask these questions right away
         | 
| 38 40 | 
             
                    mr_id
         | 
| 39 41 | 
             
                    options = {}
         | 
| 40 | 
            -
                    options[:should_remove_source_branch] =  | 
| 41 | 
            -
                    options[:squash] =  | 
| 42 | 
            -
                    options[:squash_commit_message] =  | 
| 42 | 
            +
                    options[:should_remove_source_branch] = existing_mr.should_remove_source_branch || existing_mr.force_remove_source_branch
         | 
| 43 | 
            +
                    options[:squash] = existing_mr.squash
         | 
| 44 | 
            +
                    options[:squash_commit_message] = existing_mr.title
         | 
| 43 45 |  | 
| 44 46 | 
             
                    puts "Merging merge request: #{mr_id}"
         | 
| 45 47 | 
             
                    merge = gitlab_client.accept_merge_request(local_project, mr_id, options)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    if merge.merge_commit_sha.nil?
         | 
| 50 | 
            +
                      options[:squash] = true
         | 
| 51 | 
            +
                      merge = gitlab_client.accept_merge_request(local_project, mr_id, options)
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
             | 
| 46 54 | 
             
                    puts "Merge request successfully merged: #{merge.merge_commit_sha}"
         | 
| 47 55 | 
             
                  rescue Gitlab::Error::MethodNotAllowed => e
         | 
| 48 56 | 
             
                    puts 'Could not merge merge request:'
         | 
| @@ -88,7 +96,7 @@ module GitHelper | |
| 88 96 | 
             
                end
         | 
| 89 97 |  | 
| 90 98 | 
             
                private def remove_source_branch
         | 
| 91 | 
            -
                  @remove_source_branch ||= cli.remove_source_branch?
         | 
| 99 | 
            +
                  @remove_source_branch ||= existing_project.remove_source_branch_after_merge || cli.remove_source_branch?
         | 
| 92 100 | 
             
                end
         | 
| 93 101 |  | 
| 94 102 | 
             
                private def new_mr_title
         | 
| @@ -128,8 +136,12 @@ module GitHelper | |
| 128 136 | 
             
                  @template_name_to_apply
         | 
| 129 137 | 
             
                end
         | 
| 130 138 |  | 
| 131 | 
            -
                private def  | 
| 132 | 
            -
                  @ | 
| 139 | 
            +
                private def existing_mr
         | 
| 140 | 
            +
                  @existing_mr ||= gitlab_client.merge_request(local_project, mr_id)
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                private def existing_project
         | 
| 144 | 
            +
                  @existing_project ||= gitlab_client.project(local_project)
         | 
| 133 145 | 
             
                end
         | 
| 134 146 |  | 
| 135 147 | 
             
                private def gitlab_client
         | 
| @@ -36,7 +36,7 @@ module GitHelper | |
| 36 36 | 
             
                    merge_method
         | 
| 37 37 |  | 
| 38 38 | 
             
                    puts "Merging pull request: #{pr_id}"
         | 
| 39 | 
            -
                    merge = octokit_client.merge_pull_request(local_repo, pr_id,  | 
| 39 | 
            +
                    merge = octokit_client.merge_pull_request(local_repo, pr_id, existing_pr.title, { merge_method: merge_method })
         | 
| 40 40 | 
             
                    puts "Pull request successfully merged: #{merge.sha}"
         | 
| 41 41 | 
             
                  rescue Octokit::UnprocessableEntity => e
         | 
| 42 42 | 
             
                    puts 'Could not merge pull request:'
         | 
| @@ -95,7 +95,16 @@ module GitHelper | |
| 95 95 | 
             
                end
         | 
| 96 96 |  | 
| 97 97 | 
             
                private def merge_method
         | 
| 98 | 
            -
                  @merge_method ||= cli.merge_method
         | 
| 98 | 
            +
                  @merge_method ||= merge_options.length == 1 ? merge_options.first : cli.merge_method(merge_options)
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                private def merge_options
         | 
| 102 | 
            +
                  return @merge_options if @merge_options
         | 
| 103 | 
            +
                  merge_options = []
         | 
| 104 | 
            +
                  merge_options << 'merge' if existing_project.allow_merge_commit
         | 
| 105 | 
            +
                  merge_options << 'squash' if existing_project.allow_squash_merge
         | 
| 106 | 
            +
                  merge_options << 'rebase' if existing_project.allow_rebase_merge
         | 
| 107 | 
            +
                  @merge_options = merge_options
         | 
| 99 108 | 
             
                end
         | 
| 100 109 |  | 
| 101 110 | 
             
                private def new_pr_title
         | 
| @@ -135,8 +144,12 @@ module GitHelper | |
| 135 144 | 
             
                  @template_name_to_apply
         | 
| 136 145 | 
             
                end
         | 
| 137 146 |  | 
| 138 | 
            -
                private def  | 
| 139 | 
            -
                  @ | 
| 147 | 
            +
                private def existing_pr
         | 
| 148 | 
            +
                  @existing_pr ||= octokit_client.pull_request(local_repo, pr_id)
         | 
| 149 | 
            +
                end
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                private def existing_project
         | 
| 152 | 
            +
                  @existing_project ||= octokit_client.repository(local_repo)
         | 
| 140 153 | 
             
                end
         | 
| 141 154 |  | 
| 142 155 | 
             
                private def octokit_client
         | 
    
        data/lib/git_helper/version.rb
    CHANGED