-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCommentEditor.php
More file actions
91 lines (71 loc) · 2.6 KB
/
CommentEditor.php
File metadata and controls
91 lines (71 loc) · 2.6 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
<?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;
}
}