-
Notifications
You must be signed in to change notification settings - Fork 5
Make an initial post comment with file command #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dawehner
wants to merge
9
commits into
alexpott:master
Choose a base branch
from
dawehner:post-issue-comment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
506d672
extract logic to ensure logged in user
dawehner cfcc50b
move generic issue-metadata into DoFormBase
dawehner 863fb6a
make it possible to set the tags
dawehner 2b25b55
initial version
dawehner 786c0c4
add editor helper
dawehner c989ea6
Replace drupal.org with www.drupal.org
webflo f6e9eba
Make PostIssueComment work.
webflo d811ecb
Remove unused methods
webflo 62c52c7
File upload works now
dawehner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @file | ||
| * Contains DrupalPatchUtils\Command${NAME}. | ||
| */ | ||
|
|
||
|
|
||
| namespace DrupalPatchUtils\Command; | ||
|
|
||
|
|
||
| use DrupalPatchUtils\CommentEditor; | ||
| use DrupalPatchUtils\DoBrowser; | ||
| use DrupalPatchUtils\IssuePriority; | ||
| use DrupalPatchUtils\IssueStatus; | ||
| use DrupalPatchUtils\TextEditor; | ||
| use Symfony\Component\Console\Input\InputArgument; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class PostIssueComment extends CommandBase { | ||
|
|
||
| protected function configure() | ||
| { | ||
| $this | ||
| ->setName('postIssueComment') | ||
| ->setAliases(array('pic')) | ||
| ->setDescription('Posts comment on an issue to d.o.') | ||
| ->addArgument( | ||
| 'url', | ||
| InputArgument::REQUIRED, | ||
| 'What is the url/nid of the issue to retrieve?' | ||
| ) | ||
| ->addArgument( | ||
| 'files', | ||
| InputArgument::IS_ARRAY, | ||
| 'Files' | ||
| ); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
| if (!$output instanceof ConsoleOutputInterface) { | ||
| throw new \Exception('Console output needed.'); | ||
| } | ||
|
|
||
| $url = $input->getArgument('url'); | ||
| $issue = $this->getIssue($url); | ||
|
|
||
| $browser = new DoBrowser(); | ||
| $this->ensureUserIsLoggedIn($browser, $output); | ||
|
|
||
| $comment_form = $browser->getCommentForm($issue->getUri()); | ||
|
|
||
|
|
||
| $files = $input->getArgument('files'); | ||
|
|
||
| $comment_editor = new CommentEditor($comment_form); | ||
| $template = $comment_editor->generateContent($issue, $files); | ||
|
|
||
| $editor = new TextEditor(); | ||
| $result = $editor->editor($output, $template); | ||
|
|
||
| $body = $comment_editor->getCommentText($result); | ||
| $metadata = $comment_editor->getMetadata($result); | ||
|
|
||
| $comment_form->uploadFiles($files); | ||
|
|
||
| $comment_form->setCommentText($body); | ||
|
|
||
| if (isset($metadata['status'])) { | ||
| $comment_form->setStatus(IssueStatus::toInteger($metadata['status'])); | ||
| } | ||
|
|
||
| if (isset($metadata['priority'])) { | ||
| $comment_form->setPriority(IssuePriority::toInteger($metadata['priority'])); | ||
| } | ||
|
|
||
| $crawler = $browser->submitForm($comment_form->getForm()); | ||
|
|
||
| if ($errors = $browser->getErrors($crawler)) { | ||
| $output->getErrorOutput()->writeln($errors); | ||
| } | ||
| else { | ||
| $uri = $browser->getClient()->getHistory()->current()->getUri(); | ||
| $output->writeln(sprintf('Posting the issue was successful: %s', $uri)); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @file | ||
| * Contains DrupalPatchUtils\CommentEditor. | ||
| */ | ||
|
|
||
| namespace DrupalPatchUtils; | ||
|
|
||
|
|
||
| class CommentEditor | ||
| { | ||
|
|
||
| /** | ||
| * @var \DrupalPatchUtils\CommentForm | ||
| */ | ||
| protected $commentForm; | ||
|
|
||
| public function __construct(CommentForm $comment_form) | ||
| { | ||
| $this->commentForm = $comment_form; | ||
| } | ||
|
|
||
| public function generateContent(Issue $issue, $new_files = []) | ||
| { | ||
| $output = []; | ||
|
|
||
| $output[] = "# Please enter the comment message for your changes. Lines starting"; | ||
| $output[] = "# with '#' will be ignored, and an empty message aborts the comment."; | ||
| $output[] = '#'; | ||
| $output[] = '# Comment on issue #' . $issue->getNid() . ': ' . $issue->getTitle(); | ||
|
|
||
| if (!empty($new_files)) { | ||
| $output[] = '#'; | ||
| $output[] = '# Attached files'; | ||
| foreach ($new_files as $filename) { | ||
| $output[] = '# - ' . $filename; | ||
| } | ||
| } | ||
|
|
||
| $output[] = '#'; | ||
| $output[] = '# Status: ' . IssueStatus::toString($this->commentForm->getStatus()); | ||
| foreach (IssueStatus::getDefinition() as $definition) { | ||
| $output[] = '# - ' . $definition['label'] . ' - ' . implode(', ', $definition['aliases']); | ||
| } | ||
|
|
||
| $output[] = '#'; | ||
| $output[] = '# Priority: ' . IssuePriority::toString($this->commentForm->getPriority()); | ||
| foreach (IssuePriority::getDefinition() as $definition) { | ||
| $output[] = '# - ' . $definition['label'] . ' - ' . implode(', ', $definition['aliases']); | ||
| } | ||
|
|
||
| $output[] = '#'; | ||
| $output[] = '# Tags: ' . implode(', ', $this->commentForm->getTags()); | ||
|
|
||
| return implode("\n", $output); | ||
| } | ||
|
|
||
| public function getCommentText($lines) | ||
| { | ||
| $array = explode("\n", $lines); | ||
| $lines = array_filter($array, function ($value) { | ||
| return !(isset($value[0]) && $value[0] == '#'); | ||
| }); | ||
|
|
||
| return implode("\n", $lines); | ||
| } | ||
|
|
||
| public function getMetadata($lines) | ||
| { | ||
| $metadata = array(); | ||
| foreach (explode(PHP_EOL, $lines) as $line) { | ||
| if (strpos($line, '# Tags:') === 0) { | ||
| $metadata['tags'] = trim(str_replace('# Tags: ', '', $line)); | ||
| } | ||
| if (strpos($line, '# Status:') === 0) { | ||
| $status = trim(str_replace('# Status: ', '', $line)); | ||
|
|
||
| $metadata['status'] = $status; | ||
| } | ||
| if (strpos($line, '# Priority:') === 0) { | ||
| $priority = trim(str_replace('# Priority: ', '', $line)); | ||
|
|
||
| $metadata['priority'] = $priority; | ||
| } | ||
| } | ||
|
|
||
| return $metadata; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already something there for this $this->login()