How to get history of checkins/changsets for specific Team Project?
Asked Answered
P

2

8

I'm using the TFS Client API to try and query a TFS 2010 instance. I need to be able to do the following

  • For a specified team project, say 'Project A'
  • Get a list of the history of recent check-ins made to this project (say the last 50, or the list for the last day)

Then be able to iterate through this list and get some metadata for the items (file and folder names ideally)

I think I need to use the QueryXXX methods on the VersionControlServer class, but cannot find any helpful or clear examples on how to use this.

I have seen there is GetLastestChangesetId method, but this doesn't look like it can be scoped to a specific project or directory.

Pivotal answered 30/6, 2014 at 13:25 Comment(1)
Take a look at my answer here: https://mcmap.net/q/675118/-tfs-2010-getting-list-of-changeset-idsFowler
S
15

This is pretty straightforward:

var tfsUrl = "http://myTfsServer:8080/tfs/defaultcollection";
var sourceControlRootPath = "$/MyTeamProject";
var tfsConnection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsUrl));
var vcs = tfsConnection.GetService<VersionControlServer>();

var changeSets = vcs.QueryHistory(sourceControlRootPath, RecursionType.Full);

foreach (var c in changeSets)
{
    var changeSet = vcs.GetChangeset(c.ChangesetId);
    foreach (var change in changeSet.Changes) 
    {
       // All sorts of juicy data in here
    }

}
Sincere answered 30/6, 2014 at 14:20 Comment(2)
the juicy data does not include the workitems associated :(Szechwan
@Szechwan the associated workitems are on the changeSet objectPfosi
B
0

In 2021, using azure devOps Tfs Client Api

As per the documentation, the Api is meant for following Tfs servers.

Azure DevOps Services | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 - TFS 2013

Namespaces used here:

using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.WebApi;

Create VssConnection as follows,

string myTfsProjectUri =  "url path to your tfs project";
VssConnection myConnection = new VssConnection( new Uri( collectionUri ), new VssClientCredentials() );

Create TfvcHttpClient client as follows,

TfvcHttpClient myVersionControlHttpClient = myConnection.GetClient<TfvcHttpClient>();

Get Changesets using search criteria as follows (given snippet finds all the check-ins between given fromCheckInId & toCheckInId),

List<TfvcChangesetRef> changeSets =  VersionControlHttpClient
                   .GetChangesetsAsync( 
                    projectName, /* Tfs Project name */
                    null, /* Max Comment length, can be null */
                    null, /* Number of results to Skip, can be null */
                    null, /* Maximum Number of results to return, can be null */
                    null, /* Results are sorted by ID in descending order by default. Use id asc to sort by ID in ascending order */
                    new TfvcChangesetSearchCriteria()
                    {
                            ItemPath = branchName, /* Path to Branch under given project */
                            FromId = fromCheckinId, /* From check-in id to start search */
                            ToId = toCheckinId /* To check-in id to end search */
                    } ).Result;

This API can be used with FromDate and ToDate search criteria as well.

For more information, read official documentation

Brunk answered 8/6, 2021 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.