Example #1
0
        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);
        }
Example #2
0
        public async Task UploadAsync(string pwd, IEnumerable <string> issues, IEnumerable <AggregatedTimeEntry> logs, CancellationToken token)
        {
            var settings = new JiraRestClientSettings();

            var logger = _loggingFactory.CreateLogger <Uploader>();

            logger.LogInformation($"Start to upload data to the {_config.BaseApiUrl}");

            var jira = Atlassian.Jira.Jira.CreateRestClient(
                _config.BaseApiUrl,
                _config.UserName,
                pwd,
                settings);

            try
            {
                var result = await UploadCore(issues, logs, jira).ConfigureAwait(false);

                if (result == null)
                {
                    logger.LogWarning("No issues processed.");
                    return;
                }

                logger.LogInformation($"Issues updated: {result.Item1}");
                logger.LogInformation($"Time reported to Jira: {result.Item2}");
                logger.LogInformation($"Time removed from Jira: {result.Item3}");
            }
            catch (Exception e)
            {
                logger.LogError(e.ToString());
            }
        }
Example #3
0
        public JiraRepo(string server, string userName, string password)
        {
            JiraRestClientSettings settings = new JiraRestClientSettings();

            settings.EnableUserPrivacyMode = true;


            _jira = Atlassian.Jira.Jira.CreateRestClient(server, userName, password, settings);

            _jira.Issues.MaxIssuesPerRequest = 500;

            _fieldList = GetFields();

            JField jField = _fieldList.Where(x => x.Name == "Epic Link").FirstOrDefault();

            if (jField != null)
            {
                _epicLinkFieldKey = jField.Key;
            }

            jField = _fieldList.Where(x => x.Name == "Feature Team Choices").FirstOrDefault();
            if (jField != null)
            {
                _featureTeamChoicesFieldKey = jField.Key;
            }
        }
Example #4
0
        public AtlassianClient(AtlassianSettings settings)
        {
            Settings = settings;
            JiraRestClientSettings set = new JiraRestClientSettings();

            set.EnableRequestTrace = true;
            JiraClient             = Jira.CreateOAuthRestClient(Settings.JiraURL, Settings.ConsumerKey, Settings.ConsumerSecret, Settings.OAuthAccessToken, Settings.OAuthAccessSecret, settings: set);
        }
        public JiraAccessService(SyncSystemDTO syncSystem)
        {
            SyncSystem   = syncSystem;
            jiraUserName = syncSystem.SystemLogin;
            jiraPassword = syncSystem.SystemPassword;
            jiraApiUrl   = syncSystem.SystemApiUrl.Trim('/');
            JiraRestClientSettings jiraRestClientSettings = new JiraRestClientSettings();

            jiraRestClientSettings.CustomFieldSerializers.Remove("com.pyxis.greenhopper.jira:gh-sprint");
            JiraConnection = Atlassian.Jira.Jira.CreateRestClient(syncSystem.SystemUrl, jiraUserName, jiraPassword, jiraRestClientSettings);
        }
        /// <summary>
        /// Creates a new instance of the JiraRestClient class.
        /// </summary>
        /// <param name="url">The url to the JIRA server.</param>
        /// <param name="authenticator">The authenticator used by RestSharp.</param>
        /// <param name="settings">The settings to configure the rest client.</param>
        protected JiraRestClient(string url, IAuthenticator authenticator, JiraRestClientSettings settings = null)
        {
            url             = url.EndsWith("/") ? url : url += "/";
            _clientSettings = settings ?? new JiraRestClientSettings();
            _restClient     = new RestClient(url)
            {
                Proxy = _clientSettings.Proxy
            };

            this._restClient.Authenticator = authenticator;
        }
