Reputation: 115
GitLab API how to get the last commit?
GET /projects/:id/repository/tree
{
"name": "assets",
"type": "tree",
"mode": "040000",
"id": "6229c43a7e16fcc7e95f923f8ddadb8281d9c6c6"
}
How to get logs_tree
? Last commit?
Upvotes: 6
Views: 17247
Reputation: 136
I would recommend follow the spec listed here which says that you can use
GET /projects/:id/repository/commits/tree
to return the following example data:
{
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
"short_id": "6104942438c",
"title": "Sanitize for network graph",
"author_name": "randx",
"author_email": "[email protected]",
"created_at": "2012-09-20T09:06:12+03:00",
"message": "Sanitize for network graph",
"committed_date": "2012-09-20T09:06:12+03:00",
"authored_date": "2012-09-20T09:06:12+03:00",
"parent_ids": [
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
],
"status": "running"
}
This is the latest commit. In terms of finding logs_tree
the full documentation may help you.
Upvotes: -1
Reputation: 621
At the current version of API we have only one way to solve this problem
GET /api/v4/projects/:id/repository/commits
The first commit in the array will be the desired one. You can extract it with jq '.[0]'
.
Upvotes: 3
Reputation: 81
Since at least version 12.10 GitLab supports pagination. That's why the call returns only one commit.
GET /api/v4/projects/:id/repository/commits?per_page=1
Upvotes: 6
Reputation: 31
You can use this API.
GET /projects/:id/repository/branches/:branch
The result of this API includes the latest commit of the branch.
https://docs.gitlab.com/ee/api/branches.html#get-single-repository-branch
Upvotes: 3