如何使用 curl 删除 GitLab 存储库?

typ*_*gic 5 git rest curl token gitlab

我可以使用 GitHub 实现这一点。但是我无法对 GitLab 做同样的事情。目前,我所拥有的是:

curl -u "$user:$token" -H "Content-Type:application/json" -H "PRIVATE-TOKEN:$token" \
-X DELETE https://git.lab.com/api/v4/projects/$repo_name
Run Code Online (Sandbox Code Playgroud)

然后我收到这个错误:

curl: (35) error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error
Run Code Online (Sandbox Code Playgroud)

我已经有一个使用 curl 在命令行上创建 GitLab 存储库的工作脚本,所以我的 curl 工作正常。我只需要删除部分。

zsl*_*ltg 7

按项目路径删除项目

curl -H 'Content-Type: application/json' -H 'Private-Token: $privatetoken' \
-X DELETE https://gitlab.com/api/v4/projects/$namespace%2F$projectname
Run Code Online (Sandbox Code Playgroud)

SSL 错误的可能原因

命名空间路径编码

URI 由服务器端的正斜杠分割,然后对生成的路径元素进行分类。

由于正斜杠被视为特殊字符,如果我们想将其作为 URI 路径元素包含在内,我们需要对其进行URL 编码,因此服务器不会尝试拆分它。

如果您正在执行带有 ID 后面附加参数的请求,这将如何导致问题变得更加明显。

在以下示例中$namespacefoo$projectnamebar

好的

要求: GET /projects/foo%2Fbar/users

URI 路径元素:

  • projects - 调用将在其上执行的资源
  • foo%2Fbar- 具体的资源(项目)名称是foo/bar(经过 URL 解码后)
  • users - 返回的资源

坏的

要求: GET /projects/foo/bar/users

URI 路径元素:

  • projects - 调用将在其上执行的资源
  • foo- 特定资源(项目)名称是foo(没有这样的项目,缺少命名空间)
  • bar - 要查询的资源或要执行的操作(没有这样的资源或操作)
  • users - 附加查询参数(父资源或操作首先不存在)

API 端点

如果您使用托管在https://gitlab.com/的公共 GitLab ,则应使用gitlab.com域名而不是git.lab.com,后者不归 GitLab Inc 所有。