Skip to content

Commit

Permalink
Single commit and diff of a commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nanofi committed May 5, 2014
1 parent 770c1db commit 90760cd
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/gitlab/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,33 @@ def commits(project, options={})
get("/projects/#{project}/repository/commits", :query => options)
end
alias_method :repo_commits, :commits

# Gets a specific commit identified by the commit hash or name of a branch or tag.
#
# @example
# Gitlab.commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
# Gitlab.repo_commit(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
#
# @param [Integer] project The ID of a project.
# @param [String] sha The commit hash or name of a repository branch or tag
# @return [Gitlab::ObjectifiedHash]
def commit(project, sha)
get("/projects/#{project}/repository/commits/#{sha}")
end
alias_method :repo_commit, :commit

# Get the diff of a commit in a project.
#
# @example
# Gitlab.commit_diff(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
# Gitlab.repo_commit_diff(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
#
# @param [Integer] project The ID of a project.
# @param [String] sha The name of a repository branch or tag or if not given the default branch.
# @return [Gitlab::ObjectifiedHash]
def commit_diff(project, sha)
get("/projects/#{project}/repository/commits/#{sha}/diff")
end
alias_method :repo_commit_diff, :commit_diff
end
end
13 changes: 13 additions & 0 deletions spec/fixtures/project_commit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
"short_id": "6104942438c",
"title": "Sanitize for network graph",
"author_name": "randx",
"author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2012-09-20T09:06:12+03:00",
"committed_date": "2012-09-20T09:06:12+03:00",
"authored_date": "2012-09-20T09:06:12+03:00",
"parent_ids": [
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
]
}
10 changes: 10 additions & 0 deletions spec/fixtures/project_commit_diff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"diff": "--- a/doc/update/5.4-to-6.0.md\n+++ b/doc/update/5.4-to-6.0.md\n@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files",
"new_path": "doc/update/5.4-to-6.0.md",
"old_path": "doc/update/5.4-to-6.0.md",
"a_mode": null,
"b_mode": "100644",
"new_file": false,
"renamed_file": false,
"deleted_file": false
}
34 changes: 34 additions & 0 deletions spec/gitlab/client/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
it { should respond_to :repo_branches }
it { should respond_to :repo_branch }
it { should respond_to :repo_commits }
it { should respond_to :repo_commit }
it { should respond_to :repo_commit_diff }

describe ".tags" do
before do
Expand Down Expand Up @@ -39,4 +41,36 @@
@commits.first.id.should == "f7dd067490fe57505f7226c3b54d3127d2f7fd46"
end
end

describe ".commit" do
before do
stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", "project_commit")
@commit = Gitlab.commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
end

it "should get the correct resource" do
a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6")
.should have_been_made
end

it "should return a repository commit" do
@commit.id.should == "6104942438c14ec7bd21c6cd5bd995272b3faff6"
end
end

describe ".commit_diff" do
before do
stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff", "project_commit_diff")
@diff = Gitlab.commit_diff(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
end

it "should get the correct resource" do
a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff")
.should have_been_made
end

it "should return a diff of a commit" do
@diff.new_path.should == "doc/update/5.4-to-6.0.md"
end
end
end

0 comments on commit 90760cd

Please sign in to comment.