Class: GitHelper::GitHubPullRequest
- Inherits:
- 
      Object
      
        - Object
- GitHelper::GitHubPullRequest
 
- Defined in:
- lib/git_helper/pull_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_repo  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute local_repo. 
- 
  
    
      #new_pr_title  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute new_pr_title. 
Instance Method Summary collapse
- #create(options) ⇒ Object
- 
  
    
      #initialize(options)  ⇒ GitHubPullRequest 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of GitHubPullRequest. 
- #merge ⇒ Object
Constructor Details
#initialize(options) ⇒ GitHubPullRequest
Returns a new instance of GitHubPullRequest.
| 5 6 7 8 9 10 | # File 'lib/git_helper/pull_request.rb', line 5 def initialize() @local_repo = [: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/pull_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/pull_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/pull_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/pull_request.rb', line 3 def local_code @local_code end | 
#local_repo ⇒ Object
Returns the value of attribute local_repo.
| 3 4 5 | # File 'lib/git_helper/pull_request.rb', line 3 def local_repo @local_repo end | 
#new_pr_title ⇒ Object
Returns the value of attribute new_pr_title.
| 3 4 5 | # File 'lib/git_helper/pull_request.rb', line 3 def new_pr_title @new_pr_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 | # File 'lib/git_helper/pull_request.rb', line 12 def create() @base_branch = [:base_branch] @new_pr_title = [:new_title] begin 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..include?('pull request already exists') puts ' A pull request already exists for this branch' elsif e..include?('No commits between') puts ' No commits have been pushed to GitHub' else puts e. end rescue Exception => e puts 'Could not create pull request:' puts e. end end | 
#merge ⇒ Object
| 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 69 70 71 72 | # File 'lib/git_helper/pull_request.rb', line 37 def merge begin 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. 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..include?('405 - Required status check') puts ' A required status check has not passed' elsif e..include?('405 - Base branch was modified') puts ' The base branch has been modified' elsif e..include?('405 - Pull Request is not mergeable') puts ' The pull request is not mergeable' elsif e..include?('405 - Rebase merges are not allowed on this repository') puts ' Rebase merges are not allowed on this repository' elsif e..include?('405 - Merge commits are not allowed on this repository') puts ' Merge commits are not allowed on this repository' elsif e..include?('405 - Squash commits are not allowed on this repository') puts ' Squash merges are not allowed on this repository' else puts e. end rescue Exception => e puts 'Could not merge pull request:' puts e. end end |