Permalink
Browse files

Merge pull request #167 from joeyw/implement-pull-review-comment-methods

Implement pull request review comments. Closes #161.
  • Loading branch information...
pengwynn committed Oct 24, 2012
2 parents f05df55 + 8e720b8 commit d5e9b112bfb042ef6a28ee4504562c18be693557
@@ -118,6 +118,94 @@ def pull_request_comments(repo, number, options={})
alias :pull_comments :pull_request_comments
alias :review_comments :pull_request_comments
+ # Get a pull request comment
+ #
+ # @param repo [String, Hash, Repository] A GitHub repository
+ # @param comment_id [Integer] Id of comment to get
+ # @return [Hashie::Mash] Hash representing the comment
+ # @see http://developer.github.com/v3/pulls/comments/#get-a-single-comment
+ # @example
+ # @client.pull_request_comment("pengwynn/octkit", 1903950)
+ def pull_request_comment(repo, comment_id, options={})
+ get("repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options)
+ end
+ alias :pull_comment :pull_request_comment
+ alias :review_comment :pull_request_comment
+
+ # Create a pull request comment
+ #
+ # @param repo [String, Hash, Repository] A GitHub repository
+ # @param pull_id [Integer] Pull request id
+ # @param body [String] Comment content
+ # @param commit_id [String] Sha of the commit to comment on.
+ # @param path [String] Relative path of the file to comment on.
+ # @param position [Integer] Line index in the diff to comment on.
+ # @return [Hashie::Mash] Hash representing the new comment
+ # @see http://developer.github.com/v3/pulls/comments/#create-a-comment
+ # @example
+ # @client.create_pull_request_comment("pengwynn/octokit", 163, ":shipit:",
+ # "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47)
+ def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options={})
+ options.merge!({
+ :body => body,
+ :commit_id => commit_id,
+ :path => path,
+ :position => position
+ })
+ post("repos/#{Repository.new repo}/pulls/#{pull_id}/comments", options)
+ end
+ alias :create_pull_comment :create_pull_request_comment
+ alias :create_view_comment :create_pull_request_comment
+
+ # Create reply to a pull request comment
+ #
+ # @param repo [String, Hash, Repository] A GitHub repository
+ # @param pull_id [Integer] Pull request id
+ # @param body [String] Comment contents
+ # @param comment_id [Integer] Comment id to reply to
+ # @return [Hashie::Mash] Hash representing new comment
+ # @see http://developer.github.com/v3/pulls/comments/#create-a-comment
+ # @example
+ # @client.create_pull_request_comment_reply("pengwynn/octokit", 1903950, "done.")
+ def create_pull_request_comment_reply(repo, pull_id, body, comment_id, options={})
+ options.merge!({
+ :body => body,
+ :in_reply_to => comment_id
+ })
+ post("repos/#{Repository.new repo}/pulls/#{pull_id}/comments", options)
+ end
+ alias :create_pull_reply :create_pull_request_comment_reply
+ alias :create_review_reply :create_pull_request_comment_reply
+
+ # Update pull request comment
+ #
+ # @param repo [String, Hash, Repository] A GitHub repository
+ # @param comment_id [Integer] Id of the comment to update
+ # @param body [String] Updated comment content
+ # @return [Hashie::Mash] Hash representing the updated comment
+ # @see http://developer.github.com/v3/pulls/comments/#edit-a-comment
+ # @example
+ # @client.update_pull_request_comment("pengwynn/octokit", 1903950, ":shipit:")
+ def update_pull_request_comment(repo, comment_id, body, options={})
+ options.merge! :body => body
+ patch("repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options)
+ end
+ alias :update_pull_comment :update_pull_request_comment
+ alias :update_review_comment :update_pull_request_comment
+
+ # Delete pull request comment
+ #
+ # @param repo [String, Hash, Repository] A GitHub repository
+ # @param comment_id [Integer] Id of the comment to delete
+ # @return [Boolean] True if deleted, false otherwise
+ # @example
+ # @client.delete_pull_request_comment("pengwynn/octokit", 1902707)
+ def delete_pull_request_comment(repo, comment_id, options={})
+ delete("repos/#{Repository.new repo}/pulls/comments/#{comment_id}", options, 3, true, true).status == 204
+ end
+ alias :delete_pull_comment :delete_pull_request_comment
+ alias :delete_review_comment :delete_pull_request_comment
+
# List files on a pull request
#
# @see http://developer.github.com/v3/pulls/#list-files-on-a-pull-request
@@ -0,0 +1,35 @@
+{
+ "created_at": "2012-10-22T14:05:25Z",
+ "original_commit_id": "6ed6909ceb8f285de6562cca41dd1e4331c00722",
+ "original_position": 46,
+ "position": null,
+ "path": "lib/octokit/request.rb",
+ "updated_at": "2012-10-22T20:20:10Z",
+ "commit_id": "2d3201e4440903d8b04a5487842053ca4883e5f0",
+ "id": 1903950,
+ "url": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1903950",
+ "_links": {
+ "pull_request": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/163"
+ },
+ "self": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1903950"
+ },
+ "html": {
+ "href": "https://github.com/pengwynn/octokit/pull/163#discussion_r1903950"
+ }
+ },
+ "user": {
+ "gravatar_id": "7e19cd5486b5d6dc1ef90e671ba52ae0",
+ "avatar_url": "https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
+ "url": "https://api.github.com/users/pengwynn",
+ "id": 865,
+ "login": "pengwynn",
+ "_links": {
+ "self": {
+ "href": "https://api.github.com/users/pengwynn"
+ }
+ }
+ },
+ "body": "I like that. Tests FTW. Thanks for patching this."
+}
@@ -0,0 +1,35 @@
+{
+ "created_at": "2012-10-22T14:05:25Z",
+ "original_commit_id": "6ed6909ceb8f285de6562cca41dd1e4331c00722",
+ "original_position": 46,
+ "position": null,
+ "path": "lib/octokit/request.rb",
+ "updated_at": "2012-10-22T20:20:10Z",
+ "commit_id": "2d3201e4440903d8b04a5487842053ca4883e5f0",
+ "id": 1903950,
+ "url": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1903950",
+ "_links": {
+ "pull_request": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/163"
+ },
+ "self": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1903950"
+ },
+ "html": {
+ "href": "https://github.com/pengwynn/octokit/pull/163#discussion_r1903950"
+ }
+ },
+ "user": {
+ "gravatar_id": "7e19cd5486b5d6dc1ef90e671ba52ae0",
+ "avatar_url": "https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
+ "url": "https://api.github.com/users/pengwynn",
+ "id": 865,
+ "login": "pengwynn",
+ "_links": {
+ "self": {
+ "href": "https://api.github.com/users/pengwynn"
+ }
+ }
+ },
+ "body": "I like that. Tests FTW. Thanks for patching this."
+}
@@ -0,0 +1,35 @@
+{
+ "created_at": "2012-10-22T18:28:03Z",
+ "original_position": 21,
+ "position": null,
+ "path": "lib/octokit/connection.rb",
+ "updated_at": "2012-10-22T20:20:10Z",
+ "commit_id": "2d3201e4440903d8b04a5487842053ca4883e5f0",
+ "_links": {
+ "pull_request": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/163"
+ },
+ "self": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1907270"
+ },
+ "html": {
+ "href": "https://github.com/pengwynn/octokit/pull/163#discussion_r1907270"
+ }
+ },
+ "original_commit_id": "7fdf58222dd14899eec31a6b728bc73d51dbf181",
+ "id": 1907270,
+ "url": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1907270",
+ "user": {
+ "gravatar_id": "18c2c44835cc7c5ada7c027f12674714",
+ "avatar_url": "https://secure.gravatar.com/avatar/18c2c44835cc7c5ada7c027f12674714?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
+ "_links": {
+ "self": {
+ "href": "https://api.github.com/users/joeyw"
+ }
+ },
+ "url": "https://api.github.com/users/joeyw",
+ "id": 478247,
+ "login": "joeyw"
+ },
+ "body": "done."
+}
@@ -0,0 +1,35 @@
+{
+ "created_at": "2012-10-22T18:28:03Z",
+ "original_position": 21,
+ "position": null,
+ "path": "lib/octokit/connection.rb",
+ "updated_at": "2012-10-22T20:20:10Z",
+ "commit_id": "2d3201e4440903d8b04a5487842053ca4883e5f0",
+ "_links": {
+ "pull_request": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/163"
+ },
+ "self": {
+ "href": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1907270"
+ },
+ "html": {
+ "href": "https://github.com/pengwynn/octokit/pull/163#discussion_r1907270"
+ }
+ },
+ "original_commit_id": "7fdf58222dd14899eec31a6b728bc73d51dbf181",
+ "id": 1907270,
+ "url": "https://api.github.com/repos/pengwynn/octokit/pulls/comments/1907270",
+ "user": {
+ "gravatar_id": "18c2c44835cc7c5ada7c027f12674714",
+ "avatar_url": "https://secure.gravatar.com/avatar/18c2c44835cc7c5ada7c027f12674714?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
+ "_links": {
+ "self": {
+ "href": "https://api.github.com/users/joeyw"
+ }
+ },
+ "url": "https://api.github.com/users/joeyw",
+ "id": 478247,
+ "login": "joeyw"
+ },
+ "body": ":shipit:"
+}
@@ -90,6 +90,77 @@
end
+ describe ".pull_request_comment" do
+
+ it "returns a comment on a pull request" do
+ stub_get("https://api.github.com/repos/pengwynn/octokit/pulls/comments/1903950").
+ to_return(:body => fixture("v3/pull_request_comment.json"))
+ comment = @client.pull_request_comment("pengwynn/octokit", 1903950)
+ expect(comment.id).to eq(1903950)
+ expect(comment.body).to include("Tests FTW.")
+ end
+
+ end
+
+ describe ".create_pull_request_comment" do
+
+ it "creates a new comment on a pull request" do
+ comment_content = JSON.parse(fixture("v3/pull_request_comment_create.json").read)
+ new_comment = {
+ :body => comment_content['body'],
+ :commit_id => comment_content['commit_id'],
+ :path => comment_content['path'],
+ :position => comment_content['position']
+ }
+ stub_post("https://api.github.com/repos/pengwynn/octokit/pulls/163/comments").
+ with(:body => new_comment).
+ to_return(:body => fixture("v3/pull_request_comment_create.json"))
+ comment = @client.create_pull_request_comment("pengwynn/octokit", 163, new_comment[:body], new_comment[:commit_id], new_comment[:path], new_comment[:position])
+ expect(comment).to eq(comment_content)
+ end
+
+ end
+
+ describe ".create_pull_request_comment_reply" do
+
+ it "creates a new reply to a pull request comment" do
+ new_comment = {
+ :body => "done.",
+ :in_reply_to => 1903950
+ }
+ stub_post("https://api.github.com/repos/pengwynn/octokit/pulls/163/comments").
+ with(:body => new_comment).
+ to_return(:body => fixture("v3/pull_request_comment_reply.json"))
+ reply = @client.create_pull_request_comment_reply("pengwynn/octokit", 163, new_comment[:body], new_comment[:in_reply_to])
+ expect(reply.id).to eq(1907270)
+ expect(reply.body).to eq(new_comment[:body])
+ end
+
+ end
+
+ describe ".update_pull_request_comment" do
+
+ it "updates a pull request comment" do
+ stub_patch("https://api.github.com/repos/pengwynn/octokit/pulls/comments/1907270").
+ with(:body => { :body => ":shipit:"}).
+ to_return(:body => fixture("v3/pull_request_comment_update.json"))
+ comment = @client.update_pull_request_comment("pengwynn/octokit", 1907270, ":shipit:")
+ expect(comment.body).to eq(":shipit:")
+ end
+
+ end
+
+ describe ".delete_pull_request_comment" do
+
+ it "deletes a pull request comment" do
+ stub_delete("https://api.github.com/repos/pengwynn/octokit/pulls/comments/1907270").
+ to_return(:status => 204)
+ result = @client.delete_pull_request_comment("pengwynn/octokit", 1907270)
+ expect(result).to be_true
+ end
+
+ end
+
describe ".merge_pull_request" do
it "merges the pull request" do

0 comments on commit d5e9b11

Please sign in to comment.