TFS API: How Do I Get a File's History? - tfs

It is very straightforward to get all changesets, specific changesets, or even look a specific version of a file (given a changeset id) using not only the TFS API but the .NET client libraries.
However, what I can't seem to figure out is given the name/path of a file, and a specific branch, is how to retrieve the changeset history for that file.
I've tried using both the TfvcHttpClient as well as the raw TFS API (building my http GET request by hand) and I cannot seem to find a way to make this happen.
This is very similar to viewing a file's history in Visual Studio 2017:
I'm literally looking for a way via the TFS API to give me this information back.
Is this possible?
Thanks!

Rest API request:
{tfsurl}/{project}/_api/_versioncontrol/history"
In the request body:
{repositoryId: "", searchCriteria: "{"itemPath":"$/YourProject/YourFile","itemVersion":"T","top":50}"}
It will return the history for the itemPath from your body.
Sadly I struggle to find any documentation on this :/

I can not find any history request for tfvc here - Rest Api TFVC Version Control.
As workaround you can try to run tf.exe history and parse the output.

Depending on what API version you are using, here is the reference information for changesets.
https://learn.microsoft.com/en-us/rest/api/azure/devops/tfvc/changesets/get%20changesets?view=azure-devops-rest-5.0
the core url is:
GET {tfsurl}/{organization}/{project}/_apis/tfvc/changesets?api-version=5.0

You can also do this with TfvcHttpClientBase.GetChangesetsAsync and the ItemPath property of TfvcChangesetSearchCriteria
Here's an example in Powershell
$tfvcSearchCriteria = [Microsoft.TeamFoundation.SourceControl.WebApi.TfvcChangesetSearchCriteria]::new()
$tfvcSearchCriteria.FollowRenames = $true
$tfvcSearchCriteria.ItemPath = $ItemPath
$result = $TfvcHttpClient.GetChangesetsAsync($null, $null, $null, $null, $tfvcSearchCriteria).Result

Related

How to list permissions in source control for Azure DevOps Server

I need to review all source code permissions on a particular folder structure. I have gone through the apis and can't find what I need or haven't figured out how to use them correctly yet.
I have also tried the tfssecurity command but, can't figure out how to make it look at just a specific team project.
I am using Azure DevOps Server 2020 and the source is in TFVC.
This is part of a source control audit and I need to produce a report of what permissions users have on a folder in source.
I have tried the following apis: https://learn.microsoft.com/en-us/rest/api/azure/devops/security/?view=azure-devops-server-rest-6.0
Along with the tfssecurity command.
None are producing the results I need.
Found the APIs needed to do this.
Use this one to get all of the namespaces and find the ones that you want to get the security data for.
https://{instance}/{collection}/_apis/securitynamespaces
After that call this API to get the ACLs for that namespace.
https://{instance}/{collection}/_apis/accesscontrollists/{securityNamespaceId}?alwaysAllowAdministrators=True
Once you get all of the ACLs for the namespace, you can then look at each ACE to find out the permissions.
https://{instance}/{collection}/_apis/identities?descriptors={descriptors}&queryMembership=expandedDown

TFS 2018 Call for add Administrator's API to Project Returns 404 #tfs

TFS 2018 Call for add Administrator's API to Project Returns 404:
It seems you want to list Group Entitlements. Unfortunately, this api only supports VSTS, not support on-premises TFS.
If you really mean adding, then it should be a POST request, see the docs for more details. On the other hand, if you want to GET, you should specify the groupId.

Trigger TFS Release Management with Artifact Version Number

