debian-mirror-gitlab/app/graphql/mutations/branches/create.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Mutations
module Branches
class Create < BaseMutation
2021-03-11 19:13:27 +05:30
include FindsProject
2020-05-24 23:13:21 +05:30
graphql_name 'CreateBranch'
argument :project_path, GraphQL::ID_TYPE,
required: true,
2021-03-08 18:12:59 +05:30
description: 'Project full path the branch is associated with.'
2020-05-24 23:13:21 +05:30
argument :name, GraphQL::STRING_TYPE,
required: true,
2021-03-08 18:12:59 +05:30
description: 'Name of the branch.'
2020-05-24 23:13:21 +05:30
argument :ref,
GraphQL::STRING_TYPE,
required: true,
2021-03-08 18:12:59 +05:30
description: 'Branch name or commit SHA to create branch from.'
2020-05-24 23:13:21 +05:30
field :branch,
Types::BranchType,
null: true,
2021-03-08 18:12:59 +05:30
description: 'Branch after mutation.'
2020-05-24 23:13:21 +05:30
authorize :push_code
def resolve(project_path:, name:, ref:)
2021-03-11 19:13:27 +05:30
project = authorized_find!(project_path)
2020-05-24 23:13:21 +05:30
result = ::Branches::CreateService.new(project, current_user)
.execute(name, ref)
{
branch: (result[:branch] if result[:status] == :success),
errors: Array.wrap(result[:message])
}
end
end
end
end