Commit 98522292 authored by Giorgenes Gelatti's avatar Giorgenes Gelatti Committed by Peter Leitzen

Adds package build info to api

- Adds `build_info` object to package api
- Specs for the new object
parent 3652e284
---
title: Add build metadata to package API
merge_request: 20682
author:
type: added
...@@ -79,7 +79,10 @@ Example response: ...@@ -79,7 +79,10 @@ Example response:
"web_path": "/namespace1/project1/-/packages/1", "web_path": "/namespace1/project1/-/packages/1",
"delete_api_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, "id": 2,
...@@ -90,7 +93,10 @@ Example response: ...@@ -90,7 +93,10 @@ Example response:
"web_path": "/namespace1/project1/-/packages/1", "web_path": "/namespace1/project1/-/packages/1",
"delete_api_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: ...@@ -133,7 +139,10 @@ Example response:
"web_path": "/namespace1/project1/-/packages/1", "web_path": "/namespace1/project1/-/packages/1",
"delete_api_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 ...@@ -875,6 +875,10 @@ module EE
include ::API::Helpers::RelatedResourcesHelpers include ::API::Helpers::RelatedResourcesHelpers
extend EntityHelpers extend EntityHelpers
class BuildInfo < Grape::Entity
expose :pipeline_id
end
expose :id expose :id
expose :name expose :name
expose :version expose :version
...@@ -893,6 +897,7 @@ module EE ...@@ -893,6 +897,7 @@ module EE
expose :created_at expose :created_at
expose :project_id, if: ->(_, opts) { opts[:group] } expose :project_id, if: ->(_, opts) { opts[:group] }
expose :project_path, if: ->(obj, opts) { opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project) } expose :project_path, if: ->(obj, opts) { opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project) }
expose :build_info, using: BuildInfo
private private
......
...@@ -28,6 +28,12 @@ FactoryBot.define do ...@@ -28,6 +28,12 @@ FactoryBot.define do
after :create do |package| after :create do |package|
create :package_file, :npm, package: package create :package_file, :npm, package: package
end 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 end
factory :nuget_package do factory :nuget_package do
...@@ -59,6 +65,9 @@ FactoryBot.define do ...@@ -59,6 +65,9 @@ FactoryBot.define do
end end
end end
factory :package_build_info, class: Packages::BuildInfo do
end
factory :package_file, class: Packages::PackageFile do factory :package_file, class: Packages::PackageFile do
package 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 ...@@ -167,6 +167,19 @@ describe API::ProjectPackages do
it_behaves_like 'destroy url' it_behaves_like 'destroy url'
end 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
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