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
5c9c86a3
Commit
5c9c86a3
authored
Dec 16, 2021
by
Frédéric Caplette
Committed by
Natalia Tepluhina
Dec 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restructure client queries in Pipeline editor
parent
074698af
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
161 additions
and
121 deletions
+161
-121
app/assets/javascripts/pipeline_editor/components/commit/commit_section.vue
...ipts/pipeline_editor/components/commit/commit_section.vue
+3
-0
app/assets/javascripts/pipeline_editor/components/file_nav/branch_switcher.vue
...s/pipeline_editor/components/file_nav/branch_switcher.vue
+22
-12
app/assets/javascripts/pipeline_editor/components/header/pipeline_status.vue
...pts/pipeline_editor/components/header/pipeline_status.vue
+3
-0
app/assets/javascripts/pipeline_editor/components/header/validation_segment.vue
.../pipeline_editor/components/header/validation_segment.vue
+3
-0
app/assets/javascripts/pipeline_editor/components/pipeline_editor_tabs.vue
...ripts/pipeline_editor/components/pipeline_editor_tabs.vue
+3
-0
app/assets/javascripts/pipeline_editor/graphql/queries/client/app_status.query.graphql
...ne_editor/graphql/queries/client/app_status.query.graphql
+3
-1
app/assets/javascripts/pipeline_editor/graphql/queries/client/current_branch.query.graphql
...ditor/graphql/queries/client/current_branch.query.graphql
+5
-1
app/assets/javascripts/pipeline_editor/graphql/queries/client/last_commit_branch.query.graphql
...r/graphql/queries/client/last_commit_branch.query.graphql
+5
-1
app/assets/javascripts/pipeline_editor/graphql/queries/client/pipeline_etag.query.graphql
...editor/graphql/queries/client/pipeline_etag.query.graphql
+3
-1
app/assets/javascripts/pipeline_editor/graphql/resolvers.js
app/assets/javascripts/pipeline_editor/graphql/resolvers.js
+34
-8
app/assets/javascripts/pipeline_editor/graphql/typedefs.graphql
...sets/javascripts/pipeline_editor/graphql/typedefs.graphql
+19
-3
app/assets/javascripts/pipeline_editor/index.js
app/assets/javascripts/pipeline_editor/index.js
+25
-7
app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue
...ssets/javascripts/pipeline_editor/pipeline_editor_app.vue
+6
-0
spec/features/projects/ci/editor_spec.rb
spec/features/projects/ci/editor_spec.rb
+11
-0
spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js
...peline_editor/components/file-nav/branch_switcher_spec.js
+16
-87
No files found.
app/assets/javascripts/pipeline_editor/components/commit/commit_section.vue
View file @
5c9c86a3
...
...
@@ -60,6 +60,9 @@ export default {
apollo
:
{
currentBranch
:
{
query
:
getCurrentBranch
,
update
(
data
)
{
return
data
.
workBranches
.
current
.
name
;
},
},
},
computed
:
{
...
...
app/assets/javascripts/pipeline_editor/components/file_nav/branch_switcher.vue
View file @
5c9c86a3
...
...
@@ -20,8 +20,8 @@ import {
}
from
'
~/pipeline_editor/constants
'
;
import
updateCurrentBranchMutation
from
'
~/pipeline_editor/graphql/mutations/client/update_current_branch.mutation.graphql
'
;
import
getAvailableBranchesQuery
from
'
~/pipeline_editor/graphql/queries/available_branches.query.graphql
'
;
import
getCurrentBranch
Query
from
'
~/pipeline_editor/graphql/queries/client/current_branch.query.graphql
'
;
import
getLastCommitBranch
Query
from
'
~/pipeline_editor/graphql/queries/client/last_commit_branch.query.graphql
'
;
import
getCurrentBranch
from
'
~/pipeline_editor/graphql/queries/client/current_branch.query.graphql
'
;
import
getLastCommitBranch
from
'
~/pipeline_editor/graphql/queries/client/last_commit_branch.query.graphql
'
;
export
default
{
i18n
:
{
...
...
@@ -61,8 +61,8 @@ export default {
},
data
()
{
return
{
branchSelected
:
null
,
availableBranches
:
[],
branchSelected
:
null
,
filteredBranches
:
[],
isSearchingBranches
:
false
,
pageLimit
:
this
.
paginationLimit
,
...
...
@@ -93,15 +93,25 @@ export default {
},
},
currentBranch
:
{
query
:
getCurrentBranchQuery
,
query
:
getCurrentBranch
,
update
(
data
)
{
return
data
.
workBranches
.
current
.
name
;
},
},
lastCommitBranch
:
{
query
:
getLastCommitBranchQuery
,
result
({
data
:
{
lastCommitBranch
}
})
{
if
(
lastCommitBranch
===
''
||
this
.
availableBranches
.
includes
(
lastCommitBranch
))
{
return
;
query
:
getLastCommitBranch
,
update
(
data
)
{
return
data
.
workBranches
.
lastCommit
.
name
;
},
result
({
data
})
{
if
(
data
)
{
const
{
name
:
lastCommitBranch
}
=
data
.
workBranches
.
lastCommit
;
if
(
lastCommitBranch
===
''
||
this
.
availableBranches
.
includes
(
lastCommitBranch
))
{
return
;
}
this
.
availableBranches
.
unshift
(
lastCommitBranch
);
}
this
.
availableBranches
.
unshift
(
lastCommitBranch
);
},
},
},
...
...
@@ -109,12 +119,12 @@ export default {
branches
()
{
return
this
.
searchTerm
.
length
>
0
?
this
.
filteredBranches
:
this
.
availableBranches
;
},
isBranchesLoading
()
{
return
this
.
$apollo
.
queries
.
availableBranches
.
loading
||
this
.
isSearchingBranches
;
},
enableBranchSwitcher
()
{
return
this
.
branches
.
length
>
0
||
this
.
searchTerm
.
length
>
0
;
},
isBranchesLoading
()
{
return
this
.
$apollo
.
queries
.
availableBranches
.
loading
||
this
.
isSearchingBranches
;
},
},
watch
:
{
shouldLoadNewBranch
(
flag
)
{
...
...
app/assets/javascripts/pipeline_editor/components/header/pipeline_status.vue
View file @
5c9c86a3
...
...
@@ -48,6 +48,9 @@ export default {
apollo
:
{
pipelineEtag
:
{
query
:
getPipelineEtag
,
update
(
data
)
{
return
data
.
etags
.
pipeline
;
},
},
pipeline
:
{
context
()
{
...
...
app/assets/javascripts/pipeline_editor/components/header/validation_segment.vue
View file @
5c9c86a3
...
...
@@ -43,6 +43,9 @@ export default {
apollo
:
{
appStatus
:
{
query
:
getAppStatus
,
update
(
data
)
{
return
data
.
app
.
status
;
},
},
},
computed
:
{
...
...
app/assets/javascripts/pipeline_editor/components/pipeline_editor_tabs.vue
View file @
5c9c86a3
...
...
@@ -91,6 +91,9 @@ export default {
apollo
:
{
appStatus
:
{
query
:
getAppStatus
,
update
(
data
)
{
return
data
.
app
.
status
;
},
},
},
computed
:
{
...
...
app/assets/javascripts/pipeline_editor/graphql/queries/client/app_status.query.graphql
View file @
5c9c86a3
query
getAppStatus
{
appStatus
@client
app
@client
{
status
}
}
app/assets/javascripts/pipeline_editor/graphql/queries/client/current_branch.query.graphql
View file @
5c9c86a3
query
getCurrentBranch
{
currentBranch
@client
workBranches
@client
{
current
{
name
}
}
}
app/assets/javascripts/pipeline_editor/graphql/queries/client/last_commit_branch.query.graphql
View file @
5c9c86a3
query
getLastCommitBranchQuery
{
lastCommitBranch
@client
workBranches
@client
{
lastCommit
{
name
}
}
}
app/assets/javascripts/pipeline_editor/graphql/queries/client/pipeline_etag.query.graphql
View file @
5c9c86a3
query
getPipelineEtag
{
pipelineEtag
@client
etags
@client
{
pipeline
}
}
app/assets/javascripts/pipeline_editor/graphql/resolvers.js
View file @
5c9c86a3
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
getAppStatus
from
'
./queries/client/app_status.query.graphql
'
;
import
getCurrentBranch
Query
from
'
./queries/client/current_branch.query.graphql
'
;
import
getLastCommitBranch
Query
from
'
./queries/client/last_commit_branch.query.graphql
'
;
import
getCurrentBranch
from
'
./queries/client/current_branch.query.graphql
'
;
import
getLastCommitBranch
from
'
./queries/client/last_commit_branch.query.graphql
'
;
import
getPipelineEtag
from
'
./queries/client/pipeline_etag.query.graphql
'
;
export
const
resolvers
=
{
...
...
@@ -35,25 +35,51 @@ export const resolvers = {
updateAppStatus
:
(
_
,
{
appStatus
},
{
cache
})
=>
{
cache
.
writeQuery
({
query
:
getAppStatus
,
data
:
{
appStatus
},
data
:
{
app
:
{
__typename
:
'
PipelineEditorApp
'
,
status
:
appStatus
,
},
},
});
},
updateCurrentBranch
:
(
_
,
{
currentBranch
},
{
cache
})
=>
{
cache
.
writeQuery
({
query
:
getCurrentBranchQuery
,
data
:
{
currentBranch
},
query
:
getCurrentBranch
,
data
:
{
workBranches
:
{
__typename
:
'
BranchList
'
,
current
:
{
__typename
:
'
WorkBranch
'
,
name
:
currentBranch
,
},
},
},
});
},
updateLastCommitBranch
:
(
_
,
{
lastCommitBranch
},
{
cache
})
=>
{
cache
.
writeQuery
({
query
:
getLastCommitBranchQuery
,
data
:
{
lastCommitBranch
},
query
:
getLastCommitBranch
,
data
:
{
workBranches
:
{
__typename
:
'
BranchList
'
,
lastCommit
:
{
__typename
:
'
WorkBranch
'
,
name
:
lastCommitBranch
,
},
},
},
});
},
updatePipelineEtag
:
(
_
,
{
pipelineEtag
},
{
cache
})
=>
{
cache
.
writeQuery
({
query
:
getPipelineEtag
,
data
:
{
pipelineEtag
},
data
:
{
etags
:
{
__typename
:
'
EtagValues
'
,
pipeline
:
pipelineEtag
,
},
},
});
},
},
...
...
app/assets/javascripts/pipeline_editor/graphql/typedefs.graphql
View file @
5c9c86a3
type
BlobContent
{
rawData
:
String
!
type
PipelineEditorApp
{
status
:
String
!
}
type
BranchList
{
current
:
WorkBranch
!
lastCommit
:
WorkBranch
!
}
type
EtagValues
{
pipeline
:
String
!
}
type
WorkBranch
{
name
:
String
!
commit
:
String
}
extend
type
Query
{
blobContent
:
BlobContent
app
:
PipelineEditorApp
etags
:
EtagValues
workBranches
:
BranchList
}
app/assets/javascripts/pipeline_editor/index.js
View file @
5c9c86a3
...
...
@@ -7,7 +7,7 @@ import { EDITOR_APP_STATUS_LOADING } from './constants';
import
{
CODE_SNIPPET_SOURCE_SETTINGS
}
from
'
./components/code_snippet_alert/constants
'
;
import
getCurrentBranch
from
'
./graphql/queries/client/current_branch.query.graphql
'
;
import
getAppStatus
from
'
./graphql/queries/client/app_status.query.graphql
'
;
import
getLastCommitBranch
Query
from
'
./graphql/queries/client/last_commit_branch.query.graphql
'
;
import
getLastCommitBranch
from
'
./graphql/queries/client/last_commit_branch.query.graphql
'
;
import
getPipelineEtag
from
'
./graphql/queries/client/pipeline_etag.query.graphql
'
;
import
{
resolvers
}
from
'
./graphql/resolvers
'
;
import
typeDefs
from
'
./graphql/typedefs.graphql
'
;
...
...
@@ -68,28 +68,46 @@ export const initPipelineEditor = (selector = '#js-pipeline-editor') => {
cache
.
writeQuery
({
query
:
getAppStatus
,
data
:
{
appStatus
:
EDITOR_APP_STATUS_LOADING
,
app
:
{
__typename
:
'
PipelineEditorApp
'
,
status
:
EDITOR_APP_STATUS_LOADING
,
},
},
});
cache
.
writeQuery
({
query
:
getCurrentBranch
,
data
:
{
currentBranch
:
initialBranchName
||
defaultBranch
,
workBranches
:
{
__typename
:
'
BranchList
'
,
current
:
{
__typename
:
'
WorkBranch
'
,
name
:
initialBranchName
||
defaultBranch
,
},
},
},
});
cache
.
writeQuery
({
query
:
get
PipelineEtag
,
query
:
get
LastCommitBranch
,
data
:
{
pipelineEtag
,
workBranches
:
{
__typename
:
'
BranchList
'
,
lastCommit
:
{
__typename
:
'
WorkBranch
'
,
name
:
''
,
},
},
},
});
cache
.
writeQuery
({
query
:
get
LastCommitBranchQuery
,
query
:
get
PipelineEtag
,
data
:
{
lastCommitBranch
:
''
,
etags
:
{
__typename
:
'
EtagValues
'
,
pipeline
:
pipelineEtag
,
},
},
});
...
...
app/assets/javascripts/pipeline_editor/pipeline_editor_app.vue
View file @
5c9c86a3
...
...
@@ -160,6 +160,9 @@ export default {
},
appStatus
:
{
query
:
getAppStatus
,
update
(
data
)
{
return
data
.
app
.
status
;
},
},
commitSha
:
{
query
:
getLatestCommitShaQuery
,
...
...
@@ -184,6 +187,9 @@ export default {
},
currentBranch
:
{
query
:
getCurrentBranch
,
update
(
data
)
{
return
data
.
workBranches
.
current
.
name
;
},
},
starterTemplate
:
{
query
:
getTemplate
,
...
...
spec/features/projects/ci/editor_spec.rb
View file @
5c9c86a3
...
...
@@ -51,6 +51,17 @@ RSpec.describe 'Pipeline Editor', :js do
expect
(
page
).
not_to
have_content
(
default_branch
)
end
end
it
'displays new branch as selected after commiting on a new branch'
do
find
(
'#target-branch-field'
).
set
(
'new_branch'
,
clear: :backspace
)
click_button
'Commit changes'
page
.
within
(
'[data-testid="branch-selector"]'
)
do
expect
(
page
).
to
have_content
(
'new_branch'
)
expect
(
page
).
not_to
have_content
(
default_branch
)
end
end
end
context
'Editor content'
do
...
...
spec/frontend/pipeline_editor/components/file-nav/branch_switcher_spec.js
View file @
5c9c86a3
...
...
@@ -22,7 +22,6 @@ import {
mockTotalBranches
,
mockTotalBranchResults
,
mockTotalSearchResults
,
mockNewBranch
,
}
from
'
../../mock_data
'
;
const
localVue
=
createLocalVue
();
...
...
@@ -32,18 +31,14 @@ describe('Pipeline editor branch switcher', () => {
let
wrapper
;
let
mockApollo
;
let
mockAvailableBranchQuery
;
let
mockCurrentBranchQuery
;
let
mockLastCommitBranchQuery
;
const
createComponent
=
(
{
currentBranch
,
isQueryLoading
,
mountFn
,
options
,
props
}
=
{
currentBranch
:
mockDefaultBranch
,
hasUnsavedChanges
:
false
,
isQueryLoading
:
false
,
mountFn
:
shallowMount
,
options
:
{},
},
)
=>
{
const
createComponent
=
({
currentBranch
=
mockDefaultBranch
,
isQueryLoading
=
false
,
mountFn
=
shallowMount
,
options
=
{},
props
=
{},
}
=
{})
=>
{
wrapper
=
mountFn
(
BranchSwitcher
,
{
propsData
:
{
...
props
,
...
...
@@ -74,17 +69,7 @@ describe('Pipeline editor branch switcher', () => {
const
createComponentWithApollo
=
({
mountFn
=
shallowMount
,
props
=
{}
}
=
{})
=>
{
const
handlers
=
[[
getAvailableBranchesQuery
,
mockAvailableBranchQuery
]];
const
resolvers
=
{
Query
:
{
currentBranch
()
{
return
mockCurrentBranchQuery
();
},
lastCommitBranch
()
{
return
mockLastCommitBranchQuery
();
},
},
};
mockApollo
=
createMockApollo
(
handlers
,
resolvers
);
mockApollo
=
createMockApollo
(
handlers
);
createComponent
({
mountFn
,
...
...
@@ -104,22 +89,12 @@ describe('Pipeline editor branch switcher', () => {
const
findInfiniteScroll
=
()
=>
wrapper
.
findComponent
(
GlInfiniteScroll
);
const
defaultBranchInDropdown
=
()
=>
findDropdownItems
().
at
(
0
);
const
setMockResolvedValues
=
({
availableBranches
,
currentBranch
,
lastCommitBranch
})
=>
{
if
(
availableBranches
)
{
mockAvailableBranchQuery
.
mockResolvedValue
(
availableBranches
);
}
if
(
currentBranch
)
{
mockCurrentBranchQuery
.
mockResolvedValue
(
currentBranch
);
}
mockLastCommitBranchQuery
.
mockResolvedValue
(
lastCommitBranch
||
''
);
const
setAvailableBranchesMock
=
(
availableBranches
)
=>
{
mockAvailableBranchQuery
.
mockResolvedValue
(
availableBranches
);
};
beforeEach
(()
=>
{
mockAvailableBranchQuery
=
jest
.
fn
();
mockCurrentBranchQuery
=
jest
.
fn
();
mockLastCommitBranchQuery
=
jest
.
fn
();
});
afterEach
(()
=>
{
...
...
@@ -148,10 +123,7 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
after querying
'
,
()
=>
{
beforeEach
(
async
()
=>
{
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
setAvailableBranchesMock
(
mockProjectBranches
);
createComponentWithApollo
({
mountFn
:
mount
});
await
waitForPromises
();
});
...
...
@@ -180,10 +152,7 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
on fetch error
'
,
()
=>
{
beforeEach
(
async
()
=>
{
setMockResolvedValues
({
availableBranches
:
new
Error
(),
currentBranch
:
mockDefaultBranch
,
});
setAvailableBranchesMock
(
new
Error
());
createComponentWithApollo
();
await
waitForPromises
();
});
...
...
@@ -200,10 +169,7 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
when switching branches
'
,
()
=>
{
beforeEach
(
async
()
=>
{
jest
.
spyOn
(
window
.
history
,
'
pushState
'
).
mockImplementation
(()
=>
{});
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
setAvailableBranchesMock
(
mockProjectBranches
);
createComponentWithApollo
({
mountFn
:
mount
});
await
waitForPromises
();
});
...
...
@@ -271,10 +237,7 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
when searching
'
,
()
=>
{
beforeEach
(
async
()
=>
{
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
setAvailableBranchesMock
(
mockProjectBranches
);
createComponentWithApollo
({
mountFn
:
mount
});
await
waitForPromises
();
});
...
...
@@ -374,10 +337,7 @@ describe('Pipeline editor branch switcher', () => {
describe
(
'
when scrolling to the bottom of the list
'
,
()
=>
{
beforeEach
(
async
()
=>
{
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
setAvailableBranchesMock
(
mockProjectBranches
);
createComponentWithApollo
();
await
waitForPromises
();
});
...
...
@@ -433,35 +393,4 @@ describe('Pipeline editor branch switcher', () => {
});
});
});
describe
(
'
when committing a new branch
'
,
()
=>
{
const
createNewBranch
=
async
()
=>
{
setMockResolvedValues
({
currentBranch
:
mockNewBranch
,
lastCommitBranch
:
mockNewBranch
,
});
await
wrapper
.
vm
.
$apollo
.
queries
.
currentBranch
.
refetch
();
await
wrapper
.
vm
.
$apollo
.
queries
.
lastCommitBranch
.
refetch
();
};
beforeEach
(
async
()
=>
{
setMockResolvedValues
({
availableBranches
:
mockProjectBranches
,
currentBranch
:
mockDefaultBranch
,
});
createComponentWithApollo
({
mountFn
:
mount
});
await
waitForPromises
();
await
createNewBranch
();
});
it
(
'
sets new branch as current branch
'
,
()
=>
{
expect
(
defaultBranchInDropdown
().
text
()).
toBe
(
mockNewBranch
);
expect
(
defaultBranchInDropdown
().
props
(
'
isChecked
'
)).
toBe
(
true
);
});
it
(
'
adds new branch to branch switcher
'
,
()
=>
{
expect
(
defaultBranchInDropdown
().
text
()).
toBe
(
mockNewBranch
);
expect
(
findDropdownItems
()).
toHaveLength
(
mockTotalBranchResults
+
1
);
});
});
});
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