2018-09-11 19:08:34 +00:00
# frozen_string_literal: true
2018-05-23 07:55:14 +00:00
module Types
class MergeRequestType < BaseObject
2019-03-04 02:30:32 +00:00
graphql_name 'MergeRequest'
2020-12-03 00:09:53 +00:00
connection_type_class ( Types :: MergeRequestConnectionType )
2020-08-06 18:09:41 +00:00
2021-07-05 15:07:38 +00:00
implements ( Types :: Notes :: NoteableInterface )
2020-09-09 21:08:33 +00:00
implements ( Types :: CurrentUserTodos )
2019-06-07 17:13:26 +00:00
2019-03-04 02:30:32 +00:00
authorize :read_merge_request
2018-06-25 08:59:00 +00:00
expose_permissions Types :: PermissionTypes :: MergeRequest
2018-05-23 07:55:14 +00:00
present_using MergeRequestPresenter
2018-05-21 07:52:24 +00:00
2021-07-22 09:08:22 +00:00
field :id , GraphQL :: Types :: ID , null : false ,
2021-02-05 15:09:28 +00:00
description : 'ID of the merge request.'
2021-07-22 09:08:22 +00:00
field :iid , GraphQL :: Types :: String , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Internal ID of the merge request.'
2021-07-22 09:08:22 +00:00
field :title , GraphQL :: Types :: String , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Title of the merge request.'
2019-06-20 08:02:33 +00:00
markdown_field :title_html , null : true
2021-07-22 09:08:22 +00:00
field :description , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Description of the merge request (Markdown rendered as HTML for caching).'
2019-06-20 08:02:33 +00:00
markdown_field :description_html , null : true
2019-10-31 12:06:26 +00:00
field :state , MergeRequestStateEnum , null : false ,
2021-02-05 15:09:28 +00:00
description : 'State of the merge request.'
2019-10-31 12:06:26 +00:00
field :created_at , Types :: TimeType , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Timestamp of when the merge request was created.'
2019-10-31 12:06:26 +00:00
field :updated_at , Types :: TimeType , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Timestamp of when the merge request was last updated.'
2020-05-22 18:08:21 +00:00
field :merged_at , Types :: TimeType , null : true , complexity : 5 ,
2021-02-05 15:09:28 +00:00
description : 'Timestamp of when the merge request was merged, null if not merged.'
2019-10-31 12:06:26 +00:00
field :source_project , Types :: ProjectType , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Source project of the merge request.'
2019-10-31 12:06:26 +00:00
field :target_project , Types :: ProjectType , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Target project of the merge request.'
2019-10-31 12:06:26 +00:00
field :diff_refs , Types :: DiffRefsType , null : true ,
2021-02-05 15:09:28 +00:00
description : 'References of the base SHA, the head SHA, and the start SHA for this merge request.'
2019-10-31 12:06:26 +00:00
field :project , Types :: ProjectType , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Alias for target_project.'
2021-07-22 09:08:22 +00:00
field :project_id , GraphQL :: Types :: Int , null : false , method : :target_project_id ,
2021-02-05 15:09:28 +00:00
description : 'ID of the merge request project.'
2021-07-22 09:08:22 +00:00
field :source_project_id , GraphQL :: Types :: Int , null : true ,
2021-02-05 15:09:28 +00:00
description : 'ID of the merge request source project.'
2021-07-22 09:08:22 +00:00
field :target_project_id , GraphQL :: Types :: Int , null : false ,
2021-02-05 15:09:28 +00:00
description : 'ID of the merge request target project.'
2021-07-22 09:08:22 +00:00
field :source_branch , GraphQL :: Types :: String , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Source branch of the merge request.'
2021-07-22 09:08:22 +00:00
field :source_branch_protected , GraphQL :: Types :: Boolean , null : false , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the source branch is protected.'
2021-07-22 09:08:22 +00:00
field :target_branch , GraphQL :: Types :: String , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Target branch of the merge request.'
2021-08-16 09:09:05 +00:00
field :draft , GraphQL :: Types :: Boolean , method : :draft? , null : false ,
2021-02-23 12:10:56 +00:00
description : 'Indicates if the merge request is a draft.'
2021-07-22 09:08:22 +00:00
field :merge_when_pipeline_succeeds , GraphQL :: Types :: Boolean , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the merge has been set to be merged when its pipeline succeeds (MWPS).'
2021-07-22 09:08:22 +00:00
field :diff_head_sha , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Diff head SHA of the merge request.'
2020-06-25 06:08:50 +00:00
field :diff_stats , [ Types :: DiffStatsType ] , null : true , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Details about which files were changed in this merge request.' do
2021-08-25 15:11:14 +00:00
argument :path , GraphQL :: Types :: String , required : false , description : 'Specific file path.'
2020-06-25 06:08:50 +00:00
end
field :diff_stats_summary , Types :: DiffStatsSummaryType , null : true , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Summary of which files were changed in this merge request.'
2021-07-22 09:08:22 +00:00
field :merge_commit_sha , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'SHA of the merge request commit (set once merged).'
2021-07-22 09:08:22 +00:00
field :user_notes_count , GraphQL :: Types :: Int , null : true ,
2021-02-05 15:09:28 +00:00
description : 'User notes count of the merge request.' ,
2020-12-11 21:10:13 +00:00
resolver : Resolvers :: UserNotesCountResolver
2021-07-22 09:08:22 +00:00
field :user_discussions_count , GraphQL :: Types :: Int , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Number of user discussions in the merge request.' ,
2020-12-11 21:10:13 +00:00
resolver : Resolvers :: UserDiscussionsCountResolver
2021-07-22 09:08:22 +00:00
field :should_remove_source_branch , GraphQL :: Types :: Boolean , method : :should_remove_source_branch? , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the source branch of the merge request will be deleted after merge.'
2021-07-22 09:08:22 +00:00
field :force_remove_source_branch , GraphQL :: Types :: Boolean , method : :force_remove_source_branch? , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the project settings will lead to source branch deletion after merge.'
2021-07-22 09:08:22 +00:00
field :merge_status , GraphQL :: Types :: String , method : :public_merge_status , null : true ,
2021-06-02 12:10:05 +00:00
description : 'Status of the merge request.' ,
deprecated : { reason : :renamed , replacement : 'MergeRequest.mergeStatusEnum' , milestone : '14.0' }
field :merge_status_enum , :: Types :: MergeRequests :: MergeStatusEnum ,
method : :public_merge_status , null : true ,
description : 'Merge status of the merge request.'
2021-07-22 09:08:22 +00:00
field :in_progress_merge_commit_sha , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Commit SHA of the merge request if merge is in progress.'
2021-07-22 09:08:22 +00:00
field :merge_error , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Error message due to a merge error.'
2021-07-22 09:08:22 +00:00
field :allow_collaboration , GraphQL :: Types :: Boolean , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if members of the target project can push to the fork.'
2021-07-22 09:08:22 +00:00
field :should_be_rebased , GraphQL :: Types :: Boolean , method : :should_be_rebased? , null : false , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the merge request will be rebased.'
2021-07-22 09:08:22 +00:00
field :rebase_commit_sha , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Rebase commit SHA of the merge request.'
2021-07-22 09:08:22 +00:00
field :rebase_in_progress , GraphQL :: Types :: Boolean , method : :rebase_in_progress? , null : false , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if there is a rebase currently in progress for the merge request.'
2021-12-08 12:13:04 +00:00
field :default_merge_commit_message , GraphQL :: Types :: String , null : true , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Default merge commit message of the merge request.'
2021-07-22 09:08:22 +00:00
field :default_merge_commit_message_with_description , GraphQL :: Types :: String , null : true ,
2021-11-11 09:12:21 +00:00
description : 'Default merge commit message of the merge request with description. Will have the same value as `defaultMergeCommitMessage` when project has `mergeCommitTemplate` set.' ,
deprecated : { reason : 'Define merge commit template in project and use `defaultMergeCommitMessage`' , milestone : '14.5' }
2021-07-22 09:08:22 +00:00
field :default_squash_commit_message , GraphQL :: Types :: String , null : true , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Default squash commit message of the merge request.'
2021-07-22 09:08:22 +00:00
field :merge_ongoing , GraphQL :: Types :: Boolean , method : :merge_ongoing? , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if a merge is currently occurring.'
2021-07-22 09:08:22 +00:00
field :source_branch_exists , GraphQL :: Types :: Boolean ,
2020-05-22 00:08:07 +00:00
null : false , calls_gitaly : true ,
method : :source_branch_exists? ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the source branch of the merge request exists.'
2021-07-22 09:08:22 +00:00
field :target_branch_exists , GraphQL :: Types :: Boolean ,
2020-05-22 00:08:07 +00:00
null : false , calls_gitaly : true ,
method : :target_branch_exists? ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the target branch of the merge request exists.'
2021-07-22 09:08:22 +00:00
field :diverged_from_target_branch , GraphQL :: Types :: Boolean ,
2021-02-23 09:10:45 +00:00
null : false , calls_gitaly : true ,
method : :diverged_from_target_branch? ,
description : 'Indicates if the source branch is behind the target branch.'
2021-07-22 09:08:22 +00:00
field :mergeable_discussions_state , GraphQL :: Types :: Boolean , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if all discussions in the merge request have been resolved, allowing the merge request to be merged.'
2021-07-22 09:08:22 +00:00
field :web_url , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Web URL of the merge request.'
2021-07-22 09:08:22 +00:00
field :upvotes , GraphQL :: Types :: Int , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Number of upvotes for the merge request.'
2021-07-22 09:08:22 +00:00
field :downvotes , GraphQL :: Types :: Int , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Number of downvotes for the merge request.'
2018-06-26 16:31:05 +00:00
2019-10-31 12:06:26 +00:00
field :head_pipeline , Types :: Ci :: PipelineType , null : true , method : :actual_head_pipeline ,
2021-08-25 15:11:14 +00:00
description : 'Pipeline running on the branch HEAD of the merge request.'
2020-11-17 18:09:20 +00:00
field :pipelines ,
2020-09-12 00:08:44 +00:00
null : true ,
2020-12-09 18:09:48 +00:00
description : 'Pipelines for the merge request. Note: for performance reasons, no more than the most recent 500 pipelines will be returned.' ,
2018-06-26 16:31:05 +00:00
resolver : Resolvers :: MergeRequestPipelinesResolver
2019-06-15 04:56:28 +00:00
2019-10-31 12:06:26 +00:00
field :milestone , Types :: MilestoneType , null : true ,
2021-08-25 15:11:14 +00:00
description : 'Milestone of the merge request.'
2021-04-26 15:10:20 +00:00
field :assignees ,
type : Types :: MergeRequests :: AssigneeType . connection_type ,
null : true ,
complexity : 5 ,
2021-02-05 15:09:28 +00:00
description : 'Assignees of the merge request.'
2021-04-07 00:09:26 +00:00
field :reviewers ,
type : Types :: MergeRequests :: ReviewerType . connection_type ,
null : true ,
complexity : 5 ,
2020-12-21 15:10:05 +00:00
description : 'Users from whom a review has been requested.'
2020-05-22 18:08:21 +00:00
field :author , Types :: UserType , null : true ,
2021-02-05 15:09:28 +00:00
description : 'User who created this merge request.'
2020-12-22 15:09:51 +00:00
field :participants , Types :: UserType . connection_type , null : true , complexity : 15 ,
2021-12-09 00:13:41 +00:00
description : 'Participants in the merge request. This includes the author, assignees, reviewers, and users mentioned in notes.' ,
resolver : Resolvers :: Users :: ParticipantsResolver
2021-07-22 09:08:22 +00:00
field :subscribed , GraphQL :: Types :: Boolean , method : :subscribed? , null : false , complexity : 5 ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the currently logged in user is subscribed to this merge request.'
2019-10-31 12:06:26 +00:00
field :labels , Types :: LabelType . connection_type , null : true , complexity : 5 ,
2021-02-05 15:09:28 +00:00
description : 'Labels of the merge request.'
2021-07-22 09:08:22 +00:00
field :discussion_locked , GraphQL :: Types :: Boolean ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if comments on the merge request are locked to members only.' ,
2020-12-01 12:09:17 +00:00
null : false
2021-07-22 09:08:22 +00:00
field :time_estimate , GraphQL :: Types :: Int , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Time estimate of the merge request.'
2021-07-22 09:08:22 +00:00
field :total_time_spent , GraphQL :: Types :: Int , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Total time reported as spent on the merge request.'
2021-07-22 09:08:22 +00:00
field :human_time_estimate , GraphQL :: Types :: String , null : true ,
2021-06-15 18:09:57 +00:00
description : 'Human-readable time estimate of the merge request.'
2021-07-22 09:08:22 +00:00
field :human_total_time_spent , GraphQL :: Types :: String , null : true ,
2021-06-15 18:09:57 +00:00
description : 'Human-readable total time reported as spent on the merge request.'
2021-07-22 09:08:22 +00:00
field :reference , GraphQL :: Types :: String , null : false , method : :to_reference ,
2021-02-05 15:09:28 +00:00
description : 'Internal reference of the merge request. Returned in shortened format by default.' do
2021-07-22 09:08:22 +00:00
argument :full , GraphQL :: Types :: Boolean , required : false , default_value : false ,
2021-02-05 15:09:28 +00:00
description : 'Boolean option specifying whether the reference should be returned in full.'
2019-10-17 21:06:41 +00:00
end
2019-10-31 12:06:26 +00:00
field :task_completion_status , Types :: TaskCompletionStatus , null : false ,
description : Types :: TaskCompletionStatus . description
2021-07-22 09:08:22 +00:00
field :commit_count , GraphQL :: Types :: Int , null : true , method : :commits_count ,
2021-02-05 15:09:28 +00:00
description : 'Number of commits in the merge request.'
2021-07-22 09:08:22 +00:00
field :conflicts , GraphQL :: Types :: Boolean , null : false , method : :cannot_be_merged? ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the merge request has conflicts.'
2021-07-22 09:08:22 +00:00
field :auto_merge_enabled , GraphQL :: Types :: Boolean , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if auto merge is enabled for the merge request.'
2020-06-25 06:08:50 +00:00
2020-10-05 12:08:47 +00:00
field :approved_by , Types :: UserType . connection_type , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Users who approved the merge request.'
2021-07-22 09:08:22 +00:00
field :squash_on_merge , GraphQL :: Types :: Boolean , null : false , method : :squash_on_merge? ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if squash on merge is enabled.'
2021-07-22 09:08:22 +00:00
field :squash , GraphQL :: Types :: Boolean , null : false ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if squash on merge is enabled.'
2021-07-22 09:08:22 +00:00
field :available_auto_merge_strategies , [ GraphQL :: Types :: String ] , null : true , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Array of available auto merge strategies.'
2021-07-22 09:08:22 +00:00
field :has_ci , GraphQL :: Types :: Boolean , null : false , method : :has_ci? ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the merge request has CI.'
2021-07-22 09:08:22 +00:00
field :mergeable , GraphQL :: Types :: Boolean , null : false , method : :mergeable? , calls_gitaly : true ,
2021-02-05 15:09:28 +00:00
description : 'Indicates if the merge request is mergeable.'
2020-12-09 18:09:48 +00:00
field :commits_without_merge_commits , Types :: CommitType . connection_type , null : true ,
2021-02-05 15:09:28 +00:00
calls_gitaly : true , description : 'Merge request commits excluding merge commits.'
2021-07-22 09:08:22 +00:00
field :security_auto_fix , GraphQL :: Types :: Boolean , null : true ,
2020-12-16 18:10:10 +00:00
description : 'Indicates if the merge request is created by @GitLab-Security-Bot.'
2021-07-22 09:08:22 +00:00
field :auto_merge_strategy , GraphQL :: Types :: String , null : true ,
2021-02-05 15:09:28 +00:00
description : 'Selected auto merge strategy.'
2021-01-12 12:10:49 +00:00
field :merge_user , Types :: UserType , null : true ,
2021-02-05 15:09:28 +00:00
description : 'User who merged this merge request.'
2021-04-12 12:09:15 +00:00
field :timelogs , Types :: TimelogType . connection_type , null : false ,
description : 'Timelogs on the merge request.'
2020-10-05 12:08:47 +00:00
def approved_by
object . approved_by_users
end
2020-10-14 18:08:47 +00:00
def user_notes_count
BatchLoader :: GraphQL . for ( object . id ) . batch ( key : :merge_request_user_notes_count ) do | ids , loader , args |
2020-11-04 18:08:42 +00:00
counts = Note . count_for_collection ( ids , 'MergeRequest' ) . index_by ( & :noteable_id )
2020-10-14 18:08:47 +00:00
ids . each do | id |
2020-11-04 18:08:42 +00:00
loader . call ( id , counts [ id ] & . count || 0 )
end
end
end
def user_discussions_count
BatchLoader :: GraphQL . for ( object . id ) . batch ( key : :merge_request_user_discussions_count ) do | ids , loader , args |
counts = Note . count_for_collection ( ids , 'MergeRequest' , 'COUNT(DISTINCT discussion_id) as count' ) . index_by ( & :noteable_id )
ids . each do | id |
loader . call ( id , counts [ id ] & . count || 0 )
2020-10-14 18:08:47 +00:00
end
end
end
2020-06-25 06:08:50 +00:00
def diff_stats ( path : nil )
stats = Array . wrap ( object . diff_stats & . to_a )
if path . present?
stats . select { | s | s . path == path }
else
stats
end
end
def diff_stats_summary
2020-10-19 21:09:06 +00:00
BatchLoaders :: MergeRequestDiffSummaryBatchLoader . load_for ( object )
2020-06-25 06:08:50 +00:00
end
2020-08-13 18:10:36 +00:00
2020-11-24 18:09:14 +00:00
def source_branch_protected
object . source_project . present? && ProtectedBranch . protected? ( object . source_project , object . source_branch )
end
2020-12-01 12:09:17 +00:00
def discussion_locked
! ! object . discussion_locked
end
2020-12-09 18:09:48 +00:00
def default_merge_commit_message_with_description
object . default_merge_commit_message ( include_description : true )
end
def available_auto_merge_strategies
AutoMergeService . new ( object . project , current_user ) . available_strategies ( object )
end
def commits_without_merge_commits
object . recent_commits . without_merge_commits
end
2020-12-16 18:10:10 +00:00
def security_auto_fix
object . author == User . security_bot
end
2020-12-21 15:10:05 +00:00
def reviewers
2021-02-05 12:09:31 +00:00
object . reviewers
2020-12-21 15:10:05 +00:00
end
2018-05-23 07:55:14 +00:00
end
2017-08-16 13:04:41 +00:00
end
2020-12-01 12:09:17 +00:00
2021-05-11 21:10:21 +00:00
Types :: MergeRequestType . prepend_mod_with ( 'Types::MergeRequestType' )