Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have a link to raw content of file in Azure DevOps

It's possible to generate a link to raw content of the file in GitHub, is it possible to do with VSTS/DevOps?

like image 833
Gregory Suvalian Avatar asked Jan 10 '19 22:01

Gregory Suvalian


People also ask

How do you link work items in Azure DevOps?

Open a work item and choose the Links tab. From the links control tab you can link to new or existing work items, open the linked object, edit the link type, delete a link, or open the list of links in a query or Excel or Project. The work item form opens in the web portal for Visual Studio 2017 and later versions.

How do I get Azure DevOps URL?

With the introduction of Azure DevOps Services, organizational resources and APIs are now accessible via either of the following URLs: https://dev.azure.com/{organization} (new) https://{organization}.visualstudio.com (legacy)

Can you link projects in Azure DevOps?

Can I link work items across projects? Yes. You can use any link type you want to link work items that are defined in different projects. The projects must be defined within the same organization or project collection.

How do I attach a file to Azure DevOps?

Choose the Attachment tab icon to attach a file to the work item. You can drag and drop a file onto the tab or anywhere on the work item form. Some features require upgrade to Azure DevOps Server 2019.1. You can continue viewing the attachments as a list or switch to a grid view to show a thumbnail preview.


1 Answers

Even after reading the existing answers, I still struggled with this a bit, so I wanted to leave a bit more of a thorough response.

As others have said, the pattern is (query split onto separate lines for ease of reading):

https://dev.azure.com/{{organization}}/{{project}}/_apis/sourceProviders/{{providerName}}/filecontents   ?repository={{repository}}   &path={{path}}   &commitOrBranch={{commitOrBranch}}   &api-version=5.0-preview.1 

But how do you find the values for these variables? If you go into your Azure DevOps, choose Repos > Files from the left navigation, and select a particular file, your current url should look something like this:

https://dev.azure.com/{{organization}}/{{project}}/_git/{{repository}}?path=%2Fpackage.json 

You should use those values for organization, project, and repository. For path, you'll see an HTTP encoded version of the unix file path. %2F is the HTTP encoding for /, so that path is actually just /package.json (a tool like Postman will do that encoding for you).

Commit or branch is pretty self explanatory; you either know what you want for this value or you should use master. I have "hard-coded" the api version in the above url because that's what the documentation currently points to.

For the last variable, you need providerName. In short, you should probably use TfsGit. I got this value from looking through the list of source providers and looking for one with a value of true for supportedCapabilities.queryFileContents.

However, if you just request this URL you'll get a "203 Non-Authoritative Information" response back because you still need to authenticate yourself. Referring again to the same documentation, it says to use Basic auth with any value for the username and a personal access token for the password. You can create a personal access token at https://dev.azure.com/{{organization}}/_usersSettings/tokens; ensure that it has the Token Administration - Read & Manage permission.

If you're unfamiliar with this sort of thing, again Postman is super helpful with getting these requests working before you get into the code.


So if you have a repository with a src directory at the root, and you're trying to get the file contents of src/package.json, your URL should look something like:

https://dev.azure.com/{{organization}}/{{project}}/_apis/sourceProviders/TfsGit/filecontents?repository={{repository}}&commitOrBranch=master&api-version={{api-version}}&path=src%2Fpackage.json 

And don't forget the basic auth!

like image 118
Zach Posten Avatar answered Sep 26 '22 10:09

Zach Posten