Permalink
Browse files

Support for checkin notes

Specify the code reviewer in a commit message similarly to how
work items are associated, e.g.:
git-tfs-code-reviewer: John Smith
  • Loading branch information...
1 parent dc4a16a commit 18269ea59fa939b48334e39e2822eafa39a32f46 @kgybels kgybels committed Nov 6, 2012
@@ -491,6 +491,23 @@ public IEnumerable<IWorkItemCheckedInfo> GetWorkItemCheckedInfos(IEnumerable<str
workItems, checkinAction, GetWorkItemCheckedInfo);
}
+ public ICheckinNote CreateCheckinNote(Dictionary<string, string> checkinNotes)
+ {
+ if (checkinNotes.IsEmpty())
+ {
+ return null;
+ }
+
+ var index = 0;
+ var values = new CheckinNoteFieldValue[checkinNotes.Count];
+ foreach (var pair in checkinNotes)
+ {
+ values[index++] = new CheckinNoteFieldValue(pair.Key, pair.Value);
+ }
+
+ return _bridge.Wrap<WrapperForCheckinNote, CheckinNote>(new CheckinNote(values));
+ }
+
private IEnumerable<TInterface> GetWorkItemInfosHelper<TInterface, TWrapper, TInstance>(
IEnumerable<string> workItems,
TfsWorkItemCheckinAction checkinAction,
@@ -292,6 +292,11 @@ public IEnumerable<IWorkItemCheckedInfo> GetWorkItemCheckedInfos(IEnumerable<str
throw new NotImplementedException();
}
+ public ICheckinNote CreateCheckinNote(Dictionary<string, string> checkinNotes)
+ {
+ throw new NotImplementedException();
+ }
+
public ITfsChangeset GetChangeset(int changesetId, GitTfsRemote remote)
{
throw new NotImplementedException();
@@ -34,6 +34,7 @@ public OptionSet OptionSet
private List<string> _workItemsToAssociate = new List<string>();
private List<string> _workItemsToResolve = new List<string>();
+ private Dictionary<string, string> _checkinNotes = new Dictionary<string,string>();
public string CheckinComment { get; set; }
// This can be extended to checkin when the $EDITOR is invoked.
@@ -44,5 +45,6 @@ public OptionSet OptionSet
public bool OverrideGatedCheckIn { get; set; }
public List<string> WorkItemsToAssociate { get { return _workItemsToAssociate; } }
public List<string> WorkItemsToResolve { get { return _workItemsToResolve; } }
+ public Dictionary<string, string> CheckinNotes { get { return _checkinNotes; } }
}
}
@@ -6,10 +6,10 @@ namespace Sep.Git.Tfs.Core
{
public class CheckinPolicyEvaluator
{
- public CheckinPolicyEvaluationResult EvaluateCheckin(IWorkspace workspace, IPendingChange[] pendingChanges, string comment, IEnumerable<IWorkItemCheckinInfo> workItemInfo)
+ public CheckinPolicyEvaluationResult EvaluateCheckin(IWorkspace workspace, IPendingChange[] pendingChanges, string comment, ICheckinNote checkinNote, IEnumerable<IWorkItemCheckinInfo> workItemInfo)
{
var result = workspace.EvaluateCheckin(TfsCheckinEvaluationOptions.All, pendingChanges,
- pendingChanges, comment, null,
+ pendingChanges, comment, checkinNote,
workItemInfo);
return new CheckinPolicyEvaluationResult(result);
}
@@ -16,6 +16,7 @@ public interface ITfsHelper
IShelveset CreateShelveset(IWorkspace workspace, string shelvesetName);
IEnumerable<IWorkItemCheckinInfo> GetWorkItemInfos(IEnumerable<string> workItems, TfsWorkItemCheckinAction checkinAction);
IEnumerable<IWorkItemCheckedInfo> GetWorkItemCheckedInfos(IEnumerable<string> workItems, TfsWorkItemCheckinAction checkinAction);
+ ICheckinNote CreateCheckinNote(Dictionary<string, string> checkinNotes);
IIdentity GetIdentity(string username);
ITfsChangeset GetLatestChangeset(GitTfsRemote remote);
ITfsChangeset GetChangeset(int changesetId, GitTfsRemote remote);
@@ -42,7 +42,7 @@ public void Shelve(string shelvesetName, bool evaluateCheckinPolicies, Func<stri
shelveset.WorkItemInfo = GetWorkItemInfos().ToArray();
if (evaluateCheckinPolicies)
{
- foreach (var message in _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, shelveset.Comment, shelveset.WorkItemInfo).Messages)
+ foreach (var message in _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, shelveset.Comment, null, shelveset.WorkItemInfo).Messages)
{
_stdout.WriteLine("[Checkin Policy] " + message);
}
@@ -77,7 +77,9 @@ public long Checkin(CheckinOptions options)
throw new GitTfsException("Nothing to checkin!");
var workItemInfos = GetWorkItemInfos();
- var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, options.CheckinComment, workItemInfos);
+ var checkinNote = _tfsHelper.CreateCheckinNote(options.CheckinNotes);
+
+ var checkinProblems = _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, options.CheckinComment, checkinNote, workItemInfos);
if (checkinProblems.HasErrors)
{
foreach (var message in checkinProblems.Messages)
@@ -102,7 +104,7 @@ public long Checkin(CheckinOptions options)
}
var policyOverride = GetPolicyOverrides(options, checkinProblems.Result);
- var newChangeset = _workspace.Checkin(pendingChanges, options.CheckinComment, null, workItemInfos, policyOverride, options.OverrideGatedCheckIn);
+ var newChangeset = _workspace.Checkin(pendingChanges, options.CheckinComment, checkinNote, workItemInfos, policyOverride, options.OverrideGatedCheckIn);
if (newChangeset == 0)
{
throw new GitTfsException("Checkin failed!");
@@ -26,6 +26,10 @@ public static class GitTfsConstants
public static readonly Regex TfsWorkItemRegex =
new Regex(GitTfsPrefix + @"-work-item:\s+(?<item_id>\d+)\s+(?<action>.+)");
+ // e.g. git-tfs-code-reviewer: John Smith
+ public static readonly Regex TfsCodeReviewerRegex =
+ new Regex(GitTfsPrefix + @"-code-reviewer:\s+(?<reviewer>.+)");
+
// e.g. git-tfs-force: override reason
public static readonly Regex TfsForceRegex =
new Regex(GitTfsPrefix + @"-force:\s+(?<reason>.+)\s*$");
@@ -31,6 +31,8 @@ public CheckinOptions BuildCommitSpecificCheckinOptions(CheckinOptions sourceChe
ProcessWorkItemCommands(customCheckinOptions, writer);
+ ProcessCheckinNoteCommands(customCheckinOptions, writer);
+
ProcessForceCommand(customCheckinOptions, writer);
return customCheckinOptions;
@@ -75,6 +77,22 @@ private void ProcessWorkItemCommands(CheckinOptions checkinOptions, TextWriter w
}
}
+ private void ProcessCheckinNoteCommands(CheckinOptions checkinOptions, TextWriter writer)
+ {
+ MatchCollection matches;
+ if ((matches = GitTfsConstants.TfsCodeReviewerRegex.Matches(checkinOptions.CheckinComment)).Count == 1)
+ {
+ string reviewer = matches[0].Groups["reviewer"].Value;
+
+ if (!string.IsNullOrWhiteSpace(reviewer))
+ {
+ writer.WriteLine("Code reviewer: {0}", reviewer);
+ checkinOptions.CheckinNotes.Add("Code Reviewer", reviewer);
+ }
+ checkinOptions.CheckinComment = GitTfsConstants.TfsCodeReviewerRegex.Replace(checkinOptions.CheckinComment, "").Trim(' ', '\r', '\n');
+ }
+ }
+
private void ProcessForceCommand(CheckinOptions checkinOptions, TextWriter writer)
{
MatchCollection workitemMatches;

0 comments on commit 18269ea

Please sign in to comment.