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
ef93144b
Commit
ef93144b
authored
Mar 21, 2018
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Break utils function for sast and codeclimate
parent
be832e63
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
62 deletions
+65
-62
ee/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js
...cripts/vue_merge_request_widget/stores/mr_widget_store.js
+3
-3
ee/app/assets/javascripts/vue_shared/security_reports/helpers/utils.js
.../javascripts/vue_shared/security_reports/helpers/utils.js
+45
-52
ee/changelogs/unreleased/4310-security-reports-break-utils.yml
...angelogs/unreleased/4310-security-reports-break-utils.yml
+5
-0
spec/javascripts/vue_shared/security_reports/helpers/utils_spec.js
...scripts/vue_shared/security_reports/helpers/utils_spec.js
+12
-7
No files found.
ee/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js
View file @
ef93144b
import
CEMergeRequestStore
from
'
~/vue_merge_request_widget/stores/mr_widget_store
'
;
import
{
parse
Issue
s
,
parse
CodeclimateMetric
s
,
filterByKey
,
setSastContainerReport
,
setSastReport
,
...
...
@@ -114,8 +114,8 @@ export default class MergeRequestStore extends CEMergeRequestStore {
}
compareCodeclimateMetrics
(
headIssues
,
baseIssues
,
headBlobPath
,
baseBlobPath
)
{
const
parsedHeadIssues
=
parse
Issue
s
(
headIssues
,
headBlobPath
);
const
parsedBaseIssues
=
parse
Issue
s
(
baseIssues
,
baseBlobPath
);
const
parsedHeadIssues
=
parse
CodeclimateMetric
s
(
headIssues
,
headBlobPath
);
const
parsedBaseIssues
=
parse
CodeclimateMetric
s
(
baseIssues
,
baseBlobPath
);
this
.
codeclimateMetrics
.
newIssues
=
filterByKey
(
parsedHeadIssues
,
...
...
ee/app/assets/javascripts/vue_shared/security_reports/helpers/utils.js
View file @
ef93144b
import
{
stripHtml
}
from
'
~/lib/utils/text_utility
'
;
/**
* Parses SAST and Codeclimate Issues into a common and reusable format
* to reuse the same vue component.
* [
* {
* name: String,
* priority: String,
* fingerprint: String,
* path: String,
* line: Number,
* urlPath: String
* }
* ]
* @param {array} issues
* @return {array}
*/
export
const
parseIssues
=
(
issues
=
[],
path
=
''
)
=>
issues
.
map
((
issue
)
=>
{
const
parsedIssue
=
{
name
:
issue
.
description
||
issue
.
message
,
...
issue
,
};
// code quality
if
(
issue
.
location
)
{
let
parseCodeQualityUrl
;
if
(
issue
.
location
.
path
)
{
parseCodeQualityUrl
=
`
${
path
}
/
${
issue
.
location
.
path
}
`
;
parsedIssue
.
path
=
issue
.
location
.
path
;
}
if
(
issue
.
location
.
lines
&&
issue
.
location
.
lines
.
begin
)
{
parsedIssue
.
line
=
issue
.
location
.
lines
.
begin
;
parseCodeQualityUrl
+=
`#L
${
issue
.
location
.
lines
.
begin
}
`
;
export
const
parseCodeclimateMetrics
=
(
issues
=
[],
path
=
''
)
=>
issues
.
map
(
issue
=>
{
const
parsedIssue
=
{
...
issue
,
name
:
issue
.
description
,
};
if
(
issue
.
location
)
{
let
parseCodeQualityUrl
;
if
(
issue
.
location
.
path
)
{
parseCodeQualityUrl
=
`
${
path
}
/
${
issue
.
location
.
path
}
`
;
parsedIssue
.
path
=
issue
.
location
.
path
;
if
(
issue
.
location
.
lines
&&
issue
.
location
.
lines
.
begin
)
{
parsedIssue
.
line
=
issue
.
location
.
lines
.
begin
;
parseCodeQualityUrl
+=
`#L
${
issue
.
location
.
lines
.
begin
}
`
;
}
parsedIssue
.
urlPath
=
parseCodeQualityUrl
;
}
}
parsedIssue
.
urlPath
=
parseCodeQualityUrl
;
// security
}
else
if
(
issue
.
file
)
{
let
parsedSecurityUrl
=
`
${
path
}
/
${
issue
.
file
}
`
;
parsedIssue
.
path
=
issue
.
file
;
if
(
issue
.
line
)
{
parsedSecurityUrl
+=
`#L
${
issue
.
line
}
`
;
}
parsedIssue
.
urlPath
=
parsedSecurityUrl
;
}
return
parsedIssue
;
});
return
parsedIssue
;
});
/**
* Maps SAST & Dependency scanning issues:
* { tool: String, message: String, url: String , cve: String ,
* file: String , solution: String, priority: String }
* to contain:
* { name: String, path: String, line: String, urlPath: String, priority: String }
* @param {Array} issues
* @param {String} path
*/
export
const
parseSastIssues
=
(
issues
=
[],
path
=
''
)
=>
issues
.
map
(
issue
=>
Object
.
assign
({},
issue
,
{
name
:
issue
.
message
,
path
:
issue
.
file
,
urlPath
:
issue
.
line
?
`
${
path
}
/
${
issue
.
file
}
#L
${
issue
.
line
}
`
:
`
${
path
}
/
${
issue
.
file
}
`
,
}),
);
/**
* Compares two arrays by the given key and returns the difference
...
...
@@ -105,8 +98,8 @@ export const setSastReport = (data = {}) => {
if
(
data
.
base
)
{
const
filterKey
=
'
cve
'
;
const
parsedHead
=
parseIssues
(
data
.
head
,
data
.
headBlobPath
);
const
parsedBase
=
parseIssues
(
data
.
base
,
data
.
baseBlobPath
);
const
parsedHead
=
parse
Sast
Issues
(
data
.
head
,
data
.
headBlobPath
);
const
parsedBase
=
parse
Sast
Issues
(
data
.
base
,
data
.
baseBlobPath
);
securityReport
.
newIssues
=
filterByKey
(
parsedHead
,
...
...
@@ -126,7 +119,7 @@ export const setSastReport = (data = {}) => {
filterKey
,
);
}
else
{
securityReport
.
newIssues
=
parseIssues
(
data
.
head
,
data
.
headBlobPath
);
securityReport
.
newIssues
=
parse
Sast
Issues
(
data
.
head
,
data
.
headBlobPath
);
}
return
securityReport
;
...
...
ee/changelogs/unreleased/4310-security-reports-break-utils.yml
0 → 100644
View file @
ef93144b
---
title
:
Breaks utils function to parse codeclimate and sast into separate functions
merge_request
:
author
:
type
:
other
spec/javascripts/vue_shared/security_reports/helpers/utils_spec.js
View file @
ef93144b
import
{
parseIssues
,
parseSastIssues
,
parseCodeclimateMetrics
,
parseSastContainer
,
setSastReport
,
setDastReport
,
...
...
@@ -19,16 +20,20 @@ import {
}
from
'
../mock_data
'
;
describe
(
'
security reports utils
'
,
()
=>
{
describe
(
'
parseIssues
'
,
()
=>
{
describe
(
'
parse
Sast
Issues
'
,
()
=>
{
it
(
'
should parse the received issues
'
,
()
=>
{
const
codequality
=
parseIssues
(
baseIssues
,
'
path
'
)[
0
];
const
security
=
parseSastIssues
(
sastIssues
,
'
path
'
)[
0
];
expect
(
security
.
name
).
toEqual
(
sastIssues
[
0
].
message
);
expect
(
security
.
path
).
toEqual
(
sastIssues
[
0
].
file
);
});
});
describe
(
'
parseCodeclimateMetrics
'
,
()
=>
{
it
(
'
should parse the received issues
'
,
()
=>
{
const
codequality
=
parseCodeclimateMetrics
(
baseIssues
,
'
path
'
)[
0
];
expect
(
codequality
.
name
).
toEqual
(
baseIssues
[
0
].
check_name
);
expect
(
codequality
.
path
).
toEqual
(
baseIssues
[
0
].
location
.
path
);
expect
(
codequality
.
line
).
toEqual
(
baseIssues
[
0
].
location
.
lines
.
begin
);
const
security
=
parseIssues
(
sastIssues
,
'
path
'
)[
0
];
expect
(
security
.
name
).
toEqual
(
sastIssues
[
0
].
message
);
expect
(
security
.
path
).
toEqual
(
sastIssues
[
0
].
file
);
});
});
...
...
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