Gitlab projects API "Search by project name"

Problem to solve

Background

Our developers created some very nice terraform that includes putting the project name and ref in an AWS tag for a resource. Unfortunately they did not put in the project ID, and I have a project to automate some changes in the Gitlab project files.

Goal

In a Powershell script I’m using AWS cli to retrieve the tags from the resource which includes the project name, then I’m using the gitlab projects api Search by Project Name to get the ID of the project so that my script can clone and update it.

I noticed right away that the “Search for projects by name” API is not as granular as I’d like. For instance, if I’m searching for a project with name ‘Project-A’ it returns both ‘Project-A’ and ‘Project-ABC’. I’d like for it to ONLY return ‘PROJECT-A’.

I’m working around this by further filtering results by the search term after the fact, but I want to make sure that there isn’t a way to make the API return only exact matches. The API documentation doesn’t mention anything that can help me in this.

Steps to reproduce

  1. Have two projects where the name of one is contained in the name of the other, i.e. “my-project-1” & “my-project-12”.
  2. Use the first project name “my-project-1” as the search term in the next step
  3. Use Gitlab api `GET https://<my.gitlab.url>/api/v4/projects?search=my-project-1
  4. Observe that 2 results (both projects mentioned in step 1) are returned.

Versions

Please select whether options apply, and add the version information.

Versions

  • 15.11.13-ee