Skip to content

Commit

Permalink
Add .pull_requests_comments
Browse files Browse the repository at this point in the history
Hits the new /repos/{repo}/pulls/comments api endpoint that gets all the
comments made on pull requests.

http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository

Closes #190.
  • Loading branch information
joeyw committed Dec 6, 2012
1 parent 9877d9b commit 09e77d5
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/octokit/client/pulls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ def pull_request_commits(repo, number, options={})
end
alias :pull_commits :pull_request_commits

# List pull request comments for a repository
#
# By default, Review Comments are ordered by ascending ID.
#
# @param repo [String, Repository, Hash] A GitHub repository
# @param options [Hash] Optional parameters
# @option options [String] :sort created or updated
# @option options [String] :direction asc or desc. Ignored without sort
# parameter.
# @option options [String] :since Timestamp in ISO 8601
# format: YYYY-MM-DDTHH:MM:SSZ
#
# @return [Array] List of pull request review comments.
#
# @see http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository
#
# @example Get the pull request review comments in the octokit repository
# @client.issues_comments("pengwynn/octokit")
#
# @example Get review comments, sort by updated asc since a time
# @client.pull_requests_comments("pengwynn/octokit", {
# :sort => 'asc',
# :direction => 'down',
# :since => '2010-05-04T23:45:02Z'
# })
def pull_requests_comments(repo, options={})
get("repos/#{Repository.new repo}/pulls/comments")
end
alias :pulls_comments :pull_requests_comments
alias :reviews_comments :pull_requests_comments

# List comments on a pull request
#
# @see http://developer.github.com/v3/pulls/#list-comments-on-a-pull-request
Expand Down
82 changes: 82 additions & 0 deletions spec/fixtures/pull_requests_comments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
[
{
"created_at": "2011-08-28T23:35:50Z",
"original_commit_id": "472ae972b0180136c4745df19bbb045a5c6efa38",
"body": "Please remove this.",
"url": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/104862",
"path": "lib/octokit/client/repositories.rb",
"commit_id": "3ae33359b5135c9c5e43f6eda6623465aa36427f",
"user": {
"type": "User",
"subscriptions_url": "https://api.github.com/users/sferik/subscriptions",
"url": "https://api.github.com/users/sferik",
"starred_url": "https://api.github.com/users/sferik/starred{/owner}{/repo}",
"repos_url": "https://api.github.com/users/sferik/repos",
"avatar_url": "https://secure.gravatar.com/avatar/1f74b13f1e5c6c69cb5d7fbaabb1e2cb?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"gists_url": "https://api.github.com/users/sferik/gists{/gist_id}",
"events_url": "https://api.github.com/users/sferik/events{/privacy}",
"gravatar_id": "1f74b13f1e5c6c69cb5d7fbaabb1e2cb",
"login": "sferik",
"organizations_url": "https://api.github.com/users/sferik/orgs",
"received_events_url": "https://api.github.com/users/sferik/received_events",
"followers_url": "https://api.github.com/users/sferik/followers",
"id": 10308,
"following_url": "https://api.github.com/users/sferik/following"
},
"updated_at": "2011-08-28T23:42:45Z",
"_links": {
"html": {
"href": "https://github.com/pengwynn/octokit/pull/52#discussion_r104862"
},
"self": {
"href": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/104862"
},
"pull_request": {
"href": "https://api.github.com/repos/pengwynn/octokit/pulls/52"
}
},
"original_position": 2,
"position": null,
"id": 104862
},
{
"created_at": "2011-08-28T23:43:30Z",
"original_commit_id": "472ae972b0180136c4745df19bbb045a5c6efa38",
"body": "Whoops. Fixed now.",
"url": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/104864",
"path": "lib/octokit/client/repositories.rb",
"commit_id": "3ae33359b5135c9c5e43f6eda6623465aa36427f",
"user": {
"type": "User",
"subscriptions_url": "https://api.github.com/users/alexkwolfe/subscriptions",
"url": "https://api.github.com/users/alexkwolfe",
"starred_url": "https://api.github.com/users/alexkwolfe/starred{/owner}{/repo}",
"repos_url": "https://api.github.com/users/alexkwolfe/repos",
"avatar_url": "https://secure.gravatar.com/avatar/72d403ad3c243379dfdb5da3e6179c05?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"gists_url": "https://api.github.com/users/alexkwolfe/gists{/gist_id}",
"events_url": "https://api.github.com/users/alexkwolfe/events{/privacy}",
"gravatar_id": "72d403ad3c243379dfdb5da3e6179c05",
"login": "alexkwolfe",
"organizations_url": "https://api.github.com/users/alexkwolfe/orgs",
"received_events_url": "https://api.github.com/users/alexkwolfe/received_events",
"followers_url": "https://api.github.com/users/alexkwolfe/followers",
"id": 569,
"following_url": "https://api.github.com/users/alexkwolfe/following"
},
"updated_at": "2011-08-28T23:43:30Z",
"_links": {
"html": {
"href": "https://github.com/pengwynn/octokit/pull/52#discussion_r104864"
},
"self": {
"href": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/104864"
},
"pull_request": {
"href": "https://api.github.com/repos/pengwynn/octokit/pulls/52"
}
},
"original_position": 2,
"position": null,
"id": 104864
}
]
11 changes: 11 additions & 0 deletions spec/octokit/client/pulls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@

end

describe ".pull_requests_comments" do

it "returns all comments on all pull requests" do
stub_get("https://api.github.com/repos/pengwynn/octokit/pulls/comments").
to_return(json_response("pull_requests_comments.json"))
comments = @client.pull_requests_comments("pengwynn/octokit")
expect(comments.first.user.login).to eq("sferik")
end

end

describe ".pull_request" do

it "returns a pull request" do
Expand Down

0 comments on commit 09e77d5

Please sign in to comment.