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
b0e56289
Commit
b0e56289
authored
Apr 25, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create RelatedIssues module namespace
parent
c438cc4c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
4 deletions
+51
-4
app/controllers/projects/related_issues_controller.rb
app/controllers/projects/related_issues_controller.rb
+1
-1
app/services/related_issues/create_service.rb
app/services/related_issues/create_service.rb
+47
-0
app/services/related_issues/list_service.rb
app/services/related_issues/list_service.rb
+0
-0
spec/controllers/projects/related_issues_controller_spec.rb
spec/controllers/projects/related_issues_controller_spec.rb
+2
-2
spec/services/related_issues/create_service_spec.rb
spec/services/related_issues/create_service_spec.rb
+1
-1
No files found.
app/controllers/projects/related_issues_controller.rb
View file @
b0e56289
...
...
@@ -11,7 +11,7 @@ module Projects
def
create
opts
=
{
issue_references:
params
[
:issue_references
]
}
result
=
CreateRelatedIssu
eService
.
new
(
issue
,
current_user
,
opts
).
execute
result
=
RelatedIssues
::
Creat
eService
.
new
(
issue
,
current_user
,
opts
).
execute
render
json:
result
,
status:
result
[
'http_status'
]
end
...
...
app/services/related_issues/create_service.rb
0 → 100644
View file @
b0e56289
module
RelatedIssues
class
CreateService
<
BaseService
def
initialize
(
issue
,
user
,
params
)
@issue
,
@current_user
,
@params
=
issue
,
user
,
params
.
dup
end
def
execute
if
referenced_issues
.
blank?
return
error
(
'No Issue found for given reference'
,
401
)
end
begin
create_related_issues!
rescue
=>
exception
return
error
(
exception
.
message
,
401
)
end
success
(
message:
"
#{
issues_sentence
(
referenced_issues
)
}
were successfully related"
)
end
private
def
create_related_issues!
RelatedIssue
.
transaction
do
referenced_issues
.
each
do
|
referenced_issue
|
RelatedIssue
.
create!
(
issue:
@issue
,
related_issue:
referenced_issue
)
end
end
end
def
referenced_issues
@referenced_issues
||=
begin
issue_references
=
params
[
:issue_references
]
text
=
issue_references
.
join
(
' '
)
extractor
=
Gitlab
::
ReferenceExtractor
.
new
(
@issue
.
project
,
@current_user
)
extractor
.
analyze
(
text
)
extractor
.
issues
end
end
def
issues_sentence
(
issues
)
issues
.
map
{
|
issue
|
issue
.
to_reference
(
@issue
.
project
)
}.
sort
.
to_sentence
end
end
end
app/services/related_issues/list_service.rb
0 → 100644
View file @
b0e56289
spec/controllers/projects/related_issues_controller_spec.rb
View file @
b0e56289
...
...
@@ -69,7 +69,7 @@ describe Projects::RelatedIssuesController, type: :controller do
end
describe
'POST #create'
do
let
(
:service
)
{
double
(
CreateRelatedIssu
eService
,
execute:
service_response
)
}
let
(
:service
)
{
double
(
RelatedIssues
::
Creat
eService
,
execute:
service_response
)
}
let
(
:service_response
)
{
{
'message'
=>
'yay'
}
}
let
(
:issue_references
)
{
double
}
let
(
:user_role
)
{
:developer
}
...
...
@@ -77,7 +77,7 @@ describe Projects::RelatedIssuesController, type: :controller do
before
do
project
.
team
<<
[
user
,
user_role
]
allow
(
CreateRelatedIssu
eService
).
to
receive
(
:new
)
allow
(
RelatedIssues
::
Creat
eService
).
to
receive
(
:new
)
.
with
(
issue
,
user
,
{
issue_references:
issue_references
})
.
and_return
(
service
)
end
...
...
spec/services/
create_related_issu
e_service_spec.rb
→
spec/services/
related_issues/creat
e_service_spec.rb
View file @
b0e56289
require
'spec_helper'
describe
CreateRelatedIssu
eService
,
service:
true
do
describe
RelatedIssues
::
Creat
eService
,
service:
true
do
describe
'#execute'
do
let
(
:namespace
)
{
create
:namespace
}
let
(
:project
)
{
create
:empty_project
,
namespace:
namespace
}
...
...
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