private static int? GetWorkItemIdFromText()

in Mail2Bug/WorkItemManagement/MessageToWorkItemMapper.cs [77:103]


        private static int? GetWorkItemIdFromText(string text, string regex, string capturingGroupName)
        {
            if (string.IsNullOrEmpty(regex))
            {
                return null;
            }

            var regExAppendOnlySearch = new Regex(regex, RegexOptions.IgnoreCase);
            var itemIdMatch = regExAppendOnlySearch.Match(text);

            if (!itemIdMatch.Success)
            {
                return null;
            }

            var workItemIdString = itemIdMatch.Groups[capturingGroupName].Value;

            if (string.IsNullOrEmpty(workItemIdString))
            {
                throw new BadConfigException(
                    "EmailSettings\\AppendOnlyEmailTitleRegex",
                    "Couldn't find \"id\" group when matching title. AppendOnlyEmailTitleRegex must contain a capturing group called 'id'" +
                    " that will contain the TFS item ID to update");
            }

            return Int32.Parse(workItemIdString);
        }