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
6d11e387
Commit
6d11e387
authored
Aug 09, 2018
by
Peter Leitzen
Committed by
Sean McGivern
Aug 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement QuickActions::TargetService
parent
aeabf075
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
113 additions
and
15 deletions
+113
-15
app/controllers/projects/autocomplete_sources_controller.rb
app/controllers/projects/autocomplete_sources_controller.rb
+4
-2
app/services/preview_markdown_service.rb
app/services/preview_markdown_service.rb
+2
-2
app/services/projects/autocomplete_service.rb
app/services/projects/autocomplete_service.rb
+0
-11
app/services/quick_actions/target_service.rb
app/services/quick_actions/target_service.rb
+32
-0
spec/services/quick_actions/target_service_spec.rb
spec/services/quick_actions/target_service_spec.rb
+75
-0
No files found.
app/controllers/projects/autocomplete_sources_controller.rb
View file @
6d11e387
class
Projects::AutocompleteSourcesController
<
Projects
::
ApplicationController
before_action
:load_autocomplete_service
before_action
:load_autocomplete_service
,
except:
[
:members
]
def
members
render
json:
::
Projects
::
ParticipantsService
.
new
(
@project
,
current_user
).
execute
(
target
)
...
...
@@ -32,6 +32,8 @@ class Projects::AutocompleteSourcesController < Projects::ApplicationController
end
def
target
@autocomplete_service
.
target
(
params
[
:type
],
params
[
:type_id
])
QuickActions
::
TargetService
.
new
(
project
,
current_user
)
.
execute
(
params
[
:type
],
params
[
:type_id
])
end
end
app/services/preview_markdown_service.rb
View file @
6d11e387
...
...
@@ -29,9 +29,9 @@ class PreviewMarkdownService < BaseService
end
def
find_commands_target
Projects
::
Autocomplete
Service
QuickActions
::
Target
Service
.
new
(
project
,
current_user
)
.
target
(
commands_target_type
,
commands_target_id
)
.
execute
(
commands_target_type
,
commands_target_id
)
end
def
commands_target_type
...
...
app/services/projects/autocomplete_service.rb
View file @
6d11e387
...
...
@@ -51,16 +51,5 @@ module Projects
QuickActions
::
InterpretService
.
new
(
project
,
current_user
).
available_commands
(
noteable
)
end
def
target
(
type
,
type_id
)
case
type
&
.
downcase
when
'issue'
IssuesFinder
.
new
(
current_user
,
project_id:
project
.
id
).
find_by
(
iid:
type_id
)
||
project
.
issues
.
build
when
'mergerequest'
MergeRequestsFinder
.
new
(
current_user
,
project_id:
project
.
id
).
find_by
(
iid:
type_id
)
||
project
.
merge_requests
.
build
when
'commit'
project
.
commit
(
type_id
)
end
end
end
end
app/services/quick_actions/target_service.rb
0 → 100644
View file @
6d11e387
# frozen_string_literal: true
module
QuickActions
class
TargetService
<
BaseService
def
execute
(
type
,
type_id
)
case
type
&
.
downcase
when
'issue'
issue
(
type_id
)
when
'mergerequest'
merge_request
(
type_id
)
when
'commit'
commit
(
type_id
)
end
end
private
def
issue
(
type_id
)
IssuesFinder
.
new
(
current_user
,
project_id:
project
.
id
).
find_by
(
iid:
type_id
)
||
project
.
issues
.
build
end
def
merge_request
(
type_id
)
MergeRequestsFinder
.
new
(
current_user
,
project_id:
project
.
id
).
find_by
(
iid:
type_id
)
||
project
.
merge_requests
.
build
end
def
commit
(
type_id
)
return
nil
unless
type_id
project
.
commit
(
type_id
)
end
end
end
spec/services/quick_actions/target_service_spec.rb
0 → 100644
View file @
6d11e387
require
'spec_helper'
describe
QuickActions
::
TargetService
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
before
do
project
.
add_maintainer
(
user
)
end
describe
'#execute'
do
shared_examples
'no target'
do
|
type_id
:|
it
'returns nil'
do
target
=
service
.
execute
(
type
,
type_id
)
expect
(
target
).
to
be_nil
end
end
shared_examples
'find target'
do
it
'returns the target'
do
found_target
=
service
.
execute
(
type
,
target_id
)
expect
(
found_target
).
to
eq
(
target
)
end
end
shared_examples
'build target'
do
|
type_id
:|
it
'builds a new target'
do
target
=
service
.
execute
(
type
,
type_id
)
expect
(
target
.
project
).
to
eq
(
project
)
expect
(
target
).
to
be_new_record
end
end
context
'for issue'
do
let
(
:target
)
{
create
(
:issue
,
project:
project
)
}
let
(
:target_id
)
{
target
.
iid
}
let
(
:type
)
{
'Issue'
}
it_behaves_like
'find target'
it_behaves_like
'build target'
,
type_id:
nil
it_behaves_like
'build target'
,
type_id:
-
1
end
context
'for merge request'
do
let
(
:target
)
{
create
(
:merge_request
,
source_project:
project
)
}
let
(
:target_id
)
{
target
.
iid
}
let
(
:type
)
{
'MergeRequest'
}
it_behaves_like
'find target'
it_behaves_like
'build target'
,
type_id:
nil
it_behaves_like
'build target'
,
type_id:
-
1
end
context
'for commit'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:target
)
{
project
.
commit
}
let
(
:target_id
)
{
target
.
sha
}
let
(
:type
)
{
'Commit'
}
it_behaves_like
'find target'
it_behaves_like
'no target'
,
type_id:
'invalid_sha'
it_behaves_like
'no target'
,
type_id:
nil
end
context
'for unknown type'
do
let
(
:type
)
{
'unknown'
}
it_behaves_like
'no target'
,
type_id: :unused
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