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.
-
#highline ⇒ Object
Returns the value of attribute highline.
-
#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
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
-
#initialize(options) ⇒ GitHubPullRequest
constructor
A new instance of GitHubPullRequest.
-
#merge ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(options) ⇒ GitHubPullRequest
Returns a new instance of GitHubPullRequest.
7 8 9 10 11 12 |
# File 'lib/git_helper/pull_request.rb', line 7 def initialize() @local_repo = [:local_project] @local_branch = [:local_branch] @local_code = [:local_code] @highline = [:highline] end |
Instance Attribute Details
#base_branch ⇒ Object
Returns the value of attribute base_branch.
5 6 7 |
# File 'lib/git_helper/pull_request.rb', line 5 def base_branch @base_branch end |
#highline ⇒ Object
Returns the value of attribute highline.
5 6 7 |
# File 'lib/git_helper/pull_request.rb', line 5 def highline @highline end |
#local_branch ⇒ Object
Returns the value of attribute local_branch.
5 6 7 |
# File 'lib/git_helper/pull_request.rb', line 5 def local_branch @local_branch end |
#local_code ⇒ Object
Returns the value of attribute local_code.
5 6 7 |
# File 'lib/git_helper/pull_request.rb', line 5 def local_code @local_code end |
#local_repo ⇒ Object
Returns the value of attribute local_repo.
5 6 7 |
# File 'lib/git_helper/pull_request.rb', line 5 def local_repo @local_repo end |
#new_pr_title ⇒ Object
Returns the value of attribute new_pr_title.
5 6 7 |
# File 'lib/git_helper/pull_request.rb', line 5 def new_pr_title @new_pr_title end |
Instance Method Details
#create(options) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
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 41 42 43 |
# File 'lib/git_helper/pull_request.rb', line 16 def create() @base_branch = [:base_branch] @new_pr_title = [:new_title] = { head: local_branch, base: base_branch, body: new_pr_body, title: new_pr_title } puts "Creating pull request: #{new_pr_title}" pr = github_client.create_pull_request(local_repo, ) raise StandardError, pr.errors.first['message'] if pr.html_url.nil? puts "Pull request successfully created: #{pr.html_url}" rescue StandardError => e puts 'Could not create pull request:' if e..include?('A 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.message}" end end |
#merge ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/git_helper/pull_request.rb', line 49 def merge pr_id = { merge_method: merge_method, commit_title: existing_pr.title } puts "Merging pull request: #{pr_id}" merge = github_client.merge_pull_request(local_repo, pr_id, ) raise StandardError, merge. if merge.sha.nil? puts "Pull request successfully merged: #{merge.sha}" rescue StandardError => e puts 'Could not merge pull request:' if e..include?('Not found') puts ' Could not a locate a pull request to merge with given ID' else puts " #{e.message}" end end |