2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Composer
|
|
|
|
class ComposerJsonService
|
2021-01-03 14:25:43 +05:30
|
|
|
InvalidJson = Class.new(StandardError)
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def initialize(project, target)
|
2021-04-29 21:17:54 +05:30
|
|
|
@project = project
|
|
|
|
@target = target
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
composer_json
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def composer_json
|
|
|
|
composer_file = @project.repository.blob_at(@target, 'composer.json')
|
|
|
|
|
|
|
|
composer_file_not_found! unless composer_file
|
|
|
|
|
|
|
|
Gitlab::Json.parse(composer_file.data)
|
|
|
|
rescue JSON::ParserError
|
2021-01-03 14:25:43 +05:30
|
|
|
raise InvalidJson, 'Could not parse composer.json file. Invalid JSON.'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def composer_file_not_found!
|
2021-01-03 14:25:43 +05:30
|
|
|
raise InvalidJson, 'The file composer.json was not found.'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|