Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 57
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CodeReviewShowEmails
0.00% covered (danger)
0.00%
0 / 51
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 1
2
 printSubject
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 printRule
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3$IP = getenv( 'MW_INSTALL_PATH' );
4if ( $IP === false ) {
5    $IP = __DIR__ . '/../../..';
6}
7require_once "$IP/maintenance/Maintenance.php";
8
9class CodeReviewShowEmails extends Maintenance {
10    /**
11     * @var string[]
12     */
13    private $EmailData = [
14        'author'  => 'Author',
15        'repo'    => 'Repository',
16        'rev'     => 'r88888',
17        'URL'     => 'http://www.example.org/CR/repo/r88888',
18        'prevrev' => 'r52100',
19        'prevURL'     => 'http://www.example.org/CR/repo/r52100',
20        'summary' => 'This is a patch to fix a nasty bug
21This is not the best commit summary but should be enough to:
22* display something
23* get a rough idea of message formatting
24* some other thing
25Follow up r52100
26',
27        'follow-up-summary' => 'Fix up r52100',
28        'comment' => 'My comment is that this revision is obviously wrong.
29You missed a lot of points there and need to revert or fix your code
30',
31        'oldstatus' => 'new',
32        'newstatus' => 'fixme',
33    ];
34
35    public function __construct() {
36        parent::__construct();
37        $this->addDescription( 'Show example emails for CodeReview' );
38
39        $this->requireExtension( 'CodeReview' );
40    }
41
42    public function execute() {
43        $this->printSubject( '' );
44        print wfMessage( 'codereview-email-body',
45            $this->EmailData['author'],
46            $this->EmailData['URL'],
47            $this->EmailData['rev'],
48            $this->EmailData['comment'],
49            $this->EmailData['summary']
50        )->text() . "\n";
51        $this->printRule();
52
53        $this->printSubject( 2 );
54        print wfMessage( 'codereview-email-body2',
55            $this->EmailData['author'],
56            $this->EmailData['prevrev'],
57            $this->EmailData['URL'],
58            $this->EmailData['follow-up-summary'],
59            $this->EmailData['prevURL'],
60            $this->EmailData['summary']
61        )->text() . "\n";
62        $this->printRule();
63
64        $this->printSubject( 3 );
65        print wfMessage( 'codereview-email-body3',
66            $this->EmailData['author'],
67            $this->EmailData['rev'],
68            $this->EmailData['oldstatus'],
69            $this->EmailData['newstatus'],
70            $this->EmailData['URL'],
71            $this->EmailData['summary']
72        )->text() . "\n";
73        $this->printRule();
74
75        $this->printSubject( 4 );
76        print wfMessage( 'codereview-email-body4',
77            $this->EmailData['author'],
78            $this->EmailData['rev'],
79            $this->EmailData['oldstatus'],
80            $this->EmailData['newstatus'],
81            $this->EmailData['URL'],
82            $this->EmailData['summary'],
83            $this->EmailData['follow-up-summary']
84        )->text() . "\n";
85        $this->printRule();
86    }
87
88    /**
89     * Print the subject line.
90     * @param string|int $type Either '', 2, 3 or 4
91     */
92    private function printSubject( $type ) {
93        $repo = $this->EmailData['repo'];
94        if ( $type == 2 ) {
95            $rev = $this->EmailData['prevrev'];
96        } else {
97            $rev = $this->EmailData['rev'];
98        }
99        printf( "Subject: %s\n\n",
100            wfMessage( 'codereview-email-subj' . $type,
101                $repo,
102                $rev
103            )->text()
104        );
105    }
106
107    private function printRule() {
108        print "===============================================\n";
109    }
110}
111
112$maintClass = CodeReviewShowEmails::class;
113require_once RUN_MAINTENANCE_IF_MAIN;