From 90760cdeb3dfaa7be5fdfa5eba792c3a8e617c57 Mon Sep 17 00:00:00 2001 From: nanofi Date: Thu, 1 May 2014 10:43:02 +0000 Subject: [PATCH] Single commit and diff of a commit --- lib/gitlab/client/repositories.rb | 28 ++++++++++++++++++++ spec/fixtures/project_commit.json | 13 ++++++++++ spec/fixtures/project_commit_diff.json | 10 ++++++++ spec/gitlab/client/repositories_spec.rb | 34 +++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 spec/fixtures/project_commit.json create mode 100644 spec/fixtures/project_commit_diff.json diff --git a/lib/gitlab/client/repositories.rb b/lib/gitlab/client/repositories.rb index 7bccd851f..2e16d44d9 100644 --- a/lib/gitlab/client/repositories.rb +++ b/lib/gitlab/client/repositories.rb @@ -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 diff --git a/spec/fixtures/project_commit.json b/spec/fixtures/project_commit.json new file mode 100644 index 000000000..ace52b700 --- /dev/null +++ b/spec/fixtures/project_commit.json @@ -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" + ] +} diff --git a/spec/fixtures/project_commit_diff.json b/spec/fixtures/project_commit_diff.json new file mode 100644 index 000000000..ad3dfde86 --- /dev/null +++ b/spec/fixtures/project_commit_diff.json @@ -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 +} diff --git a/spec/gitlab/client/repositories_spec.rb b/spec/gitlab/client/repositories_spec.rb index 9b87bd20e..37e9b7822 100644 --- a/spec/gitlab/client/repositories_spec.rb +++ b/spec/gitlab/client/repositories_spec.rb @@ -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 @@ -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