Commit dbcd4ec7 authored by James Lopez's avatar James Lopez

Merge branch '247531-composer-source-jsonn' into 'master'

Include source in composer json payload

See merge request gitlab-org/gitlab!56693
parents 53a8c352 e6b45798
...@@ -29,6 +29,7 @@ class Packages::Package < ApplicationRecord ...@@ -29,6 +29,7 @@ class Packages::Package < ApplicationRecord
delegate :recipe, :recipe_path, to: :conan_metadatum, prefix: :conan delegate :recipe, :recipe_path, to: :conan_metadatum, prefix: :conan
delegate :codename, :suite, to: :debian_distribution, prefix: :debian_distribution delegate :codename, :suite, to: :debian_distribution, prefix: :debian_distribution
delegate :target_sha, to: :composer_metadatum, prefix: :composer
validates :project, presence: true validates :project, presence: true
validates :name, 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: ...@@ -274,8 +274,21 @@ To install a package:
composer update 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. 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: WARNING:
Never commit the `auth.json` file to your repository. To install packages from a CI/CD job, 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 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 ...@@ -28,20 +28,34 @@ module Gitlab
def package_metadata(package) def package_metadata(package)
json = package.composer_metadatum.composer_json 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 end
def package_dist(package) 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) 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', 'type' => 'zip',
'url' => expose_url(archive_api_path) + "?sha=#{sha}", 'url' => expose_url(archive_api_path) + "?sha=#{package.composer_target_sha}",
'reference' => sha, 'reference' => package.composer_target_sha,
'shasum' => '' 'shasum' => ''
} }
end 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 end
end end
...@@ -27,6 +27,11 @@ RSpec.describe Gitlab::Composer::VersionIndex do ...@@ -27,6 +27,11 @@ RSpec.describe Gitlab::Composer::VersionIndex do
'type' => 'zip', 'type' => 'zip',
'url' => "http://localhost/api/v4/projects/#{project.id}/packages/composer/archives/#{package.name}.zip?sha=#{branch.target}" '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, 'name' => package.name,
'uid' => package.id, 'uid' => package.id,
'version' => package.version 'version' => package.version
......
...@@ -9,8 +9,8 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do ...@@ -9,8 +9,8 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do
let_it_be(:json) { { 'name' => package_name } } let_it_be(:json) { { 'name' => package_name } }
let_it_be(:group) { create(:group) } 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(: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!(: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!(:package2) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '2.0.0', json: json) }
let(:branch) { project.repository.find_branch('master') } let(:branch) { project.repository.find_branch('master') }
...@@ -28,6 +28,11 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do ...@@ -28,6 +28,11 @@ RSpec.describe ::Packages::Composer::PackagesPresenter do
'type' => 'zip', 'type' => 'zip',
'url' => "http://localhost/api/v4/projects/#{project.id}/packages/composer/archives/#{package.name}.zip?sha=#{branch.target}" '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, 'name' => package.name,
'uid' => package.id, 'uid' => package.id,
'version' => package.version '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