Class: Status::Github::PullRequest

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

Instance Method Summary collapse

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_requestObject



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_requestObject



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_requestObject



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

#payloadObject



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_requestObject



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_apiObject



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

Returns:

  • (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

#titleObject



32
33
34
# File 'lib/status/github/pull_request.rb', line 32

def title
  `git log #{@branch} -1 --pretty=format:'%s'`
end