From 43d292866ba2c1a940a18c93680bbfceb850c855 Mon Sep 17 00:00:00 2001 From: Mathias Olausson Date: Thu, 7 Feb 2019 20:53:11 +0100 Subject: [PATCH] Adding check for jira email when mapping user. #26 --- .../JiraExport/JiraProvider.cs | 23 +++++++++++++++---- .../Migration.Common/Logger.cs | 14 +++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/WorkItemMigrator/JiraExport/JiraProvider.cs b/src/WorkItemMigrator/JiraExport/JiraProvider.cs index 0557277a..bb7806d8 100644 --- a/src/WorkItemMigrator/JiraExport/JiraProvider.cs +++ b/src/WorkItemMigrator/JiraExport/JiraProvider.cs @@ -266,13 +266,28 @@ public int GetNumberOfComments(string key) public string GetUserEmail(string username) { if (_userEmailCache.TryGetValue(username, out string email)) + { return email; + } else { - var user = Jira.Users.GetUserAsync(username).Result; - email = user.Email; - _userEmailCache.Add(username, email); - return email; + try + { + var user = Jira.Users.GetUserAsync(username).Result; + if(string.IsNullOrEmpty(user.Email)) + { + Logger.Log(LogLevel.Warning, $"Email for user '{username}' not found in Jira, using '{username}' for mapping."); + return username; + } + email = user.Email; + _userEmailCache.Add(username, email); + return email; + } + catch(Exception e) + { + Logger.Log(LogLevel.Warning, $"User '{username}' not found in Jira, using '{username}' for mapping."); + return username; + } } } diff --git a/src/WorkItemMigrator/Migration.Common/Logger.cs b/src/WorkItemMigrator/Migration.Common/Logger.cs index 81a1a623..b0ff03c9 100644 --- a/src/WorkItemMigrator/Migration.Common/Logger.cs +++ b/src/WorkItemMigrator/Migration.Common/Logger.cs @@ -130,15 +130,21 @@ public static void Summary() { Console.WriteLine("::: SUMMARY :::"); Console.WriteLine("==============="); - foreach (var warning in Warnings) + if(Warnings.Count > 0) { Console.WriteLine("Warnings:"); - LogInternal(LogLevel.Warning, warning); + foreach (var warning in Warnings) + { + LogInternal(LogLevel.Warning, warning); + } } - foreach (var error in Errors) + if (Errors.Count > 0) { Console.WriteLine("Errors:"); - LogInternal(LogLevel.Error, error); + foreach (var error in Errors) + { + LogInternal(LogLevel.Error, error); + } } } }