我在 Github 存储库中有一个代码,想将它 clone/copy 到 Azure 存储库,有没有办法通过 Rest 做到这一点

I have a code in Github repo and wants to clone/copy it to the Azure repository, Is there any way to do it via Rest

我在 Github 存储库中有一个代码,想将它 clone/copy 到 Azure 存储库,有什么方法可以通过 Curl 实现吗

Is there any way to do it via Curl

是的。方法存在。

您需要使用curl来运行以下RestAPI创建其他Git服务连接

Post https://dev.azure.com/{Organization Name}/_apis/serviceendpoint/endpoints?api-version=6.0-preview.4 

卷曲示例:

curl -X  POST \
-u USERName:PAT  "https://dev.azure.com/org/_apis/serviceendpoint/endpoints?api-version=6.0-preview.4" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{ 
    "authorization":{"scheme":"UsernamePassword","parameters":{"username":"{User name}","password":"{Password}"}},
    "data":{"accessExternalGitServer":"true"},
    "name":"{name}",
    "serviceEndpointProjectReferences":[{"description":"","name":"{Service connection name}","projectReference":{"id":"{Project Id}","name":"{Project Name}"}}],
    "type":"git",
    "url":"{Target Git URL}",
    "isShared":false,
    "owner":"library"

}' 

然后您可以使用 importRequests Rest API 将 Github Repo 导入到 Azure Repo。

Post https://dev.azure.com/{Organization Name}/{Project Name}/_apis/git/repositories/{Repo Name}/importRequests?api-version=5.0-preview.1

更详细的可以参考我的另一张工单:

这个方法比较复杂。我建议您可以使用 Azure Repo 中的 Import repository 选项直接导入 github repo。

您可以导入克隆 URL 和授权信息,然后 repo 将直接克隆到 Azure Repo。