Skip to content

Commit

Permalink
Get identity correctly after changed assignedTo format
Browse files Browse the repository at this point in the history
Fixes #42
  • Loading branch information
kria committed May 22, 2016
1 parent d595685 commit 24e1780
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
48 changes: 48 additions & 0 deletions TfsNotificationRelay/EventHandlers/UserField.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* TfsNotificationRelay - http://github.com/kria/TfsNotificationRelay
*
* Copyright (C) 2016 Kristian Adrup
*
* This file is part of TfsNotificationRelay.
*
* TfsNotificationRelay is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. See included file COPYING for details.
*/

using System;
using System.Text.RegularExpressions;

namespace DevCore.TfsNotificationRelay.EventHandlers
{
class UserField
{
private UserField() {}

private UserField(string displayName, Guid identifier)
{
DisplayName = displayName;
Identifier = identifier;
}

public string DisplayName { get; }
public Guid Identifier { get; }

public static bool TryParse(string userstring, out UserField field)
{
const string pattern = @"^\|(.*)%(.*)\|$";
field = null;

var match = Regex.Match(userstring, pattern);
if (!match.Success) return false;

Guid id = Guid.Empty;
if (!Guid.TryParse(match.Groups[2].Value, out id)) return false;

field = new UserField(match.Groups[1].Value, id);

return true;
}
}
}
13 changes: 9 additions & 4 deletions TfsNotificationRelay/EventHandlers/WorkItemChangedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ protected override IEnumerable<INotification> CreateNotifications(TeamFoundation
if (idField == null) throw new TfsNotificationRelayException("missing System.Id");
int id = idField.NewValue;

var assignedTo = ev.CoreFields.StringFields.GetFieldValue("System.AssignedTo", f => f.NewValue);
var assignedToString = ev.CoreFields.StringFields.GetFieldValue("System.AssignedTo", f => f.NewValue);
string assignedToUniqueName = null;
if (!string.IsNullOrEmpty(assignedTo))
string assignedTo = null;
if (!string.IsNullOrEmpty(assignedToString))
{
var assignedToIdentity = identityService.ReadIdentity(requestContext, IdentitySearchFactor.DisplayName, assignedTo);
if (assignedToIdentity != null)
UserField assignedToField = null;
if (UserField.TryParse(assignedToString, out assignedToField) && assignedToField.Identifier != Guid.Empty)
{
assignedTo = assignedToField.DisplayName;
var assignedToIdentity = identityService.ReadIdentities(requestContext, new[] { assignedToField.Identifier }).First();
assignedToUniqueName = assignedToIdentity.UniqueName;
}
}

var teamNames = GetUserTeamsByProjectUri(requestContext, ev.ProjectNodeId, identity.Descriptor).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

using DevCore.TfsNotificationRelay.Configuration;
using DevCore.TfsNotificationRelay.EventHandlers;
using Microsoft.TeamFoundation.WorkItemTracking.Server;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -162,9 +163,8 @@ public UnifiedField(IntegerField field)

private string GetDisplayName(string value)
{
string pattern = @"\|(.*)%";
var match = Regex.Match(value, pattern);
if (match.Success) return match.Groups[1].Value;
UserField field = null;
if (UserField.TryParse(value, out field)) return field.DisplayName;

return value;
}
Expand Down
6 changes: 3 additions & 3 deletions TfsNotificationRelay/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.15.0.0")]
[assembly: AssemblyFileVersion("1.15.0.0")]
[assembly: AssemblyInformationalVersion("1.15.0.0")]
[assembly: AssemblyVersion("1.15.1.0")]
[assembly: AssemblyFileVersion("1.15.1.0")]
[assembly: AssemblyInformationalVersion("1.15.1.0")]
1 change: 1 addition & 0 deletions TfsNotificationRelay/TfsNotificationRelay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
<Compile Include="EventHandlers\PullRequestReviewerVoteHandler.cs" />
<Compile Include="EventHandlers\PullRequestStatusUpdateHandler.cs" />
<Compile Include="EventHandlers\RepositoryCreatedHandler.cs" />
<Compile Include="EventHandlers\UserField.cs" />
<Compile Include="HtmlToText.cs" />
<Compile Include="Notifications\ChangesetCommentNotification.cs" />
<Compile Include="Notifications\CommitCommentNotification.cs" />
Expand Down

0 comments on commit 24e1780

Please sign in to comment.