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
0544fb9f
Commit
0544fb9f
authored
Apr 13, 2021
by
Miranda Fluharty
Committed by
Phil Hughes
Apr 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements to the code quality badge in the MR diff file header
parent
cedff10d
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
236 additions
and
191 deletions
+236
-191
app/assets/javascripts/diffs/components/app.vue
app/assets/javascripts/diffs/components/app.vue
+6
-8
app/assets/javascripts/diffs/components/diff_file.vue
app/assets/javascripts/diffs/components/diff_file.vue
+4
-7
app/assets/javascripts/diffs/store/actions.js
app/assets/javascripts/diffs/store/actions.js
+0
-47
app/assets/javascripts/diffs/store/getters.js
app/assets/javascripts/diffs/store/getters.js
+0
-10
app/assets/javascripts/diffs/store/modules/diff_state.js
app/assets/javascripts/diffs/store/modules/diff_state.js
+0
-1
app/assets/javascripts/diffs/store/modules/index.js
app/assets/javascripts/diffs/store/modules/index.js
+3
-3
app/assets/javascripts/diffs/store/mutation_types.js
app/assets/javascripts/diffs/store/mutation_types.js
+0
-1
app/assets/javascripts/diffs/store/mutations.js
app/assets/javascripts/diffs/store/mutations.js
+0
-6
ee/app/assets/javascripts/diffs/components/code_quality_badge.vue
...ssets/javascripts/diffs/components/code_quality_badge.vue
+1
-1
ee/app/assets/javascripts/diffs/store/actions.js
ee/app/assets/javascripts/diffs/store/actions.js
+59
-0
ee/app/assets/javascripts/diffs/store/modules/diff_state.js
ee/app/assets/javascripts/diffs/store/modules/diff_state.js
+8
-0
ee/app/assets/javascripts/diffs/store/mutation_types.js
ee/app/assets/javascripts/diffs/store/mutation_types.js
+2
-0
ee/app/assets/javascripts/diffs/store/mutations.js
ee/app/assets/javascripts/diffs/store/mutations.js
+15
-0
ee/spec/frontend/diffs/components/diff_file_spec.js
ee/spec/frontend/diffs/components/diff_file_spec.js
+35
-25
ee/spec/frontend/diffs/store/actions_spec.js
ee/spec/frontend/diffs/store/actions_spec.js
+71
-0
ee/spec/frontend/diffs/store/mutations_spec.js
ee/spec/frontend/diffs/store/mutations_spec.js
+28
-0
locale/gitlab.pot
locale/gitlab.pot
+4
-1
spec/frontend/diffs/store/actions_spec.js
spec/frontend/diffs/store/actions_spec.js
+0
-48
spec/frontend/diffs/store/getters_spec.js
spec/frontend/diffs/store/getters_spec.js
+0
-20
spec/frontend/diffs/store/mutations_spec.js
spec/frontend/diffs/store/mutations_spec.js
+0
-13
No files found.
app/assets/javascripts/diffs/components/app.vue
View file @
0544fb9f
...
@@ -184,12 +184,7 @@ export default {
...
@@ -184,12 +184,7 @@ export default {
'
viewDiffsFileByFile
'
,
'
viewDiffsFileByFile
'
,
'
mrReviews
'
,
'
mrReviews
'
,
]),
]),
...
mapGetters
(
'
diffs
'
,
[
...
mapGetters
(
'
diffs
'
,
[
'
whichCollapsedTypes
'
,
'
isParallelView
'
,
'
currentDiffIndex
'
]),
'
whichCollapsedTypes
'
,
'
isParallelView
'
,
'
currentDiffIndex
'
,
'
fileCodequalityDiff
'
,
]),
...
mapGetters
([
'
isNotesFetched
'
,
'
getNoteableData
'
]),
...
mapGetters
([
'
isNotesFetched
'
,
'
getNoteableData
'
]),
diffs
()
{
diffs
()
{
if
(
!
this
.
viewDiffsFileByFile
)
{
if
(
!
this
.
viewDiffsFileByFile
)
{
...
@@ -287,7 +282,6 @@ export default {
...
@@ -287,7 +282,6 @@ export default {
endpointMetadata
:
this
.
endpointMetadata
,
endpointMetadata
:
this
.
endpointMetadata
,
endpointBatch
:
this
.
endpointBatch
,
endpointBatch
:
this
.
endpointBatch
,
endpointCoverage
:
this
.
endpointCoverage
,
endpointCoverage
:
this
.
endpointCoverage
,
endpointCodequality
:
this
.
endpointCodequality
,
endpointUpdateUser
:
this
.
endpointUpdateUser
,
endpointUpdateUser
:
this
.
endpointUpdateUser
,
projectPath
:
this
.
projectPath
,
projectPath
:
this
.
projectPath
,
dismissEndpoint
:
this
.
dismissEndpoint
,
dismissEndpoint
:
this
.
dismissEndpoint
,
...
@@ -297,6 +291,10 @@ export default {
...
@@ -297,6 +291,10 @@ export default {
mrReviews
:
this
.
rehydratedMrReviews
,
mrReviews
:
this
.
rehydratedMrReviews
,
});
});
if
(
this
.
endpointCodequality
)
{
this
.
setCodequalityEndpoint
(
this
.
endpointCodequality
);
}
if
(
this
.
shouldShow
)
{
if
(
this
.
shouldShow
)
{
this
.
fetchData
();
this
.
fetchData
();
}
}
...
@@ -341,6 +339,7 @@ export default {
...
@@ -341,6 +339,7 @@ export default {
...
mapActions
(
'
diffs
'
,
[
...
mapActions
(
'
diffs
'
,
[
'
moveToNeighboringCommit
'
,
'
moveToNeighboringCommit
'
,
'
setBaseConfig
'
,
'
setBaseConfig
'
,
'
setCodequalityEndpoint
'
,
'
fetchDiffFilesMeta
'
,
'
fetchDiffFilesMeta
'
,
'
fetchDiffFilesBatch
'
,
'
fetchDiffFilesBatch
'
,
'
fetchCoverageFiles
'
,
'
fetchCoverageFiles
'
,
...
@@ -532,7 +531,6 @@ export default {
...
@@ -532,7 +531,6 @@ export default {
:help-page-path=
"helpPagePath"
:help-page-path=
"helpPagePath"
:can-current-user-fork=
"canCurrentUserFork"
:can-current-user-fork=
"canCurrentUserFork"
:view-diffs-file-by-file=
"viewDiffsFileByFile"
:view-diffs-file-by-file=
"viewDiffsFileByFile"
:codequality-diff=
"fileCodequalityDiff(file.file_path)"
/>
/>
<div
<div
v-if=
"showFileByFileNavigation"
v-if=
"showFileByFileNavigation"
...
...
app/assets/javascripts/diffs/components/diff_file.vue
View file @
0544fb9f
...
@@ -67,11 +67,6 @@ export default {
...
@@ -67,11 +67,6 @@ export default {
type
:
Boolean
,
type
:
Boolean
,
required
:
true
,
required
:
true
,
},
},
codequalityDiff
:
{
type
:
Array
,
required
:
false
,
default
:
()
=>
[],
},
},
},
data
()
{
data
()
{
return
{
return
{
...
@@ -85,7 +80,7 @@ export default {
...
@@ -85,7 +80,7 @@ export default {
genericError
:
GENERIC_ERROR
,
genericError
:
GENERIC_ERROR
,
},
},
computed
:
{
computed
:
{
...
mapState
(
'
diffs
'
,
[
'
currentDiffFileId
'
]),
...
mapState
(
'
diffs
'
,
[
'
currentDiffFileId
'
,
'
codequalityDiff
'
]),
...
mapGetters
([
'
isNotesFetched
'
]),
...
mapGetters
([
'
isNotesFetched
'
]),
...
mapGetters
(
'
diffs
'
,
[
'
getDiffFileDiscussions
'
]),
...
mapGetters
(
'
diffs
'
,
[
'
getDiffFileDiscussions
'
]),
viewBlobHref
()
{
viewBlobHref
()
{
...
@@ -154,7 +149,9 @@ export default {
...
@@ -154,7 +149,9 @@ export default {
return
loggedIn
&&
featureOn
;
return
loggedIn
&&
featureOn
;
},
},
hasCodequalityChanges
()
{
hasCodequalityChanges
()
{
return
this
.
codequalityDiff
.
length
>
0
;
return
(
this
.
codequalityDiff
?.
files
&&
this
.
codequalityDiff
?.
files
[
this
.
file
.
file_path
]?.
length
>
0
);
},
},
},
},
watch
:
{
watch
:
{
...
...
app/assets/javascripts/diffs/store/actions.js
View file @
0544fb9f
import
Cookies
from
'
js-cookie
'
;
import
Cookies
from
'
js-cookie
'
;
import
Visibility
from
'
visibilityjs
'
;
import
Vue
from
'
vue
'
;
import
Vue
from
'
vue
'
;
import
{
deprecatedCreateFlash
as
createFlash
}
from
'
~/flash
'
;
import
{
deprecatedCreateFlash
as
createFlash
}
from
'
~/flash
'
;
import
{
diffViewerModes
}
from
'
~/ide/constants
'
;
import
{
diffViewerModes
}
from
'
~/ide/constants
'
;
...
@@ -53,15 +52,12 @@ import {
...
@@ -53,15 +52,12 @@ import {
prepareLineForRenamedFile
,
prepareLineForRenamedFile
,
}
from
'
./utils
'
;
}
from
'
./utils
'
;
let
eTagPoll
;
export
const
setBaseConfig
=
({
commit
},
options
)
=>
{
export
const
setBaseConfig
=
({
commit
},
options
)
=>
{
const
{
const
{
endpoint
,
endpoint
,
endpointMetadata
,
endpointMetadata
,
endpointBatch
,
endpointBatch
,
endpointCoverage
,
endpointCoverage
,
endpointCodequality
,
endpointUpdateUser
,
endpointUpdateUser
,
projectPath
,
projectPath
,
dismissEndpoint
,
dismissEndpoint
,
...
@@ -75,7 +71,6 @@ export const setBaseConfig = ({ commit }, options) => {
...
@@ -75,7 +71,6 @@ export const setBaseConfig = ({ commit }, options) => {
endpointMetadata
,
endpointMetadata
,
endpointBatch
,
endpointBatch
,
endpointCoverage
,
endpointCoverage
,
endpointCodequality
,
endpointUpdateUser
,
endpointUpdateUser
,
projectPath
,
projectPath
,
dismissEndpoint
,
dismissEndpoint
,
...
@@ -238,48 +233,6 @@ export const fetchCoverageFiles = ({ commit, state }) => {
...
@@ -238,48 +233,6 @@ export const fetchCoverageFiles = ({ commit, state }) => {
coveragePoll
.
makeRequest
();
coveragePoll
.
makeRequest
();
};
};
export
const
clearEtagPoll
=
()
=>
{
eTagPoll
=
null
;
};
export
const
stopCodequalityPolling
=
()
=>
{
if
(
eTagPoll
)
eTagPoll
.
stop
();
};
export
const
restartCodequalityPolling
=
()
=>
{
if
(
eTagPoll
)
eTagPoll
.
restart
();
};
export
const
fetchCodequality
=
({
commit
,
state
,
dispatch
})
=>
{
eTagPoll
=
new
Poll
({
resource
:
{
getCodequalityDiffReports
:
(
endpoint
)
=>
axios
.
get
(
endpoint
),
},
data
:
state
.
endpointCodequality
,
method
:
'
getCodequalityDiffReports
'
,
successCallback
:
({
status
,
data
})
=>
{
if
(
status
===
httpStatusCodes
.
OK
)
{
commit
(
types
.
SET_CODEQUALITY_DATA
,
data
);
eTagPoll
.
stop
();
}
},
errorCallback
:
()
=>
createFlash
(
__
(
'
Something went wrong on our end. Please try again!
'
)),
});
if
(
!
Visibility
.
hidden
())
{
eTagPoll
.
makeRequest
();
}
Visibility
.
change
(()
=>
{
if
(
!
Visibility
.
hidden
())
{
dispatch
(
'
restartCodequalityPolling
'
);
}
else
{
dispatch
(
'
stopCodequalityPolling
'
);
}
});
};
export
const
setHighlightedRow
=
({
commit
},
lineCode
)
=>
{
export
const
setHighlightedRow
=
({
commit
},
lineCode
)
=>
{
const
fileHash
=
lineCode
.
split
(
'
_
'
)[
0
];
const
fileHash
=
lineCode
.
split
(
'
_
'
)[
0
];
commit
(
types
.
SET_HIGHLIGHTED_ROW
,
lineCode
);
commit
(
types
.
SET_HIGHLIGHTED_ROW
,
lineCode
);
...
...
app/assets/javascripts/diffs/store/getters.js
View file @
0544fb9f
...
@@ -135,16 +135,6 @@ export const fileLineCoverage = (state) => (file, line) => {
...
@@ -135,16 +135,6 @@ export const fileLineCoverage = (state) => (file, line) => {
return
{};
return
{};
};
};
/**
* Returns the codequality diff data for a given file
* @param {string} filePath
* @returns {Array}
*/
export
const
fileCodequalityDiff
=
(
state
)
=>
(
filePath
)
=>
{
if
(
!
state
.
codequalityDiff
.
files
||
!
state
.
codequalityDiff
.
files
[
filePath
])
return
[];
return
state
.
codequalityDiff
.
files
[
filePath
];
};
/**
/**
* Returns index of a currently selected diff in diffFiles
* Returns index of a currently selected diff in diffFiles
* @returns {number}
* @returns {number}
...
...
app/assets/javascripts/diffs/store/modules/diff_state.js
View file @
0544fb9f
...
@@ -29,7 +29,6 @@ export default () => ({
...
@@ -29,7 +29,6 @@ export default () => ({
startVersion
:
null
,
// Null unless a target diff is selected for comparison that is not the "base" diff
startVersion
:
null
,
// Null unless a target diff is selected for comparison that is not the "base" diff
diffFiles
:
[],
diffFiles
:
[],
coverageFiles
:
{},
coverageFiles
:
{},
codequalityDiff
:
{},
mergeRequestDiffs
:
[],
mergeRequestDiffs
:
[],
mergeRequestDiff
:
null
,
mergeRequestDiff
:
null
,
diffViewType
:
viewTypeFromQueryString
||
viewTypeFromCookie
||
defaultViewType
,
diffViewType
:
viewTypeFromQueryString
||
viewTypeFromCookie
||
defaultViewType
,
...
...
app/assets/javascripts/diffs/store/modules/index.js
View file @
0544fb9f
import
*
as
actions
from
'
../actions
'
;
import
*
as
actions
from
'
ee_else_ce/diffs/store/actions
'
;
import
createState
from
'
ee_else_ce/diffs/store/modules/diff_state
'
;
import
mutations
from
'
ee_else_ce/diffs/store/mutations
'
;
import
*
as
getters
from
'
../getters
'
;
import
*
as
getters
from
'
../getters
'
;
import
mutations
from
'
../mutations
'
;
import
createState
from
'
./diff_state
'
;
export
default
()
=>
({
export
default
()
=>
({
namespaced
:
true
,
namespaced
:
true
,
...
...
app/assets/javascripts/diffs/store/mutation_types.js
View file @
0544fb9f
...
@@ -11,7 +11,6 @@ export const SET_MR_FILE_REVIEWS = 'SET_MR_FILE_REVIEWS';
...
@@ -11,7 +11,6 @@ export const SET_MR_FILE_REVIEWS = 'SET_MR_FILE_REVIEWS';
export
const
SET_DIFF_VIEW_TYPE
=
'
SET_DIFF_VIEW_TYPE
'
;
export
const
SET_DIFF_VIEW_TYPE
=
'
SET_DIFF_VIEW_TYPE
'
;
export
const
SET_COVERAGE_DATA
=
'
SET_COVERAGE_DATA
'
;
export
const
SET_COVERAGE_DATA
=
'
SET_COVERAGE_DATA
'
;
export
const
SET_CODEQUALITY_DATA
=
'
SET_CODEQUALITY_DATA
'
;
export
const
SET_MERGE_REQUEST_DIFFS
=
'
SET_MERGE_REQUEST_DIFFS
'
;
export
const
SET_MERGE_REQUEST_DIFFS
=
'
SET_MERGE_REQUEST_DIFFS
'
;
export
const
TOGGLE_LINE_HAS_FORM
=
'
TOGGLE_LINE_HAS_FORM
'
;
export
const
TOGGLE_LINE_HAS_FORM
=
'
TOGGLE_LINE_HAS_FORM
'
;
export
const
ADD_CONTEXT_LINES
=
'
ADD_CONTEXT_LINES
'
;
export
const
ADD_CONTEXT_LINES
=
'
ADD_CONTEXT_LINES
'
;
...
...
app/assets/javascripts/diffs/store/mutations.js
View file @
0544fb9f
...
@@ -33,7 +33,6 @@ export default {
...
@@ -33,7 +33,6 @@ export default {
endpointMetadata
,
endpointMetadata
,
endpointBatch
,
endpointBatch
,
endpointCoverage
,
endpointCoverage
,
endpointCodequality
,
endpointUpdateUser
,
endpointUpdateUser
,
projectPath
,
projectPath
,
dismissEndpoint
,
dismissEndpoint
,
...
@@ -47,7 +46,6 @@ export default {
...
@@ -47,7 +46,6 @@ export default {
endpointMetadata
,
endpointMetadata
,
endpointBatch
,
endpointBatch
,
endpointCoverage
,
endpointCoverage
,
endpointCodequality
,
endpointUpdateUser
,
endpointUpdateUser
,
projectPath
,
projectPath
,
dismissEndpoint
,
dismissEndpoint
,
...
@@ -91,10 +89,6 @@ export default {
...
@@ -91,10 +89,6 @@ export default {
Object
.
assign
(
state
,
{
coverageFiles
});
Object
.
assign
(
state
,
{
coverageFiles
});
},
},
[
types
.
SET_CODEQUALITY_DATA
](
state
,
codequalityDiffData
)
{
Object
.
assign
(
state
,
{
codequalityDiff
:
codequalityDiffData
});
},
[
types
.
RENDER_FILE
](
state
,
file
)
{
[
types
.
RENDER_FILE
](
state
,
file
)
{
renderFile
(
file
);
renderFile
(
file
);
},
},
...
...
ee/app/assets/javascripts/diffs/components/code_quality_badge.vue
View file @
0544fb9f
...
@@ -12,7 +12,7 @@ export default {
...
@@ -12,7 +12,7 @@ export default {
i18n
:
{
i18n
:
{
badgeTitle
:
__
(
'
Code Quality
'
),
badgeTitle
:
__
(
'
Code Quality
'
),
badgeTooltip
:
__
(
badgeTooltip
:
__
(
'
The merge request has
been updated, and the number of code quality violations in this file has changed
.
'
,
'
The merge request has
made changes to this file that affect the number of code quality violations in it
.
'
,
),
),
},
},
};
};
...
...
ee/app/assets/javascripts/diffs/store/actions.js
0 → 100644
View file @
0544fb9f
import
Visibility
from
'
visibilityjs
'
;
import
createFlash
from
'
~/flash
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
httpStatusCodes
from
'
~/lib/utils/http_status
'
;
import
Poll
from
'
~/lib/utils/poll
'
;
import
{
__
}
from
'
~/locale
'
;
import
*
as
types
from
'
./mutation_types
'
;
export
*
from
'
~/diffs/store/actions
'
;
let
codequalityPoll
;
export
const
setCodequalityEndpoint
=
({
commit
},
endpoint
)
=>
{
commit
(
types
.
SET_CODEQUALITY_ENDPOINT
,
endpoint
);
};
export
const
clearCodequalityPoll
=
()
=>
{
codequalityPoll
=
null
;
};
export
const
stopCodequalityPolling
=
()
=>
{
if
(
codequalityPoll
)
codequalityPoll
.
stop
();
};
export
const
restartCodequalityPolling
=
()
=>
{
if
(
codequalityPoll
)
codequalityPoll
.
restart
();
};
export
const
fetchCodequality
=
({
commit
,
state
,
dispatch
})
=>
{
codequalityPoll
=
new
Poll
({
resource
:
{
getCodequalityDiffReports
:
(
endpoint
)
=>
axios
.
get
(
endpoint
),
},
data
:
state
.
endpointCodequality
,
method
:
'
getCodequalityDiffReports
'
,
successCallback
:
({
status
,
data
})
=>
{
if
(
status
===
httpStatusCodes
.
OK
)
{
commit
(
types
.
SET_CODEQUALITY_DATA
,
data
);
dispatch
(
'
stopCodequalityPolling
'
);
}
},
errorCallback
:
()
=>
createFlash
(
__
(
'
Something went wrong on our end while loading the code quality diff.
'
)),
});
if
(
!
Visibility
.
hidden
())
{
codequalityPoll
.
makeRequest
();
}
Visibility
.
change
(()
=>
{
if
(
!
Visibility
.
hidden
())
{
dispatch
(
'
restartCodequalityPolling
'
);
}
else
{
dispatch
(
'
stopCodequalityPolling
'
);
}
});
};
ee/app/assets/javascripts/diffs/store/modules/diff_state.js
0 → 100644
View file @
0544fb9f
import
createStateCE
from
'
~/diffs/store/modules/diff_state
'
;
export
default
()
=>
({
...
createStateCE
(),
endpointCodequality
:
''
,
codequalityDiff
:
{},
});
ee/app/assets/javascripts/diffs/store/mutation_types.js
0 → 100644
View file @
0544fb9f
export
const
SET_CODEQUALITY_ENDPOINT
=
'
SET_CODEQUALITY_ENDPOINT
'
;
export
const
SET_CODEQUALITY_DATA
=
'
SET_CODEQUALITY_DATA
'
;
ee/app/assets/javascripts/diffs/store/mutations.js
0 → 100644
View file @
0544fb9f
import
CEMutations
from
'
~/diffs/store/mutations
'
;
import
*
as
types
from
'
./mutation_types
'
;
export
default
{
...
CEMutations
,
[
types
.
SET_CODEQUALITY_ENDPOINT
](
state
,
endpoint
)
{
Object
.
assign
(
state
,
{
endpointCodequality
:
endpoint
});
},
[
types
.
SET_CODEQUALITY_DATA
](
state
,
codequalityDiffData
)
{
Object
.
assign
(
state
,
{
codequalityDiff
:
codequalityDiffData
});
},
};
ee/spec/frontend/diffs/components/diff_file_spec.js
View file @
0544fb9f
import
{
shallowM
ount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
m
ount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
Vuex
from
'
vuex
'
;
import
Vuex
from
'
vuex
'
;
import
CodeQualityBadge
from
'
ee/diffs/components/code_quality_badge.vue
'
;
import
CodeQualityBadge
from
'
ee/diffs/components/code_quality_badge.vue
'
;
...
@@ -9,7 +9,7 @@ import createDiffsStore from '~/diffs/store/modules';
...
@@ -9,7 +9,7 @@ import createDiffsStore from '~/diffs/store/modules';
const
getReadableFile
=
()
=>
JSON
.
parse
(
JSON
.
stringify
(
diffFileMockDataReadable
));
const
getReadableFile
=
()
=>
JSON
.
parse
(
JSON
.
stringify
(
diffFileMockDataReadable
));
function
createComponent
({
first
=
false
,
last
=
false
,
options
=
{},
props
=
{}
})
{
function
createComponent
({
withCodequality
=
true
})
{
const
file
=
getReadableFile
();
const
file
=
getReadableFile
();
const
localVue
=
createLocalVue
();
const
localVue
=
createLocalVue
();
...
@@ -23,18 +23,31 @@ function createComponent({ first = false, last = false, options = {}, props = {}
...
@@ -23,18 +23,31 @@ function createComponent({ first = false, last = false, options = {}, props = {}
store
.
state
.
diffs
.
diffFiles
=
[
file
];
store
.
state
.
diffs
.
diffFiles
=
[
file
];
const
wrapper
=
shallowMount
(
DiffFileComponent
,
{
if
(
withCodequality
)
{
store
.
state
.
diffs
.
codequalityDiff
=
{
files
:
{
[
file
.
file_path
]:
[
{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
},
{
line
:
3
,
description
:
'
Arrow function has too many statements (52). Maximum allowed is 30.
'
,
severity
:
'
minor
'
,
},
],
},
};
}
const
wrapper
=
mount
(
DiffFileComponent
,
{
store
,
store
,
localVue
,
localVue
,
propsData
:
{
propsData
:
{
file
,
file
,
canCurrentUserFork
:
false
,
canCurrentUserFork
:
false
,
viewDiffsFileByFile
:
false
,
viewDiffsFileByFile
:
false
,
isFirstFile
:
first
,
isFirstFile
:
false
,
isLastFile
:
last
,
isLastFile
:
false
,
...
props
,
},
},
...
options
,
});
});
return
{
return
{
...
@@ -52,27 +65,24 @@ describe('EE DiffFile', () => {
...
@@ -52,27 +65,24 @@ describe('EE DiffFile', () => {
});
});
describe
(
'
code quality badge
'
,
()
=>
{
describe
(
'
code quality badge
'
,
()
=>
{
it
(
'
is shown when there is diff data for the file
'
,
()
=>
{
describe
(
'
when there is diff data for the file
'
,
()
=>
{
({
wrapper
}
=
createComponent
({
beforeEach
(()
=>
{
props
:
{
({
wrapper
}
=
createComponent
({
withCodequality
:
true
}));
codequalityDiff
:
[
});
{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
},
{
it
(
'
shows the code quality badge
'
,
()
=>
{
line
:
3
,
expect
(
wrapper
.
find
(
CodeQualityBadge
).
exists
()).
toBe
(
true
);
description
:
'
Arrow function has too many statements (52). Maximum allowed is 30.
'
,
});
severity
:
'
minor
'
,
},
],
},
}));
expect
(
wrapper
.
find
(
CodeQualityBadge
)).
toExist
();
});
});
it
(
'
is not shown when there is no diff data for the file
'
,
()
=>
{
describe
(
'
when there is no diff data for the file
'
,
()
=>
{
({
wrapper
}
=
createComponent
({}));
beforeEach
(()
=>
{
({
wrapper
}
=
createComponent
({
withCodequality
:
false
}));
});
expect
(
wrapper
.
find
(
CodeQualityBadge
)).
toExist
();
it
(
'
does not show the code quality badge
'
,
()
=>
{
expect
(
wrapper
.
find
(
CodeQualityBadge
).
exists
()).
toBe
(
false
);
});
});
});
});
});
});
});
ee/spec/frontend/diffs/store/actions_spec.js
0 → 100644
View file @
0544fb9f
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
{
setCodequalityEndpoint
,
clearCodequalityPoll
,
stopCodequalityPolling
,
fetchCodequality
,
}
from
'
ee/diffs/store/actions
'
;
import
*
as
types
from
'
ee/diffs/store/mutation_types
'
;
import
testAction
from
'
helpers/vuex_action_helper
'
;
import
createFlash
from
'
~/flash
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
jest
.
mock
(
'
~/flash
'
);
describe
(
'
EE DiffsStoreActions
'
,
()
=>
{
describe
(
'
setCodequalityEndpoint
'
,
()
=>
{
it
(
'
should set given endpoint
'
,
(
done
)
=>
{
const
endpoint
=
'
/codequality_mr_diff.json
'
;
testAction
(
setCodequalityEndpoint
,
{
endpoint
},
{},
[{
type
:
types
.
SET_CODEQUALITY_ENDPOINT
,
payload
:
{
endpoint
}
}],
[],
done
,
);
});
});
describe
(
'
fetchCodequality
'
,
()
=>
{
let
mock
;
const
endpoint
=
'
/codequality_mr_diff.json
'
;
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
stopCodequalityPolling
();
clearCodequalityPoll
();
});
it
(
'
should commit SET_CODEQUALITY_DATA with received response and stop polling
'
,
(
done
)
=>
{
const
data
=
{
files
:
{
'
app.js
'
:
[{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
}]
},
};
mock
.
onGet
(
endpoint
).
reply
(
200
,
{
data
});
testAction
(
fetchCodequality
,
{},
{
endpointCodequality
:
endpoint
},
[{
type
:
types
.
SET_CODEQUALITY_DATA
,
payload
:
{
data
}
}],
[{
type
:
'
stopCodequalityPolling
'
}],
done
,
);
});
it
(
'
should show flash on API error
'
,
(
done
)
=>
{
mock
.
onGet
(
endpoint
).
reply
(
400
);
testAction
(
fetchCodequality
,
{},
{
endpoint
},
[],
[],
()
=>
{
expect
(
createFlash
).
toHaveBeenCalledTimes
(
1
);
expect
(
createFlash
).
toHaveBeenCalledWith
(
expect
.
stringMatching
(
'
Something went wrong
'
));
done
();
});
});
});
});
ee/spec/frontend/diffs/store/mutations_spec.js
0 → 100644
View file @
0544fb9f
import
*
as
types
from
'
ee/diffs/store/mutation_types
'
;
import
mutations
from
'
ee/diffs/store/mutations
'
;
describe
(
'
EE DiffsStoreMutations
'
,
()
=>
{
describe
(
'
SET_CODEQUALITY_ENDPOINT
'
,
()
=>
{
it
(
'
sets the endpoint into state
'
,
()
=>
{
const
state
=
{};
const
endpoint
=
'
/codequality_mr_diff.json
'
;
mutations
[
types
.
SET_CODEQUALITY_ENDPOINT
](
state
,
endpoint
);
expect
(
state
.
endpointCodequality
).
toEqual
(
endpoint
);
});
});
describe
(
'
SET_CODEQUALITY_DATA
'
,
()
=>
{
it
(
'
should set codequality data
'
,
()
=>
{
const
state
=
{
codequalityDiff
:
{}
};
const
codequality
=
{
files
:
{
'
app.js
'
:
[{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
}]
},
};
mutations
[
types
.
SET_CODEQUALITY_DATA
](
state
,
codequality
);
expect
(
state
.
codequalityDiff
).
toEqual
(
codequality
);
});
});
});
locale/gitlab.pot
View file @
0544fb9f
...
@@ -28900,6 +28900,9 @@ msgstr ""
...
@@ -28900,6 +28900,9 @@ msgstr ""
msgid "Something went wrong on our end"
msgid "Something went wrong on our end"
msgstr ""
msgstr ""
msgid "Something went wrong on our end while loading the code quality diff."
msgstr ""
msgid "Something went wrong on our end."
msgid "Something went wrong on our end."
msgstr ""
msgstr ""
...
@@ -30856,7 +30859,7 @@ msgstr ""
...
@@ -30856,7 +30859,7 @@ msgstr ""
msgid "The merge request can now be merged."
msgid "The merge request can now be merged."
msgstr ""
msgstr ""
msgid "The merge request has
been updated, and the number of code quality violations in this file has changed
."
msgid "The merge request has
made changes to this file that affect the number of code quality violations in it
."
msgstr ""
msgstr ""
msgid "The metric must be one of %{metrics}."
msgid "The metric must be one of %{metrics}."
...
...
spec/frontend/diffs/store/actions_spec.js
View file @
0544fb9f
...
@@ -17,9 +17,6 @@ import {
...
@@ -17,9 +17,6 @@ import {
fetchDiffFilesBatch
,
fetchDiffFilesBatch
,
fetchDiffFilesMeta
,
fetchDiffFilesMeta
,
fetchCoverageFiles
,
fetchCoverageFiles
,
clearEtagPoll
,
stopCodequalityPolling
,
fetchCodequality
,
assignDiscussionsToDiff
,
assignDiscussionsToDiff
,
removeDiscussionsFromDiff
,
removeDiscussionsFromDiff
,
startRenderDiffsQueue
,
startRenderDiffsQueue
,
...
@@ -101,7 +98,6 @@ describe('DiffsStoreActions', () => {
...
@@ -101,7 +98,6 @@ describe('DiffsStoreActions', () => {
const
endpointMetadata
=
'
/diffs/set/endpoint/metadata
'
;
const
endpointMetadata
=
'
/diffs/set/endpoint/metadata
'
;
const
endpointBatch
=
'
/diffs/set/endpoint/batch
'
;
const
endpointBatch
=
'
/diffs/set/endpoint/batch
'
;
const
endpointCoverage
=
'
/diffs/set/coverage_reports
'
;
const
endpointCoverage
=
'
/diffs/set/coverage_reports
'
;
const
endpointCodequality
=
'
/diffs/set/codequality_diff
'
;
const
projectPath
=
'
/root/project
'
;
const
projectPath
=
'
/root/project
'
;
const
dismissEndpoint
=
'
/-/user_callouts
'
;
const
dismissEndpoint
=
'
/-/user_callouts
'
;
const
showSuggestPopover
=
false
;
const
showSuggestPopover
=
false
;
...
@@ -113,7 +109,6 @@ describe('DiffsStoreActions', () => {
...
@@ -113,7 +109,6 @@ describe('DiffsStoreActions', () => {
endpointBatch
,
endpointBatch
,
endpointMetadata
,
endpointMetadata
,
endpointCoverage
,
endpointCoverage
,
endpointCodequality
,
projectPath
,
projectPath
,
dismissEndpoint
,
dismissEndpoint
,
showSuggestPopover
,
showSuggestPopover
,
...
@@ -123,7 +118,6 @@ describe('DiffsStoreActions', () => {
...
@@ -123,7 +118,6 @@ describe('DiffsStoreActions', () => {
endpointBatch
:
''
,
endpointBatch
:
''
,
endpointMetadata
:
''
,
endpointMetadata
:
''
,
endpointCoverage
:
''
,
endpointCoverage
:
''
,
endpointCodequality
:
''
,
projectPath
:
''
,
projectPath
:
''
,
dismissEndpoint
:
''
,
dismissEndpoint
:
''
,
showSuggestPopover
:
true
,
showSuggestPopover
:
true
,
...
@@ -136,7 +130,6 @@ describe('DiffsStoreActions', () => {
...
@@ -136,7 +130,6 @@ describe('DiffsStoreActions', () => {
endpointMetadata
,
endpointMetadata
,
endpointBatch
,
endpointBatch
,
endpointCoverage
,
endpointCoverage
,
endpointCodequality
,
projectPath
,
projectPath
,
dismissEndpoint
,
dismissEndpoint
,
showSuggestPopover
,
showSuggestPopover
,
...
@@ -306,47 +299,6 @@ describe('DiffsStoreActions', () => {
...
@@ -306,47 +299,6 @@ describe('DiffsStoreActions', () => {
});
});
});
});
describe
(
'
fetchCodequality
'
,
()
=>
{
let
mock
;
const
endpointCodequality
=
'
/fetch
'
;
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
});
afterEach
(()
=>
{
stopCodequalityPolling
();
clearEtagPoll
();
});
it
(
'
should commit SET_CODEQUALITY_DATA with received response
'
,
(
done
)
=>
{
const
data
=
{
files
:
{
'
app.js
'
:
[{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
}]
},
};
mock
.
onGet
(
endpointCodequality
).
reply
(
200
,
{
data
});
testAction
(
fetchCodequality
,
{},
{
endpointCodequality
},
[{
type
:
types
.
SET_CODEQUALITY_DATA
,
payload
:
{
data
}
}],
[],
done
,
);
});
it
(
'
should show flash on API error
'
,
(
done
)
=>
{
mock
.
onGet
(
endpointCodequality
).
reply
(
400
);
testAction
(
fetchCodequality
,
{},
{
endpointCodequality
},
[],
[],
()
=>
{
expect
(
createFlash
).
toHaveBeenCalledTimes
(
1
);
expect
(
createFlash
).
toHaveBeenCalledWith
(
expect
.
stringMatching
(
'
Something went wrong
'
));
done
();
});
});
});
describe
(
'
setHighlightedRow
'
,
()
=>
{
describe
(
'
setHighlightedRow
'
,
()
=>
{
it
(
'
should mark currently selected diff and set lineHash and fileHash of highlightedRow
'
,
()
=>
{
it
(
'
should mark currently selected diff and set lineHash and fileHash of highlightedRow
'
,
()
=>
{
testAction
(
setHighlightedRow
,
'
ABC_123
'
,
{},
[
testAction
(
setHighlightedRow
,
'
ABC_123
'
,
{},
[
...
...
spec/frontend/diffs/store/getters_spec.js
View file @
0544fb9f
...
@@ -376,26 +376,6 @@ describe('Diffs Module Getters', () => {
...
@@ -376,26 +376,6 @@ describe('Diffs Module Getters', () => {
});
});
});
});
describe
(
'
fileCodequalityDiff
'
,
()
=>
{
beforeEach
(()
=>
{
Object
.
assign
(
localState
.
codequalityDiff
,
{
files
:
{
'
app.js
'
:
[{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
}]
},
});
});
it
(
'
returns empty array when no codequality data is available
'
,
()
=>
{
Object
.
assign
(
localState
.
codequalityDiff
,
{});
expect
(
getters
.
fileCodequalityDiff
(
localState
)(
'
test.js
'
)).
toEqual
([]);
});
it
(
'
returns array when codequality data is available for given file
'
,
()
=>
{
expect
(
getters
.
fileCodequalityDiff
(
localState
)(
'
app.js
'
)).
toEqual
([
{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
},
]);
});
});
describe
(
'
suggestionCommitMessage
'
,
()
=>
{
describe
(
'
suggestionCommitMessage
'
,
()
=>
{
let
rootState
;
let
rootState
;
...
...
spec/frontend/diffs/store/mutations_spec.js
View file @
0544fb9f
...
@@ -115,19 +115,6 @@ describe('DiffsStoreMutations', () => {
...
@@ -115,19 +115,6 @@ describe('DiffsStoreMutations', () => {
});
});
});
});
describe
(
'
SET_CODEQUALITY_DATA
'
,
()
=>
{
it
(
'
should set codequality data
'
,
()
=>
{
const
state
=
{
codequalityDiff
:
{}
};
const
codequality
=
{
files
:
{
'
app.js
'
:
[{
line
:
1
,
description
:
'
Unexpected alert.
'
,
severity
:
'
minor
'
}]
},
};
mutations
[
types
.
SET_CODEQUALITY_DATA
](
state
,
codequality
);
expect
(
state
.
codequalityDiff
).
toEqual
(
codequality
);
});
});
describe
(
'
SET_DIFF_VIEW_TYPE
'
,
()
=>
{
describe
(
'
SET_DIFF_VIEW_TYPE
'
,
()
=>
{
it
(
'
should set diff view type properly
'
,
()
=>
{
it
(
'
should set diff view type properly
'
,
()
=>
{
const
state
=
{};
const
state
=
{};
...
...
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