debian-mirror-gitlab/app/graphql/mutations/releases/update.rb

71 lines
2 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module Mutations
module Releases
class Update < Base
graphql_name 'ReleaseUpdate'
field :release,
Types::ReleaseType,
null: true,
description: 'The release after mutation.'
argument :tag_name, GraphQL::STRING_TYPE,
required: true, as: :tag,
2021-03-08 18:12:59 +05:30
description: 'Name of the tag associated with the release.'
2021-02-22 17:27:13 +05:30
argument :name, GraphQL::STRING_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Name of the release.'
2021-02-22 17:27:13 +05:30
argument :description, GraphQL::STRING_TYPE,
required: false,
2021-03-08 18:12:59 +05:30
description: 'Description (release notes) of the release.'
2021-02-22 17:27:13 +05:30
argument :released_at, Types::TimeType,
required: false,
2021-03-08 18:12:59 +05:30
description: 'The release date.'
2021-02-22 17:27:13 +05:30
argument :milestones, [GraphQL::STRING_TYPE],
required: false,
description: 'The title of each milestone the release is associated with. GitLab Premium customers can specify group milestones.'
authorize :update_release
def ready?(**args)
if args.key?(:released_at) && args[:released_at].nil?
raise Gitlab::Graphql::Errors::ArgumentError,
'if the releasedAt argument is provided, it cannot be null'
end
if args.key?(:milestones) && args[:milestones].nil?
raise Gitlab::Graphql::Errors::ArgumentError,
'if the milestones argument is provided, it cannot be null'
end
super
end
def resolve(project_path:, **scalars)
2021-03-11 19:13:27 +05:30
project = authorized_find!(project_path)
2021-02-22 17:27:13 +05:30
params = scalars.with_indifferent_access
2021-03-08 18:12:59 +05:30
result = ::Releases::UpdateService.new(project, current_user, params).execute
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
if result[:status] == :success
2021-02-22 17:27:13 +05:30
{
2021-03-08 18:12:59 +05:30
release: result[:release],
2021-02-22 17:27:13 +05:30
errors: []
}
else
{
release: nil,
2021-03-08 18:12:59 +05:30
errors: [result[:message]]
2021-02-22 17:27:13 +05:30
}
end
end
end
end
end