Commit 7df75cf1 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '197923-add-pipeline-to-packages-list-api' into 'master'

Add additional pipeline information to packages list api endpoint

See merge request gitlab-org/gitlab!28040
parents b8eda52e 68e10d3f
...@@ -73,6 +73,10 @@ GET /groups/:id/packages ...@@ -73,6 +73,10 @@ GET /groups/:id/packages
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/packages?exclude_subgroups=true curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/groups/:id/packages?exclude_subgroups=true
``` ```
CAUTION: **Deprecation**
> The `build_info` attribute in the response is deprecated in favour of `pipeline`.
> Introduced [GitLab 12.10](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28040).
Example response: Example response:
```json ```json
...@@ -87,15 +91,17 @@ Example response: ...@@ -87,15 +91,17 @@ Example response:
"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": {
"pipeline": { "id": 123,
"id": 123, "status": "pending",
"status": "pending", "ref": "new-pipeline",
"ref": "new-pipeline", "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", "web_url": "https://example.com/foo/bar/pipelines/47",
"web_url": "https://example.com/foo/bar/pipelines/47", "created_at": "2016-08-11T11:28:34.085Z",
"created_at": "2016-08-11T11:28:34.085Z", "updated_at": "2016-08-11T11:32:35.169Z",
"updated_at": "2016-08-11T11:32:35.169Z", "user": {
"name": "Administrator",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
} }
} }
}, },
...@@ -109,15 +115,17 @@ Example response: ...@@ -109,15 +115,17 @@ Example response:
"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": {
"pipeline": { "id": 123,
"id": 123, "status": "pending",
"status": "pending", "ref": "new-pipeline",
"ref": "new-pipeline", "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", "web_url": "https://example.com/foo/bar/pipelines/47",
"web_url": "https://example.com/foo/bar/pipelines/47", "created_at": "2016-08-11T11:28:34.085Z",
"created_at": "2016-08-11T11:28:34.085Z", "updated_at": "2016-08-11T11:32:35.169Z",
"updated_at": "2016-08-11T11:32:35.169Z", "user": {
"name": "Administrator",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
} }
} }
} }
...@@ -150,6 +158,10 @@ GET /projects/:id/packages/:package_id ...@@ -150,6 +158,10 @@ GET /projects/:id/packages/:package_id
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/:id/packages/:package_id curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/:id/packages/:package_id
``` ```
CAUTION: **Deprecation**
> The `build_info` attribute in the response is deprecated in favour of `pipeline`.
> Introduced [GitLab 12.10](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28040).
Example response: Example response:
```json ```json
...@@ -163,15 +175,17 @@ Example response: ...@@ -163,15 +175,17 @@ Example response:
"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": {
"pipeline": { "id": 123,
"id": 123, "status": "pending",
"status": "pending", "ref": "new-pipeline",
"ref": "new-pipeline", "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", "web_url": "https://example.com/foo/bar/pipelines/47",
"web_url": "https://example.com/foo/bar/pipelines/47", "created_at": "2016-08-11T11:28:34.085Z",
"created_at": "2016-08-11T11:28:34.085Z", "updated_at": "2016-08-11T11:32:35.169Z",
"updated_at": "2016-08-11T11:32:35.169Z", "user": {
"name": "Administrator",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
} }
} }
} }
......
---
title: Adds additional pipeline information to packages API result
merge_request: 28040
author:
type: added
...@@ -25,14 +25,19 @@ module EE ...@@ -25,14 +25,19 @@ 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: Package::BuildInfo
expose :tags expose :tags
expose :pipeline, if: ->(package) { package.build_info }, using: Package::Pipeline
private private
def project_path def project_path
object.project.full_path object.project.full_path
end end
def pipeline
object.build_info.pipeline
end
end end
end end
end end
......
...@@ -4,8 +4,8 @@ module EE ...@@ -4,8 +4,8 @@ module EE
module API module API
module Entities module Entities
class Package < Grape::Entity class Package < Grape::Entity
class BuildInfo < Grape::Entity class Pipeline < ::API::Entities::PipelineBasic
expose :pipeline, using: ::API::Entities::PipelineBasic expose :user, using: ::API::Entities::UserBasic
end end
end end
end end
......
{ {
"type": "object", "type": "object",
"required": ["name", "version", "package_type"], "required": ["name", "version", "package_type", "pipeline"],
"properties": { "properties": {
"name": { "type": "string" }, "name": { "type": "string" },
"version": { "type": "string" }, "version": { "type": "string" },
"package_type": { "type": "string" }, "package_type": { "type": "string" },
"build_info": { "pipeline": { "$ref": "../pipeline.json" }
"type": "object",
"required": ["pipeline"],
"properties": {
"pipeline": { "$ref": "../pipeline.json" }
}
}
} }
} }
...@@ -227,10 +227,10 @@ describe API::ProjectPackages do ...@@ -227,10 +227,10 @@ describe API::ProjectPackages do
it_behaves_like 'destroy url' it_behaves_like 'destroy url'
end end
context 'with build info' do context 'with pipeline' do
let!(:package1) { create(:npm_package, :with_build, project: project) } let!(:package1) { create(:npm_package, :with_build, project: project) }
it 'returns the build info' do it 'returns the pipeline info' do
project.add_developer(user) project.add_developer(user)
get api(package_url, user) get api(package_url, user)
......
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