diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 14:36:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 14:36:54 +0000 |
commit | f61bb2a16a514b71bf33aabbbb999d6732016a24 (patch) | |
tree | 9548caa89e60b4f40b99bbd1dac030420b812aa8 /lib/api/repositories.rb | |
parent | 35fc54e5d261f8898e390aea7c2f5ec5fdf0539d (diff) | |
download | gitlab-ce-13.11.0-rc42.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc42
Diffstat (limited to 'lib/api/repositories.rb')
-rw-r--r-- | lib/api/repositories.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index f6ffeeea829..033cc6744b0 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -116,10 +116,23 @@ module API params do requires :from, type: String, desc: 'The commit, branch name, or tag name to start comparison' requires :to, type: String, desc: 'The commit, branch name, or tag name to stop comparison' + optional :from_project_id, type: String, desc: 'The project to compare from' 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 - compare = CompareService.new(user_project, params[:to]).execute(user_project, params[:from], straight: params[:straight]) + 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]) + + 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 |