Commit 4c7d1942 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'add-milestone-mr-git-push-options' into 'master'

Support specifying a milestone for MR via push options

See merge request gitlab-org/gitlab!63960
parents da34b9fc be94b8a3
...@@ -142,6 +142,8 @@ module MergeRequests ...@@ -142,6 +142,8 @@ module MergeRequests
params[:add_assignee_ids] = params.delete(:assign).keys if params.has_key?(:assign) params[:add_assignee_ids] = params.delete(:assign).keys if params.has_key?(:assign)
params[:remove_assignee_ids] = params.delete(:unassign).keys if params.has_key?(:unassign) params[:remove_assignee_ids] = params.delete(:unassign).keys if params.has_key?(:unassign)
params[:milestone] = project.milestones&.find_by_name(push_options[:milestone]) if push_options[:milestone]
params params
end end
......
...@@ -66,6 +66,7 @@ time as pushing changes: ...@@ -66,6 +66,7 @@ time as pushing changes:
| `merge_request.remove_source_branch` | Set the merge request to remove the source branch when it's merged. | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) | | `merge_request.remove_source_branch` | Set the merge request to remove the source branch when it's merged. | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) |
| `merge_request.title="<title>"` | Set the title of the merge request. Ex: `git push -o merge_request.title="The title I want"`. | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) | | `merge_request.title="<title>"` | Set the title of the merge request. Ex: `git push -o merge_request.title="The title I want"`. | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) |
| `merge_request.description="<description>"` | Set the description of the merge request. Ex: `git push -o merge_request.description="The description I want"`. | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) | | `merge_request.description="<description>"` | Set the description of the merge request. Ex: `git push -o merge_request.description="The description I want"`. | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) |
| `merge_request.milestone="<milestone>"` | Set the milestone of the merge request. Ex: `git push -o merge_request.milestone="3.0"`. | [14.1](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63960) |
| `merge_request.label="<label>"` | Add labels to the merge request. If the label does not exist, it is created. For example, for two labels: `git push -o merge_request.label="label1" -o merge_request.label="label2"`. | [12.3](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31831) | | `merge_request.label="<label>"` | Add labels to the merge request. If the label does not exist, it is created. For example, for two labels: `git push -o merge_request.label="label1" -o merge_request.label="label2"`. | [12.3](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31831) |
| `merge_request.unlabel="<label>"` | Remove labels from the merge request. For example, for two labels: `git push -o merge_request.unlabel="label1" -o merge_request.unlabel="label2"`. | [12.3](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31831) | | `merge_request.unlabel="<label>"` | Remove labels from the merge request. For example, for two labels: `git push -o merge_request.unlabel="label1" -o merge_request.unlabel="label2"`. | [12.3](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31831) |
| `merge_request.assign="<user>"` | Assign users to the merge request. For example, for two users: `git push -o merge_request.assign="user1" -o merge_request.assign="user2"`. | [13.10](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25904) | | `merge_request.assign="<user>"` | Assign users to the merge request. For example, for two users: `git push -o merge_request.assign="user1" -o merge_request.assign="user2"`. | [13.10](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25904) |
......
...@@ -10,6 +10,7 @@ module Gitlab ...@@ -10,6 +10,7 @@ module Gitlab
:description, :description,
:label, :label,
:merge_when_pipeline_succeeds, :merge_when_pipeline_succeeds,
:milestone,
:remove_source_branch, :remove_source_branch,
:target, :target,
:title, :title,
......
...@@ -10,6 +10,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do ...@@ -10,6 +10,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
let_it_be(:user2) { create(:user, developer_projects: [project]) } let_it_be(:user2) { create(:user, developer_projects: [project]) }
let_it_be(:user3) { create(:user, developer_projects: [project]) } let_it_be(:user3) { create(:user, developer_projects: [project]) }
let_it_be(:forked_project) { fork_project(project, user1, repository: true) } let_it_be(:forked_project) { fork_project(project, user1, repository: true) }
let_it_be(:milestone) { create(:milestone, project: project, title: '1.0') }
let(:service) { described_class.new(project: project, current_user: user1, changes: changes, push_options: push_options) } let(:service) { described_class.new(project: project, current_user: user1, changes: changes, push_options: push_options) }
let(:source_branch) { 'fix' } let(:source_branch) { 'fix' }
...@@ -59,6 +60,16 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do ...@@ -59,6 +60,16 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
end end
end end
shared_examples_for 'a service that can set the milestone of a merge request' do
subject(:last_mr) { MergeRequest.last }
it 'sets the milestone' do
service.execute
expect(last_mr.milestone&.title).to eq(expected_milestone)
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 }
...@@ -514,6 +525,70 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do ...@@ -514,6 +525,70 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
it_behaves_like 'with the project default branch' it_behaves_like 'with the project default branch'
end end
describe '`milestone` push option' do
context 'with a valid milestone' do
let(:expected_milestone) { milestone.title }
let(:push_options) { { milestone: milestone.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
service.execute
expect(service.errors).to include(error_mr_required)
end
context 'when coupled with the `create` push option' do
let(:push_options) { { create: true, milestone: milestone.title } }
it_behaves_like 'a service that can create a merge request'
it_behaves_like 'a service that can set the milestone 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
service.execute
expect(service.errors).to include(error_mr_required)
end
context 'when coupled with the `create` push option' do
let(:push_options) { { create: true, milestone: milestone.title } }
it_behaves_like 'a service that can create a merge request'
it_behaves_like 'a service that can set the milestone 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 milestone of a merge request'
end
it_behaves_like 'with a deleted branch'
it_behaves_like 'with the project default branch'
end
context 'with invalid milestone' do
let(:expected_milestone) { nil }
let(:changes) { new_branch_changes }
let(:push_options) { { create: true, milestone: 'invalid_milestone' } }
it_behaves_like 'a service that can set the milestone of a merge request'
end
end
shared_examples 'with an existing branch that has a merge request open in foss' do shared_examples 'with an existing branch that has a merge request open in foss' do
let(:changes) { existing_branch_changes } let(:changes) { existing_branch_changes }
let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)} let!(:merge_request) { create(:merge_request, source_project: project, source_branch: source_branch)}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment