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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
6ae3098e
Commit
6ae3098e
authored
Apr 19, 2018
by
Jacopo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Uses Uniquify to calculate Issue#suggested_branch_name
parent
4f2e4947
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
6 deletions
+16
-6
app/models/concerns/uniquify.rb
app/models/concerns/uniquify.rb
+5
-2
app/models/issue.rb
app/models/issue.rb
+4
-4
spec/models/concerns/uniquify_spec.rb
spec/models/concerns/uniquify_spec.rb
+7
-0
No files found.
app/models/concerns/uniquify.rb
View file @
6ae3098e
...
...
@@ -3,11 +3,14 @@ class Uniquify
# by appending a counter to it. Uniqueness is determined by
# repeated calls to the passed block.
#
# You can pass an initial value for the counter, if not given
# counting starts from 1.
#
# If `base` is a function/proc, we expect that calling it with a
# candidate counter returns a string to test/return.
def
string
(
base
)
def
string
(
base
,
counter
=
nil
)
@base
=
base
@counter
=
nil
@counter
=
counter
increment_counter!
while
yield
(
base_string
)
base_string
...
...
app/models/issue.rb
View file @
6ae3098e
...
...
@@ -197,10 +197,10 @@ class Issue < ActiveRecord::Base
def
suggested_branch_name
return
to_branch_name
unless
project
.
repository
.
branch_exists?
(
to_branch_name
)
index
=
2
index
+=
1
while
project
.
repository
.
branch_exists?
(
"
#{
to_branch_name
}
-
#{
index
}
"
)
"
#{
to_branch_name
}
-
#{
index
}
"
start_counting_from
=
2
Uniquify
.
new
.
string
(
->
(
counter
)
{
"
#{
to_branch_name
}
-
#{
counter
}
"
},
start_counting_from
)
do
|
suggested_branch_name
|
project
.
repository
.
branch_exists?
(
suggested_branch_name
)
end
end
# Returns boolean if a related branch exists for the current issue
...
...
spec/models/concerns/uniquify_spec.rb
View file @
6ae3098e
...
...
@@ -22,6 +22,13 @@ describe Uniquify do
expect
(
result
).
to
eq
(
'test_string2'
)
end
it
'allows to pass an initial value for the counter'
do
start_counting_from
=
2
result
=
uniquify
.
string
(
'test_string'
,
start_counting_from
)
{
|
s
|
s
==
'test_string'
}
expect
(
result
).
to
eq
(
'test_string2'
)
end
it
'allows passing in a base function that defines the location of the counter'
do
result
=
uniquify
.
string
(
->
(
counter
)
{
"test_
#{
counter
}
_string"
})
do
|
s
|
s
==
'test__string'
...
...
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