public static OfflineJiraProvider Initialize(string backupLocation, JiraSettings settings) { if (!Directory.Exists(backupLocation)) { throw new ArgumentException("backupLocation not correct"); } OfflineJiraProvider provider = new OfflineJiraProvider(); provider.backupDirectory = new DirectoryInfo(backupLocation); provider.Settings = settings; Logger.Log(LogLevel.Info, "Loading backup files into ram"); FileInfo[] files = provider.backupDirectory.GetFiles(); foreach (FileInfo file in files) { if (file.Name == "activeobjects.xml") { provider.activeObjects = XDocument.Load(file.FullName); } else if (file.Name == "entities.xml") { provider.entities = XDocument.Load(file.FullName); } } return(provider); }
public static JiraProvider Initialize(JiraSettings settings) { var provider = new JiraProvider(); provider.Jira = ConnectToJira(settings); provider.Settings = settings; Logger.Log(LogLevel.Info, "Retrieving Jira fields..."); provider.Jira.Fields.GetCustomFieldsAsync().Wait(); Logger.Log(LogLevel.Info, "Retrieving Jira link types..."); provider.LinkTypes = provider.Jira.Links.GetLinkTypesAsync().Result; return(provider); }
private static Jira ConnectToJira(JiraSettings jiraSettings) { Jira jira = null; try { Logger.Log(LogLevel.Info, "Connecting to Jira..."); jira = Jira.CreateRestClient(jiraSettings.Url, jiraSettings.UserID, jiraSettings.Pass); } catch (Exception ex) { Logger.Log(ex, $"Could not connect to Jira!", LogLevel.Critical); } return(jira); }
private static Jira ConnectToJira(JiraSettings jiraSettings) { Logger.Log(LogLevel.Debug, "Connecting to Jira..."); Jira jira = null; try { jira = Jira.CreateRestClient(jiraSettings.Url, jiraSettings.UserID, jiraSettings.Pass); Logger.Log(LogLevel.Info, "Connected to Jira."); } catch (Exception ex) { Logger.Log(LogLevel.Critical, $"Could not connect to Jira! Message: {ex.Message}"); } return(jira); }
private static Jira ConnectToJira(JiraSettings jiraSettings) { Jira jira = null; try { Logger.Log(LogLevel.Info, "Connecting to Jira..."); jira = Jira.CreateRestClient(jiraSettings.Url, jiraSettings.UserID, jiraSettings.Pass); jira.RestClient.RestSharpClient.AddDefaultHeader("X-Atlassian-Token", "no-check"); } catch (Exception ex) { Logger.Log(ex, $"Could not connect to Jira!", LogLevel.Critical); } return(jira); }
public static JiraProvider Initialize(JiraSettings settings) { var provider = new JiraProvider(); provider.Jira = ConnectToJira(settings); provider.Settings = settings; Logger.Log(LogLevel.Info, "Gathering project info..."); // ensure that Custom fields cache is full provider.Jira.Fields.GetCustomFieldsAsync().Wait(); Logger.Log(LogLevel.Info, "Custom field cache set up."); Logger.Log(LogLevel.Info, "Custom parsers set up."); provider.LinkTypes = provider.Jira.Links.GetLinkTypesAsync().Result; Logger.Log(LogLevel.Info, "Link types cache set up."); return(provider); }
public static JiraProvider Initialize(JiraSettings settings) { var provider = new JiraProvider(); provider.Jira = ConnectToJira(settings); provider.Settings = settings; Logger.Log(LogLevel.Info, "Retrieving Jira fields..."); provider.Jira.Fields.GetCustomFieldsAsync().Wait(); Logger.Log(LogLevel.Info, "Retrieving Jira link types..."); try { provider.LinkTypes = provider.Jira.Links.GetLinkTypesAsync().Result; } catch (Exception e) { Logger.Log(e, "Failed to retrive linktypes from Jira"); } return(provider); }
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) { 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 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); } }