Class: Geet::Services::MergePr

Inherits:
Object
  • Object
show all
Includes:
Helpers::ServicesWorkflowHelper, Geet::Shared
Defined in:
lib/geet/services/merge_pr.rb

Overview

Merges the PR for the current branch.

The workflow of this services is oriented to the a commondline usage: the user doesn’t need to lookup the merge for the working branch; this comes at the cost of extra operations and constraints, but speeds up the workflow.

Constant Summary collapse

DEFAULT_GIT_CLIENT =
Geet::Utils::GitClient.new

Instance Method Summary collapse

Methods included from Helpers::ServicesWorkflowHelper

#checked_find_branch_pr

Constructor Details

#initialize(repository, out: $stdout, git_client: DEFAULT_GIT_CLIENT) ⇒ MergePr

Returns a new instance of MergePr.



19
20
21
22
23
# File 'lib/geet/services/merge_pr.rb', line 19

def initialize(repository, out: $stdout, git_client: DEFAULT_GIT_CLIENT)
  @repository = repository
  @out = out
  @git_client = git_client
end

Instance Method Details

#execute(delete_branch: false, squash: false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/geet/services/merge_pr.rb', line 25

def execute(delete_branch: false, squash: false, **)
  merge_method = 'squash' if squash

  @git_client.fetch

  @git_client.push

  check_no_missing_upstream_commits if !squash

  pr = checked_find_branch_pr

  merge_pr(pr, merge_method:)

  if delete_branch
    branch = @git_client.current_branch

    delete_remote_branch(branch)
  end

  fetch_repository

  if @git_client.remote_branch_gone?
    pr_branch = @git_client.current_branch
    main_branch = @git_client.main_branch

    # The rebase could also be placed after the branch deletion. There are pros/cons;
    # currently, it's not important.
    #
    checkout_branch(main_branch)
    rebase

    # When squashing, we need to force delete, since Git doesn't recognize that the branch has
    # been merged.
    #
    delete_local_branch(pr_branch, force: squash)
  end

  pr
end