| 1 | <?php |
| 2 | /** |
| 3 | * Tool to generate the BP Legacy's changelog |
| 4 | */ |
| 5 | |
| 6 | // Major releases |
| 7 | $releases = array( |
| 8 | "1.7.0" => 6899, |
| 9 | "1.8.0" => 7280, |
| 10 | "1.9.0" => 7683, |
| 11 | "2.0.0" => 8278, |
| 12 | "2.1.0" => 9031, |
| 13 | "2.2.0" => 9440, |
| 14 | "2.3.0" => 9911, |
| 15 | ); |
| 16 | |
| 17 | // Building the changelog |
| 18 | $changelog = new stdClass; |
| 19 | $changelog->author = 'The BuddyPress Contributors'; |
| 20 | $changelog->vesion = '2.4.0'; |
| 21 | $changelog->templates = array(); |
| 22 | |
| 23 | // To strip legacy path from templates |
| 24 | $bp_legacy_path = 'src/bp-templates/bp-legacy/buddypress/'; |
| 25 | $output = 'src/bp-templates/bp-legacy/changelog.json'; |
| 26 | $changes = array(); |
| 27 | |
| 28 | $git_commits = shell_exec( 'git log --name-only --pretty=format:"||%s|%b|" src/bp-templates/bp-legacy/buddypress' ); |
| 29 | |
| 30 | $commits = explode( '||', $git_commits ); |
| 31 | |
| 32 | if ( ! is_array( $commits ) ) { |
| 33 | fwrite( STDOUT, "Error: could not generate the changelog, are you using git?\n" ); |
| 34 | exit( 2 ); |
| 35 | } |
| 36 | |
| 37 | // Remove the old file |
| 38 | if ( file_exists( $output ) ) { |
| 39 | @unlink( $output ); |
| 40 | } |
| 41 | |
| 42 | foreach( $commits as $commit ) { |
| 43 | $parts = explode( '|', $commit ); |
| 44 | $log = $parts[0]; |
| 45 | |
| 46 | preg_match( '/trunk@(\d*)/', $parts[1], $match ); |
| 47 | |
| 48 | if ( ! $match[1] ) { |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | $revision = $match[1]; |
| 53 | |
| 54 | // Defaults to release if nothing found in releases |
| 55 | // It has been introduced in current release |
| 56 | $version = $changelog->vesion; |
| 57 | |
| 58 | foreach ( $releases as $key => $changeset ) { |
| 59 | if ( $changeset > $revision ) { |
| 60 | $version = $key; |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | $files = explode( "\n", trim( $parts[2], "\n" ) ); |
| 66 | |
| 67 | foreach ( $files as $file ) { |
| 68 | $changes[ str_replace( $bp_legacy_path, '', $file ) ][] = (object) array( |
| 69 | 'version' => $version, |
| 70 | 'revision' => $revision, |
| 71 | 'log' => $log, |
| 72 | ); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if ( empty( $changes ) ) { |
| 77 | fwrite( STDOUT, "Error: could not generate the changelog.\n" ); |
| 78 | exit( 2 ); |
| 79 | } |
| 80 | |
| 81 | ksort( $changes ); |
| 82 | |
| 83 | foreach ( $changes as $template => $logs ) { |
| 84 | $entry = new stdClass; |
| 85 | |
| 86 | $entry->template = $template; |
| 87 | |
| 88 | // Get version when the template was last edited |
| 89 | $edited = reset( $logs ); |
| 90 | $entry->edited = $edited->version; |
| 91 | |
| 92 | // Attach logs |
| 93 | $entry->changes = $logs; |
| 94 | |
| 95 | $changelog->templates[] = $entry; |
| 96 | } |
| 97 | |
| 98 | $created = file_put_contents( $output, json_encode( $changelog, JSON_PRETTY_PRINT ) ); |
| 99 | |
| 100 | if ( ! $created ) { |
| 101 | fwrite( STDOUT, "Error: could not generate the changelog.\n" ); |
| 102 | exit( 2 ); |
| 103 | } else { |
| 104 | fwrite( STDOUT, "Success: Changelog generated.\n" ); |
| 105 | exit( 0 ); |
| 106 | } |