Skip to:
Content

BuddyPress.org

Ticket #6642: 6642.gruntlog.3.patch

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

    diff --git .changelog.php .changelog.php
    index e69de29..4964d1a 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/**
     46 * Codex entries
     47 *
     48 * When a new codex page is detailing some explanation about
     49 * the introduced changes, add new entries to this array
     50 */
     51$codex_pages = array(
     52        'https://codex.buddypress.org/themes/activity-dropdown-filters-in-templates/' => array( 8428 ),
     53);
     54
     55// Building the changelog
     56$changelog = new stdClass;
     57$changelog->author = 'The BuddyPress Contributors';
     58
     59// Update this after each release
     60$changelog->vesion = '2.4.0';
     61
     62// Init the templates listing
     63$changelog->templates = array();
     64
     65// Init the template's changes
     66$changes              = array();
     67
     68// To strip legacy path from templates
     69$bp_legacy_path = 'src/bp-templates/bp-legacy/buddypress/';
     70
     71// Path to the generated changelog
     72$output = 'src/bp-templates/bp-legacy/changelog.json';
     73
     74
     75$git_commits = shell_exec( 'git log --name-only --pretty=format:"||%s|%b|" src/bp-templates/bp-legacy/buddypress' );
     76
     77$commits = explode( '||', $git_commits );
     78
     79if ( ! is_array( $commits ) ) {
     80        fwrite( STDOUT, "Error: could not generate the changelog, are you using git?\n" );
     81        exit( 2 );
     82}
     83
     84// Remove the old file
     85if ( file_exists( $output ) ) {
     86        @unlink( $output );
     87}
     88
     89foreach( $commits as $commit ) {
     90        $parts = explode( '|', $commit );
     91        $log = $parts[0];
     92
     93        preg_match( '/trunk@(\d*)/', $parts[1], $match );
     94
     95        if ( ! $match[1] ) {
     96                continue;
     97        }
     98
     99        $revision = $match[1];
     100
     101        // Defaults to release if nothing found in releases
     102        // It has been introduced in current release
     103        $version  = $changelog->vesion;
     104
     105        foreach ( $releases as $key => $changeset ) {
     106                if ( $changeset > $revision ) {
     107                        $version = $key;
     108                        break;
     109                }
     110        }
     111
     112        // Reset changeset's importance
     113        $importance = 'low';
     114
     115        // How important is this change?
     116        if ( in_array( $revision, $important_changesets ) ) {
     117                $importance = 'high';
     118        }
     119
     120        // Codex Page ?
     121        $codex_page = false;
     122
     123        foreach ( $codex_pages as $codex_link => $crevision ) {
     124                if ( in_array( $revision, $crevision ) ) {
     125                        $codex_page = $codex_link;
     126                }
     127        }
     128
     129        $files = explode( "\n", trim( $parts[2], "\n" ) );
     130
     131        foreach ( $files as $file ) {
     132                $changes[ str_replace( $bp_legacy_path, '', $file ) ][] = (object) array(
     133                        'version'    => $version,
     134                        'revision'   => $revision,
     135                        'importance' => $importance,
     136                        'log'        => $log,
     137                        'codex_page' => $codex_page,
     138                );
     139        }
     140}
     141
     142if ( empty( $changes ) ) {
     143        fwrite( STDOUT, "Error: could not generate the changelog.\n" );
     144        exit( 2 );
     145}
     146
     147ksort( $changes );
     148
     149foreach ( $changes as $template => $logs )  {
     150        $entry = new stdClass;
     151
     152        $entry->template = $template;
     153
     154        // Get version when the template was last edited
     155        $edited = reset( $logs );
     156        $entry->edited = $edited->version;
     157
     158        // Attach logs
     159        $entry->changes = $logs;
     160
     161        $changelog->templates[] = $entry;
     162}
     163
     164$created = file_put_contents( $output, json_encode( $changelog, JSON_PRETTY_PRINT ) );
     165
     166if ( ! $created ) {
     167        fwrite( STDOUT, "Error: could not generate the changelog.\n" );
     168        exit( 2 );
     169} else {
     170        fwrite( STDOUT, "Success: Changelog generated.\n" );
     171        exit( 0 );
     172}
  • 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};