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

create.rb « release_asset_links « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ff9d98d2c0f5ba9652b8c3462928033465dcf097 (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
# frozen_string_literal: true

module Mutations
  module ReleaseAssetLinks
    class Create < BaseMutation
      include FindsProject

      graphql_name 'ReleaseAssetLinkCreate'

      authorize :create_release

      include Types::ReleaseAssetLinkSharedInputArguments

      argument :project_path, GraphQL::ID_TYPE,
               required: true,
               description: 'Full path of the project the asset link is associated with.'

      argument :tag_name, GraphQL::STRING_TYPE,
               required: true, as: :tag,
               description: "Name of the associated release's tag."

      field :link,
            Types::ReleaseAssetLinkType,
            null: true,
            description: 'The asset link after mutation.'

      def resolve(project_path:, tag:, **link_attrs)
        project = authorized_find!(project_path)
        release = project.releases.find_by_tag(tag)

        if release.nil?
          message = _('Release with tag "%{tag}" was not found') % { tag: tag }
          return { link: nil, errors: [message] }
        end

        unless Ability.allowed?(current_user, :update_release, release)
          raise_resource_not_available_error!
        end

        new_link = release.links.create(link_attrs)

        unless new_link.persisted?
          return { link: nil, errors: new_link.errors.full_messages }
        end

        { link: new_link, errors: [] }
      end
    end
  end
end