Azure DevOps 导入 Git 个需要通过 API 授权的存储库
Azure DevOps import Git repositories requiring authorization via API
我能够使用记录在案的 Azure DevOps API public Git 存储库 here。
但是我无法处理需要使用相同 API 授权的存储库。
我查看了使用 UI 时发送的请求,并尝试通过按以下方式提交各种请求来进行逆向工程:
{
"parameters": {
"gitSource": {
"url": "[URL]",
"username": "[USERNAME]",
"password": "[PASSWORD]"
}
}
}
...但似乎没有任何效果。没有关于如何为 Git 导入传递授权参数的文档。我也尝试模仿允许这样做的其他调用,但无济于事。
有没有其他人成功地尝试过这个,或者有任何我应该尝试的其他选择?
这就是我在脚本中所做的:
# create endpoint
$endpoint = irm "$targetUrl/serviceendpoint/endpoints?api-version=5.0-preview" -Method:Post -ContentType "application/json" `
-Headers @{Authorization = "Basic $base64AuthInfo"} `
-Body ( '{{"name":"temporary-script-git-import","type":"git","url":"https://{3}@dev.azure.com/{3}/{0}/_git/{0}","authorization":{{"parameters":{{"username":"{1}","password":"{2}"}},"scheme":"UsernamePassword"}}}}' -f $sourceName, $username, $token, $organization )
# import repository
$importRepo = irm "$targetUrl/git/repositories/$sourceName/importRequests?api-version=5.0-preview" -Method:Post -ContentType "application/json" `
-Headers @{Authorization = "Basic $base64AuthInfo"} `
-Body ( '{{"parameters":{{"deleteServiceEndpointAfterImportIsDone":true,"gitSource":{{"url":"https://{2}@dev.azure.com/{2}/{0}/_git/{0}","overwrite":false}},"tfvcSource":null,"serviceEndpointId":"{1}"}}}}' -f $sourceName, $endpoint.id, $organization )
这将创建一个用于连接到 git 的服务端点(在我的例子中是 Azure Devops,但它也可以与 Github 一起使用),然后使用该服务端点导入回购协议。 $targetUrl - 你的 Azure Devops 路径:$targetUrl = "https://dev.azure.com/$organization/$targetName/_apis"
我能够使用记录在案的 Azure DevOps API public Git 存储库 here。
但是我无法处理需要使用相同 API 授权的存储库。
我查看了使用 UI 时发送的请求,并尝试通过按以下方式提交各种请求来进行逆向工程:
{
"parameters": {
"gitSource": {
"url": "[URL]",
"username": "[USERNAME]",
"password": "[PASSWORD]"
}
}
}
...但似乎没有任何效果。没有关于如何为 Git 导入传递授权参数的文档。我也尝试模仿允许这样做的其他调用,但无济于事。
有没有其他人成功地尝试过这个,或者有任何我应该尝试的其他选择?
这就是我在脚本中所做的:
# create endpoint
$endpoint = irm "$targetUrl/serviceendpoint/endpoints?api-version=5.0-preview" -Method:Post -ContentType "application/json" `
-Headers @{Authorization = "Basic $base64AuthInfo"} `
-Body ( '{{"name":"temporary-script-git-import","type":"git","url":"https://{3}@dev.azure.com/{3}/{0}/_git/{0}","authorization":{{"parameters":{{"username":"{1}","password":"{2}"}},"scheme":"UsernamePassword"}}}}' -f $sourceName, $username, $token, $organization )
# import repository
$importRepo = irm "$targetUrl/git/repositories/$sourceName/importRequests?api-version=5.0-preview" -Method:Post -ContentType "application/json" `
-Headers @{Authorization = "Basic $base64AuthInfo"} `
-Body ( '{{"parameters":{{"deleteServiceEndpointAfterImportIsDone":true,"gitSource":{{"url":"https://{2}@dev.azure.com/{2}/{0}/_git/{0}","overwrite":false}},"tfvcSource":null,"serviceEndpointId":"{1}"}}}}' -f $sourceName, $endpoint.id, $organization )
这将创建一个用于连接到 git 的服务端点(在我的例子中是 Azure Devops,但它也可以与 Github 一起使用),然后使用该服务端点导入回购协议。 $targetUrl - 你的 Azure Devops 路径:$targetUrl = "https://dev.azure.com/$organization/$targetName/_apis"