コード例 #1
0
        protected override async Task ExecuteCoreAsync(ReportExecutionContext context)
        {
            foreach (RepositoryConfiguration repositoryConfiguration in context.RepositoryConfigurations)
            {
                HtmlPageCreator emailBody      = new HtmlPageCreator($"Customer reported issues with invalid state in {repositoryConfiguration.Name}");
                bool            hasFoundIssues = ValidateCustomerReportedIssues(context, repositoryConfiguration, emailBody);

                if (hasFoundIssues)
                {
                    // send the email
                    EmailSender.SendEmail(context.SendGridToken, context.FromAddress, emailBody.GetContent(), repositoryConfiguration.ToEmail, repositoryConfiguration.CcEmail,
                                          $"Customer reported issues in invalid state in repo {repositoryConfiguration.Name}", context.Log);
                }
            }
        }
コード例 #2
0
        protected override async Task ExecuteCoreAsync(ReportExecutionContext context)
        {
            foreach (RepositoryConfiguration repositoryConfiguration in context.RepositoryConfigurations)
            {
                HtmlPageCreator emailBody   = new HtmlPageCreator($"Pull Requests older than 3 months in {repositoryConfiguration.Name}");
                bool            hasFoundPRs = FindStalePRsInRepo(context, repositoryConfiguration, emailBody);

                if (hasFoundPRs)
                {
                    // send the email
                    EmailSender.SendEmail(context.SendGridToken, context.FromAddress, emailBody.GetContent(), repositoryConfiguration.ToEmail, repositoryConfiguration.CcEmail,
                                          $"Pull Requests older than 3 months in {repositoryConfiguration.Name}", context.Log);
                }
            }
        }
コード例 #3
0
        protected override async Task ExecuteCoreAsync(ReportExecutionContext context)
        {
            foreach (RepositoryConfiguration repositoryConfiguration in context.RepositoryConfigurations)
            {
                HtmlPageCreator emailBody      = new HtmlPageCreator($"Issues in expired milestones for {repositoryConfiguration.Name}");
                bool            hasFoundIssues = GetIssuesInBacklogMilestones(context, repositoryConfiguration, emailBody);

                if (hasFoundIssues)
                {
                    // send the email
                    EmailSender.SendEmail(context.SendGridToken, context.FromAddress, emailBody.GetContent(), repositoryConfiguration.ToEmail, repositoryConfiguration.CcEmail,
                                          $"Issues in old milestone for {repositoryConfiguration.Name}", context.Log);
                }
            }
        }
コード例 #4
0
        public async Task ExecuteAsync(ILogger log)
        {
            try
            {
                Task <string> pendingGitHubPersonalAccessToken = ConfigurationService.GetGitHubPersonalAccessTokenAsync();

                var gitHubClient = new GitHubClient(new ProductHeaderValue("github-issues"))
                {
                    Credentials = new Credentials(await pendingGitHubPersonalAccessToken)
                };

                log.LogInformation("Preparing report execution context for: {reportType}", this.GetType());

                var context = new ReportExecutionContext(
                    log,
                    await ConfigurationService.GetFromAddressAsync(),
                    await ConfigurationService.GetSendGridTokenAsync(),
                    await pendingGitHubPersonalAccessToken,
                    await ConfigurationService.GetRepositoryConfigurationsAsync(),
                    gitHubClient
                    );

                log.LogInformation("Executing report: {reportType}", this.GetType());
                await ExecuteCoreAsync(context);

                log.LogInformation("Executed report: {reportType}", this.GetType());
            }
            catch (RateLimitExceededException ex)
            {
                log.LogError("GitHub rate limit exceeded for report {reportType}. Rate limit is {callsPerHour} calls per Hour. Limit resets at {limitResets}.",
                             this.GetType(),
                             ex.Limit,
                             ex.Reset
                             );

                throw ex;
            }
        }
