我正在使用邮差和Azure Devops REST API创建一些存储库(https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0) 之后,我需要将仓库从另一个项目转移或克隆到新项目,但是使用API无法实现。唯一的方法是获取.git文件,因此我将存储库放入私有github中,但我不知道如何将凭据传递到PostMan中。我尝试了一个公开的尝试。
答案 0 :(得分:1)
使用Rest API将私有存储库导入到新存储库中:
您需要先创建一个“其他git”服务连接,然后才能使用Rest API将Github私有存储库导入到新存储库。
请参考以下步骤:
第一步:创建一个 Other Git 服务连接。
您可以使用Rest API来创建它。
例如:
Post https://dev.azure.com/{Organization Name}/_apis/serviceendpoint/endpoints?api-version=6.0-preview.4
请求正文示例:
{
"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"
}
或者您可以在项目设置->服务连接->新服务连接->其他Git
中创建它然后您可以获取 ServiceEndPointId ,并可以在Import Repo Rest API中使用它。
例如:
URL
Post https://dev.azure.com/{Organization Name}/{Project Name}/_apis/git/repositories/{Repo Name}/importRequests?api-version=5.0-preview.1
请求正文:
{
"parameters": {
"gitSource": {
"url": "Git URL"
},
"serviceEndpointId": "{Service EndPoint Id}",
"deleteServiceEndpointAfterImportIsDone": true
}
}