我在 Github 存储库中有一个代码,想将其克隆/复制到 Azure 存储库,有没有办法通过 Rest 来完成

问题描述

我在 Github 存储库中有一个代码,想将其克隆/复制到 Azure 存储库,有什么方法可以通过 Curl 做到这一点

解决方法

有没有办法通过 Curl 做到这一点

是的。方法存在。

您需要使用 curl 运行以下 Rest API 来创建其他 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 存储库导入 Azure 存储库。

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

更详细的信息,你可以参考我的另一张票:Get github repository using Azure devops REST API

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

enter image description here

您可以导入克隆 URL 和身份验证信息,然后 repo 将直接克隆到 Azure Repo。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...