Get gitlab file archive for most recent release

Viewed 330

This will let me get an archive from a repo:

GET /projects/:id/repository/archive.tar.gz

Is there any way to pass a parameter such that I get an archive for the latest release rather than just the HEAD?

1 Answers

You can get the tags of repository using the following API:

GET /projects/:id/repository/tags

As the docs describe https://docs.gitlab.com/ee/api/tags.html#list-project-repository-tags
You get a list of repository tags from a project, sorted by update date and time in descending order

In combination with the archive API

GET /projects/:id/repository/archive[.format]

We can have the latest release with the following one-liner:

curl  --header "PRIVATE-TOKEN: <private token>" https://gitlab.com/api/v4/projects/<project id>/repository/archive.tar.gz?sha=$(curl -s --header "PRIVATE-TOKEN: <private token>" "https://gitlab.com/api/v4/projects/<project id>/repository/tags" | jq '.[0].commit.id' | sed 's/^"\(.*\)"$/\1/') -o /path/to/file
Related