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
9841861b
Commit
9841861b
authored
Aug 20, 2021
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Compare support to UrlBuilder
parent
ef5c16af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
0 deletions
+51
-0
lib/gitlab/url_builder.rb
lib/gitlab/url_builder.rb
+8
-0
spec/factories/compares.rb
spec/factories/compares.rb
+22
-0
spec/lib/gitlab/url_builder_spec.rb
spec/lib/gitlab/url_builder_spec.rb
+21
-0
No files found.
lib/gitlab/url_builder.rb
View file @
9841861b
...
...
@@ -24,6 +24,8 @@ module Gitlab
instance
.
project_job_url
(
object
.
project
,
object
,
**
options
)
when
Commit
commit_url
(
object
,
**
options
)
when
Compare
compare_url
(
object
,
**
options
)
when
Group
instance
.
group_canonical_url
(
object
,
**
options
)
when
Issue
...
...
@@ -68,6 +70,12 @@ module Gitlab
instance
.
commit_url
(
commit
,
**
options
)
end
def
compare_url
(
compare
,
**
options
)
return
''
unless
compare
.
project
instance
.
project_compare_url
(
compare
.
project
,
**
options
.
merge
(
compare
.
to_param
))
end
def
note_url
(
note
,
**
options
)
if
note
.
for_commit?
return
''
unless
note
.
project
...
...
spec/factories/compares.rb
0 → 100644
View file @
9841861b
# frozen_string_literal: true
FactoryBot
.
define
do
factory
:compare
do
skip_create
# No persistence
start_project
{
association
(
:project
,
:repository
)
}
target_project
{
start_project
}
start_ref
{
'master'
}
target_ref
{
'feature'
}
base_sha
{
nil
}
straight
{
false
}
initialize_with
do
CompareService
.
new
(
start_project
,
start_ref
)
.
execute
(
target_project
,
target_ref
,
base_sha:
base_sha
,
straight:
straight
)
end
end
end
spec/lib/gitlab/url_builder_spec.rb
View file @
9841861b
...
...
@@ -69,6 +69,27 @@ RSpec.describe Gitlab::UrlBuilder do
end
end
context
'when passing a compare'
do
# NOTE: The Compare requires an actual repository, which isn't available
# with the `build_stubbed` strategy used by the table tests above
let_it_be
(
:compare
)
{
create
(
:compare
)
}
let_it_be
(
:project
)
{
compare
.
project
}
it
'returns the full URL'
do
expect
(
subject
.
build
(
compare
)).
to
eq
(
"
#{
Gitlab
.
config
.
gitlab
.
url
}
/
#{
project
.
full_path
}
/-/compare/
#{
compare
.
base_commit_sha
}
...
#{
compare
.
head_commit_sha
}
"
)
end
it
'returns only the path if only_path is given'
do
expect
(
subject
.
build
(
compare
,
only_path:
true
)).
to
eq
(
"/
#{
project
.
full_path
}
/-/compare/
#{
compare
.
base_commit_sha
}
...
#{
compare
.
head_commit_sha
}
"
)
end
it
'returns an empty string for missing project'
do
expect
(
compare
).
to
receive
(
:project
).
and_return
(
nil
)
expect
(
subject
.
build
(
compare
)).
to
eq
(
''
)
end
end
context
'when passing a commit without a project'
do
let
(
:commit
)
{
build_stubbed
(
:commit
)
}
...
...
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