Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a link to a file from a VSO repo

Tags:

azure-devops

When I browse a GitHub repo, I can copy the URL from the browser, and I can share it like this - https://github.com/zlatko-michailov/onesql/blob/master/lang/src/onesql.syntax.ts. The file content is returned in the http response stream without any decorations.

How can I do the same thing for a VSO repo? If I have to tweak the URL a little bit, that's OK.

I see the browser uses a REST API that is documented here - https://learn.microsoft.com/en-us/rest/api/azure/devops/git/items/get?view=azure-devops-rest-5.0. I played with different combinations of includeContent, $format, download, etc., but I could only get the content as a separate download, not in the http response body.

The subject file is some CSV data, and the client is Excel, which doesn't seem to be able to handle downloads.

like image 649
Zlatko Michailov - MSFT Avatar asked Oct 21 '25 15:10

Zlatko Michailov - MSFT


1 Answers

I solved my own problem. There is no need to create a feed.

The API that fetches raw files is sourceProviders. The link is here: https://learn.microsoft.com/en-us/rest/api/azure/devops/build/source%20providers/get%20file%20contents?view=azure-devops-rest-5.0

It is not very well documented - examples for the required parameters are missing. The tricky one is sourceProvider. It has to be tfsgit. Skipping serviceEndpointId worked for me.

Here is the pattern:

GET https://dev.azure.com/{organization}/{project}/_apis/sourceProviders/tfsgit/filecontents?&repository={repository}&commitOrBranch={commitOrBranch}&path={path}&api-version=5.0-preview.1
like image 66
Zlatko Michailov - MSFT Avatar answered Oct 23 '25 09:10

Zlatko Michailov - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!