【发布时间】:2021-05-05 11:15:15
【问题描述】:
我在 Github 存储库中有一个代码,想将其克隆/复制到 Azure 存储库,有什么方法可以通过 Curl 来实现
【问题讨论】:
标签: rest curl azure-devops azure-repos
我在 Github 存储库中有一个代码,想将其克隆/复制到 Azure 存储库,有什么方法可以通过 Curl 来实现
【问题讨论】:
标签: rest curl azure-devops azure-repos
有什么办法可以通过 Curl 做到这一点
是的。该方法存在。
您需要使用 curl 运行以下 Rest API 来创建 Other 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
更详细的信息可以参考我的另一张票:Get github repository using Azure devops REST API
这个方法比较复杂。我建议您可以在 Azure Repo 中使用 Import repository 选项直接导入 github repo。
您可以导入克隆 URL 和身份验证信息,然后 repo 将直接克隆到 Azure Repo。
【讨论】: