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
13 changes: 13 additions & 0 deletions lib/gitlab/client/commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ def commit(project, sha)
end
alias repo_commit commit

# Cherry picks a commit to a given branch.
#
# @example
# Gitlab.cherry_pick_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
# @return [Gitlab::ObjectifiedHash]
def cherry_pick_commit(project, sha, branch)
post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch })
end

# Get the diff of a commit in a project.
#
# @example
Expand Down
18 changes: 18 additions & 0 deletions spec/gitlab/client/commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@
end
end

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

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

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

describe '.commit_diff' do
before do
stub_get('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff', 'project_commit_diff')
Expand Down