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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
a0adf877
Commit
a0adf877
authored
Jan 21, 2018
by
Mateusz Bajorski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed command name to copy_metadata and added MR support
parent
4f10cad9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
32 deletions
+34
-32
app/services/quick_actions/interpret_service.rb
app/services/quick_actions/interpret_service.rb
+9
-7
changelogs/unreleased/add-inherit-command.yml
changelogs/unreleased/add-inherit-command.yml
+1
-1
doc/user/project/quick_actions.md
doc/user/project/quick_actions.md
+1
-1
spec/services/quick_actions/interpret_service_spec.rb
spec/services/quick_actions/interpret_service_spec.rb
+23
-23
No files found.
app/services/quick_actions/interpret_service.rb
View file @
a0adf877
...
...
@@ -268,18 +268,20 @@ module QuickActions
end
end
desc
'
Inherit (copy) labels and milestone from other issue
'
explanation
do
|
issue_id
|
"
Inherit (copy) labels and milestone from issue
\"
#{
issu
e_id
}
\"
."
desc
'
Copy labels and milestone from other issue or merge request
'
explanation
do
|
issue
able
_id
|
"
Copy labels and milestone from issue or merge_request
\"
#{
issueabl
e_id
}
\"
."
end
params
'
#issue
'
params
'
< #issue | !merge_request >
'
condition
do
issuable
.
persisted?
&&
current_user
.
can?
(
:"update_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
end
command
:inherit
do
|
issue_id
|
issue
=
extract_references
(
issue_id
,
:issue
).
first
if
issue
.
present?
&&
issue
.
project_id
==
issuable
.
project_id
command
:copy_metadata
do
|
issueable_id
|
reference_type
=
issueable_id
.
include?
(
"#"
)
?
:issue
:
:merge_request
issue
=
extract_references
(
issueable_id
,
reference_type
).
first
if
issue
.
present?
&&
issue
.
project
.
id
==
issuable
.
project
.
id
@updates
[
:add_label_ids
]
=
issue
.
labels
.
map
(
&
:id
)
@updates
[
:milestone_id
]
=
issue
.
milestone
.
id
if
issue
.
milestone
...
...
changelogs/unreleased/add-inherit-command.yml
View file @
a0adf877
---
title
:
Add Inherit quick action
merge_request
:
merge_request
:
16473
author
:
Mateusz Bajorski
type
:
added
doc/user/project/quick_actions.md
View file @
a0adf877
...
...
@@ -41,4 +41,4 @@ do.
|
`/move path/to/project`
| Moves issue to another project |
|
`/tableflip`
| Append the comment with
`(╯°□°)╯︵ ┻━┻`
|
|
`/shrug`
| Append the comment with
`¯\_(ツ)_/¯`
|
|
`/inherit #issue`
| Inherit (copy) labels and milestone from other issue
|
|
<code>
/copy_metadata
<
#issue
|
!merge_request
>
</code>
| copy_metadata labels and milestone from other issue or merge request
|
spec/services/quick_actions/interpret_service_spec.rb
View file @
a0adf877
...
...
@@ -306,17 +306,17 @@ describe QuickActions::InterpretService do
end
end
shared_examples
'
inherit
command'
do
it
'fetches issue
and copies labels and milestone if content contains /inherit issue_
reference'
do
issue_father
# populate the issue
shared_examples
'
copy_metadata
command'
do
it
'fetches issue
or merge request and copies labels and milestone if content contains /copy_metadata
reference'
do
issue
able
_father
# 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
issue_father
.
milestone
expect
(
updates
[
:milestone_id
]).
to
eq
(
issue_father
.
milestone
.
id
)
if
issue
able
_father
.
milestone
expect
(
updates
[
:milestone_id
]).
to
eq
(
issue
able
_father
.
milestone
.
id
)
else
expect
(
updates
).
not_to
have_key
(
:milestone_id
)
end
...
...
@@ -774,49 +774,49 @@ describe QuickActions::InterpretService do
let
(
:issuable
)
{
issue
}
end
context
'/
inherit
command'
do
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
'inherit command'
do
# Without milestone assignment
let
(
:issue_father
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
inreview_label
,
todo_label
])
}
let
(
:content
)
{
"/inherit
#{
issue_father
.
to_reference
}
"
}
it_behaves_like
'empty command'
do
let
(
:content
)
{
'/copy_metadata'
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'inherit command'
do
# With milestone assignment
let
(
:issue_father
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
todo_label
,
inreview_label
],
milestone:
milestone
)
}
it_behaves_like
'copy_metadata command'
do
let
(
:issueable_father
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
inreview_label
,
todo_label
])
}
let
(
:content
)
{
"/
inherit
#{
issue_father
.
to_reference
(
project
)
}
"
}
let
(
:content
)
{
"/
copy_metadata
#{
issueable_father
.
to_reference
}
"
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'empty command'
do
let
(
:content
)
{
'/inherit'
}
context
'when the parent issueable has a milestone'
do
it_behaves_like
'copy_metadata command'
do
let
(
:issueable_father
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
todo_label
,
inreview_label
],
milestone:
milestone
)
}
let
(
:content
)
{
"/copy_metadata
#{
issueable_father
.
to_reference
(
project
)
}
"
}
let
(
:issuable
)
{
issue
}
end
end
context
'cross project references'
do
it_behaves_like
'empty command'
do
let
(
:other_project
)
{
create
(
:project
,
:public
)
}
let
(
:issue_father
)
{
create
(
:labeled_issue
,
project:
other_project
,
labels:
[
todo_label
,
inreview_label
])
}
let
(
:content
)
{
"/
inherit
#{
issu
e_father
.
to_reference
(
project
)
}
"
}
let
(
:issue
able
_father
)
{
create
(
:labeled_issue
,
project:
other_project
,
labels:
[
todo_label
,
inreview_label
])
}
let
(
:content
)
{
"/
copy_metadata
#{
issueabl
e_father
.
to_reference
(
project
)
}
"
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'empty command'
do
let
(
:content
)
{
"/
inherit
imaginary#1234"
}
let
(
:content
)
{
"/
copy_metadata
imaginary#1234"
}
let
(
:issuable
)
{
issue
}
end
it_behaves_like
'empty command'
do
let
(
:other_project
)
{
create
(
:project
,
:private
)
}
let
(
:issue_father
)
{
create
(
:issue
,
project:
other_project
)
}
let
(
:issue
able
_father
)
{
create
(
:issue
,
project:
other_project
)
}
let
(
:content
)
{
"/
inherit
#{
issu
e_father
.
to_reference
(
project
)
}
"
}
let
(
:content
)
{
"/
copy_metadata
#{
issueabl
e_father
.
to_reference
(
project
)
}
"
}
let
(
:issuable
)
{
issue
}
end
end
...
...
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