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, 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:, actions:, **args) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/graphql/mutations/commits/create.rb', line 54

def resolve(project_path:, branch:, message:, actions:, **args)
  project = authorized_find!(project_path)

  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 because actions is an Array, not a Relation
    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