Class: Status::Github::PullRequest
- Inherits:
-
Object
- Object
- Status::Github::PullRequest
- Defined in:
- lib/status/github/pull_request.rb
Instance Method Summary collapse
- #create_pull_request ⇒ Object
- #get_pull_request ⇒ Object
-
#initialize(branch) ⇒ PullRequest
constructor
A new instance of PullRequest.
- #new_pull_request ⇒ Object
- #payload ⇒ Object
- #post_pull_request ⇒ Object
- #pull_request_api ⇒ Object
- #pull_request_found? ⇒ Boolean
- #title ⇒ Object
Constructor Details
#initialize(branch) ⇒ PullRequest
Returns a new instance of PullRequest.
6 7 8 |
# File 'lib/status/github/pull_request.rb', line 6 def initialize(branch) @branch = branch end |
Instance Method Details
#create_pull_request ⇒ Object
14 15 16 17 18 |
# File 'lib/status/github/pull_request.rb', line 14 def create_pull_request puts "No pull request found, create one? (y/n)" answer = gets answer.chomp.downcase == "y" ? new_pull_request : abort("exit") end |
#get_pull_request ⇒ Object
36 37 38 |
# File 'lib/status/github/pull_request.rb', line 36 def get_pull_request Status::Request.new.get(pull_request_api) end |
#new_pull_request ⇒ Object
20 21 22 23 |
# File 'lib/status/github/pull_request.rb', line 20 def new_pull_request response = post_pull_request puts response == "not found" ? response : response["url"] end |
#payload ⇒ Object
25 26 27 28 29 30 |
# File 'lib/status/github/pull_request.rb', line 25 def payload puts "enter a description" body = gets {:title => title, :body => body, :base => "master", :head => @branch } end |
#post_pull_request ⇒ Object
40 41 42 |
# File 'lib/status/github/pull_request.rb', line 40 def post_pull_request Status::Request.new.post(pull_request_api, payload) end |
#pull_request_api ⇒ Object
44 45 46 |
# File 'lib/status/github/pull_request.rb', line 44 def pull_request_api "/repos/#{Status.owner}/#{Status.repo}/pulls?access_token=#{Status.token}" end |
#pull_request_found? ⇒ Boolean
10 11 12 |
# File 'lib/status/github/pull_request.rb', line 10 def pull_request_found? !get_pull_request.select {|pull| pull["head"]["ref"] == @branch}.empty? end |
#title ⇒ Object
32 33 34 |
# File 'lib/status/github/pull_request.rb', line 32 def title `git log #{@branch} -1 --pretty=format:'%s'` end |