Commit d420b566 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '33596-package-ci-package-pipeline-api' into 'master'

Add build metadata to package API

See merge request gitlab-org/gitlab!20682
parents d777539a 98522292
---
title: Add build metadata to package API
merge_request: 20682
author:
type: added
......@@ -79,7 +79,10 @@ Example response:
"web_path": "/namespace1/project1/-/packages/1",
"delete_api_path": "/namespace1/project1/-/packages/1"
},
"created_at": "2019-11-27T03:37:38.711Z"
"created_at": "2019-11-27T03:37:38.711Z",
"build_info": {
"pipeline_id": 123
}
},
{
"id": 2,
......@@ -90,7 +93,10 @@ Example response:
"web_path": "/namespace1/project1/-/packages/1",
"delete_api_path": "/namespace1/project1/-/packages/1"
},
"created_at": "2019-11-27T03:37:38.711Z"
"created_at": "2019-11-27T03:37:38.711Z",
"build_info": {
"pipeline_id": 123
}
}
]
```
......@@ -133,7 +139,10 @@ Example response:
"web_path": "/namespace1/project1/-/packages/1",
"delete_api_path": "/namespace1/project1/-/packages/1"
},
"created_at": "2019-11-27T03:37:38.711Z"
"created_at": "2019-11-27T03:37:38.711Z",
"build_info": {
"pipeline_id": 123
}
}
```
......
......@@ -875,6 +875,10 @@ module EE
include ::API::Helpers::RelatedResourcesHelpers
extend EntityHelpers
class BuildInfo < Grape::Entity
expose :pipeline_id
end
expose :id
expose :name
expose :version
......@@ -893,6 +897,7 @@ module EE
expose :created_at
expose :project_id, if: ->(_, opts) { opts[:group] }
expose :project_path, if: ->(obj, opts) { opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project) }
expose :build_info, using: BuildInfo
private
......
......@@ -28,6 +28,12 @@ FactoryBot.define do
after :create do |package|
create :package_file, :npm, package: package
end
trait :with_build do
after :create do |package|
create :package_build_info, package: package, pipeline: create(:ci_build, user: package.project.creator).pipeline
end
end
end
factory :nuget_package do
......@@ -59,6 +65,9 @@ FactoryBot.define do
end
end
factory :package_build_info, class: Packages::BuildInfo do
end
factory :package_file, class: Packages::PackageFile do
package
......
{
"type": "object",
"required": ["name", "version", "package_type"],
"properties": {
"name": { "type": "string" },
"version": { "type": "string" },
"package_type": { "type": "string" },
"build_info": {
"type": "object",
"required": ["pipeline_id"],
"properties": {
"pipeline_id": { "type": "integer" }
}
}
}
}
......@@ -167,6 +167,19 @@ describe API::ProjectPackages do
it_behaves_like 'destroy url'
end
context 'with build info' do
let!(:package1) { create(:npm_package, :with_build, project: project) }
it 'returns the build info' do
project.add_developer(user)
get api(package_url, user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/packages/package_with_build', dir: 'ee')
end
end
end
end
......
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