Example #7
0
        async void DataInit()
        {
            var settings = new JiraRestClientSettings()
            {
                EnableRequestTrace = true
            };
            ErrorCode err;

            // create a connection to JIRA using the Rest client
            myJira = Jira.CreateRestClient("http://intranet.ctdc.siemens.com.cn:8995", "z003hkns", "!QAZ5tgb", settings);
            GetIssues();
            //GetUsers();
            myUsers = new List <User>();
            foreach (Issue curItem in IssueListView.Items)
            {
                if (myUsers.Any(x => x.Name == curItem.Assignee))
                {
                    continue;
                }
                if (curItem.Assignee == null)
                {
                    continue;
                }
                var newUser = await GetUsers(curItem.Assignee);

                myUsers.Add(newUser);
                myProjectGraph.AddNode(newUser, out err);
            }

            myIssues = new List <JiraIssue>();
            foreach (Issue curItem in IssueListView.Items)
            {
                var newIssue = new JiraIssue(curItem);
                myIssues.Add(newIssue);
                myProjectGraph.AddNode(newIssue, out err);
                if (curItem.Reporter != null)
                {
                    INode reporter = myUsers.First(x => x.Name == curItem.Reporter);
                    myProjectGraph.AddEdge(newIssue, reporter, new ReportBy(), out err);
                    myProjectGraph.AddEdge(reporter, newIssue, new Report(), out err);
                }
                if (curItem.Assignee != null)
                {
                    INode assignee = myUsers.First(x => x.Name == curItem.Assignee);
                    myProjectGraph.AddEdge(newIssue, assignee, new AssignedTo(), out err);
                    myProjectGraph.AddEdge(assignee, newIssue, new Assigned(), out err);
                }
            }

            myProjectGraph.SaveDataBase(out err);
            return;
        }
Example #8
0
        public JiraRestClient(Options options)
        {
            var url = options.Url.EndsWith("/") ? options.Url : options.Url += "/";

            this._clientSettings     = options.RestClientSettings ?? new JiraRestClientSettings();
            this._getCurrentJiraFunc = options.GetCurrentJiraFunc;
            this._restClient         = new RestClient(url);

            if (!String.IsNullOrEmpty(options.Username) && !String.IsNullOrEmpty(options.Password))
            {
                this._restClient.Authenticator = new HttpBasicAuthenticator(options.Username, options.Password);
            }
        }
Example #9
0
        internal JiraRestClient(ServiceLocator services, string url, string username = null, string password = null, JiraRestClientSettings settings = null)
        {
            url = url.EndsWith("/") ? url : url += "/";

            _clientSettings = settings ?? new JiraRestClientSettings();
            _restClient     = new RestClient(url);
            _services       = services;

            if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password))
            {
                this._restClient.Authenticator = new HttpBasicAuthenticator(username, password);
            }
        }
Example #10
0
        /// <summary>
        /// Creates a new instance of the JiraRestClient class.
        /// </summary
        /// <param name="url">Url to the JIRA server.</param>
        /// <param name="consumerKey">Consumer key to use for OAuth1 authentication.</param>
        /// <param name="consumerSecret">Consumer secret to use for OAuth1 authentication. Should be private key in xml format.</param>
        /// <param name="accessToken">User access token to use for authenticating API requests.</param>
        /// <param name="accessTokenSecret">User access token secret to use for authenticating API requests.</param>
        /// <param name="settings">Settings to configure the rest client.</param>
        public JiraRestClient(string url, string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret, JiraRestClientSettings settings = null)
        {
            url = url.EndsWith("/") ? url : url += "/";

            _clientSettings = settings ?? new JiraRestClientSettings();
            _restClient     = new RestClient(url)
            {
                Proxy = _clientSettings.Proxy
            };

            if (!String.IsNullOrEmpty(consumerKey) && !String.IsNullOrEmpty(consumerSecret) && !String.IsNullOrEmpty(accessToken) && !String.IsNullOrEmpty(accessTokenSecret))
            {
                this._restClient.Authenticator = OAuth1Authenticator.ForProtectedResource(consumerKey, consumerSecret, accessToken, accessTokenSecret, OAuthSignatureMethod.RsaSha1);
            }
        }
Example #11
0
        /// <summary>
        /// Creates a new instance of the JiraRestClient class.
        /// </summary
        /// <param name="url">Url to the JIRA server.</param>
        /// <param name="username">Username used to authenticate.</param>
        /// <param name="password">Password used to authenticate.</param>
        /// <param name="settings">Settings to configure the rest client.</param>
        public JiraRestClient(string url, string username = null, string password = null, JiraRestClientSettings settings = null)
        {
            url = url.EndsWith("/") ? url : url += "/";

            _clientSettings = settings ?? new JiraRestClientSettings();
            _restClient     = new RestClient(url)
            {
                Proxy = _clientSettings.Proxy
            };

            if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password))
            {
                this._restClient.Authenticator = new HttpBasicAuthenticator(username, password);
            }
        }