I am excited to see TFS Update 2 available for on premise and including the Release Management Feature part of the web experience. We have been waiting for this.
I need some help on how best to trigger the release.
A release can be triggered in 3 ways:
Continuous Deployment Trigger based on linking to TFS Build Definition
Manually
REST API
This is great but I don't think it fits what I would expect. I need help in a technical solve or in how I think about the problem.
My Thinking:
I believe the Build should create an artifact and put the artifact in a Drop location to be released now or a year from now. (need to rebuild or add a server later)
I feel the continuous deployment trigger breaks down as it depends on the artifact being in the TFS Build and the TFS Build will be deleted depending on your settings.
Possible Solution:
I believe the solution I need is to create a draft release using the REST Api and then pass in the path to the artifact in the drop location. In my case I would simply provide a version number and build the path inside the release.
Problem:
At this point the REST api is not documented.
I appreciate your thoughts on my thinking. It could be that I'm thinking about the problem in the wrong way.
Also, If anyone knows how to create a release using the REST api that would likely get me to where I need to be.
I see the REST api is to be documented at the following spot but is is not yet. I really want to get going, I have over 100 apps to deploy.
https://msdn.microsoft.com/en-us/library/vs/alm/release/managing-releases/create-release#CreateareleasebyusingtheRESTAPI
We also use TFS 2015 update 2 on-prem and use PowerShell to interface with TFS REST API.
As stated in comments on this thread the REST API documentation is live and to create a release refer to the following link: https://www.visualstudio.com/en-us/docs/integrate/api/rm/releases#create-a-release
To answer your question: - to create a release using a PowerShell script try the following:
$filePath = "C:\PATH_TO_JSON"
$username = 'DOMAIN\USRNAME'
$password = 'PASSWORD'
$body = Get-Content $filePath
$resource = "http://TFS_URL/_apis/release/releases`?api-version=2.2-preview.1"
$cred = New-Object System.Management.Automation.PSCredential($username, (ConvertTo-SecureString -String $password -AsPlainText -Force))
Invoke-RestMethod -Method Post -Uri "$resource" -Credential $cred -ContentType "application/json" -Body $body
The $filePath variable should point to a file containing the following JSON markup. Be sure to alter the variables within the example JSON to fit your on-prem Release Definition:
{
"definitionId": 12,
"description": "M 98 release",
"artifacts": [
{
"alias": "Fabrikam.CI",
"instanceReference": {
"id": "90"
}
}
]
}
You could also use JavaScript to interface with TFS REST API. See the post by #Elmar here: TFS 2015 REST API Authentication
The Release Management API docs for VSTS are live here. Most of the APIs should work for TFS 2015.2 also.
For creating a new release, refer to my earlier answer for the same.
You can retain a build indefinitely so it will always be available when you need it.
ReleaseManagement REST API got public at
https://www.visualstudio.com/integrate/api/rm/releases#Createarelease. Please have a look. While creating the release pass three things in the artifact :- alias, instanceReference (name and Id).

Getting git items for a particular branch/tag via TFS rest api

Now that TFS 2015 comes with the same new Rest API of VS Team Services, I've taken a look at the API doc:
https://www.visualstudio.com/en-us/integrate/api/git/overview
One question naturally raised is that most queries do not expose an parameter for git branch or tag (e.g. download /path/to/my/file with tag 'release_v1.0'), which looks like a show stopper. As in my case, I need programatically pull out some source file under a certain branch/tag.
Is it not supported yet?
Yes you can. As or the link that you have above you can use the provided so to retrieve both branches and yes. In git they are really all the same thing, pointers. This use the "refs" api.
https://www.visualstudio.com/integrate/api/git/refs

Bitbucket: How to create a list of issues from multiple repositories?

We have several repositories on BitBucket. For every repository we
have the issue tracker enabled. For our progress reports I would like
to be able to see all issues from all related repositories in one
overview.
Is this possible and how can it be done?
Thanks,
Paul
Bitbucket has an API. You could quickly put together a script (or webpage using JSONP) calling:
https://api.bitbucket.org/1.0/repositories/USERNAME/REPOSITORY/issues/
for each repository? (Replacing USERNAME and REPOSITORY with appropriate values)
For something more advanced you could query the USER, get all their repositories, then iterate.
I needed the same thing today so I made the following python script available here on github.
The two API call URLs you need are
https://bitbucket.org/api/1.0/user/repositories/
https://bitbucket.org/api/1.0/repositories/{owner}/{slug}/issues/
You'll have to authenticate with your BitBucket credentials which I did using the python requests library:
response = requests.get(url, auth=HTTPBasicAuth(_USERNAME, _PASSWORD))

Resources