From 39f991ec0ede28c4b8d6e38fb4054da57dee1303 Mon Sep 17 00:00:00 2001 From: AkashSrivastava Date: Fri, 26 Oct 2018 12:02:45 +0530 Subject: [PATCH 1/2] Added Cherry pick a commit client method --- lib/gitlab/client/commits.rb | 13 +++++++++++++ spec/gitlab/client/commits_spec.rb | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/gitlab/client/commits.rb b/lib/gitlab/client/commits.rb index 7f28e5052..ad43a16b5 100644 --- a/lib/gitlab/client/commits.rb +++ b/lib/gitlab/client/commits.rb @@ -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 diff --git a/spec/gitlab/client/commits_spec.rb b/spec/gitlab/client/commits_spec.rb index 8c90b8fff..4717fe3ac 100644 --- a/spec/gitlab/client/commits_spec.rb +++ b/spec/gitlab/client/commits_spec.rb @@ -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') From 7d4f8c826ca6eddbea6c2fb85d9c143425a42029 Mon Sep 17 00:00:00 2001 From: AkashSrivastava Date: Fri, 26 Oct 2018 12:25:01 +0530 Subject: [PATCH 2/2] Rubocop fixes --- lib/gitlab/client/commits.rb | 2 +- spec/gitlab/client/commits_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/gitlab/client/commits.rb b/lib/gitlab/client/commits.rb index ad43a16b5..0a3039e60 100644 --- a/lib/gitlab/client/commits.rb +++ b/lib/gitlab/client/commits.rb @@ -45,7 +45,7 @@ def commit(project, sha) # @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}) + post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch }) end # Get the diff of a commit in a project. diff --git a/spec/gitlab/client/commits_spec.rb b/spec/gitlab/client/commits_spec.rb index 4717fe3ac..73601859e 100644 --- a/spec/gitlab/client/commits_spec.rb +++ b/spec/gitlab/client/commits_spec.rb @@ -48,14 +48,14 @@ describe '.cherry_pick_commit' do before do - stub_post('/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/cherry_pick', 'project_commit').with(body: {branch: 'master'}) + 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 + .with(body: { branch: 'master' })) + .to have_been_made end it 'returns the correct response' do