2020-05-05 09:09:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Branches
|
|
|
|
class Create < BaseMutation
|
|
|
|
graphql_name 'CreateBranch'
|
|
|
|
|
2022-02-15 12:14:49 +00:00
|
|
|
include FindsProject
|
|
|
|
|
2021-07-23 15:09:21 +00:00
|
|
|
argument :project_path, GraphQL::Types::ID,
|
2020-05-05 09:09:37 +00:00
|
|
|
required: true,
|
2021-01-07 12:10:24 +00:00
|
|
|
description: 'Project full path the branch is associated with.'
|
2020-05-05 09:09:37 +00:00
|
|
|
|
2021-07-23 15:09:21 +00:00
|
|
|
argument :name, GraphQL::Types::String,
|
2020-05-05 09:09:37 +00:00
|
|
|
required: true,
|
2021-01-07 12:10:24 +00:00
|
|
|
description: 'Name of the branch.'
|
2020-05-05 09:09:37 +00:00
|
|
|
|
|
|
|
argument :ref,
|
2021-07-23 15:09:21 +00:00
|
|
|
GraphQL::Types::String,
|
2020-05-05 09:09:37 +00:00
|
|
|
required: true,
|
2021-01-07 12:10:24 +00:00
|
|
|
description: 'Branch name or commit SHA to create branch from.'
|
2020-05-05 09:09:37 +00:00
|
|
|
|
|
|
|
field :branch,
|
|
|
|
Types::BranchType,
|
|
|
|
null: true,
|
2021-01-07 12:10:24 +00:00
|
|
|
description: 'Branch after mutation.'
|
2020-05-05 09:09:37 +00:00
|
|
|
|
|
|
|
authorize :push_code
|
|
|
|
|
|
|
|
def resolve(project_path:, name:, ref:)
|
2021-01-26 18:09:30 +00:00
|
|
|
project = authorized_find!(project_path)
|
2020-05-05 09:09:37 +00:00
|
|
|
|
|
|
|
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
|