A Social solution for Code Reviews using TFS and Pulse

Let me start by explaining the problem first and then my solution for it:

 
Problem:

In a software project, code reviews is one of the major problems.  Most of the times managers are chasing senior developers to do code review and sometimes its laziness of developers due to which they never send it for code review. If Changesets gets missed for code reviews then its not a good sign for health of the project.

Mostly code reviews in organizations happens over emails, these are the disadvantages of using email:

  1. Comments of code reviewers reaches to a specific individuals on to/cc line of email, people who are not on email did not get an opportunity to learn.   
  2. Code reviewers might feel frustrated by giving same comments again and again to different developers.
  3. Emails does not know what is happening in TFS. Manual process is bad, developers identifying the changeset manually and sending emails is cumbersome and there are chances they might not send it.
  4. Information in emails remains in emails, it can not be used in other projects.

I have seen many solutions developed for code reviews, like developing a visual studio addin, using separate tool for code review. Also found out that next version of TFS is bringing enhancement to code review process, 2011 code review workflow.

I feel the solution for this problem should have a social touch.  Of course we can not use sites like facebook, twitter however as an employee of Neudesic I got an opportunity to work with Pulse : http://www.neudesic.com/what/products/pulse/Pages/index.aspx which is a social platform for enterprise.

Neudesic pulse is an enterprise social microblogging platform which allows employees to exchange information in a social way. Developers should be excited about Pulse because it has its own SDK which is set of RESTful API’s.  Documented at : https://pulse.neudesic.com/#!developers/

Pulse is available mostly on all smartphones like : Android, Iphone, WP7.

Solution:

Since most of the organizations use Team Foundation Server as code repository and for collaboration. The solution is to connect TFS with Pulse i.e. using TFS SDK and posting a developer’s checkin information to a group in pulse.

A group is a feature in pulse which is like a common page where you can invite people to join and share statuses, files, photos, articles etc. Once a project kicks off you can start by creating a group in pulse and by inviting code reviewers and developers.

Here is workflow of how this solution will work:

 

image

 

To demonstrate this I have prepared a demo UI,  using this demo I can subscribe to checkin event of TFS server.  After launching it specify your TFS URL.

DemoUIHome

Once you have subscribed to checkin event UI will display subscription created.

AfterSubscription

Once a subscription is created and a developer tries to checkin the code, the WCF service method will be called which will automatically post it to pulse page.

Here is how it looks like in pulse after a user checks in the code.

image

As you can see apart from posting changeset I am posting information like comments, date, user name etc. The information posted to pulse can be customized easily.  Once posted on pulse, code reviewers can view the changeset in TFS and write comments on pulse group.  Developers can also reply back on comments from code reviewers.

Implementation of this solution

I have defined a WCF service end point which is listening for TFS CheckinEvent.

Here is how my WCF service interface looks like:

[ServiceContract(Namespace = “http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03″)]
   public interface INotificationService
   {
       [OperationContract(Action = “http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Notification/03/Notify”, ReplyAction = “*”)]
       [XmlSerializerFormat(Style = OperationFormatStyle.Document)]
       void Notify(string eventXml, string tfsIdentityXml);
   }

A subscription to TFS Checkin can be created like this:

TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(txtTfsURL.Text), new UICredentialsProvider());
            tpc.EnsureAuthenticated();
            IEventService eventService = tpc.GetService(typeof(IEventService)) as IEventService;
            DeliveryPreference delPref = new DeliveryPreference();
            delPref.Address = “http://” + System.Environment.MachineName + “:8001/CheckInNotify”;
            delPref.Schedule = DeliverySchedule.Immediate;
            delPref.Type = DeliveryType.Soap;
            subscriptionId = eventService.SubscribeEvent(System.Environment.UserDomainName + “\\” + System.Environment.UserName, “CheckInEvent”, “”, delPref);
            lblSubscription.Content = string.Format(“A checkin subscription is created with subscription id : {0} “,subscriptionId.ToString());

In the service implementation method all you have to do is extract information from XML which is sent by TFS and post it to your group page in Pulse.

public class NotificationService : INotificationService
   {
       void INotificationService.Notify(string eventXml, string tfsIdentityXml)
       {
           // Extract required attributes from event xml
           string pulseStatus = ExtractAndBuildPulseStatus(eventXml);

           //Post it to pulse
           var success = PostToPulse(pulseStatus);

           // Write to event logs if not successful.
           if (!success)
               Logger.WriteToEventLog(string.Format(“Failed to post to pulse page following message : {0}”, pulseStatus));
       }

}

The best part of pulse SDK is that you do not need a hard reference to any assembly, it can be accessed by using .net classes like HttpWebRequest and HttpWebResponse to post to pulse group.

Pulse API’s are documented here: https://pulse.neudesic.com/#!developers/ 

Advantages of this solution:

1.  Monitoring – ChangeSets are not missed, every checkin is in front of your eyes.  Anyone can take a look at group page and figure out if code reviews are done or not.

2. Follow People – Chasing people is easy Smile, just write @NameofCodeReviewer a familiar syntax that we use in Facebook.  Pulse will automatically notify the user, you have been mentioned…

3. Repository : Valuable code comments from one project can be used in another project. In this way information is never lost.

4. Code debt can be identified.

Enhancing this Solution Further:

1. Apart from posting it to group page we can also create a task in pulse.  A task in Pulse is kind of similar to TFS task.  Assign it to another user and that user will see that task in his list.

2. All the changesets submitted are not eligible for code review for eg: a checkin for change in file name.  In situations like this developer can checkin with a comment containing hashtag like “#NoCodeReview.  When your service receives the comment and finds a particular hash tag in comment it can decide whether to post it in Pulse or not.

3. The content of pulse group can be displayed in your sharepoint team site, using a web part.

In this blog post I have covered how a social solution can be used for solving problem of code reviews.  Feel free to share your thoughts by commenting on this blog post.

Advertisements

7 comments

  1. Also want to mention that this solution can be made more reliable by emailing to pulse page. When you create a page/group in Pulse it automatically gets an email address (visible in settings). If for some reason pulse is down when check in happens, email will ensure that your TFS checkin/comment is not lost.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s