Reputation: 3367
I am able to import public Git repositories using the Azure DevOps API documented here.
However I am unable to handle repositories that require authorization with the same API.
I looked at the requests sent when using the UI and tried to reverse engineer by submitting various requests along these lines:
{
"parameters": {
"gitSource": {
"url": "[URL]",
"username": "[USERNAME]",
"password": "[PASSWORD]"
}
}
}
...But nothing seems to work. There is no documentation on how to pass in authorization parameters for Git imports. I tried to mimic other calls that allow for this as well, to no avail.
Has anyone else tried this with any success or have any additional options I should attempt?
Upvotes: 2
Views: 1603
Reputation: 72191
this is what I've been doing in my script:
# 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 )
this would create a service endpoint to use to connect to git (in my case its Azure Devops but it would work with Github as well) and then its using that service endpoint to import the repo. $targetUrl - your Azure Devops path: $targetUrl = "https://dev.azure.com/$organization/$targetName/_apis"
Upvotes: 1