Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create.rb « branches « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9fe9bef54034642ff185a9f8bccdcd624eaec412 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

module Mutations
  module Branches
    class Create < BaseMutation
      include ResolvesProject

      graphql_name 'CreateBranch'

      argument :project_path, GraphQL::ID_TYPE,
               required: true,
               description: 'Project full path the branch is associated with.'

      argument :name, GraphQL::STRING_TYPE,
               required: true,
               description: 'Name of the branch.'

      argument :ref,
               GraphQL::STRING_TYPE,
               required: true,
               description: 'Branch name or commit SHA to create branch from.'

      field :branch,
            Types::BranchType,
            null: true,
            description: 'Branch after mutation.'

      authorize :push_code

      def resolve(project_path:, name:, ref:)
        project = authorized_find!(full_path: project_path)

        context.scoped_set!(:branch_project, project)

        result = ::Branches::CreateService.new(project, current_user)
                   .execute(name, ref)

        {
          branch: (result[:branch] if result[:status] == :success),
          errors: Array.wrap(result[:message])
        }
      end

      private

      def find_object(full_path:)
        resolve_project(full_path: full_path)
      end
    end
  end
end