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
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:
```json
......@@ -87,15 +91,17 @@ Example response:
"delete_api_path": "/namespace1/project1/-/packages/1"
},
"created_at": "2019-11-27T03:37:38.711Z",
"build_info": {
"pipeline": {
"id": 123,
"status": "pending",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
"created_at": "2016-08-11T11:28:34.085Z",
"updated_at": "2016-08-11T11:32:35.169Z",
"pipeline": {
"id": 123,
"status": "pending",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
"created_at": "2016-08-11T11:28:34.085Z",
"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:
"delete_api_path": "/namespace1/project1/-/packages/1"
},
"created_at": "2019-11-27T03:37:38.711Z",
"build_info": {
"pipeline": {
"id": 123,
"status": "pending",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
"created_at": "2016-08-11T11:28:34.085Z",
"updated_at": "2016-08-11T11:32:35.169Z",
"pipeline": {
"id": 123,
"status": "pending",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
"created_at": "2016-08-11T11:28:34.085Z",
"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
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:
```json
......@@ -163,15 +175,17 @@ Example response:
"delete_api_path": "/namespace1/project1/-/packages/1"
},
"created_at": "2019-11-27T03:37:38.711Z",
"build_info": {
"pipeline": {
"id": 123,
"status": "pending",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
"created_at": "2016-08-11T11:28:34.085Z",
"updated_at": "2016-08-11T11:32:35.169Z",
"pipeline": {
"id": 123,
"status": "pending",
"ref": "new-pipeline",
"sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
"web_url": "https://example.com/foo/bar/pipelines/47",
"created_at": "2016-08-11T11:28:34.085Z",
"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
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: Package::BuildInfo
expose :tags
expose :pipeline, if: ->(package) { package.build_info }, using: Package::Pipeline
private
def project_path
object.project.full_path
end
def pipeline
object.build_info.pipeline
end
end
end
end
......
......@@ -4,8 +4,8 @@ module EE
module API
module Entities
class Package < Grape::Entity
class BuildInfo < Grape::Entity
expose :pipeline, using: ::API::Entities::PipelineBasic
class Pipeline < ::API::Entities::PipelineBasic
expose :user, using: ::API::Entities::UserBasic
end
end
end
......
{
"type": "object",
"required": ["name", "version", "package_type"],
"required": ["name", "version", "package_type", "pipeline"],
"properties": {
"name": { "type": "string" },
"version": { "type": "string" },
"package_type": { "type": "string" },
"build_info": {
"type": "object",
"required": ["pipeline"],
"properties": {
"pipeline": { "$ref": "../pipeline.json" }
}
}
"pipeline": { "$ref": "../pipeline.json" }
}
}
......@@ -227,10 +227,10 @@ describe API::ProjectPackages do
it_behaves_like 'destroy url'
end
context 'with build info' do
context 'with pipeline' do
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)
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