diff --git a/issues_bot/bot_templates/comment.html.twig b/issues_bot/bot_templates/comment.html.twig index 14ced8461cc7e74f83d0545d2960042bdaf20217..8d74c21bb9ed460ca7566f5fecff4a1b8f0e0ad6 100644 --- a/issues_bot/bot_templates/comment.html.twig +++ b/issues_bot/bot_templates/comment.html.twig @@ -28,6 +28,10 @@ It is important that any automated tests available are run and that you manually Therefore these changes <strong>did not update</strong> the <code>info.yml</code> file for Drupal 11 compatibility. {% endif %} +{% if post_rector_results_posted %} + After the Drupal Rector fixes were applied, Upgrade Status still reported outstanding compatibility issues, those are also attached to help you resolve them manually. +{% endif %} + Leaving this issue open, <strong>even after committing the current patch</strong>, will allow the <a href="/u/project-update-bot">Project Update Bot</a> to post additional Drupal 11 compatibility fixes as they become available in <a href="https://github.com/palantirnet/drupal-rector">Drupal Rector</a>. <h3>Debug info</h3> diff --git a/issues_bot/composer.json b/issues_bot/composer.json index b349e615db5b2a41a4b6eec43f4b1d8298bf89e6..729f8e8dd2bbbbc31e6c70c2e29116d8824f43e8 100644 --- a/issues_bot/composer.json +++ b/issues_bot/composer.json @@ -8,6 +8,7 @@ "nategood/httpful": "dev-PHP7.2_to_8.2", "symfony/cache": "^5.0", "composer/semver": "^1.5", + "dekor/php-array-table": "^2.0", "ext-zip": "*", "symfony/yaml": "^5.0", "seld/cli-prompt": "^1.0", diff --git a/issues_bot/src/DrupalOrg/IssueCreator.php b/issues_bot/src/DrupalOrg/IssueCreator.php index c2f0f6d0e7fbb10670e2f382bce01c75bdcd6ab5..7f7f4719ce6e90eec6ad07b884d8d14d7cefab2e 100644 --- a/issues_bot/src/DrupalOrg/IssueCreator.php +++ b/issues_bot/src/DrupalOrg/IssueCreator.php @@ -2,6 +2,7 @@ namespace RectorIssues\DrupalOrg; +use dekor\ArrayToTextTable; use RectorIssues\Cache; use RectorIssues\Config; use RectorIssues\Settings; @@ -512,7 +513,46 @@ class IssueCreator extends IssueBase { // Set to needs review. $page->fillField('edit-field-issue-status-und', self::ISSUE_STATUS_NEEDS_REVIEW); - $comment_tokens['info_yml_updated'] = $this->updatedInfoYml($file_path); + $info_is_updated = $this->updatedInfoYml($file_path); + + // If the info file was not updated, there are error left that we know. + $post_rector_txt_path = FALSE; + if (!$info_is_updated) { + // Upload the previous file first (done here, as Save would also + // upload it and avoid one extra HTTP request this way). + $page->pressButton('Upload'); + + // Look for the post_rector report results. + $files = glob(static::RESULTS_DIR . '/*/*.post_rector.xml'); + if (!empty($files)) { + $txt_contents = ''; + $post_rector_xml = simplexml_load_file($files[0]); + foreach($xml->checkstyle->file as $file_result) { + // Start a new section in the text for each file. + $file_path = wordwrap($file_result['name'], 80, "\n", TRUE); + $txt_contents .= $short_path . ":\n"; + $table = []; + foreach ($rector_result->error as $error_result) { + $error_message = str_replace("\n", ' ', $error_result['message']); + $table[] = [ + 'severity' => wordwrap($error_result['severity'], 8, "\n", true), + 'line' => wordwrap($error_result['line'], 7, "\n", true), + 'message' => wordwrap($error_message . "\n", 60, "\n", true) + ]; + } + // Format found errors in an ASCII table. + $asciiRenderer = new ArrayToTextTable($table); + $txt_contents .= $asciiRenderer->render() . "\n"; + } + // Save the resulting content in a temporary text file for upload. + $post_rector_txt_name = basename($files[0], '.xml') . '.txt'; + $post_rector_txt_path = sys_get_temp_dir() . "/" . $post_rector_txt_name; + file_put_contents($post_rector_txt_path, $txt_contents); + } + } + + $comment_tokens['info_yml_updated'] = $info_is_updated; + $comment_tokens['post_rector_results_posted'] = !empty($post_rector_txt_path); $body = $this->getTemplateText('comment', $comment_tokens); $page->fillField('edit-nodechanges-comment-comment-body-und-0-value', $body); @@ -521,9 +561,19 @@ class IssueCreator extends IssueBase { $page->find('css', 'input.form-file')->setValue($diff_file); $page->pressButton('Upload'); } - // Add the actual diff file as well. $page->find('css', 'input.form-file')->setValue($file_path); + + if (!empty($post_rector_txt_path)) { + // Upload the previous file first (done here, as Save would also + // upload it and avoid one extra HTTP request this way). + $page->pressButton('Upload'); + + // Upload the post-rector report file. + $page->find('css', 'input.form-file')->setValue($post_rector_txt_path); + } + + // Save the comment (and upload the last file as well). $page->pressButton('Save'); $this->debugOutput();