Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions lib/gitlab/client/commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,30 @@ def commit_refs(project, sha, options = {})
# @param [Integer, String] project The ID or name of a project.
# @param [String] sha The commit hash or name of a repository branch or tag
# @param [String] branch The name of the branch
# @param [Hash] options A customizable set of options.
# @option options [Boolean] :dry_run Don't commit any changes
# @return [Gitlab::ObjectifiedHash]
def cherry_pick_commit(project, sha, branch)
post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch })
def cherry_pick_commit(project, sha, branch, options = {})
options[:branch] = branch

post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: options)
end

# Reverts a commit in a given branch.
#
# @example
# Gitlab.revert_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')
#
# @param [Integer, String] project The ID or name of a project.
# @param [String] sha The commit hash or name of a repository branch or tag
# @param [String] branch The name of the branch
# @param [Hash] options A customizable set of options.
# @option options [Boolean] :dry_run Don't commit any changes
# @return [Gitlab::ObjectifiedHash]
def revert_commit(project, sha, branch, options = {})
options[:branch] = branch

post("/projects/#{url_encode project}/repository/commits/#{sha}/revert", body: options)
end

# Get the diff of a commit in a project.
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/revert_commit_failure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"message":"Sorry, we cannot revert this commit automatically. This commit may already have been reverted, or a more recent commit may have updated some of its content.","error_code":"empty"}
56 changes: 56 additions & 0 deletions spec/gitlab/client/commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,62 @@
end
end
end

context 'with additional options' do
it 'passes additional options' do
stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/cherry_pick', 'project_commit')
.with(body: { branch: 'master', dry_run: true })

Gitlab.cherry_pick_commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master', dry_run: true)

expect(a_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/cherry_pick')
.with(body: { branch: 'master', dry_run: true }))
.to have_been_made
end
end
end

describe '.revert_commit' do
context 'on success' do
before do
stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/revert', 'project_commit').with(body: { branch: 'master' })
@revert_commit = Gitlab.revert_commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')
end

it 'gets the correct resource' do
expect(a_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/revert')
.with(body: { branch: 'master' }))
.to have_been_made
end

it 'returns the correct response' do
expect(@revert_commit).to be_a Gitlab::ObjectifiedHash
expect(@revert_commit.id).to eq('6104942438c14ec7bd21c6cd5bd995272b3faff6')
end
end

context 'on failure' do
it 'includes the error_code' do
stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/revert', 'revert_commit_failure', 400)

expect { Gitlab.revert_commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master') }.to raise_error(Gitlab::Error::BadRequest) do |ex|
expect(ex.error_code).to eq('empty')
end
end
end

context 'with additional options' do
it 'passes additional options' do
stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/revert', 'project_commit')
.with(body: { branch: 'master', dry_run: true })

Gitlab.revert_commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master', dry_run: true)

expect(a_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/revert')
.with(body: { branch: 'master', dry_run: true }))
.to have_been_made
end
end
end

describe '.commit_diff' do
Expand Down