Permalink
Browse files

Add comment api support

  • Loading branch information...
1 parent fae2ff4 commit d27ce255d00e985950698e06b8c74607e1d0339d @holysugar committed May 23, 2012
Showing with 62 additions and 11 deletions.
  1. +34 −11 lib/github_pulls.rb
  2. +28 −0 spec/github_pulls_spec.rb
View
@@ -1,3 +1,4 @@
+require 'time'
require 'httpclient'
require 'json'
@@ -18,6 +19,10 @@ def pulls
call_pulls.map(&Pull.method(:new))
end
+ def comments(number)
+ get("/repos/#{@repo}/issues/#{number}/comments").map(&Comment.method(:new))
+ end
+
private
def call(name)
name.sub!(/^\//, '')
@@ -26,8 +31,12 @@ def call(name)
http_result
end
+ def get(name)
+ JSON.parse(call(name).body)
+ end
+
def call_pulls
- JSON.parse(call("/repos/#{@repo}/pulls").body)
+ get("/repos/#{@repo}/pulls")
end
def header
@@ -37,16 +46,19 @@ def header
end
class Pull
- attr :username, :label, :body, :sha, :html_url, :number, :private, :repo
- def initialize(pull)
- @username = pull['user']['login']
- @label = pull['head']['label']
- @body = pull['body']
- @sha = pull['head']['sha']
- @html_url = pull['html_url']
- @number = pull['number']
- @private = pull['head']['repo']['private']
- @repo = pull['head']['repo']['ssh_url']
+ attr :username, :label, :body, :sha, :html_url, :number, :private, :repo, :pushed_at
+
+ def initialize(pull) # give a pull request api result json data
+ @data = pull
+ @username = pull['user']['login']
+ @label = pull['head']['label']
+ @body = pull['body']
+ @sha = pull['head']['sha']
+ @html_url = pull['html_url']
+ @number = pull['number']
+ @private = pull['head']['repo']['private']
+ @repo = pull['head']['repo']['ssh_url']
+ @updated_at = Time.parse(pull['updated_at']).localtime
end
alias private? private
@@ -62,7 +74,18 @@ def fetch_and_merge_command
git merge FETCH_HEAD
EOD
end
+ end
+
+ class Comment
+ attr :username, :body, :created_at, :updated_at
+ def initialize(comment) # give a pull request api
+ @data = comment
+ @username = comment['user']['login']
+ @body = comment['body']
+ @created_at = Time.parse(comment['created_at']).localtime
+ @updated_at = Time.parse(comment['updated_at']).localtime
+ end
end
end
View
@@ -12,16 +12,44 @@
should satisfy {|pulls| pulls.all?{|pull| pull.is_a? GithubPulls::Pull } }
end
end
+
+ describe "#comments" do
+ subject { api.comments(1) }
+
+ it "is a collection of GithubPulls::Comment" do
+ should satisfy {|comments| comments.all?{|comment| comment.is_a? GithubPulls::Comment } }
+ end
+
+ end
end
describe GithubPulls::Pull do
let(:api) { GithubPulls::API.new('holysugar/github_pulls') }
let(:pull) { api.pulls.last }
+ subject { pull }
+
+ its(:sha) { should == '483bef9dcd6e2f99f885be5011fafc1b5dc82bbf' }
+
describe "#branch" do
it "is branch name of head pull requested" do
pull.branch.should == "pull-sample"
end
end
end
+describe GithubPulls::Comment do
+ let(:api) { GithubPulls::API.new('holysugar/github_pulls') }
+ let(:comment) { api.comments(1).first }
+
+ subject { comment }
+
+ it { should be }
+
+ describe "#body" do
+ it 'is comment body' do
+ comment.body.should == 'first comment'
+ end
+ end
+end
+

0 comments on commit d27ce25

Please sign in to comment.