I'm using:
GET https://localhost/api/v4/search?scope=projects&search=test
to find project named "test" , but I get not only project named "test" but "qtest", "testot" or "test1" too.
Is it possible to get only exact name?
I'm using:
GET https://localhost/api/v4/search?scope=projects&search=test
to find project named "test" , but I get not only project named "test" but "qtest", "testot" or "test1" too.
Is it possible to get only exact name?
According to the Projects API, no. It will return all projects that contain your search string, but you should be able to filter the results once you retrieve it.
The available options are sort
and order_by
. You can order by the fields id
, name
, created_at
, and last_activity_at
One may use jq
to filter the returned results from a fuzzy search:
project_name="test"
curl --silent --show-error --location \
"https://gitlab.com/api/v4/search?scope=projects&search=${project_name}" \
--header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq \
--raw-output --arg project_name "${project_name}" '.[] | \
select(.name == $project_name)'
Of course, this returns 12 projects. Which one is mine?
It is far better if you can include a namespace.
project_path_with_namespace="$username/test"
curl --silent --show-error --location \
"https://gitlab.com/api/v4/search?scope=projects&search=${project_path_with_namespace}" \
--header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq \
--arg path_with_namespace "${project_path_with_namespace}" '.[] | \
select(.path_with_namespace == $path_with_namespace)'
Now the search is not fuzzy and will always return a precise result so long as such a project exists at that path.