Skip to content

Commit

Permalink
Add merge_base support (#405)
Browse files Browse the repository at this point in the history
* Add support for merge_base API endpoint

* Update merge_base stub to use the correct stubbed response from docs

* Update comments
  • Loading branch information
timhaines authored and NARKOZ committed Aug 17, 2018
1 parent 493b5b0 commit 805d2ef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/gitlab/client/repositories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,18 @@ def compare(project, from, to)
get("/projects/#{url_encode project}/repository/compare", query: { from: from, to: to })
end
alias repo_compare compare

# Get the common ancestor for 2 refs (commit SHAs, branch names or tags).
#
# @example
# Gitlab.merge_base(42, ['master', 'feature/branch'])
# Gitlab.merge_base(42, ['master', 'feature/branch'])
#
# @param [Integer, String] project The ID or URL-encoded path of the project.
# @param [Array] refs Array containing 2 commit SHAs, branch names, or tags.
# @return [Gitlab::ObjectifiedHash]
def merge_base(project, refs)
get("/projects/#{url_encode project}/repository/merge_base", query: { refs: refs })
end
end
end
14 changes: 14 additions & 0 deletions spec/fixtures/merge_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
"short_id": "1a0b36b3",
"title": "Initial commit",
"created_at": "2014-02-27T08:03:18.000Z",
"parent_ids": [],
"message": "Initial commit\n",
"author_name": "Dmitriy Zaporozhets",
"author_email": "[email protected]",
"authored_date": "2014-02-27T08:03:18.000Z",
"committer_name": "Dmitriy Zaporozhets",
"committer_email": "[email protected]",
"committed_date": "2014-02-27T08:03:18.000Z"
}
18 changes: 18 additions & 0 deletions spec/gitlab/client/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,22 @@
expect(@diff.diffs.last['new_path']).to eq 'files/js/application.js'
end
end

describe '.merge_base' do
before do
stub_get('/projects/3/repository/merge_base', 'merge_base')
.with(query: { refs: %w[master feature] })
@response = Gitlab.merge_base(3, %w[master feature])
end

it 'gets the correct resource' do
expect(a_get('/projects/3/repository/merge_base')
.with(query: { refs: %w[master feature] })).to have_been_made
end

it 'gets common ancestor of the two refs' do
expect(@response).to be_kind_of Gitlab::ObjectifiedHash
expect(@response.id).to eq '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863'
end
end
end

0 comments on commit 805d2ef

Please sign in to comment.