private void ExecuteMigration(CommandOption user, CommandOption password, CommandOption url, CommandOption configFile, bool forceFresh) { ConfigJson config = null; try { string configFileName = configFile.Value(); ConfigReaderJson configReaderJson = new ConfigReaderJson(configFileName); config = configReaderJson.Deserialize(); // Migration session level settings // where the logs and journal will be saved, logs aid debugging, journal is for recovery of interupted process string migrationWorkspace = config.Workspace; // level of log messages that will be let through to console LogLevel logLevel; switch (config.LogLevel) { case "Info": logLevel = LogLevel.Info; break; case "Debug": logLevel = LogLevel.Debug; break; case "Warning": logLevel = LogLevel.Warning; break; case "Error": logLevel = LogLevel.Error; break; case "Critical": logLevel = LogLevel.Critical; break; default: logLevel = LogLevel.Debug; break; } var downloadOptions = JiraProvider.DownloadOptions.IncludeParentEpics | JiraProvider.DownloadOptions.IncludeSubItems | JiraProvider.DownloadOptions.IncludeParents; Logger.Init(migrationWorkspace, logLevel); var jiraSettings = new JiraSettings(user.Value(), password.Value(), url.Value(), config.SourceProject) { BatchSize = config.BatchSize, UserMappingFile = config.UserMappingFile != null?Path.Combine(migrationWorkspace, config.UserMappingFile) : string.Empty, AttachmentsDir = Path.Combine(migrationWorkspace, config.AttachmentsFolder), JQL = config.Query, DomainMapping = config.DomainMapping }; JiraProvider jiraProvider = JiraProvider.Initialize(jiraSettings); // Get the custom field names for epic link field and sprint field jiraSettings.EpicLinkField = jiraProvider.GetCustomId(config.EpicLinkField); jiraSettings.SprintField = jiraProvider.GetCustomId(config.SprintField); var mapper = new JiraMapper(jiraProvider, config); var localProvider = new WiItemProvider(migrationWorkspace); var exportedKeys = new HashSet <string>(Directory.EnumerateFiles(migrationWorkspace, "*.json").Select(f => Path.GetFileNameWithoutExtension(f))); var skips = forceFresh ? new HashSet <string>(Enumerable.Empty <string>()) : exportedKeys; foreach (var issue in jiraProvider.EnumerateIssues(jiraSettings.JQL, skips, downloadOptions)) { WiItem wiItem = mapper.Map(issue); localProvider.Save(wiItem); Logger.Log(LogLevel.Info, $"Exported {wiItem.ToString()}"); } } catch (CommandParsingException e) { Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}"); } catch (Exception e) { Logger.Log(LogLevel.Error, $"Unexpected error: {e}"); } }
private void ExecuteMigration(CommandOption user, CommandOption password, CommandOption useOfflineBackup, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical) { var itemsCount = 0; var exportedItemsCount = 0; var sw = new Stopwatch(); sw.Start(); try { string configFileName = configFile.Value(); ConfigReaderJson configReaderJson = new ConfigReaderJson(configFileName); var config = configReaderJson.Deserialize(); InitSession(config, continueOnCritical.Value()); // Migration session level settings // where the logs and journal will be saved, logs aid debugging, journal is for recovery of interupted process string migrationWorkspace = config.Workspace; var downloadOptions = (DownloadOptions)config.DownloadOptions; var jiraSettings = new JiraSettings(user.Value(), password.Value(), url.Value(), config.SourceProject) { BatchSize = config.BatchSize, UserMappingFile = config.UserMappingFile != null ? Path.Combine(migrationWorkspace, config.UserMappingFile) : string.Empty, AttachmentsDir = Path.Combine(migrationWorkspace, config.AttachmentsFolder), JQL = config.Query, UsingJiraCloud = config.UsingJiraCloud }; IJiraProvider jiraProvider = null; if (useOfflineBackup.HasValue()) { jiraProvider = OfflineJiraProvider.Initialize(useOfflineBackup.Value(), jiraSettings); } else { jiraProvider = JiraProvider.Initialize(jiraSettings); } itemsCount = jiraProvider.GetItemCount(jiraSettings.JQL); BeginSession(configFileName, config, forceFresh, jiraProvider, itemsCount); jiraSettings.EpicLinkField = jiraProvider.GetCustomId(config.EpicLinkField); if (string.IsNullOrEmpty(jiraSettings.EpicLinkField)) { Logger.Log(LogLevel.Warning, $"Epic link field missing for config field '{config.EpicLinkField}'."); } jiraSettings.SprintField = jiraProvider.GetCustomId(config.SprintField); if (string.IsNullOrEmpty(jiraSettings.SprintField)) { Logger.Log(LogLevel.Warning, $"Sprint link field missing for config field '{config.SprintField}'."); } var mapper = new JiraMapper(jiraProvider, config); var localProvider = new WiItemProvider(migrationWorkspace); var exportedKeys = new HashSet<string>(Directory.EnumerateFiles(migrationWorkspace, "*.json").Select(f => Path.GetFileNameWithoutExtension(f))); var skips = forceFresh ? new HashSet<string>(Enumerable.Empty<string>()) : exportedKeys; var issues = jiraProvider.EnumerateIssues(jiraSettings.JQL, skips, downloadOptions); foreach (var issue in issues) { if (issue == null) continue; WiItem wiItem = mapper.Map(issue); if (wiItem != null) { localProvider.Save(wiItem); exportedItemsCount++; Logger.Log(LogLevel.Debug, $"Exported as type '{wiItem.Type}'."); } } } catch (CommandParsingException e) { Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}"); } catch (Exception e) { Logger.Log(e, $"Unexpected migration error."); } finally { EndSession(itemsCount, sw); } }
private void ExecuteMigration(CommandOption user, CommandOption password, CommandOption url, CommandOption configFile, bool forceFresh) { var itemsCount = 0; var exportedItemsCount = 0; var sw = new Stopwatch(); sw.Start(); try { string configFileName = configFile.Value(); var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); ConfigReaderJson configReaderJson = new ConfigReaderJson($"{assemblyPath}\\{configFileName}"); var config = configReaderJson.Deserialize(); InitSession(config); // Migration session level settings // where the logs and journal will be saved, logs aid debugging, journal is for recovery of interupted process string migrationWorkspace = config.Workspace; var downloadOptions = (DownloadOptions)config.DownloadOptions; var jiraSettings = new JiraSettings(user.Value(), password.Value(), url.Value(), config.SourceProject) { BatchSize = config.BatchSize, UserMappingFile = config.UserMappingFile != null?Path.Combine(assemblyPath, config.UserMappingFile) : string.Empty, AttachmentsDir = Path.Combine(migrationWorkspace, config.AttachmentsFolder), JQL = config.Query }; JiraProvider jiraProvider = JiraProvider.Initialize(jiraSettings); itemsCount = jiraProvider.GetItemCount(jiraSettings.JQL); BeginSession(configFileName, config, forceFresh, jiraProvider, itemsCount); //change to retrive from fields jiraSettings.EpicLinkField = jiraProvider.Fields.FirstOrDefault(f => f.Name == "Epic Link")?.Id; if (string.IsNullOrEmpty(jiraSettings.EpicLinkField)) { Logger.Log(LogLevel.Warning, $"Epic link field missing for config field '{config.EpicLinkField}'."); } jiraSettings.SprintField = jiraProvider.Fields.FirstOrDefault(f => f.Name == "Sprint")?.Id; if (string.IsNullOrEmpty(jiraSettings.SprintField)) { Logger.Log(LogLevel.Warning, $"Sprint link field missing for config field '{config.SprintField}'."); } jiraSettings.ConfluenceLinkField = config.ConfluenceLinkField; if (string.IsNullOrEmpty(jiraSettings.ConfluenceLinkField)) { Logger.Log(LogLevel.Warning, $"Confluence link field missing for config field '{config.ConfluenceLinkField}'."); } var mapper = new JiraMapper(jiraProvider, config); var localProvider = new WiItemProvider(migrationWorkspace); var exportedKeys = new HashSet <string>(Directory.EnumerateFiles(migrationWorkspace, "*.json").Select(f => Path.GetFileNameWithoutExtension(f))); var skips = forceFresh ? new HashSet <string>(Enumerable.Empty <string>()) : exportedKeys; var query = jiraSettings.JQL; //Debugging id ex: query = "project = PL AND id = PL-2449"; var issues = jiraProvider.EnumerateIssues(query, skips, downloadOptions); foreach (var issue in issues) { WiItem wiItem = mapper.Map(issue); if (wiItem != null) { localProvider.Save(wiItem); exportedItemsCount++; Logger.Log(LogLevel.Debug, $"Exported as type '{wiItem.Type}'."); } } } catch (CommandParsingException e) { Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}"); } catch (Exception e) { Logger.Log(e, $"Unexpected migration error."); } finally { EndSession(itemsCount, sw); } }