Commit e6b45798 authored by Steve Abrams's avatar Steve Abrams

Include source in composer json payload

Include git source as part of the
Composer version spec json
parent ea498493
......@@ -29,6 +29,7 @@ class Packages::Package < ApplicationRecord
delegate :recipe, :recipe_path, to: :conan_metadatum, prefix: :conan
delegate :codename, :suite, to: :debian_distribution, prefix: :debian_distribution
delegate :target_sha, to: :composer_metadatum, prefix: :composer
validates :project, presence: true
validates :name, presence: true
......
---
title: Support for --prefer-source option for Composer registry
merge_request: 56693
author:
type: changed
......@@ -274,8 +274,21 @@ To install a package:
composer update
```
Or to install the single package:
```shell
composer req <package-name>:<package-version>
```
If successful, you should see output indicating that the package installed successfully.
You can also install from source (by pulling the Git repository directly) using the
`--prefer-source` option:
```shell
composer update --prefer-source
```
WARNING:
Never commit the `auth.json` file to your repository. To install packages from a CI/CD job,
consider using the [`composer config`](https://getcomposer.org/doc/articles/handling-private-packages.md#satis) tool with your personal access token
......
......@@ -28,20 +28,34 @@ module Gitlab
def package_metadata(package)
json = package.composer_metadatum.composer_json
json.merge('dist' => package_dist(package), 'uid' => package.id, 'version' => package.version)
json.merge(
'dist' => package_dist(package),
'source' => package_source(package),
'uid' => package.id,
'version' => package.version
)
end
def package_dist(package)
sha = package.composer_metadatum.target_sha
archive_api_path = api_v4_projects_packages_composer_archives_package_name_path({ id: package.project_id, package_name: package.name, format: '.zip' }, true)
{
'type' => 'zip',
'url' => expose_url(archive_api_path) + "?sha=#{sha}",
'reference' => sha,
'url' => expose_url(archive_api_path) + "?sha=#{package.composer_target_sha}",
'reference' => package.composer_target_sha,
'shasum' => ''
}
end
def package_source(package)
git_url = package.project.http_url_to_repo
{
'type' => 'git',
'url' => git_url,
'reference' => package.composer_target_sha
}
end
end
end
end
......@@ -27,6 +27,11 @@ RSpec.describe Gitlab::Composer::VersionIndex do
'type' => 'zip',
'url' => "http://localhost/api/v4/projects/#{project.id}/packages/composer/archives/#{package.name}.zip?sha=#{branch.target}"
},
'source' => {
'reference' => branch.target,
'type' => 'git',
'url' => project.http_url_to_repo
},
'name' => package.name,
'uid' => package.id,
'version' => package.version
......
......@@ -9,8 +9,8 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do
let_it_be(:json) { { 'name' => package_name } }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :custom_repo, files: { 'composer.json' => json.to_json }, group: group) }
let_it_be(:package1) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '1.0.0', json: json) }
let_it_be(:package2) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '2.0.0', json: json) }
let!(:package1) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '1.0.0', json: json) }
let!(:package2) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '2.0.0', json: json) }
let(:branch) { project.repository.find_branch('master') }
......@@ -28,6 +28,11 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do
'type' => 'zip',
'url' => "http://localhost/api/v4/projects/#{project.id}/packages/composer/archives/#{package.name}.zip?sha=#{branch.target}"
},
'source' => {
'reference' => branch.target,
'type' => 'git',
'url' => "http://localhost/#{group.path}/#{project.path}.git"
},
'name' => package.name,
'uid' => package.id,
'version' => package.version
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment