BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
424c7cf9
Commit
424c7cf9
authored
Apr 28, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '28457-slash-command-board-move' into 'master'
Add board_move slash command Closes #28457 See merge request !10433
parents
f2d637f7
85bb4d6b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
107 additions
and
9 deletions
+107
-9
label.rb
app/models/label.rb
+1
-0
move_service.rb
app/services/boards/issues/move_service.rb
+1
-1
interpret_service.rb
app/services/slash_commands/interpret_service.rb
+22
-0
28457-slash-command-board-move.yml
changelogs/unreleased/28457-slash-command-board-move.yml
+4
-0
slash_commands.md
doc/user/project/slash_commands.md
+1
-0
interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+78
-8
No files found.
app/models/label.rb
View file @
424c7cf9
...
...
@@ -34,6 +34,7 @@ class Label < ActiveRecord::Base
scope
:templates
,
->
{
where
(
template:
true
)
}
scope
:with_title
,
->
(
title
)
{
where
(
title:
title
)
}
scope
:on_project_boards
,
->
(
project_id
)
{
joins
(
lists: :board
).
merge
(
List
.
movable
).
where
(
boards:
{
project_id:
project_id
})
}
def
self
.
prioritized
(
project
)
joins
(
:priorities
)
...
...
app/services/boards/issues/move_service.rb
View file @
424c7cf9
...
...
@@ -61,7 +61,7 @@ module Boards
if
moving_to_list
.
movable?
moving_from_list
.
label_id
else
project
.
boards
.
joins
(
:lists
).
merge
(
List
.
movable
).
pluck
(
:label_id
)
Label
.
on_project_boards
(
project
.
id
).
pluck
(
:label_id
)
end
Array
(
label_ids
).
compact
...
...
app/services/slash_commands/interpret_service.rb
View file @
424c7cf9
...
...
@@ -330,6 +330,28 @@ module SlashCommands
@updates
[
:target_branch
]
=
branch_name
if
project
.
repository
.
branch_names
.
include?
(
branch_name
)
end
desc
'Move issue from one column of the board to another'
params
'~"Target column"'
condition
do
issuable
.
is_a?
(
Issue
)
&&
current_user
.
can?
(
:"update_
#{
issuable
.
to_ability_name
}
"
,
issuable
)
&&
issuable
.
project
.
boards
.
count
==
1
end
command
:board_move
do
|
target_list_name
|
label_ids
=
find_label_ids
(
target_list_name
)
if
label_ids
.
size
==
1
label_id
=
label_ids
.
first
# Ensure this label corresponds to a list on the board
next
unless
Label
.
on_project_boards
(
issuable
.
project_id
).
where
(
id:
label_id
).
exists?
@updates
[
:remove_label_ids
]
=
issuable
.
labels
.
on_project_boards
(
issuable
.
project_id
).
where
.
not
(
id:
label_id
).
pluck
(
:id
)
@updates
[
:add_label_ids
]
=
[
label_id
]
end
end
def
find_label_ids
(
labels_param
)
label_ids_by_reference
=
extract_references
(
labels_param
,
:label
).
map
(
&
:id
)
labels_ids_by_name
=
LabelsFinder
.
new
(
current_user
,
project_id:
project
.
id
,
name:
labels_param
.
split
).
execute
.
select
(
:id
)
...
...
changelogs/unreleased/28457-slash-command-board-move.yml
0 → 100644
View file @
424c7cf9
---
title
:
Add board_move slash command
merge_request
:
10433
author
:
Alex Sanford
doc/user/project/slash_commands.md
View file @
424c7cf9
...
...
@@ -36,3 +36,4 @@ do.
|
`/remove_time_spent`
| Remove time spent |
|
`/target_branch <Branch Name>`
| Set target branch for current merge request |
|
`/award :emoji:`
| Toggle award for :emoji: |
|
`/board_move ~column`
| Move issue to column on the board |
spec/services/slash_commands/interpret_service_spec.rb
View file @
424c7cf9
...
...
@@ -52,7 +52,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'unassign command'
do
it
'populates assignee_id: nil if content contains /unassign'
do
issuable
.
update
(
assignee_id:
developer
.
id
)
issuable
.
update
!
(
assignee_id:
developer
.
id
)
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
assignee_id:
nil
)
...
...
@@ -70,7 +70,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'remove_milestone command'
do
it
'populates milestone_id: nil if content contains /remove_milestone'
do
issuable
.
update
(
milestone_id:
milestone
.
id
)
issuable
.
update
!
(
milestone_id:
milestone
.
id
)
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
milestone_id:
nil
)
...
...
@@ -108,7 +108,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'unlabel command'
do
it
'fetches label ids and populates remove_label_ids if content contains /unlabel'
do
issuable
.
update
(
label_ids:
[
inprogress
.
id
])
# populate the label
issuable
.
update
!
(
label_ids:
[
inprogress
.
id
])
# populate the label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
remove_label_ids:
[
inprogress
.
id
])
...
...
@@ -117,7 +117,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'multiple unlabel command'
do
it
'fetches label ids and populates remove_label_ids if content contains mutiple /unlabel'
do
issuable
.
update
(
label_ids:
[
inprogress
.
id
,
bug
.
id
])
# populate the label
issuable
.
update
!
(
label_ids:
[
inprogress
.
id
,
bug
.
id
])
# populate the label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
remove_label_ids:
[
inprogress
.
id
,
bug
.
id
])
...
...
@@ -126,7 +126,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'unlabel command with no argument'
do
it
'populates label_ids: [] if content contains /unlabel with no arguments'
do
issuable
.
update
(
label_ids:
[
inprogress
.
id
])
# populate the label
issuable
.
update
!
(
label_ids:
[
inprogress
.
id
])
# populate the label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
label_ids:
[])
...
...
@@ -135,7 +135,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'relabel command'
do
it
'populates label_ids: [] if content contains /relabel'
do
issuable
.
update
(
label_ids:
[
bug
.
id
])
# populate the label
issuable
.
update
!
(
label_ids:
[
bug
.
id
])
# populate the label
inprogress
# populate the label
_
,
updates
=
service
.
execute
(
content
,
issuable
)
...
...
@@ -187,7 +187,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'remove_due_date command'
do
it
'populates due_date: nil if content contains /remove_due_date'
do
issuable
.
update
(
due_date:
Date
.
today
)
issuable
.
update
!
(
due_date:
Date
.
today
)
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
due_date:
nil
)
...
...
@@ -204,7 +204,7 @@ describe SlashCommands::InterpretService, services: true do
shared_examples
'unwip command'
do
it
'returns wip_event: "unwip" if content contains /wip'
do
issuable
.
update
(
title:
issuable
.
wip_title
)
issuable
.
update
!
(
title:
issuable
.
wip_title
)
_
,
updates
=
service
.
execute
(
content
,
issuable
)
expect
(
updates
).
to
eq
(
wip_event:
'unwip'
)
...
...
@@ -727,5 +727,75 @@ describe SlashCommands::InterpretService, services: true do
end
end
end
context
'/board_move command'
do
let
(
:todo
)
{
create
(
:label
,
project:
project
,
title:
'To Do'
)
}
let
(
:inreview
)
{
create
(
:label
,
project:
project
,
title:
'In Review'
)
}
let
(
:content
)
{
%{/board_move ~"#{inreview.title}"}
}
let!
(
:board
)
{
create
(
:board
,
project:
project
)
}
let!
(
:todo_list
)
{
create
(
:list
,
board:
board
,
label:
todo
)
}
let!
(
:inreview_list
)
{
create
(
:list
,
board:
board
,
label:
inreview
)
}
let!
(
:inprogress_list
)
{
create
(
:list
,
board:
board
,
label:
inprogress
)
}
it
'populates remove_label_ids for all current board columns'
do
issue
.
update!
(
label_ids:
[
todo
.
id
,
inprogress
.
id
])
_
,
updates
=
service
.
execute
(
content
,
issue
)
expect
(
updates
[
:remove_label_ids
]).
to
match_array
([
todo
.
id
,
inprogress
.
id
])
end
it
'populates add_label_ids with the id of the given label'
do
_
,
updates
=
service
.
execute
(
content
,
issue
)
expect
(
updates
[
:add_label_ids
]).
to
eq
([
inreview
.
id
])
end
it
'does not include the given label id in remove_label_ids'
do
issue
.
update!
(
label_ids:
[
todo
.
id
,
inreview
.
id
])
_
,
updates
=
service
.
execute
(
content
,
issue
)
expect
(
updates
[
:remove_label_ids
]).
to
match_array
([
todo
.
id
])
end
it
'does not remove label ids that are not lists on the board'
do
issue
.
update!
(
label_ids:
[
todo
.
id
,
bug
.
id
])
_
,
updates
=
service
.
execute
(
content
,
issue
)
expect
(
updates
[
:remove_label_ids
]).
to
match_array
([
todo
.
id
])
end
context
'if the project has multiple boards'
do
let
(
:issuable
)
{
issue
}
before
{
create
(
:board
,
project:
project
)
}
it_behaves_like
'empty command'
end
context
'if the given label does not exist'
do
let
(
:issuable
)
{
issue
}
let
(
:content
)
{
'/board_move ~"Fake Label"'
}
it_behaves_like
'empty command'
end
context
'if multiple labels are given'
do
let
(
:issuable
)
{
issue
}
let
(
:content
)
{
%{/board_move ~"#{inreview.title}" ~"#{todo.title}"}
}
it_behaves_like
'empty command'
end
context
'if the given label is not a list on the board'
do
let
(
:issuable
)
{
issue
}
let
(
:content
)
{
%{/board_move ~"#{bug.title}"}
}
it_behaves_like
'empty command'
end
context
'if issuable is not an Issue'
do
let
(
:issuable
)
{
merge_request
}
it_behaves_like
'empty command'
end
end
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