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
cb2ee27d
Commit
cb2ee27d
authored
Jan 18, 2022
by
Jonathan Schafer
Committed by
Bob Van Landuyt
Jan 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for removed external issues before creation
Changelog: changed EE:true
parent
fc586beb
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
3 deletions
+49
-3
ee/app/models/vulnerabilities/external_issue_link.rb
ee/app/models/vulnerabilities/external_issue_link.rb
+2
-0
ee/app/services/vulnerability_external_issue_links/create_service.rb
...ices/vulnerability_external_issue_links/create_service.rb
+11
-0
ee/spec/models/vulnerabilities/external_issue_link_spec.rb
ee/spec/models/vulnerabilities/external_issue_link_spec.rb
+8
-0
ee/spec/services/vulnerability_external_issue_links/create_service_spec.rb
...vulnerability_external_issue_links/create_service_spec.rb
+28
-3
No files found.
ee/app/models/vulnerabilities/external_issue_link.rb
View file @
cb2ee27d
...
...
@@ -18,5 +18,7 @@ module Vulnerabilities
message:
N_
(
'already has a "created" issue link'
)
},
if: :created?
scope
:created_for_vulnerability
,
->
(
vulnerability
)
{
where
(
vulnerability:
vulnerability
,
link_type:
'created'
)
}
end
end
ee/app/services/vulnerability_external_issue_links/create_service.rb
View file @
cb2ee27d
...
...
@@ -13,6 +13,9 @@ module VulnerabilityExternalIssueLinks
def
execute
return
error
([
'External provider service is not configured to create issues.'
])
unless
external_provider_service
&
.
configured_to_create_issues_from_vulnerabilities?
remove_links_for_nonexistent_external_issues
return
error
(
external_issue_link
.
errors
.
full_messages
)
unless
external_issue_link
.
valid?
external_issue
=
create_external_issue
...
...
@@ -57,6 +60,14 @@ module VulnerabilityExternalIssueLinks
)
end
def
remove_links_for_nonexistent_external_issues
Vulnerabilities
::
ExternalIssueLink
.
created_for_vulnerability
(
vulnerability
).
each
do
|
link
|
unless
external_provider_service
.
find_issue
(
link
.
external_issue_key
)
link
.
destroy
end
end
end
def
success
ServiceResponse
.
success
(
payload:
{
record:
external_issue_link
})
end
...
...
ee/spec/models/vulnerabilities/external_issue_link_spec.rb
View file @
cb2ee27d
...
...
@@ -45,4 +45,12 @@ RSpec.describe Vulnerabilities::ExternalIssueLink do
end
end
end
describe
'created_for_vulnerability'
do
let_it_be
(
:external_links
)
{
create_list
(
:vulnerabilities_external_issue_link
,
2
,
:created
)
}
it
'gets external issue links for the specified vulnerability'
do
expect
(
described_class
.
created_for_vulnerability
(
external_links
.
first
.
vulnerability
).
take
).
to
eq
(
external_links
.
first
)
end
end
end
ee/spec/services/vulnerability_external_issue_links/create_service_spec.rb
View file @
cb2ee27d
...
...
@@ -38,10 +38,35 @@ RSpec.describe VulnerabilityExternalIssueLinks::CreateService do
create
(
:vulnerabilities_external_issue_link
,
vulnerability:
vulnerability
)
end
context
'and the external issue exists'
do
let!
(
:jira_issue
)
{
ExternalIssue
.
new
(
'JIRA-123'
,
project
)
}
before
do
allow
(
jira_integration
).
to
receive
(
:find_issue
).
and_return
(
jira_issue
)
end
it
{
is_expected
.
not_to
be_success
}
it
'returns response with error messages'
do
expect
(
subject
.
message
).
to
eq
([
'Vulnerability already has a "created" issue link'
])
expect
(
subject
.
message
).
to
match_array
([
'Vulnerability already has a "created" issue link'
])
end
end
context
'and the external issue does not exist'
do
let
(
:jira_issue_id
)
{
nil
}
let
(
:errors
)
{
{}
}
let
(
:jira_issue
)
{
double
(
has_errors?:
errors
.
present?
,
id:
jira_issue_id
,
errors:
errors
)
}
before
do
allow
(
jira_integration
).
to
receive
(
:create_issue
).
and_return
(
jira_issue
)
allow
(
jira_integration
).
to
receive
(
:find_issue
).
and_return
(
nil
)
end
it
'creates issue using jira service'
do
expect
(
jira_integration
).
to
receive
(
:create_issue
).
with
(
"Investigate vulnerability:
#{
vulnerability
.
title
}
"
,
kind_of
(
String
),
user
)
subject
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