public void HandleWorkItemChanged(WorkItemChangedEvent changedEvent) { var teamProjectMapping = FindTeamProjectMapping(changedEvent.PortfolioProject); if (teamProjectMapping == null) { _logger.Trace("Ignoring project {0}", changedEvent.PortfolioProject); return; } var workItemTypeField = changedEvent.GetFieldOrNull("Work Item Type"); if (workItemTypeField == null) { _logger.Warn("Could not find field 'Work Item Type'"); return; } if (changedEvent.ChangeType == "Change") { if (workItemTypeField.NewValue == "Task") { if (!IsNotificationSubscribedTo(teamProjectMapping, Notification.TaskWorkChange)) { return; } var stateChangedField = changedEvent.GetChangedFieldOrNull("State"); if (stateChangedField != null) { _hipChatNotifier.SendTaskStateChangedNotification( changedEvent, teamProjectMapping.HipChatRoomId); } var stateField = changedEvent.GetFieldOrNull("State"); var remainingWorkChangedField = changedEvent.GetChangedFieldOrNull("Remaining Work"); if (remainingWorkChangedField != null && stateField.NewValue == "In Progress") { _hipChatNotifier.SendTaskChangedRemainingNotification( changedEvent, teamProjectMapping.HipChatRoomId); } var assignedToField = changedEvent.GetChangedFieldOrNull("Assigned To"); if (assignedToField != null && assignedToField.NewValue != assignedToField.OldValue && stateField.NewValue == "In Progress") { _hipChatNotifier.SendTaskOwnerChangedNotification( changedEvent, teamProjectMapping.HipChatRoomId); } var historyField = changedEvent.GetTextFieldOrNull("History"); if (historyField != null) { if (!historyField.Value.StartsWith("Associated with changeset") && !historyField.Value.Contains( "The Fixed In field was updated as part of associating work items with the build.")) { _hipChatNotifier.SendTaskHistoryCommentNotification(changedEvent, teamProjectMapping.HipChatRoomId); } } } else { _logger.Info(string.Format("Ignoring unhandled field type: {0}", workItemTypeField.NewValue)); return; } } else if (changedEvent.ChangeType == "New") { _logger.Trace("Ignoring new work item event"); return; } }
public void SendTaskHistoryCommentNotification(WorkItemChangedEvent changedEvent, int roomId) { var shortTitle = Shorten(changedEvent.GetFieldOrNull("Title").NewValue, 25); var userName = GetChangedByOrNull(changedEvent) ?? GetAssignedToOrNull(changedEvent); var comment = Shorten(changedEvent.GetTextFieldOrNull("History").Value, 250); var message = string.Format("<a href='{0}'>{1}</a> comment: <i>{2}</i>", changedEvent.DisplayUrl, shortTitle, comment); if (userName != null) { message = string.Format("{0} - {1}", userName, message); } _hipChatClient.From = GetFromValue("Task"); _hipChatClient.RoomId = roomId; _hipChatClient.SendMessage(message, HipChatClient.BackgroundColor.purple); }