Class: Zenflow::PullRequest
- Inherits:
-
Object
- Object
- Zenflow::PullRequest
- Defined in:
- lib/zenflow/helpers/pull_request.rb
Instance Attribute Summary collapse
-
#pull ⇒ Object
readonly
Returns the value of attribute pull.
Class Method Summary collapse
- .create(options = {}) ⇒ Object
- .exist?(ref) ⇒ Boolean
- .find(number) ⇒ Object
- .find_by_ref(ref, options = {}) ⇒ Object
- .find_by_ref!(ref) ⇒ Object
- .list ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(pull) ⇒ PullRequest
constructor
A new instance of PullRequest.
- #valid? ⇒ Boolean
Constructor Details
#initialize(pull) ⇒ PullRequest
Returns a new instance of PullRequest.
55 56 57 |
# File 'lib/zenflow/helpers/pull_request.rb', line 55 def initialize(pull) @pull = pull || {} end |
Instance Attribute Details
#pull ⇒ Object (readonly)
Returns the value of attribute pull.
53 54 55 |
# File 'lib/zenflow/helpers/pull_request.rb', line 53 def pull @pull end |
Class Method Details
.create(options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/zenflow/helpers/pull_request.rb', line 39 def create(={}) response = Zenflow::GithubRequest.post("/pulls", body: { "base" => [:base], "head" => [:head], "title" => [:title], "body" => [:body] }.to_json ) new(response.parsed_response) end |
.exist?(ref) ⇒ Boolean
35 36 37 |
# File 'lib/zenflow/helpers/pull_request.rb', line 35 def exist?(ref) !!find_by_ref(ref) end |
.find(number) ⇒ Object
10 11 12 |
# File 'lib/zenflow/helpers/pull_request.rb', line 10 def find(number) new(Zenflow::GithubRequest.get("/pulls/#{number}").parsed_response["pull"]) end |
.find_by_ref(ref, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zenflow/helpers/pull_request.rb', line 14 def find_by_ref(ref, ={}) Zenflow::Log("Looking up pull request for #{ref}") unless [:silent] if list.any? pull = list.detect do |p| p["head"]["ref"] == ref end if pull new(pull) end end end |
.find_by_ref!(ref) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/zenflow/helpers/pull_request.rb', line 26 def find_by_ref!(ref) if pull = find_by_ref(ref) new(pull) else Zenflow::Log("No open pull request was found for #{ref}", color: :red) exit(1) end end |
.list ⇒ Object
5 6 7 8 |
# File 'lib/zenflow/helpers/pull_request.rb', line 5 def list response = Zenflow::GithubRequest.get("/pulls").parsed_response response.map{ |pull| new(pull) } end |
Instance Method Details
#[](key) ⇒ Object
63 64 65 |
# File 'lib/zenflow/helpers/pull_request.rb', line 63 def [](key) pull[key.to_s] end |
#valid? ⇒ Boolean
59 60 61 |
# File 'lib/zenflow/helpers/pull_request.rb', line 59 def valid? !pull["errors"] && pull['html_url'] end |