Skip to content

Commit

Permalink
Add CUD operations for commit comments. Closes #114
Browse files Browse the repository at this point in the history
Add create_commit_comment, update_commit_comment and delete_commit_comment
  • Loading branch information
joeyw committed Sep 25, 2012
1 parent 3c53574 commit 6a7aa36
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/octokit/client/commits.rb
Expand Up @@ -81,6 +81,62 @@ def commit_comment(repo, id, options={})
get("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
end

# Create a commit comment
#
# @param repo [String, Hash, Repository] A GitHub repository
# @param sha [String] Sha of the commit to comment on
# @param body [String] Message
# @param path [String] Relative path of file to comment on
# @param line [Integer] Line number in the file to comment on
# @param position [Integer] Line index in the diff to comment on
# @return [Hashie::Mash] A hash representing the new commit comment
# @see http://developer.github.com/v3/git/commits/
# @example Create a commit comment
# commit = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1)
# commit.commit_id # => "827efc6d56897b048c772eb4087f854f46256132"
# commit.body # => "My comment message"
# commit.path # => "README.md"
# commit.line # => 10
# commit.position # => 1
def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options={})
params = {
:body => body,
:commit_id => sha,
:path => path,
:line => line,
:position => position
}
post("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params), 3)
end

# Update a commit comment
#
# @param repo [String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to update
# @param body [String] Message
# @return [Hashie::Mash] A hash representing the updated commit comment
# @see http://developer.github.com/v3/git/commits/
# @example Update a commit comment
# commit = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment")
# commit.id # => 860296
# commit.body # => "Updated commit comment"
def update_commit_comment(repo, id, body, options={})
params = {
:body => body
}
patch("repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params), 3)
end

# Delete a commit comment
#
# @param repo [String, Hash, Repository] A GitHub repository
# @param id [String] The ID of the comment to delete
# @return [nil] nil
# @see http://developer.github.com/v3/git/commits/
def delete_commit_comment(repo, id, options={})
delete("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
end

# Compare two commits
#
# @param repo [String, Hash, Repository] A GitHub repository
Expand Down
19 changes: 19 additions & 0 deletions spec/fixtures/v3/commit_comment_create.json
@@ -0,0 +1,19 @@
{
"updated_at": "2012-01-12T10:21:32Z",
"path": ".rspec",
"body": "Hey Eric,\r\n\r\nI think it's a terrible idea: for a number of reasons (dissections, etc.), test suite should stay deterministic IMO.\r\n",
"line": 1,
"user": {
"avatar_url": "https://secure.gravatar.com/avatar/c1607873b99845b2cd53f8634860d4d4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"login": "bbenezech",
"gravatar_id": "c1607873b99845b2cd53f8634860d4d4",
"id": 26794,
"url": "https://api.github.com/users/bbenezech"
},
"created_at": "2012-01-12T10:21:32Z",
"commit_id": "629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3",
"position": 4,
"id": 860296,
"html_url": "https://github.com/sferik/rails_admin/commit/629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3#commitcomment-860296",
"url": "https://api.github.com/repos/sferik/rails_admin/comments/860296"
}
19 changes: 19 additions & 0 deletions spec/fixtures/v3/commit_comment_update.json
@@ -0,0 +1,19 @@
{
"updated_at": "2012-01-12T10:21:32Z",
"path": ".rspec",
"body": "Hey Eric,\r\n\r\nI think it's a terrible idea. The test suite should stay deterministic IMO.\r\n",
"line": 1,
"user": {
"avatar_url": "https://secure.gravatar.com/avatar/c1607873b99845b2cd53f8634860d4d4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"login": "bbenezech",
"gravatar_id": "c1607873b99845b2cd53f8634860d4d4",
"id": 26794,
"url": "https://api.github.com/users/bbenezech"
},
"created_at": "2012-01-12T10:21:32Z",
"commit_id": "629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3",
"position": 4,
"id": 860296,
"html_url": "https://github.com/sferik/rails_admin/commit/629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3#commitcomment-860296",
"url": "https://api.github.com/repos/sferik/rails_admin/comments/860296"
}
41 changes: 41 additions & 0 deletions spec/octokit/client/commits_spec.rb
Expand Up @@ -78,6 +78,47 @@

end

describe ".create_commit_comment" do

it "should create a commit comment" do
stub_post("/repos/sferik/rails_admin/commits/629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3/comments").
with(:body => { :body => "Hey Eric,\r\n\r\nI think it's a terrible idea: for a number of reasons (dissections, etc.), test suite should stay deterministic IMO.\r\n", :commit_id => "629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3", :line => 1, :path => ".rspec", :position => 4 },
:headers => { "Content-Type" => "application/json" }).
to_return(:body => fixture("v3/commit_comment_create.json"))
commit_comment = @client.create_commit_comment("sferik/rails_admin", "629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3", "Hey Eric,\r\n\r\nI think it's a terrible idea: for a number of reasons (dissections, etc.), test suite should stay deterministic IMO.\r\n", ".rspec", 1, 4)
commit_comment.body.should == "Hey Eric,\r\n\r\nI think it's a terrible idea: for a number of reasons (dissections, etc.), test suite should stay deterministic IMO.\r\n"
commit_comment.commit_id.should == "629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3"
commit_comment.path.should == ".rspec"
commit_comment.line.should == 1
commit_comment.position.should == 4
end

end

describe ".update_commit_comment" do

it "should update a commit comment" do
stub_patch("/repos/sferik/rails_admin/comments/860296").
with(:body => { :body => "Hey Eric,\r\n\r\nI think it's a terrible idea. The test suite should stay deterministic IMO.\r\n" },
:headers => { "Content-Type" => "application/json" }).
to_return(:body => fixture("v3/commit_comment_update.json"))
commit_comment = @client.update_commit_comment("sferik/rails_admin", "860296", "Hey Eric,\r\n\r\nI think it's a terrible idea. The test suite should stay deterministic IMO.\r\n")
commit_comment.body.should == "Hey Eric,\r\n\r\nI think it's a terrible idea. The test suite should stay deterministic IMO.\r\n"
end

end

describe ".delete_commit_comment" do

it "should delete a commit comment" do
stub_delete("/repos/sferik/rails_admin/comments/860296").
to_return(:status => 204, :body => "")
commit_comment = @client.delete_commit_comment("sferik/rails_admin", "860296")
commit_comment.should be_false
end

end

describe ".compare" do

it "should return a comparison" do
Expand Down

0 comments on commit 6a7aa36

Please sign in to comment.