Skip to:
Content

Ticket #6642: 6642.gruntlog.2.patch

File 6642.gruntlog.2.patch, 4.2 KB (added by imath, 3 years ago)
  • .changelog.php

    diff --git .changelog.php .changelog.php
    index e69de29..4e7bac2 100644
     
     1<?php
     2/**
     3 * Tool to generate the BP Legacy's changelog
     4 *
     5 * Requires:
     6 * - PHP 5.4
     7 * - BuddyPress Git repo:
     8 *  - git://buddypress.git.wordpress.org/
     9 *  - or https://github.com/buddypress/BuddyPress.git
     10 */
     11
     12/**
     13 * Major releases
     14 *
     15 * Each time a new major release tag is created on trac
     16 * Insert a new entry to this array containing the name
     17 * of the tag and the corresponding changeset reference.
     18 *
     19 * NB: this may be inexact sometimes as revisions are also
     20 * incremented while working on a previous release's branch
     21 */
     22$releases = array(
     23        "1.7.0" => 6899,
     24        "1.8.0" => 7280,
     25        "1.9.0" => 7683,
     26        "2.0.0" => 8278,
     27        "2.1.0" => 9031,
     28        "2.2.0" => 9440,
     29        "2.3.0" => 9911,
     30);
     31
     32/**
     33 * Important changesets
     34 *
     35 * After any significative commit involving templates
     36 * insert a new entry to this array containing the
     37 * changeset reference of the commit.
     38 *
     39 * eg: The introduction of bp_activity_show_filters()
     40 */
     41$important_changesets = array(
     42        8428,
     43);
     44
     45// Building the changelog
     46$changelog = new stdClass;
     47$changelog->author = 'The BuddyPress Contributors';
     48
     49// Update this after each release
     50$changelog->vesion = '2.4.0';
     51
     52// Init the templates listing
     53$changelog->templates = array();
     54
     55// Init the template's changes
     56$changes              = array();
     57
     58// To strip legacy path from templates
     59$bp_legacy_path = 'src/bp-templates/bp-legacy/buddypress/';
     60
     61// Path to the generated changelog
     62$output = 'src/bp-templates/bp-legacy/changelog.json';
     63
     64
     65$git_commits = shell_exec( 'git log --name-only --pretty=format:"||%s|%b|" src/bp-templates/bp-legacy/buddypress' );
     66
     67$commits = explode( '||', $git_commits );
     68
     69if ( ! is_array( $commits ) ) {
     70        fwrite( STDOUT, "Error: could not generate the changelog, are you using git?\n" );
     71        exit( 2 );
     72}
     73
     74// Remove the old file
     75if ( file_exists( $output ) ) {
     76        @unlink( $output );
     77}
     78
     79foreach( $commits as $commit ) {
     80        $parts = explode( '|', $commit );
     81        $log = $parts[0];
     82
     83        preg_match( '/trunk@(\d*)/', $parts[1], $match );
     84
     85        if ( ! $match[1] ) {
     86                continue;
     87        }
     88
     89        $revision = $match[1];
     90
     91        // Defaults to release if nothing found in releases
     92        // It has been introduced in current release
     93        $version  = $changelog->vesion;
     94
     95        foreach ( $releases as $key => $changeset ) {
     96                if ( $changeset > $revision ) {
     97                        $version = $key;
     98                        break;
     99                }
     100        }
     101
     102        // Reset changeset's importance
     103        $importance = 'low';
     104
     105        // How important is this change?
     106        if ( in_array( $revision, $important_changesets ) ) {
     107                $importance = 'high';
     108        }
     109
     110        $files = explode( "\n", trim( $parts[2], "\n" ) );
     111
     112        foreach ( $files as $file ) {
     113                $changes[ str_replace( $bp_legacy_path, '', $file ) ][] = (object) array(
     114                        'version'    => $version,
     115                        'revision'   => $revision,
     116                        'importance' => $importance,
     117                        'log'        => $log,
     118                );
     119        }
     120}
     121
     122if ( empty( $changes ) ) {
     123        fwrite( STDOUT, "Error: could not generate the changelog.\n" );
     124        exit( 2 );
     125}
     126
     127ksort( $changes );
     128
     129foreach ( $changes as $template => $logs )  {
     130        $entry = new stdClass;
     131
     132        $entry->template = $template;
     133
     134        // Get version when the template was last edited
     135        $edited = reset( $logs );
     136        $entry->edited = $edited->version;
     137
     138        // Attach logs
     139        $entry->changes = $logs;
     140
     141        $changelog->templates[] = $entry;
     142}
     143
     144$created = file_put_contents( $output, json_encode( $changelog, JSON_PRETTY_PRINT ) );
     145
     146if ( ! $created ) {
     147        fwrite( STDOUT, "Error: could not generate the changelog.\n" );
     148        exit( 2 );
     149} else {
     150        fwrite( STDOUT, "Success: Changelog generated.\n" );
     151        exit( 0 );
     152}
  • Gruntfile.js

    diff --git Gruntfile.js Gruntfile.js
    index 0445052..4389d52 100644
    module.exports = function( grunt ) { 
    222222                                command: 'svn export --force https://github.com/buddypress/BP-Default.git/trunk bp-themes/bp-default',
    223223                                cwd: BUILD_DIR,
    224224                                stdout: false
     225                        },
     226                        templates_changelog: {
     227                                command: 'php .changelog.php'
    225228                        }
    226229                },
    227230                jsvalidate:{
    module.exports = function( grunt ) { 
    278281
    279282        // Default task.
    280283        grunt.registerTask( 'default', ['src'] );
     284
     285        // BP Legacy templates changelog task.
     286        grunt.registerTask( 'templates_changelog', 'exec:templates_changelog' );
    281287};