使用 Azure devops REST API 获取 github 存储库 [英] Get github repository using Azure devops REST API
问题描述
我正在使用邮递员和 Azure Devops REST API 创建一些存储库 (https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0)之后,我需要将另一个项目的 repo 转移或克隆到新的项目,但 API 无法实现.唯一的方法是获取 .git 文件,因此我将 repo 放在私有 github 中,但我不知道如何将凭据传递给 PostMan.我尝试了一个公开的,它奏效了.
I am using postman and Azure Devops REST API to create some repositories (https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=6.0) After that I need to transfer or clone a repo from another projet to the new one but it is not possible with the API. The only way is to get an .git file so I put the repo in a private github but I don't know how to pass the credentials into PostMan. I tried with a public one, it worked.
推荐答案
用于使用 Rest API 将 Private Repo 导入新的 repo:
For using Rest API to import Private Repo to new repo:
您需要创建一个其他 git";首先服务连接,然后您可以使用 Rest API 将 Github 私有仓库导入新仓库.
You need to create an "other git" service connection first, then you could use the Rest API to import the Github Private Repo to New Repo.
请参考以下步骤:
步骤 1:创建一个其他 Git 服务连接.
Step1: Create an Other Git Service connection.
您可以使用 Rest API 来创建它.
You could use Rest API to create it.
例如:
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,并且您可以在导入存储库 Rest API 中使用它.
Then you could get the ServiceEndPointId, and you could use it in the Import Repo Rest API.
例如:
网址
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
}
}
这篇关于使用 Azure devops REST API 获取 github 存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!