【问题标题】: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 存储库中有一个代码,想将其克隆/复制到 Azure 存储库,有什么方法可以通过 Rest 完成
【发布时间】:2021-05-05 11:15:15
【问题描述】:

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

【问题讨论】:

标签: rest curl azure-devops azure-repos


【解决方案1】:

有什么办法可以通过 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。

【讨论】:

  • 非常感谢凯文,这回答了我的问题。你帮了大忙。
  • @Vishal 很高兴知道这个答案会有所帮助。您可以考虑接受它作为这样的答案:meta.stackexchange.com/questions/5234/…。这将对其他用户有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 2016-10-09
  • 1970-01-01
相关资源
最近更新 更多