Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1c652f03
Commit
1c652f03
authored
Apr 20, 2018
by
Sean McGivern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add copy_metadata quick action
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/18497
parent
dc62ac84
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
2 deletions
+105
-2
app/services/quick_actions/interpret_service.rb
app/services/quick_actions/interpret_service.rb
+20
-0
changelogs/unreleased/add-copy-metadata-command.yml
changelogs/unreleased/add-copy-metadata-command.yml
+5
-0
doc/user/project/quick_actions.md
doc/user/project/quick_actions.md
+3
-2
spec/services/quick_actions/interpret_service_spec.rb
spec/services/quick_actions/interpret_service_spec.rb
+77
-0
No files found.
app/services/quick_actions/interpret_service.rb
View file @
1c652f03
...
@@ -269,6 +269,26 @@ module QuickActions
...
@@ -269,6 +269,26 @@ module QuickActions
end
end
end
end
desc
'Copy labels and milestone from other issue or merge request'
explanation
do
|
source_issuable
|
"Copy labels and milestone from
#{
source_issuable
.
to_reference
}
."
end
params
'#issue | !merge_request'
condition
do
issuable
.
persisted?
&&
current_user
.
can?
(
:"update_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
end
parse_params
do
|
issuable_param
|
extract_references
(
issuable_param
,
:issue
).
first
||
extract_references
(
issuable_param
,
:merge_request
).
first
end
command
:copy_metadata
do
|
source_issuable
|
if
source_issuable
.
present?
&&
source_issuable
.
project
.
id
==
issuable
.
project
.
id
@updates
[
:add_label_ids
]
=
source_issuable
.
labels
.
map
(
&
:id
)
@updates
[
:milestone_id
]
=
source_issuable
.
milestone
.
id
if
source_issuable
.
milestone
end
end
desc
'Add a todo'
desc
'Add a todo'
explanation
'Adds a todo.'
explanation
'Adds a todo.'
condition
do
condition
do
...
...
changelogs/unreleased/add-copy-metadata-command.yml
0 → 100644
View file @
1c652f03
---
title
:
Add Copy metadata quick action
merge_request
:
16473
author
:
Mateusz Bajorski
type
:
added
doc/user/project/quick_actions.md
View file @
1c652f03
...
@@ -42,8 +42,9 @@ do.
...
@@ -42,8 +42,9 @@ do.
|
`/board_move ~column`
| Move issue to column on the board |
|
`/board_move ~column`
| Move issue to column on the board |
|
`/duplicate #issue`
| Closes this issue and marks it as a duplicate of another issue |
|
`/duplicate #issue`
| Closes this issue and marks it as a duplicate of another issue |
|
`/move path/to/project`
| Moves issue to another project |
|
`/move path/to/project`
| Moves issue to another project |
|
`/tableflip`
| Append the comment with
`(╯°□°)╯︵ ┻━┻`
|
|
`/tableflip`
| Append the comment with
`(╯°□°)╯︵ ┻━┻`
|
|
`/shrug`
| Append the comment with
`¯\_(ツ)_/¯`
|
|
`/shrug`
| Append the comment with
`¯\_(ツ)_/¯`
|
|
<code>
/copy_metadata #issue
|
!merge_request
</code>
| Copy labels and milestone from other issue or merge request |
Note: In GitLab Starter every issue can have more than one assignee, so commands
`/assign`
,
`/unassign`
and
`/reassign`
Note: In GitLab Starter every issue can have more than one assignee, so commands
`/assign`
,
`/unassign`
and
`/reassign`
support multiple assignees.
support multiple assignees.
spec/services/quick_actions/interpret_service_spec.rb
View file @
1c652f03
# coding: utf-8
require
'spec_helper'
require
'spec_helper'
describe
QuickActions
::
InterpretService
do
describe
QuickActions
::
InterpretService
do
...
@@ -325,6 +326,23 @@ describe QuickActions::InterpretService do
...
@@ -325,6 +326,23 @@ describe QuickActions::InterpretService do
end
end
end
end
shared_examples
'copy_metadata command'
do
it
'fetches issue or merge request and copies labels and milestone if content contains /copy_metadata reference'
do
source_issuable
# populate the issue
todo_label
# populate this label
inreview_label
# populate this label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
[
:add_label_ids
]).
to
match_array
([
inreview_label
.
id
,
todo_label
.
id
])
if
source_issuable
.
milestone
expect
(
updates
[
:milestone_id
]).
to
eq
(
source_issuable
.
milestone
.
id
)
else
expect
(
updates
).
not_to
have_key
(
:milestone_id
)
end
end
end
shared_examples
'shrug command'
do
shared_examples
'shrug command'
do
it
'appends ¯\_(ツ)_/¯ to the comment'
do
it
'appends ¯\_(ツ)_/¯ to the comment'
do
new_content
,
_
=
service
.
execute
(
content
,
issuable
)
new_content
,
_
=
service
.
execute
(
content
,
issuable
)
...
@@ -833,6 +851,65 @@ describe QuickActions::InterpretService do
...
@@ -833,6 +851,65 @@ describe QuickActions::InterpretService do
end
end
end
end
context
'/copy_metadata command'
do
let
(
:todo_label
)
{
create
(
:label
,
project:
project
,
title:
'To Do'
)
}
let
(
:inreview_label
)
{
create
(
:label
,
project:
project
,
title:
'In Review'
)
}
it_behaves_like
'empty command'
do
let
(
:content
)
{
'/copy_metadata'
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'copy_metadata command'
do
let
(
:source_issuable
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
inreview_label
,
todo_label
])
}
let
(
:content
)
{
"/copy_metadata
#{
source_issuable
.
to_reference
}
"
}
let
(
:issuable
)
{
issue
}
end
context
'when the parent issuable has a milestone'
do
it_behaves_like
'copy_metadata command'
do
let
(
:source_issuable
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
todo_label
,
inreview_label
],
milestone:
milestone
)
}
let
(
:content
)
{
"/copy_metadata
#{
source_issuable
.
to_reference
(
project
)
}
"
}
let
(
:issuable
)
{
issue
}
end
end
context
'when more than one issuable is passed'
do
it_behaves_like
'copy_metadata command'
do
let
(
:source_issuable
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
inreview_label
,
todo_label
])
}
let
(
:other_label
)
{
create
(
:label
,
project:
project
,
title:
'Other'
)
}
let
(
:other_source_issuable
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
other_label
])
}
let
(
:content
)
{
"/copy_metadata
#{
source_issuable
.
to_reference
}
#{
other_source_issuable
.
to_reference
}
"
}
let
(
:issuable
)
{
issue
}
end
end
context
'cross project references'
do
it_behaves_like
'empty command'
do
let
(
:other_project
)
{
create
(
:project
,
:public
)
}
let
(
:source_issuable
)
{
create
(
:labeled_issue
,
project:
other_project
,
labels:
[
todo_label
,
inreview_label
])
}
let
(
:content
)
{
"/copy_metadata
#{
source_issuable
.
to_reference
(
project
)
}
"
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'empty command'
do
let
(
:content
)
{
"/copy_metadata imaginary#1234"
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'empty command'
do
let
(
:other_project
)
{
create
(
:project
,
:private
)
}
let
(
:source_issuable
)
{
create
(
:issue
,
project:
other_project
)
}
let
(
:content
)
{
"/copy_metadata
#{
source_issuable
.
to_reference
(
project
)
}
"
}
let
(
:issuable
)
{
issue
}
end
end
end
context
'/duplicate command'
do
context
'/duplicate command'
do
it_behaves_like
'duplicate command'
do
it_behaves_like
'duplicate command'
do
let
(
:issue_duplicate
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue_duplicate
)
{
create
(
:issue
,
project:
project
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment