diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /app/graphql/mutations/branches/create.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'app/graphql/mutations/branches/create.rb')
-rw-r--r-- | app/graphql/mutations/branches/create.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/app/graphql/mutations/branches/create.rb b/app/graphql/mutations/branches/create.rb new file mode 100644 index 00000000000..127d5447d0a --- /dev/null +++ b/app/graphql/mutations/branches/create.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Mutations + module Branches + class Create < BaseMutation + include Mutations::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 |