Commit 96db70a4 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Simplify merge_ref_head methods

parent b965009d
...@@ -1080,16 +1080,14 @@ class MergeRequest < ApplicationRecord ...@@ -1080,16 +1080,14 @@ class MergeRequest < ApplicationRecord
# Returns the current merge-ref HEAD commit. # Returns the current merge-ref HEAD commit.
# #
# Consider calling mergeability_check method _before_ this if you need
# the latest possible version of it (it's already automatically updated
# along the merge_status).
#
def merge_ref_head def merge_ref_head
project.repository.commit(merge_ref_path) project.repository.commit(merge_ref_path)
end end
# Returns the updated merge-ref HEAD commit.
#
def merge_ref_head!
merge_ref_head if check_mergeability.success?
end
def ref_path def ref_path
"refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/head" "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/head"
end end
......
...@@ -1159,7 +1159,7 @@ Parameters: ...@@ -1159,7 +1159,7 @@ Parameters:
} }
``` ```
## Return up to date merge-ref ## Returns the up to date merge-ref HEAD commit
Merge the changes between the merge request source and target branches into `refs/merge-requests/:iid/merge` Merge the changes between the merge request source and target branches into `refs/merge-requests/:iid/merge`
ref, of the target project repository, if possible. This ref will have the state the target branch would have if ref, of the target project repository, if possible. This ref will have the state the target branch would have if
......
...@@ -398,11 +398,11 @@ module API ...@@ -398,11 +398,11 @@ module API
present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project present merge_request, with: Entities::MergeRequest, current_user: current_user, project: user_project
end end
desc 'Returns an up to date merge-ref HEAD' desc 'Returns the up to date merge-ref HEAD commit'
get ':id/merge_requests/:merge_request_iid/merge_ref' do get ':id/merge_requests/:merge_request_iid/merge_ref' do
merge_request = find_project_merge_request(params[:merge_request_iid]) merge_request = find_project_merge_request(params[:merge_request_iid])
result = merge_request.check_mergeability result = ::MergeRequests::MergeabilityCheckService.new(merge_request).execute
if result.success? && commit = merge_request.merge_ref_head if result.success? && commit = merge_request.merge_ref_head
present :commit_id, commit.sha present :commit_id, commit.sha
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment