TeamFoundation 2008 SDK - How to get a list of all changesets programmatically?
What I am trying to achieve is writing a task which will list all the changesets associated with a build and write a changelog file from that list.
I manage to get a list of the changesets associated with a build programmatically using the "informationNodeConverters.GetAssociatedChangesets" method when using the default team build definition, however in our teambuilds we have skipped the CoreLabel target because we don't want to have a new label everytime a new build happens.
When we skip the "CoreLabel" target the "CoreGetChangesetsAndUpdateWorkItems" target won't associate any changeset with the build because this target needs labels to work properly and the method "GetAssociatedChangesets" will return no changeset.
I searched in the documentati开发者_开发知识库on if there is a way to list all the changesets from the Version Source, so I could find all the changesets with items in a specific folder and use that to create my file but I couln't find anything. I know it is possible to do because the Team Foundation Server Power Tools 2008 has a similar functionality which allow you to find Changesets inside some folders.
Could anyone help me to find out how to get all the changesets from the version control?
Thanks in advance.
I found the method "QueryHistory" of the class "VersionControlServer" did the trick.
System.Collections.IEnumerable changesets = vcs.QueryHistory("$/" ,
VersionSpec.Latest,
0,
RecursionType.Full,
null,
new ChangesetVersionSpec(1),
VersionSpec.Latest,
int.MaxValue,
true,
false);
The first parameter of this method can be any folder in source control you want to retrieve the changesets.
Instead of label we can use date and changeset too:
public static void main(String[] args)
{
Credentials cred=new UsernamePasswordCredentials("username","password") ;
TFSTeamProjectCollection tpc =new TFSTeamProjectCollection(URIUtils.newURI("Application_Collection_url")
, cred);
WorkItemClient workItemClient = tpc.getWorkItemClient();
Changeset[] chngset=null;
LabelSpec lable=new LabelSpec("tfs_start_Label", null);
LabelSpec lable1=new LabelSpec("tfs_end_label", null);
try {
chngset = tpc.getVersionControlClient().queryHistory("$project_directory", LatestVersionSpec.INSTANCE, 0,
RecursionType.FULL, null,new LabelVersionSpec(lable1), new LabelVersionSpec(lable), Integer.MAX_VALUE, true, true, false, true);
} catch (ServerPathFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(Changeset ch : chngset)
{
System.out.println("Change Set ID : "+ ch.getChangesetID());
System.out.println("Owner : "+ ch.getOwner());
Change changes[]=ch.getChanges();
System.out.println("Date : "+ new Date(ch.getDate().getTimeInMillis()));
for(Change chang:changes)
{
System.out.println(chang.getItem().getServerItem());;
//System.out.println("Owner : "+ chang.getItem().getItemType().toString());
}
}
}
精彩评论