你可以使用 REST API 从 github 迁移到 azure,参考文档在这里:Import Request-Create-REST API(Azure DevOps Git)
但是,如果您的存储库是私有的,那么首先创建“其他 git”服务连接对您来说至关重要,然后您可以使用 Rest API 将 Github Private Repo 导入到 New Repo。
1、你可以使用Rest API来创建它。文件在这里:
EndPoints-Create-REST-API
例如:
网址
POST https://dev.azure.com/{organization}/_apis/serviceendpoint/endpoints?api-version=6.0-preview.4
请求正文
{
"authorization":{"scheme":"UsernamePassword","parameters":{"username":"{User name}","password":"{github access token }"}},
"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"
}
您可以在邮递员中进行测试:
发送创建端点 API 后,它将在您的 Azure DevOps 中成功创建端点。
注意:如何获取 github 访问令牌:
路径:设置->开发设置->个人访问令牌
2 然后您可以在步骤 1 中获取 ServiceEndPointId,您可以在 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": false
}
}
您可以在邮递员中进行测试:
3 此外,以下脚本是一个 power shell 示例:
[String]$Org = "your organization name"
[String]$project = "your project name"
[String]$PAT="your PAT "
[String]$Repo="your Repo name"
[String]$serviceEndpointId="your serviceEndpointId"
$url = https://dev.azure.com/+$Org+"/"+"$project"+"/_apis/git/repositories/"+$Repo+"/importRequests?api-version=6.1-preview.1"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$PAT )))
$body = @{
"parameters" = @{
"gitSource" =@{
# the source git repository to import and remember to replace with your correct url
"url" = https://github.com/xxxx
}
"serviceEndpointId" = ]$serviceEndpointId
"deleteServiceEndpointAfterImportIsDone" = false
}
}
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$PAT )))
$result = Invoke-RestMethod -Method 'Post' -Uri $url -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body ($body|ConvertTo-Json) -ContentType "application/json"
$result | ConvertTo-Json
在 power shell 中运行脚本后,您可以在 json 中获得以下响应信息,这意味着您已成功从 github 迁移到 azure 并使用 REST API: