Sample checkin policy: make sure the comment isn't empty
I'm not actually the original author, but it seems pretty useful so I thought I'd pass it along - you'll need a reference to Microsoft.TeamFoundation.VersionControl.Client.dll, of course, which should be in your GAC if you have the Team Explorer bits installed.
using System;
using System.Windows.Forms;
using Microsoft.TeamFoundation.VersionControl.Client;
namespace CheckForCommentsPolicy
{
[Serializable]
public class CheckForComments : PolicyBase
{
public override string Description
{
get { return "Remind users to add meaningful comments to their checkins"; }
}
// This is a string that is stored with the policy definition on the source
// control server. If a user does not have our policy plugin installed, this string
// will be displayed. We can use this as an opportunity to explain to the user
// how they might go about installing our policy plugin.
public override string InstallationInstructions
{
get { return "To install this policy, follow the instructions in CheckForComments.cs."; }
}
// This string is the type of our policy. It will be displayed to the user in a list
// of all installed policy types when they are creating a new policy.
public override string Type
{
get { return "Check for Comments Policy"; }
}
// This string is a description of the type of our policy. It will be displayed to the
// user when they select our policy type in the list of policies installed on the system
// as mentioned above.
public override string TypeDescription
{
get { return "This policy will prompt the user to decide whether or not they should be allowed to check in."; }
}
// This method is invoked by the policy framework when the user creates a new checkin
// policy or edits an existing checkin policy. We can use this as an opportunity to
// display UI specific to this policy type allowing the user to change the parameters
// of the policy.
public override bool Edit(IPolicyEditArgs args)
{
// no configuration to save
return true;
}
// This method performs the actual evaluation. It is called by the policy framework at various points in time
// when policy should be evaluated. In this example, we invoke this method ourselves when various asyc
// events occur that may have invalidated the current list of failures.
public override PolicyFailure[] Evaluate()
{
string proposedComment = PendingCheckin.PendingChanges.Comment;
if (String.IsNullOrEmpty(proposedComment))
{
return new PolicyFailure[] {
new PolicyFailure("Please provide some comments about your checkin", this),
};
}
else
{
return new PolicyFailure[0];
}
}
// This method is called if the user double-clicks on a policy failure in the UI.
// We can handle this as we please, potentially prompting the user to perform
// some activity that would eliminate the policy failure.
public override void Activate(PolicyFailure failure)
{
MessageBox.Show("Please provide comments for your checkin.", "How to fix your policy failure");
}
// This method is called if the user presses F1 when a policy failure is active in the UI.
// We can handle this as we please, displaying help in whatever format is appropriate.
// For this example, we'll just pop up a dialog.
public override void DisplayHelp(PolicyFailure failure)
{
MessageBox.Show("This policy helps you to remember to add comments to your checkins.", "Prompt Policy Help");
}
}
}
Comments
Anonymous
February 08, 2006
Now that the RC is out, I thought I'd post a summary with links to version control posts from the last...Anonymous
March 06, 2006
Jeff Atwood has posted a sample to allow you to implement what has got to be the single most requested check-in policy for Team System, forcing a user to comment their change. Based on some earlier posts by James Manning,...Anonymous
August 12, 2006
I recently had to put together a list of links to code samples.  This isn't even close to comprehensive,...Anonymous
August 12, 2006
I recently had to put together a list of links to code samples.  This isn't even close to comprehensive,...Anonymous
August 23, 2006
A check-in policy to require a comment has always been a frequent request.  Jeff Atwood has posted...Anonymous
September 25, 2006
This policy states that comments related with current check-ins are “must-to-have”. TFS does not provide...Anonymous
November 20, 2006
Use this tool to enforce comments being added by developers when the check-in their code to a tfs sourceAnonymous
August 30, 2007
I recently had to put together a list of links to code samples. This isn't even close to comprehensive,Anonymous
September 28, 2007
Подсистема контроля версий файлов в TFS позволяет работать из командной строки. Находится эта утилитаAnonymous
December 19, 2007
PingBack from http://hacker.maxblog.eu/?p=10Anonymous
December 23, 2007
PingBack from http://hacker.maxblog.eu/?p=155Anonymous
December 29, 2007
PingBack from http://hacker.maxblog.eu/?p=287Anonymous
January 03, 2008
PingBack from http://hacker.maxblog.eu/?p=486Anonymous
January 06, 2008
PingBack from http://hacker.maxblog.eu/?p=548Anonymous
January 18, 2008
PingBack from http://hacker.mixer.blogdns.com/?p=807Anonymous
January 18, 2008
PingBack from http://hacker.mixer.blogdns.com/?p=822Anonymous
January 22, 2008
PingBack from http://hacker.mixer.blogdns.com/?p=928Anonymous
February 03, 2008
PingBack from http://hacker.0ms.eu/?p=1197Anonymous
February 06, 2008
PingBack from http://hacker.0ms.eu/?p=1273Anonymous
February 07, 2008
PingBack from http://hacker.0ms.eu/?p=1312Anonymous
February 21, 2008
PingBack from http://hacker.0ms.eu/?p=1636Anonymous
June 18, 2008
PingBack from http://blogs.southworks.net/ebella/2006/09/26/mandatory-comments-check-in-policy-for-tfs/