Class: GitHelper::GitHubPullRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/git_helper/pull_request.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/git_helper/pull_request.rb', line 7

def create
  begin
    # Ask these questions right away
    base_branch
    new_pr_title
    new_pr_body

    puts "Creating pull request: #{new_pr_title}"
    pr = octokit_client.create_pull_request(local_repo, base_branch, local_branch, new_pr_title, new_pr_body)
    puts "Pull request successfully created: #{pr.html_url}"
  rescue Octokit::UnprocessableEntity => e
    puts 'Could not create pull request:'
    if e.message.include?('pull request already exists')
      puts '  A pull request already exists for this branch'
    elsif e.message.include?('No commits between')
      puts '  No commits have been pushed to GitHub'
    else
      puts e.message
    end
  rescue Exception => e
    puts 'Could not create pull request:'
    puts e.message
  end
end

#mergeObject



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
64
65
66
67
68
# File 'lib/git_helper/pull_request.rb', line 32

def merge
  begin
    # Ask these questions right away
    pr_id
    merge_method

    puts "Merging pull request: #{pr_id}"
    merge = octokit_client.merge_pull_request(local_repo, pr_id, existing_pr.title, { merge_method: merge_method })
    puts "Pull request successfully merged: #{merge.sha}"
  rescue Octokit::UnprocessableEntity => e
    puts 'Could not merge pull request:'
    puts e.message
  rescue Octokit::NotFound => e
    puts 'Could not merge pull request:'
    puts "  Could not a locate a pull request to merge with ID #{pr_id}"
  rescue Octokit::MethodNotAllowed => e
    puts 'Could not merge pull request:'
    if e.message.include?('405 - Required status check')
      puts '  A required status check has not passed'
    elsif e.message.include?('405 - Base branch was modified')
      puts '  The base branch has been modified'
    elsif e.message.include?('405 - Pull Request is not mergeable')
      puts '  The pull request is not mergeable'
    elsif e.message.include?('405 - Rebase merges are not allowed on this repository')
      puts '  Rebase merges are not allowed on this repository'
    elsif e.message.include?('405 - Merge commits are not allowed on this repository')
      puts '  Merge commits are not allowed on this repository'
    elsif e.message.include?('405 - Squash commits are not allowed on this repository')
      puts '  Squash merges are not allowed on this repository'
    else
      puts e.message
    end
  rescue Exception => e
    puts 'Could not merge pull request:'
    puts e.message
  end
end