-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPostIssueComment.php
More file actions
93 lines (69 loc) · 2.62 KB
/
PostIssueComment.php
File metadata and controls
93 lines (69 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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;
}
}