示例#1
0
        /// <summary>
        /// Creates a new metrics extractor for the given Kanban configuration
        /// </summary>
        /// <param name="config">configuration to use</param>
        /// <param name="logCallback">optional callback delegate to receive log messages</param>
        public MetricsExtractor(JiraKanbanConfig config, Action <string> logCallback = null)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (string.IsNullOrWhiteSpace(config.JiraInstanceBaseAddress))
            {
                throw new ArgumentNullException(nameof(config.JiraInstanceBaseAddress));
            }
            if (string.IsNullOrWhiteSpace(config.JiraUsername))
            {
                throw new ArgumentNullException(nameof(config.JiraUsername));
            }
            if (config.JiraPassword == null || config.JiraPassword.Length == 0)
            {
                throw new ArgumentNullException(nameof(config.JiraPassword));
            }
            _config      = config;
            _logCallback = logCallback;

            _client = new HttpClient
            {
                BaseAddress = new Uri(config.JiraInstanceBaseAddress)
            };

            var auth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{config.JiraUsername}:{Crypto.GetStr(config.JiraPassword)}"));

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", auth);
        }
        /// <summary>
        /// Create charts for the given configuration and list of issues
        /// </summary>
        /// <param name="config">Jira Kanban configuration</param>
        /// <param name="issues">list of issues</param>
        /// <returns>Kanban charts</returns>
        public static KanbanCharts Create(JiraKanbanConfig config, Issue[] issues)
        {
            var c = new KanbanCharts
            {
                Config    = config,
                Issues    = issues,
                StartDate = DateTime.Today.AddMonths(config.MonthsToAnalyse * -1),
                EndDate   = DateTime.Today.AddDays((int)DateTime.Today.DayOfWeek * -1),
            };

            // Consolidate information about tickets that are done
            c.DoneIssues = issues
                           .Where(ticket => ticket.Entered(config.CommitmentStartColumns).HasValue)
                           .Where(ticket => ticket.Entered(config.InProgressStartColumns).HasValue)
                           .Where(ticket => ticket.Entered(config.DoneColumns).HasValue)
                           .Select(ticket => new DoneIssue
            {
                IssueKey  = ticket.IssueKey,
                IssueType = ticket.IssueType,
                LeadTime  = ticket.LeadTime(config),
                TouchTime = ticket.TouchTime(config),
                QueueTime = ticket.QueueTime(config),
                Columns   = ticket.Columns,
                // ReSharper disable PossibleInvalidOperationException
                ToDo       = ticket.Entered(config.CommitmentStartColumns).Value,
                InProgress = ticket.Entered(config.InProgressStartColumns).Value,
                Done       = ticket.FirstEntered(config.DoneColumns).Value,
                // ReSharper restore PossibleInvalidOperationException
            })
                           .Where(ticket => ticket.Done >= c.StartDate)
                           .Where(ticket => ticket.Done <= c.EndDate)
                           .ToArray();

            c.ComputeAllCharts();
            return(c);
        }
        /// <summary>
        /// Determines if a given issue type is a defect, given a configuration
        /// </summary>
        /// <param name="issueType">issue type</param>
        /// <param name="config">kanban configuration</param>
        /// <returns>true if the issue type is a defect</returns>
        public static bool IsDefect(this string issueType, JiraKanbanConfig config)
        {
            var defects = config.DefectIssueTypes;

            return(defects.Any(s => s.Equals(issueType, StringComparison.InvariantCultureIgnoreCase)));
        }