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

2019-08-16 16:18发布

问题:

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://docs.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.

回答1:

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://docs.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