GitLab API - 搜索项目
GitLab API - search project
我正在使用:
GET https://localhost/api/v4/search?scope=projects&search=test
找到名为“test”的项目,但我不仅找到了名为“test”的项目,还找到了“qtest”、“testot”或“test1”。
是否可以只得到确切的名字?
根据 Projects API,没有。它将 return 所有包含您的搜索字符串的项目,但您应该能够在检索到结果后对其进行过滤。
可用的选项是 sort
和 order_by
。您可以按 id
、name
、created_at
和 last_activity_at
字段排序
可以使用 jq
从模糊搜索中过滤 returned 结果:
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)'
当然,这returns 12个项目。哪一个是我的?
如果能包含命名空间就更好了。
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)'
现在搜索不再模糊,只要在该路径上存在这样的项目,搜索总是 return 精确的结果。
我正在使用:
GET https://localhost/api/v4/search?scope=projects&search=test
找到名为“test”的项目,但我不仅找到了名为“test”的项目,还找到了“qtest”、“testot”或“test1”。
是否可以只得到确切的名字?
根据 Projects API,没有。它将 return 所有包含您的搜索字符串的项目,但您应该能够在检索到结果后对其进行过滤。
可用的选项是 sort
和 order_by
。您可以按 id
、name
、created_at
和 last_activity_at
可以使用 jq
从模糊搜索中过滤 returned 结果:
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)'
当然,这returns 12个项目。哪一个是我的?
如果能包含命名空间就更好了。
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)'
现在搜索不再模糊,只要在该路径上存在这样的项目,搜索总是 return 精确的结果。