debian-mirror-gitlab/app/graphql/mutations/release_asset_links/create.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.5 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
module Mutations
module ReleaseAssetLinks
class Create < BaseMutation
graphql_name 'ReleaseAssetLinkCreate'
2022-04-04 11:22:00 +05:30
include FindsProject
2021-04-17 20:07:23 +05:30
include Types::ReleaseAssetLinkSharedInputArguments
2022-04-04 11:22:00 +05:30
authorize :create_release
2021-10-27 15:23:28 +05:30
argument :project_path, GraphQL::Types::ID,
2021-04-17 20:07:23 +05:30
required: true,
description: 'Full path of the project the asset link is associated with.'
2021-10-27 15:23:28 +05:30
argument :tag_name, GraphQL::Types::String,
2021-04-17 20:07:23 +05:30
required: true, as: :tag,
description: "Name of the associated release's tag."
field :link,
Types::ReleaseAssetLinkType,
null: true,
2021-10-27 15:23:28 +05:30
description: 'Asset link after mutation.'
2021-04-17 20:07:23 +05:30
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
2021-09-30 23:02:18 +05:30
unless Ability.allowed?(current_user, :update_release, release)
raise_resource_not_available_error!
end
2023-05-27 22:25:52 +05:30
result = ::Releases::Links::CreateService
.new(release, current_user, link_attrs)
.execute
if result.success?
{ link: result.payload[:link], errors: [] }
else
{ link: nil, errors: result.message }
2021-04-17 20:07:23 +05:30
end
end
end
end
end