Example #12
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NullReferenceException"></exception>
        private Jira GetJiraClient()
        {
            var data = _settingsHandler.LoadSettings();

            if (string.IsNullOrEmpty(data.HostAddress))
            {
                throw new NullReferenceException("Host Address is not set.");
            }
            var settings = new JiraRestClientSettings {
                EnableRequestTrace = true
            };
            var client = Jira.CreateRestClient(data.HostAddress, data.UserId, data.Password.ConvertToInsecureString(), settings);

            client.MaxIssuesPerRequest = data.MaxResult;
            return(client);
        }
Example #13
0
        private static List <Object> GetJiraTasks()
        {
            var settings = new JiraRestClientSettings()
            {
                EnableRequestTrace = true
            };
            var thingie =
                new IssueStatus(new RemoteStatus()
            {
                id          = "10510",
                description = "",
                iconUrl     = "https://epm.verisk.com/jira/images/icons/status_generic.gif",
                name        = "Acceptance Testing"
            });
            var jiraConn = Jira.CreateRestClient("https://epm.verisk.com/jira/", "I59098",
                                                 File.ReadAllText(@"C:\Users\i59098\Google Drive\pword.txt"), settings);

            var tasks = jiraConn.Issues.Queryable.Where(i => i.Project == "XWESVC").Take(1000000000).ToList();

            var jiraIssues = new List <JiraIssue>();
            var issues     = new List <Issue>();
            var subtasks   = new List <Issue>();

            foreach (var issue in tasks)
            {
                if (issue.Type.IsSubTask && (issue.Assignee == "I59098" || issue.Assignee == "I55711"))
                {
                    subtasks.Add(issue);
                }
                else
                {
                    var status = "";
                    jiraIssues.Add(new JiraIssue()
                    {
                        DevTask = issue.Key.Value,
                    });
                }
            }
            foreach (var issueStatus in subtasks)
            {
                Console.WriteLine($@"Status: {issueStatus.Key} Count: {issueStatus.Key.Value}");
            }

            //Issue thing = jiraConn.GetIssue("XWESVC-974");
            //var user = jiraConn.Users.GetUserAsync(thing.Assignee).Result;
            return(null);
        }
