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
e8c1d3e7
Commit
e8c1d3e7
authored
May 06, 2021
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move offset and limit params to BranchNamesFinder
Moves the offset and limit parameters to the BranchNamesFinder.
parent
f5910a20
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
52 deletions
+72
-52
app/finders/repositories/branch_names_finder.rb
app/finders/repositories/branch_names_finder.rb
+10
-2
app/graphql/resolvers/repository_branch_names_resolver.rb
app/graphql/resolvers/repository_branch_names_resolver.rb
+1
-10
spec/finders/repositories/branch_names_finder_spec.rb
spec/finders/repositories/branch_names_finder_spec.rb
+26
-13
spec/graphql/resolvers/repository_branch_names_resolver_spec.rb
...raphql/resolvers/repository_branch_names_resolver_spec.rb
+35
-27
No files found.
app/finders/repositories/branch_names_finder.rb
View file @
e8c1d3e7
...
@@ -10,9 +10,9 @@ module Repositories
...
@@ -10,9 +10,9 @@ module Repositories
end
end
def
execute
def
execute
return
unless
search
return
unless
search
&&
offset
&&
limit
repository
.
search_branch_names
(
search
)
repository
.
search_branch_names
(
search
)
.
lazy
.
drop
(
offset
).
take
(
limit
)
# rubocop:disable CodeReuse/ActiveRecord
end
end
private
private
...
@@ -20,5 +20,13 @@ module Repositories
...
@@ -20,5 +20,13 @@ module Repositories
def
search
def
search
@params
[
:search
].
presence
@params
[
:search
].
presence
end
end
def
offset
@params
[
:offset
]
end
def
limit
@params
[
:limit
]
end
end
end
end
end
app/graphql/resolvers/repository_branch_names_resolver.rb
View file @
e8c1d3e7
...
@@ -19,16 +19,7 @@ module Resolvers
...
@@ -19,16 +19,7 @@ module Resolvers
description:
'The number of branch names to return.'
description:
'The number of branch names to return.'
def
resolve
(
search_pattern
:,
offset
:,
limit
:)
def
resolve
(
search_pattern
:,
offset
:,
limit
:)
names
=
branch_names
(
search_pattern
)
Repositories
::
BranchNamesFinder
.
new
(
object
,
offset:
offset
,
limit:
limit
,
search:
search_pattern
).
execute
return
unless
names
names
.
lazy
.
drop
(
offset
).
take
(
limit
)
# rubocop:disable CodeReuse/ActiveRecord
end
private
def
branch_names
(
search_pattern
)
Repositories
::
BranchNamesFinder
.
new
(
object
,
search:
search_pattern
).
execute
end
end
end
end
end
end
spec/finders/repositories/branch_names_finder_spec.rb
View file @
e8c1d3e7
...
@@ -5,21 +5,34 @@ require 'spec_helper'
...
@@ -5,21 +5,34 @@ require 'spec_helper'
RSpec
.
describe
Repositories
::
BranchNamesFinder
do
RSpec
.
describe
Repositories
::
BranchNamesFinder
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:branch_names_finder
)
{
described_class
.
new
(
project
.
repository
,
search:
'conflict-*'
)
}
describe
'#execute'
do
describe
'#execute'
do
subject
(
:execute
)
{
branch_names_finder
.
execute
}
it
'returns all filtered branch names'
do
expect
(
create_branch_names_finder
(
0
,
100
).
execute
).
to
contain_exactly
(
it
'filters branch names'
do
'snippet/edit-file'
,
expect
(
execute
).
to
contain_exactly
(
'snippet/multiple-files'
,
'conflict-binary-file'
,
'snippet/no-files'
,
'conflict-resolvable'
,
'snippet/rename-and-edit-file'
,
'conflict-contains-conflict-markers'
,
'snippet/single-file'
'conflict-missing-side'
,
'conflict-start'
,
'conflict-non-utf8'
,
'conflict-too-large'
)
)
end
end
it
'returns a limited number of offset filtered branch names'
do
starting_names
=
create_branch_names_finder
(
0
,
3
).
execute
offset_names
=
create_branch_names_finder
(
3
,
2
).
execute
expect
(
starting_names
.
count
).
to
eq
(
3
)
expect
(
offset_names
.
count
).
to
eq
(
2
)
expect
(
offset_names
).
not_to
include
(
*
starting_names
)
all_names
=
create_branch_names_finder
(
0
,
100
).
execute
expect
(
all_names
).
to
contain_exactly
(
*
starting_names
,
*
offset_names
)
end
private
def
create_branch_names_finder
(
offset
,
limit
)
described_class
.
new
(
project
.
repository
,
search:
'snippet/*'
,
offset:
offset
,
limit:
limit
)
end
end
end
end
end
spec/graphql/resolvers/repository_branch_names_resolver_spec.rb
View file @
e8c1d3e7
...
@@ -8,42 +8,50 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do
...
@@ -8,42 +8,50 @@ RSpec.describe Resolvers::RepositoryBranchNamesResolver do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
describe
'#resolve'
do
describe
'#resolve'
do
subject
(
:resolve_branch_names
)
do
context
'with empty search pattern'
do
resolve
(
let
(
:pattern
)
{
''
}
described_class
,
obj:
project
.
repository
,
args:
{
search_pattern:
pattern
,
offset:
offset
,
limit:
1
},
ctx:
{
current_user:
project
.
creator
}
)
end
context
'with zero offset'
do
it
'returns nil'
do
let
(
:offset
)
{
0
}
expect
(
resolve_branch_names
(
pattern
,
0
,
100
)).
to
eq
(
nil
)
end
end
context
'with empty
search pattern'
do
context
'with a valid
search pattern'
do
let
(
:pattern
)
{
'
'
}
let
(
:pattern
)
{
'snippet/*
'
}
it
'returns nil'
do
it
'returns matching branches'
do
expect
(
resolve_branch_names
).
to
eq
(
nil
)
expect
(
resolve_branch_names
(
pattern
,
0
,
100
)).
to
contain_exactly
(
end
'snippet/edit-file'
,
'snippet/multiple-files'
,
'snippet/no-files'
,
'snippet/rename-and-edit-file'
,
'snippet/single-file'
)
end
end
context
'with a valid search pattern'
do
it
'properly offsets and limits branch name results'
do
let
(
:pattern
)
{
'snippet/*'
}
starting_names
=
resolve_branch_names
(
pattern
,
0
,
3
)
offset_names
=
resolve_branch_names
(
pattern
,
3
,
2
)
it
'returns matching branches'
do
expect
(
starting_names
.
count
).
to
eq
(
3
)
expect
(
resolve_branch_names
).
to
contain_exactly
(
'snippet/rename-and-edit-file'
)
expect
(
offset_names
.
count
).
to
eq
(
2
)
end
end
end
context
'with offset'
do
expect
(
offset_names
).
not_to
include
(
*
starting_names
)
let
(
:pattern
)
{
'snippet/*'
}
let
(
:offset
)
{
1
}
it
'skips first match'
do
all_names
=
resolve_branch_names
(
pattern
,
0
,
100
)
expect
(
resolve_branch_names
).
to
contain_exactly
(
'snippet/edit-file'
)
expect
(
all_names
).
to
contain_exactly
(
*
starting_names
,
*
offset_names
)
end
end
end
end
end
end
private
def
resolve_branch_names
(
pattern
,
offset
,
limit
)
resolve
(
described_class
,
obj:
project
.
repository
,
args:
{
search_pattern:
pattern
,
offset:
offset
,
limit:
limit
},
ctx:
{
current_user:
project
.
creator
}
)
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