0

We have a plugin in tfs. This plugin notifies us when any work item changes. We can get work item details like id, changeset list as follows. But we need work item related branch name also.

Could you please help me, is there any way to get related branch name when workitem changed in below code.

Thanks

    public EventNotificationStatus ProcessEvent(
        IVssRequestContext requestContext, 
        NotificationType notificationType, 
        object notificationEventArgs, 
        out int statusCode, 
        out string statusMessage, 
        out ExceptionPropertyCollection properties)
    {
        statusCode = 0;
        properties = null;
        statusMessage = String.Empty;
        

        try
        {
            if (notificationType == NotificationType.Notification && notificationEventArgs is WorkItemChangedEvent)
            {
                WorkItemChangedEvent ev = notificationEventArgs as WorkItemChangedEvent;
                int workItemId = Convert.ToInt32(ev.CoreFields.IntegerFields[0].NewValue);
                
                WriteLog("1WorkItemChangedEventHandler WorkItem " + ev.WorkItemTitle + " - Id " + workItemId.ToString() + " was modified");
                

            }

        }
        catch (Exception)
        {
        }

        return EventNotificationStatus.ActionPermitted;
    }
Pronto
  • 179
  • 1
  • 2
  • 11

1 Answers1

-1

You can use workItemStore.GetWorkItem(workItemId ) to get all work item info. Check the similar question here: How can I get a reference to the TFS WorkItem in a WorkItemChangedEvent?

If you use git, you can try the following example to get branch reference:

int workitemId = YOUR_ID;

WorkItemStore wiStore = new WorkItemStore("{YOUR_URI}");

WorkItem wi = wiStore.GetWorkItem(workitemId);            

foreach (Link link in wi.Links)
{
    if (link.BaseType == BaseLinkType.ExternalLink)
    {
        var brList = ((ExternalLink)link).LinkedArtifactUri.Split(new string[] { "%2F" }, StringSplitOptions.RemoveEmptyEntries).ToList();

        brList.RemoveAt(0); //remove project and repo giuds
        brList.RemoveAt(0);
        brList[0] = brList[0].Replace("GB", ""); // remove GB prefix

        Console.WriteLine("Branch: {0}", string.Join("/", brList));
    }
}
Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31