Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Last active December 19, 2015 13:18
Show Gist options
  • Save DrewAPicture/5960771 to your computer and use it in GitHub Desktop.
Save DrewAPicture/5960771 to your computer and use it in GitHub Desktop.
SVN log props counter. WordPress function to trawl the commits log and count props. Counts are more accurate after removing the array_reduce(). Still not totally accurate.
<?php
/**
* List contributor props from most to least
*
* @param string $url (optional) The SVN repo URL.
*/
function ww_svn_log_props( $url = 'http://core.svn.wordpress.org/trunk' ) {
$log = get_transient( '36_log' ); // 12 Hour transient
if ( ! $log ) {
$log = shell_exec( 'svn log -r 23171:HEAD --xml ' . esc_url( $url ) );
set_transient( '36_log', $log, 12 * HOUR_IN_SECONDS );
}
$xml = simplexml_load_string( $log );
$msgs = $matches = array();
foreach ( $xml as $key => $entry ) {
$msgs[] = (string) $entry->msg;
}
foreach ( $msgs as $msg ) {
if ( preg_match( '/props.*/i', $msg, $matched ) );
$matches = array_merge( $matches, $matched );
}
$names = get_transient( '36_log_names' ); // 12 Hour transient
if ( ! $names ) {
$names = array();
foreach ( $matches as $match ) {
// Remove 'props ' or '.' or 'for' or 'the' or 'initial' or 'patch' or 'starter' or 'trunk' or 'nudge'
$name = str_ireplace( array( 'props ', '.', ';', 'to ', 'for ', 'the ', 'initial ', 'patch', 'starter', 'trunk', 'nudge' ), '', $match );
// Removes 'fixes #123456' or 'see #123456'
$name = preg_replace( '/((?:[a-z][a-z]+))(\\s+)(#)(\\d+)/is', '', $name );
// Replaces 'and' with ', '
$name = str_replace( ' and ', ',', $name );
// Removes spaces at the last minute
$name = str_replace( ' ', '', $name );
if ( strpos( $name, ',' ) ) {
$new_names = explode( ',', $name );
foreach ( $new_names as $new_name )
$names[] = $new_name;
} else {
$names[] = $name;
}
}
set_transient( '36_log_names', $names, 12 * HOUR_IN_SECONDS );
}
$names_list = array_unique( $names );
// The first time you run this, it may talk a lot of time
// and a lot of processing power. Just sayin.
$props = get_transient( '36_log_props' );
if ( false == $props ) {
$props = array();
foreach ( $names_list as $name ) {
if ( '' == $name )
continue;
$props[$name] = (int) shell_exec( 'svn log http://core.svn.wordpress.org/trunk -r 23171:HEAD | grep -i "props" | grep -ic "' . $name . '"' );
}
set_transient( '36_log_props', $props, HOUR_IN_SECONDS );
}
arsort( $props );
foreach ( $props as $name => $count ) {
echo $count . ' - ' . $name . '<br />';
}
}
/* Outputs as:
### - Contributor
## - Contributor
... (high to low)
*/
ww_svn_log_props();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment