Exemplo n.º 1
0
        public async Task CreateReportAsync()
        {
            _log.Enter(this);

            // If a Query does not exist, generate it
            var adoQueries = await _queryManager.LoadAllAsync();

            var reportQuery = adoQueries.FirstOrDefault(q => q.Name == EXPECTED_QUERY_NAME);

            if (reportQuery == null)
            {
                reportQuery = await _queryManager.GenerateKanbanReportQueryAsync(EXPECTED_QUERY_NAME);
            }

            // Get AzDO WorkItems from Query
            var workItems = await _exceptionHandler.GetAsync(() => _queryManager.GetWorkItemsFromQueryAsync(reportQuery));

            if (workItems == null || !workItems.Any())
            {
                _log.LogWarning("CreateReportAsync() did not find any workItems to process");
                return;
            }

            // Generate Markdown Report
            var finalReport = _markdownReportCreator.CreateFromWorkItems(workItems);

            if (string.IsNullOrEmpty(finalReport))
            {
                _log.LogWarning("MarkdownReportCreator failed to create a valid markdown report");
                return;
            }

            // Retrieve version details for our target README.md file
            var readmefileDetails = await _sourceControlManager.GetVersionDetailsForReadmeFileAsync();

            if (readmefileDetails == null)
            {
                _log.LogWarning($"Unable to find target file: {_settings["MarkdownFilePath"]}");
                return;
            }

            // Commit and create pull request
            if (!await _sourceControlManager.CommitReportAndCreatePullRequestAsync(finalReport, readmefileDetails))
            {
                _log.LogWarning("Unable to push the latest report to source control");
                return;
            }
            _log.LogInfo("Report created and pushed to source control.");
        }