diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 18:18:33 +0000 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/graphql/mutations/release_asset_links/create.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) | |
download | gitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/graphql/mutations/release_asset_links/create.rb')
-rw-r--r-- | app/graphql/mutations/release_asset_links/create.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/app/graphql/mutations/release_asset_links/create.rb b/app/graphql/mutations/release_asset_links/create.rb new file mode 100644 index 00000000000..02704efb47c --- /dev/null +++ b/app/graphql/mutations/release_asset_links/create.rb @@ -0,0 +1,46 @@ +# 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 + + 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 |