Skip to content

Commit

Permalink
Add repo compare API
Browse files Browse the repository at this point in the history
  • Loading branch information
zlx committed Sep 24, 2014
1 parent 38ad27f commit 6d8a98f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/gitlab/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,20 @@ def commit_diff(project, sha)
get("/projects/#{project}/repository/commits/#{sha}/diff")
end
alias_method :repo_commit_diff, :commit_diff

# Compare branches, tags or commits
#
# @example
# Gitlab.compare(42, 'master', 'feature/branch')
# Gitlab.repo_compare(42, 'master', 'feature/branch')
#
# @param [Integer] project The ID of a project.
# @param [String] the commit SHA or branch name of from branch
# @param [String] the commit SHA or branch name of to branch
# @retuen [Gitlab::ObjectifiedHash]
def compare(project, from, to)
get("/projects/#{project}/repository/compare?from=#{from}&to=#{to}")
end
alias_method :repo_compare, :compare
end
end
31 changes: 31 additions & 0 deletions spec/fixtures/compare_merge_request_diff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

{
"commit": {
"id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",
"short_id": "12d65c8dd2b",
"title": "JS fix",
"author_name": "Dmitriy Zaporozhets",
"author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2014-02-27T10:27:00+02:00"
},
"commits": [{
"id": "12d65c8dd2b2676fa3ac47d955accc085a37a9c1",
"short_id": "12d65c8dd2b",
"title": "JS fix",
"author_name": "Dmitriy Zaporozhets",
"author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2014-02-27T10:27:00+02:00"
}],
"diffs": [{
"old_path": "files/js/application.js",
"new_path": "files/js/application.js",
"a_mode": null,
"b_mode": "100644",
"diff": "--- a/files/js/application.js\n+++ b/files/js/application.js\n@@ -24,8 +24,10 @@\n //= require g.raphael-min\n //= require g.bar-min\n //= require branch-graph\n-//= require highlightjs.min\n-//= require ace/ace\n //= require_tree .\n //= require d3\n //= require underscore\n+\n+function fix() { \n+ alert(\"Fixed\")\n+}",
"new_file": false,
"renamed_file": false,
"deleted_file": false
}],
"compare_timeout": false,
"compare_same_ref": false
}
13 changes: 13 additions & 0 deletions spec/gitlab/client/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
it { should respond_to :repo_commits }
it { should respond_to :repo_commit }
it { should respond_to :repo_commit_diff }
it { should respond_to :repo_compare}

describe ".tags" do
before do
Expand Down Expand Up @@ -89,4 +90,16 @@
expect(@diff.new_path).to eq("doc/update/5.4-to-6.0.md")
end
end

describe ".compare" do
before do
stub_get("/projects/3/repository/compare?from=master&to=feature", "compare_merge_request_diff")
@diff = Gitlab.compare(3, 'master', 'feature')
end

it "should get diffs of a merge request" do
expect(@diff.diffs).to be_kind_of Array
expect(@diff.diffs.last["new_path"]).to eq "files/js/application.js"
end
end
end

0 comments on commit 6d8a98f

Please sign in to comment.