Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
1 | <?php |
2 | /** |
3 | * Update the CREDITS list by merging in the list of git commit authors. |
4 | * |
5 | * The contents of the existing contributors list will be preserved. If a name |
6 | * needs to be removed for some reason that must be done manually before or |
7 | * after running this script. |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
22 | * http://www.gnu.org/copyleft/gpl.html |
23 | */ |
24 | |
25 | // NO_AUTOLOAD -- file-scope code |
26 | |
27 | if ( PHP_SAPI != 'cli' ) { |
28 | die( "This script can only be run from the command line.\n" ); |
29 | } |
30 | |
31 | $CREDITS = 'CREDITS'; |
32 | $START_CONTRIBUTORS = '<!-- BEGIN CONTRIBUTOR LIST -->'; |
33 | $END_CONTRIBUTORS = '<!-- END CONTRIBUTOR LIST -->'; |
34 | |
35 | $inHeader = true; |
36 | $inFooter = false; |
37 | $header = []; |
38 | $contributors = []; |
39 | $footer = []; |
40 | |
41 | if ( !file_exists( $CREDITS ) ) { |
42 | exit( 'No CREDITS file found. Are you running this script in the right directory?' ); |
43 | } |
44 | |
45 | $lines = explode( "\n", file_get_contents( $CREDITS ) ); |
46 | foreach ( $lines as $line ) { |
47 | if ( $inHeader ) { |
48 | $header[] = $line; |
49 | $inHeader = $line !== $START_CONTRIBUTORS; |
50 | } elseif ( $inFooter ) { |
51 | $footer[] = $line; |
52 | } elseif ( $line == $END_CONTRIBUTORS ) { |
53 | $inFooter = true; |
54 | $footer[] = $line; |
55 | } else { |
56 | $name = substr( $line, 2 ); |
57 | $contributors[$name] = true; |
58 | } |
59 | } |
60 | unset( $lines ); |
61 | |
62 | $lines = explode( "\n", (string)shell_exec( 'git log --format="%aN"' ) ); |
63 | foreach ( $lines as $line ) { |
64 | if ( empty( $line ) ) { |
65 | continue; |
66 | } |
67 | if ( str_starts_with( $line, '[BOT]' ) ) { |
68 | continue; |
69 | } |
70 | $contributors[$line] = true; |
71 | } |
72 | |
73 | $contributors = array_keys( $contributors ); |
74 | $collator = Collator::create( 'root' ); |
75 | $collator->setAttribute( Collator::NUMERIC_COLLATION, Collator::ON ); |
76 | $collator->sort( $contributors ); |
77 | array_walk( $contributors, static function ( &$v, $k ) { |
78 | $v = "* {$v}"; |
79 | } ); |
80 | |
81 | file_put_contents( |
82 | $CREDITS, |
83 | implode( "\n", array_merge( $header, $contributors, $footer ) ) |
84 | ); |