Support title and desc on merge w/ push option
MergeRequests::PushOptionsHandlerService has been updated to allow creating and updating merge requests with the `title` and `description` set using git push options. To create a new merge request and set its title and description: git push -u origin -o merge_request.create \ -o merge_request.title="My title" \ -o merge_request.description="My description" To update an existing merge request and set its title and description: git push -u origin -o merge_request.title="My title" \ -o merge_request.description="My description" Issue https://gitlab.com/gitlab-org/gitlab-ce/issues/64320
This commit is contained in:
parent
b2e4a7957a
commit
7cf4bf848f
5 changed files with 194 additions and 10 deletions
|
@ -118,7 +118,14 @@ module MergeRequests
|
||||||
end
|
end
|
||||||
|
|
||||||
def base_params
|
def base_params
|
||||||
params = {}
|
params = {
|
||||||
|
title: push_options[:title],
|
||||||
|
description: push_options[:description],
|
||||||
|
target_branch: push_options[:target],
|
||||||
|
force_remove_source_branch: push_options[:remove_source_branch]
|
||||||
|
}
|
||||||
|
|
||||||
|
params.compact!
|
||||||
|
|
||||||
if push_options.key?(:merge_when_pipeline_succeeds)
|
if push_options.key?(:merge_when_pipeline_succeeds)
|
||||||
params.merge!(
|
params.merge!(
|
||||||
|
@ -127,14 +134,6 @@ module MergeRequests
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
if push_options.key?(:remove_source_branch)
|
|
||||||
params[:force_remove_source_branch] = push_options[:remove_source_branch]
|
|
||||||
end
|
|
||||||
|
|
||||||
if push_options.key?(:target)
|
|
||||||
params[:target_branch] = push_options[:target]
|
|
||||||
end
|
|
||||||
|
|
||||||
params
|
params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
5
changelogs/unreleased/label-descr-push-opts.yml
Normal file
5
changelogs/unreleased/label-descr-push-opts.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Support setting of merge request title and description using git push options
|
||||||
|
merge_request: 31068
|
||||||
|
author:
|
||||||
|
type: added
|
|
@ -343,6 +343,30 @@ git push -o merge_request.remove_source_branch
|
||||||
You can also use this push option in addition to the
|
You can also use this push option in addition to the
|
||||||
`merge_request.create` push option.
|
`merge_request.create` push option.
|
||||||
|
|
||||||
|
### Set merge request title using git push options
|
||||||
|
|
||||||
|
To set the title of an existing merge request, use
|
||||||
|
the `merge_request.title` push option:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git push -o merge_request.title="The title I want"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use this push option in addition to the
|
||||||
|
`merge_request.create` push option.
|
||||||
|
|
||||||
|
### Set merge request description using git push options
|
||||||
|
|
||||||
|
To set the description of an existing merge request, use
|
||||||
|
the `merge_request.description` push option:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git push -o merge_request.description="The description I want"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also use this push option in addition to the
|
||||||
|
`merge_request.create` push option.
|
||||||
|
|
||||||
## Find the merge request that introduced a change
|
## Find the merge request that introduced a change
|
||||||
|
|
||||||
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/2383) in GitLab 10.5.
|
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/2383) in GitLab 10.5.
|
||||||
|
|
|
@ -6,9 +6,11 @@ module Gitlab
|
||||||
merge_request: {
|
merge_request: {
|
||||||
keys: [
|
keys: [
|
||||||
:create,
|
:create,
|
||||||
|
:description,
|
||||||
:merge_when_pipeline_succeeds,
|
:merge_when_pipeline_succeeds,
|
||||||
:remove_source_branch,
|
:remove_source_branch,
|
||||||
:target
|
:target,
|
||||||
|
:title
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
ci: {
|
ci: {
|
||||||
|
|
|
@ -11,6 +11,8 @@ describe MergeRequests::PushOptionsHandlerService do
|
||||||
let(:service) { described_class.new(project, user, changes, push_options) }
|
let(:service) { described_class.new(project, user, changes, push_options) }
|
||||||
let(:source_branch) { 'fix' }
|
let(:source_branch) { 'fix' }
|
||||||
let(:target_branch) { 'feature' }
|
let(:target_branch) { 'feature' }
|
||||||
|
let(:title) { 'my title' }
|
||||||
|
let(:description) { 'my description' }
|
||||||
let(:new_branch_changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" }
|
let(:new_branch_changes) { "#{Gitlab::Git::BLANK_SHA} 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" }
|
||||||
let(:existing_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" }
|
let(:existing_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{source_branch}" }
|
||||||
let(:deleted_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 #{Gitlab::Git::BLANK_SHA} refs/heads/#{source_branch}" }
|
let(:deleted_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 #{Gitlab::Git::BLANK_SHA} refs/heads/#{source_branch}" }
|
||||||
|
@ -73,6 +75,26 @@ describe MergeRequests::PushOptionsHandlerService do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'a service that can set the title of a merge request' do
|
||||||
|
subject(:last_mr) { MergeRequest.last }
|
||||||
|
|
||||||
|
it 'sets the title' do
|
||||||
|
service.execute
|
||||||
|
|
||||||
|
expect(last_mr.title).to eq(title)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples_for 'a service that can set the description of a merge request' do
|
||||||
|
subject(:last_mr) { MergeRequest.last }
|
||||||
|
|
||||||
|
it 'sets the description' do
|
||||||
|
service.execute
|
||||||
|
|
||||||
|
expect(last_mr.description).to eq(description)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
shared_examples_for 'a service that can set the merge request to merge when pipeline succeeds' do
|
shared_examples_for 'a service that can set the merge request to merge when pipeline succeeds' do
|
||||||
subject(:last_mr) { MergeRequest.last }
|
subject(:last_mr) { MergeRequest.last }
|
||||||
|
|
||||||
|
@ -350,6 +372,138 @@ describe MergeRequests::PushOptionsHandlerService do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '`title` push option' do
|
||||||
|
let(:push_options) { { title: title } }
|
||||||
|
|
||||||
|
context 'with a new branch' do
|
||||||
|
let(:changes) { new_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does not create a merge request'
|
||||||
|
|
||||||
|
it 'adds an error to the service' do
|
||||||
|
error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}"
|
||||||
|
|
||||||
|
service.execute
|
||||||
|
|
||||||
|
expect(service.errors).to include(error)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when coupled with the `create` push option' do
|
||||||
|
let(:push_options) { { create: true, title: title } }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that can create a merge request'
|
||||||
|
it_behaves_like 'a service that can set the title of a merge request'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with an existing branch but no open MR' do
|
||||||
|
let(:changes) { existing_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does not create a merge request'
|
||||||
|
|
||||||
|
it 'adds an error to the service' do
|
||||||
|
error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}"
|
||||||
|
|
||||||
|
service.execute
|
||||||
|
|
||||||
|
expect(service.errors).to include(error)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when coupled with the `create` push option' do
|
||||||
|
let(:push_options) { { create: true, title: title } }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that can create a merge request'
|
||||||
|
it_behaves_like 'a service that can set the title of a merge request'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with an existing branch that has a merge request open' do
|
||||||
|
let(:changes) { existing_branch_changes }
|
||||||
|
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)}
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does not create a merge request'
|
||||||
|
it_behaves_like 'a service that can set the title of a merge request'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a deleted branch' do
|
||||||
|
let(:changes) { deleted_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does nothing'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with the project default branch' do
|
||||||
|
let(:changes) { default_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does nothing'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '`description` push option' do
|
||||||
|
let(:push_options) { { description: description } }
|
||||||
|
|
||||||
|
context 'with a new branch' do
|
||||||
|
let(:changes) { new_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does not create a merge request'
|
||||||
|
|
||||||
|
it 'adds an error to the service' do
|
||||||
|
error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}"
|
||||||
|
|
||||||
|
service.execute
|
||||||
|
|
||||||
|
expect(service.errors).to include(error)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when coupled with the `create` push option' do
|
||||||
|
let(:push_options) { { create: true, description: description } }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that can create a merge request'
|
||||||
|
it_behaves_like 'a service that can set the description of a merge request'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with an existing branch but no open MR' do
|
||||||
|
let(:changes) { existing_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does not create a merge request'
|
||||||
|
|
||||||
|
it 'adds an error to the service' do
|
||||||
|
error = "A merge_request.create push option is required to create a merge request for branch #{source_branch}"
|
||||||
|
|
||||||
|
service.execute
|
||||||
|
|
||||||
|
expect(service.errors).to include(error)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when coupled with the `create` push option' do
|
||||||
|
let(:push_options) { { create: true, description: description } }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that can create a merge request'
|
||||||
|
it_behaves_like 'a service that can set the description of a merge request'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with an existing branch that has a merge request open' do
|
||||||
|
let(:changes) { existing_branch_changes }
|
||||||
|
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)}
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does not create a merge request'
|
||||||
|
it_behaves_like 'a service that can set the description of a merge request'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a deleted branch' do
|
||||||
|
let(:changes) { deleted_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does nothing'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with the project default branch' do
|
||||||
|
let(:changes) { default_branch_changes }
|
||||||
|
|
||||||
|
it_behaves_like 'a service that does nothing'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'multiple pushed branches' do
|
describe 'multiple pushed branches' do
|
||||||
let(:push_options) { { create: true } }
|
let(:push_options) { { create: true } }
|
||||||
let(:changes) do
|
let(:changes) do
|
||||||
|
|
Loading…
Reference in a new issue