Skip to content

Add versions array to package api response

Steve Abrams requested to merge 197962-package-versions-api into master

What does this MR do?

This adds an array of versions to the Package entity:

$ curl --header "PRIVATE-TOKEN: <redacted>" http://localhost:3001/api/v4/projects/1/packages/66

{
   "id":66,
   "name":"my/company/app/maven-app",
   "version":"1.0.0-SNAPSHOT",
   "package_type":"maven",
   "_links":{
      "web_path":"/gitlab-org/gitlab-test/-/packages/66",
      "delete_api_path":"http://127.0.0.1:3001/api/v4/projects/1/packages/66"
   },
   "created_at":"2020-04-28T04:42:11.551Z",
   "tags":[],
   "versions":[
      {
         "id":67,
         "version":"1.0.1-SNAPSHOT",
         "created_at":"2020-04-28T04:42:11.573Z"
         "pipeline": {...}
         "tags":[...]
      },
      {
         "id":68,
         "version":"1.0.2-SNAPSHOT",
         "created_at":"2020-04-29T04:42:11.573Z"
         "pipeline": {...}
         "tags":[...]
      },
      ...
   ]
}

Database

Query for the versions method:

EXPLAIN ANALYZE SELECT "packages_packages".* 
FROM   "packages_packages" 
WHERE  "packages_packages"."project_id" = 1 
       AND "packages_packages"."name" = 'my/company/app/maven-app' 
       AND "packages_packages"."version" != '1.0.0-SNAPSHOT' 
       AND "packages_packages"."package_type" = 1 
ORDER  BY "packages_packages"."version" ASC 
                                                                                    QUERY PLAN
══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
 Index Scan using idx_packages_packages_on_project_id_name_version_package_type on packages_packages  (cost=0.27..2.29 rows=1 width=68) (actual time=0.014..0.016 rows=4 loops=1)
   Index Cond: ((project_id = 1) AND ((name)::text = 'my/company/app/maven-app'::text) AND (package_type = 1))
   Filter: ((version)::text <> '1.0.0-SNAPSHOT'::text)
   Rows Removed by Filter: 1
 Planning Time: 0.310 ms
 Execution Time: 0.054 ms
(6 rows)

Visual Explain

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team

Related #197962 (closed)

Edited by Steve Abrams

Merge request reports