Class: Mutations::Commits::Create

Inherits:
BaseMutation
  • Object
show all
Includes:
FindsProject
Defined in:
app/graphql/mutations/commits/create.rb

Defined Under Namespace

Classes: UrlHelpers

Constant Summary

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods inherited from BaseMutation

#api_user?, authorization, authorization_scopes, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #ready?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

Instance Method Details

#resolve(project_path:, branch:, message:, **args) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/graphql/mutations/commits/create.rb', line 63

def resolve(project_path:, branch:, message:, **args)
  actions = args[:actions]
  allow_empty = args[:allow_empty]

  project = authorized_find!(project_path)

  if actions.blank? && !allow_empty
    raise Gitlab::Graphql::Errors::ArgumentError,
      'Provide at least one action, or set allowEmpty to true.'
  end

  attributes = {
    commit_message: message,
    branch_name: branch,
    start_branch: args[:start_branch] || branch,
    actions: actions.map(&:to_h)
  }

  result = ::Files::MultiService.new(project, current_user, attributes).execute

  {
    content: actions.pluck(:content), # rubocop:disable CodeReuse/ActiveRecord -- Array#pluck
    commit: (project.repository.commit(result[:result]) if result[:status] == :success),
    commit_pipeline_path: UrlHelpers.new.graphql_etag_pipeline_sha_path(result[:result]),
    errors: Array.wrap(result[:message])
  }
end