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
254f1ae5
Commit
254f1ae5
authored
Apr 06, 2021
by
Mathias Neerup
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit comparing to forked projects with their respective root project
parent
bebab8fc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
+26
-3
lib/api/repositories.rb
lib/api/repositories.rb
+12
-2
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+14
-1
No files found.
lib/api/repositories.rb
View file @
254f1ae5
...
...
@@ -120,9 +120,19 @@ module API
optional
:straight
,
type:
Boolean
,
desc:
'Comparison method, `true` for direct comparison between `from` and `to` (`from`..`to`), `false` to compare using merge base (`from`...`to`)'
,
default:
false
end
get
':id/repository/compare'
do
from_project
=
params
[
:from_project_id
].
present?
?
find_project!
(
params
[
:from_project_id
])
:
user_project
if
params
[
:from_project_id
].
present?
target_project
=
MergeRequestTargetProjectFinder
.
new
(
current_user:
current_user
,
source_project:
user_project
,
project_feature: :repository
)
.
execute
(
include_routes:
true
).
find_by_id
(
params
[
:from_project_id
])
compare
=
CompareService
.
new
(
user_project
,
params
[
:to
]).
execute
(
from_project
,
params
[
:from
],
straight:
params
[
:straight
])
if
target_project
.
blank?
render_api_error!
(
"Target project id:
#{
params
[
:from_project_id
]
}
is not a fork of project id:
#{
params
[
:id
]
}
"
,
400
)
end
else
target_project
=
user_project
end
compare
=
CompareService
.
new
(
user_project
,
params
[
:to
]).
execute
(
target_project
,
params
[
:from
],
straight:
params
[
:straight
])
if
compare
present
compare
,
with:
Entities
::
Compare
...
...
spec/requests/api/repositories_spec.rb
View file @
254f1ae5
...
...
@@ -6,6 +6,7 @@ require 'mime/types'
RSpec
.
describe
API
::
Repositories
do
include
RepoHelpers
include
WorkhorseHelpers
include
ProjectForksHelper
let
(
:user
)
{
create
(
:user
)
}
let
(
:guest
)
{
create
(
:user
).
tap
{
|
u
|
create
(
:project_member
,
:guest
,
user:
u
,
project:
project
)
}
}
...
...
@@ -392,11 +393,23 @@ RSpec.describe API::Repositories do
expect
(
json_response
[
'diffs'
]).
to
be_present
end
it
"compare commits between different projects"
do
it
"compare commits between different projects
with non-forked relation
"
do
public_project
=
create
(
:project
,
:repository
,
:public
)
get
api
(
route
,
current_user
),
params:
{
from:
sample_commit
.
parent_id
,
to:
sample_commit
.
id
,
from_project_id:
public_project
.
id
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it
"compare commits between different projects"
do
group
=
create
(
:group
)
group
.
add_owner
(
current_user
)
forked_project
=
fork_project
(
project
,
current_user
,
repository:
true
,
namespace:
group
)
forked_project
.
repository
.
create_ref
(
'refs/heads/improve/awesome'
,
'refs/heads/improve/more-awesome'
)
get
api
(
route
,
current_user
),
params:
{
from:
'improve/awesome'
,
to:
'feature'
,
from_project_id:
forked_project
.
id
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'commits'
]).
to
be_present
expect
(
json_response
[
'diffs'
]).
to
be_present
...
...
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