public static bool CreateRestClient(JiraConfiguration config) { bool ret = false; try { _settings = new JiraRestClientSettings(); _settings.EnableUserPrivacyMode = true; _jiraRepo = new JiraRepo(config.jiraBaseUrl, config.jiraUserName, config.jiraAPIToken); if (_jiraRepo != null) { var test = _jiraRepo.GetJira().IssueTypes.GetIssueTypesAsync().Result.ToList(); if (test != null && test.Count > 0) { ret = true; } } } catch (Exception ex) { Console.Beep(); Console.Beep(); Console.Error.WriteLine("Sorry, there seems to be a problem connecting to Jira with the arguments you provided. Error: {0}, {1}\r\n\r\n{2}", ex.Message, ex.Source, ex.StackTrace); return(false); } return(ret); }
public static string[] GetConfig() { string[] ret = null; var personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/Library/Application Support/JiraCon"; if (!Directory.Exists(personalFolder)) { Directory.CreateDirectory(personalFolder); } string configFile = Path.Combine(personalFolder, configFileName); if (File.Exists(configFile)) { //check to confirm file has 3 arguments using (StreamReader reader = new StreamReader(configFile)) { var text = reader.ReadLine(); if (!string.IsNullOrWhiteSpace(text)) { var arr = text.Split(' '); if (arr.Length == 3) { ret = arr; } } } } if (ret == null) { string userName = ""; string apiToken = ""; string jiraBaseUrl = ""; userName = GetConsoleInput("Missing config -- please enter username (email address) for Jira login:"******"Missing config -- please enter API token for Jira login:"******"Missing config -- please enter base url for Jira instance:"); bool validCredentials = false; //test connection try { ConsoleUtil.WriteLine("testing Jira connection ..."); var testConn = new JiraRepo(jiraBaseUrl, userName, apiToken); if (testConn != null) { var test = testConn.GetJira().IssueTypes.GetIssueTypesAsync().Result.ToList(); if (test != null && test.Count > 0) { validCredentials = true; ConsoleUtil.WriteLine("testing Jira connection ... successful"); } } } catch (Exception ex) { ConsoleUtil.WriteLine("testing Jira connection ... failed"); ConsoleUtil.WriteLine(ex.Message); } if (!validCredentials) { return(GetConfig()); } else { using (StreamWriter writer = new StreamWriter(configFile)) { writer.WriteLine(string.Format("{0} {1} {2}", userName, apiToken, jiraBaseUrl)); } return(GetConfig()); } } return(ret); }