How can I determine the author of a block of code

2019-07-17 15:22发布

We are working with Team Foundation Server (Visual Studio 2010).

How can I get writer of the specific code block programmatically?

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-17 15:54

MSDN has Annotate option for the tracking of such information, but the default is on file-level and check-in operations. For such info, we usually use code comments, it may be not so professional but it is good.

查看更多
欢心
3楼-- · 2019-07-17 16:15

With TFS API, you may be able to get to that data. Each changeset has a commiter. I would take the code offered up here. From this, you can add:

foreach (var change in cs.Changes)
{
    if (change.Item.ServerItem != serverItem)
    {
        return;
    }
    //Get commiter
    cs.Committer

While this doesn't get you 100% of the way there, it is at least a starting point.

查看更多
Melony?
4楼-- · 2019-07-17 16:16

Fairly simple.

I have a working demo on my blog => http://geekswithblogs.net/TarunArora/archive/2011/06/26/tfs-2010-sdk-smart-merge-programmatically-create-your-own-merge.aspx

Edited

I am very sorry i misunderstood your question. What you are looking for is to be able to get a changesetId based on a specific file path in TFS and then being able to see the modified items for that changeset and then being able to see the modification in the source code and know who the author of that source change is. Right?

If that's correct, can you not do the following,

public static void GetMergeDetailsForChangeSet()
    {
        var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("Enter the url of team project"));
        var versionControl = tfs.GetService<VersionControlServer>();

        var a = versionControl.GetChangeset(12322);

        VersionSpec changeSpec = new ChangesetVersionSpec(a.Changes[0].Item.ChangesetId);

        var changeSetDetails = a.Changes[0].Item.VersionControlServer.QueryMergesWithDetails(
            null,
            null,
            0,
            a.Changes[0].Item.ServerItem,
            changeSpec,
            a.Changes[0].Item.DeletionId,
            changeSpec,
            changeSpec,
            RecursionType.Full);

    }
  1. My blog post shows you how to get changesets programmatically from TFS
  2. Now that you have the changeset you can retrive the changed file.
  3. In the example above, i am getting the details of the merge from that changeset. In your case you will have to use GetItems(String, VersionSpec, RecursionType, DeletedState, ItemType, Boolean)
  4. The changeset object has a property 'Owner' this will tell u who the author of the change is.
  5. Now if you want to select the details of the first changeset in that list, You will have to access Item.VersionControlServer see the details here http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.item.versioncontrolserver.aspx

Does this help, can i provide additional details?

HTH.

Cheers, Tarun

查看更多
登录 后发表回答