2020-07-10 11:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
module Composer
|
|
|
|
class ComposerJsonService
|
2020-10-13 14:08:58 -04:00
|
|
|
InvalidJson = Class.new(StandardError)
|
|
|
|
|
2020-07-10 11:09:07 -04:00
|
|
|
def initialize(project, target)
|
2021-04-19 17:09:27 -04:00
|
|
|
@project = project
|
|
|
|
@target = target
|
2020-07-10 11:09:07 -04:00
|
|
|
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
|
2020-10-13 14:08:58 -04:00
|
|
|
raise InvalidJson, 'Could not parse composer.json file. Invalid JSON.'
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def composer_file_not_found!
|
2020-10-13 14:08:58 -04:00
|
|
|
raise InvalidJson, 'The file composer.json was not found.'
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|