Example #14
0
        public JiraController()
        {
            var settings = new JiraRestClientSettings()
            {
                EnableRequestTrace = true
            };
            var thingie =
                new IssueStatus(new RemoteStatus()
            {
                id          = "10510",
                description = "",
                iconUrl     = "https://epm.verisk.com/jira/images/icons/status_generic.gif",
                name        = "Acceptance Testing"
            });

            jiraConn = Jira.CreateRestClient("https://epm.verisk.com/jira/", "I59098",
                                             File.ReadAllText(@"C:\Users\i59098\Google Drive\pword.txt"), settings);
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JiraOAuthRestClient"/> class.
 /// </summary>
 /// <param name="url">The url of the Jira instance to request to.</param>
 /// <param name="consumerKey">The consumer key provided by the Jira application link.</param>
 /// <param name="consumerSecret">The consumer private key in XML format.</param>
 /// <param name="oAuthAccessToken">The OAuth access token obtained from Jira.</param>
 /// <param name="oAuthTokenSecret">The OAuth token secret generated by Jira.</param>
 /// <param name="oAuthSignatureMethod">The signature method used to sign the request.</param>
 /// <param name="settings">The settings used to configure the rest client.</param>
 public JiraOAuthRestClient(
     string url,
     string consumerKey,
     string consumerSecret,
     string oAuthAccessToken,
     string oAuthTokenSecret,
     JiraOAuthSignatureMethod oAuthSignatureMethod = JiraOAuthSignatureMethod.RsaSha1,
     JiraRestClientSettings settings = null)
     : base(
         url,
         OAuth1Authenticator.ForProtectedResource(
             consumerKey,
             consumerSecret,
             oAuthAccessToken,
             oAuthTokenSecret,
             oAuthSignatureMethod.ToOAuthSignatureMethod()),
         settings)
 {
 }
        public async Task <IEnumerable <WorkItem> > GetWorkItems()
        {
            var user = AuthHelper.GetCurrentUser();

            //connect to JIRA and get a list of work items for an Epic
            List <WorkItem> list = new List <WorkItem>();

            try
            {
                var settings = new JiraRestClientSettings()
                {
                    EnableRequestTrace = true
                };

                var jira   = Jira.CreateRestClient(JIRAUrl, JIRAUserName, JIRAPassword);
                var issues = await jira.Issues.GetIsssuesFromJqlAsync("cf[10003]=" + user.JIRAEpicId);

                foreach (var issue in issues)
                {
                    list.Add(new WorkItem()
                    {
                        Description   = issue.Summary,
                        Status        = issue.Status.Name,
                        CreatedOn     = issue.Created,
                        WorkDone      = 0,
                        WorkRemaining = 0
                    });
                }

                //Calculate the account balance for the user
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(list);
        }
Example #17
0
 public IssueService(Jira jira, JiraRestClientSettings restSettings)
 {
     _jira         = jira;
     _restSettings = restSettings;
 }
 /// <summary>
 /// Creates a new instance of the JiraRestClient class.
 /// </summary>
 /// <param name="url">Url to the JIRA server.</param>
 /// <param name="username">Username used to authenticate.</param>
 /// <param name="password">Password used to authenticate.</param>
 /// <param name="settings">Settings to configure the rest client.</param>
 public JiraRestClient(string url, string username = null, string password = null, JiraRestClientSettings settings = null)
     : this(url, new HttpBasicAuthenticator(username, password), settings)
 {
 }
Example #19
0
        private static List <Object> GetJiraTasks()
        {
            var settings = new JiraRestClientSettings()
            {
                EnableRequestTrace = true
            };
            var thingie =
                new IssueStatus(new RemoteStatus()
            {
                id          = "10510",
                description = "",
                iconUrl     = "https://epm.verisk.com/jira/images/icons/status_generic.gif",
                name        = "Acceptance Testing"
            });
            var jiraConn = Jira.CreateRestClient("https://epm.verisk.com/jira/", "I59098",
                                                 File.ReadAllText(@"C:\Users\i59098\Google Drive\pword.txt"), settings);

            var tasks = jiraConn.Issues.Queryable.Where(i => i.Project == "XWESVC").Take(1000000000).ToList();
            //var jiraenum = query.GetEnumerator();
            //Issue asdf = jiraenum.Current;
            //List<Issue> jiraIssues = new List<Issue>
            //{
            //    jiraenum.Current
            //};
            //while (jiraenum.MoveNext())
            //{
            //    jiraIssues.Add(jiraenum.Current);
            //}
            //foreach (var issue in jiraIssues)
            //{
            //    var s = issue.Project;
            //}
            var issueStatuses = new Dictionary <string, int>();

            foreach (var issue in tasks)
            {
                //if (issue.Assignee == "I59098" || issue.Assignee == "I55711")
                //{
                //    Console.WriteLine(issue.Key.Value + " " + issue.Summary + "\n" + issue.Description);
                //}
                //if (issue.Assignee != null && jiraConn.Users.GetUserAsync(issue.Assignee).Result.DisplayName == "McPherson, Bryan D")
                //    Console.WriteLine(issue.Assignee);
                //else
                //    Console.WriteLine(issue.Key.Value);
                if (issueStatuses.ContainsKey(issue.Status.Name))
                {
                    issueStatuses[issue.Status.Name]++;
                }
                else
                {
                    issueStatuses[issue.Status.Name] = 1;
                }
            }
            foreach (var issueStatus in issueStatuses)
            {
                Console.WriteLine($"Status: {issueStatus.Key} Count: {issueStatus.Value}");
            }

            //Issue thing = jiraConn.GetIssue("XWESVC-974");
            //var user = jiraConn.Users.GetUserAsync(thing.Assignee).Result;
            return(null);
        }