如何递归克隆 Github App 的 repo

时间:2021-04-06 22:09:27

标签: git github github-app

我正在开发一个 Github 应用,它需要能够在发生推送事件时克隆 Github 存储库。

我已经成功地设置了所有内容,包括服务器并且可以 clone repositories using using access tokens 但是我在处理具有子模块的存储库时遇到了一些问题。

我发现如果 git clone --recurse-submodules https://x-access-token:<token>@github.com/owner/repo.git 具有使用 SSH 配置的子模块,则使用 repo.git 不起作用。有没有一种简单的方法可以使用访问令牌执行递归子模块获取?

我尝试了另一种方法,该方法涉及使用我的 github 应用程序的私有密钥 .pem 文件作为 SSH 身份。这涉及运行 ssh-agent bash -c 'ssh-add /path/to/private-key.pem; git clone --recurse-submodules git@github.com:owner/repo.git',但最终出现了 Permission denied (publickey) 错误,这是有道理的,因为 .pem 文件并不意味着有权访问存储库,只是为了验证 github 应用程序。

在编写 Github 应用程序时执行递归子模块克隆/获取的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

如果您认为对子模块使用 HTTPS 会更容易,您可以添加到您的配置中:

 git -c url."https://x-access-token:<token>@github.com/".insteadOf='git@github.com/' clone ...

对于具有 GitHub SSH URL 的任何子模块,将使用 HTTPS URL(使用您的访问令牌)。