コード例 #5
0
        public async Task ExecuteAsync()
        {
            Task <string> pendingGitHubPersonalAccessToken = ConfigurationService.GetGitHubPersonalAccessTokenAsync();

            var gitHubClient = new GitHubClient(new ProductHeaderValue("github-issues"))
            {
                Credentials = new Credentials(await pendingGitHubPersonalAccessToken)
            };

            Logger.LogInformation("Preparing report execution context for: {reportType}", this.GetType());

            var context = new ReportExecutionContext(
                await ConfigurationService.GetFromAddressAsync(),
                await ConfigurationService.GetSendGridTokenAsync(),
                await pendingGitHubPersonalAccessToken,
                await ConfigurationService.GetRepositoryConfigurationsAsync(),
                gitHubClient
                );

            Logger.LogInformation("Executing report: {reportType}", this.GetType());
            await ExecuteCoreAsync(context);

            Logger.LogInformation("Executed report: {reportType}", this.GetType());
        }
コード例 #6
0
 protected abstract Task ExecuteCoreAsync(ReportExecutionContext context);
コード例 #7
0
        private bool GetIssuesInBacklogMilestones(ReportExecutionContext context, RepositoryConfiguration repositoryConfig, HtmlPageCreator emailBody)
        {
            Logger.LogInformation($"Retrieving milestone information for repo {repositoryConfig.Name}");
            IEnumerable <Milestone> milestones = context.GitHubClient.ListMilestones(repositoryConfig).GetAwaiter().GetResult();

            List <Milestone> backlogMilestones = new List <Milestone>();

            foreach (Milestone item in milestones)
            {
                if (item.DueOn == null)
                {
                    Logger.LogWarning($"Milestone {item.Title} has {item.OpenIssues} open issue(s).");
                    if (item.OpenIssues > 0)
                    {
                        backlogMilestones.Add(item);
                    }
                }
            }

            Logger.LogInformation($"Found {backlogMilestones.Count} past due milestones with active issues");
            List <ReportIssue> issuesInBacklogMilestones = new List <ReportIssue>();

            foreach (Milestone item in backlogMilestones)
            {
                Logger.LogInformation($"Retrieve issues for milestone {item.Title}");

                foreach (Issue issue in context.GitHubClient.SearchForGitHubIssues(CreateQuery(repositoryConfig, item)))
                {
                    issuesInBacklogMilestones.Add(new ReportIssue()
                    {
                        Issue     = issue,
                        Milestone = item,
                        Note      = string.Empty
                    });
                }
            }

            // Split the list into 3:
            // > 12months
            // > 6months
            // 0-6months

            IEnumerable <IGrouping <string, ReportIssue> > groups = issuesInBacklogMilestones.GroupBy(i =>
                                                                                                      i.Issue.CreatedAt > DateTime.Now.AddMonths(-6) ?
                                                                                                      "C. Issues created in the last 6 months" :
                                                                                                      i.Issue.CreatedAt <= DateTime.Now.AddMonths(-6) && i.Issue.CreatedAt > DateTime.Now.AddMonths(-12) ?
                                                                                                      "B. Issues created between 6 and 12 months ago" :
                                                                                                      "A. Issues created more than 12 months ago");

            foreach (IGrouping <string, ReportIssue> group in groups.OrderBy(g => g.Key))
            {
                TableCreator tc = new TableCreator(group.Key);
                tc.DefineTableColumn("Milestone", TableCreator.Templates.Milestone);
                tc.DefineTableColumn("Created", i => i.Issue.CreatedAt.UtcDateTime.ToShortDateString());
                tc.DefineTableColumn("Title", TableCreator.Templates.Title);
                tc.DefineTableColumn("Labels", TableCreator.Templates.Labels);
                tc.DefineTableColumn("Author", TableCreator.Templates.Author);
                tc.DefineTableColumn("Assigned", TableCreator.Templates.Assigned);

                emailBody.AddContent(tc.GetContent(group));
            }

            return(issuesInBacklogMilestones.Any());
        }