0

I am writing application which consume gitlab api.

for that i want to search / filter commits by both branch and commit message.

But Gitlab support two endpoints which are

Search :

/api/v4/projects/24/search?scope=commits&search=fixed

this will filter only by message, not by branch.

From Commits api

/projects/:id/repository/commits

Repository commits

Even this support only for few parameters.

But i want to filter commits done for specific branch.

Chamly Idunil
  • 1,848
  • 1
  • 18
  • 33

1 Answers1

0

Don't think you can get filtered response both by message and branch in single api call.

  1. You can use commits api to get all commits filtered by branch and then you can filter them by message within your application.

GET /projects/:id/repository/commits?ref_name=<your branch name>

Sample response:

[
  {
    "id": "ed899a2f4b50b4370feeea94676502b42383c746",
    "short_id": "ed899a2f4b5",
    "title": "Replace sanitize with escape once",
    "author_name": "Example User",
    "author_email": "user@example.com",
    "authored_date": "2012-09-20T11:50:22+03:00",
    "committer_name": "Administrator",
    "committer_email": "admin@example.com",
    "committed_date": "2012-09-20T11:50:22+03:00",
    "created_at": "2012-09-20T11:50:22+03:00",
    "message": "Replace sanitize with escape once",   ----> Message
    "parent_ids": [
      "6104942438c14ec7bd21c6cd5bd995272b3faff6"
    ],
    "web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
  }
]
  1. Or you can search by the message first and then get the list of refs a commit belongs to using GET /projects/:id/repository/commits/:sha/refs This will entail two API calls though, one to get commits filtered by message and then to get list of refs a commit belongs to.
[
  {"type": "branch", "name": "'test'"},
  {"type": "branch", "name": "add-balsamiq-file"},
  {"type": "branch", "name": "wip"},
  {"type": "tag", "name": "v1.1.0"}
 ]
Shashank V
  • 10,007
  • 2
  • 25
  • 41