Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created November 29, 2016 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/e0ad7bb4ba560f48dfc91bb0ca0798c7 to your computer and use it in GitHub Desktop.
Save westonruter/e0ad7bb4ba560f48dfc91bb0ca0798c7 to your computer and use it in GitHub Desktop.
<?php
# Generate props list for usernames coming from STDIN between two given commits.
# Author: Weston Ruter
#
# USAGE:
# cat team-usernames.txt | php list-team-props.php 4.6.0 4.7
array_shift( $argv );
$start_commit = array_shift( $argv );
$end_commit = array_shift( $argv );
$files = $argv;
$team_usernames = array_filter( explode( "\n", trim( file_get_contents( 'php://stdin' ) ) ) );
exec( "git log -z --format='%h\n%ae\n%s\n%b' $start_commit..$end_commit -- " . join( ' ', $files ), $lines );
$output = join( "\n", $lines );
$commits = explode( "\x00", $output );
$committers = array();
$committer_tally = array();
$props_tally = array();
$commit_hashes = array();
$fixed_tickets = array();
foreach ( $commits as $commit ) {
$commit_message_lines = explode( "\n", $commit );
$commit_hash = array_shift( $commit_message_lines );
$committer = strtok( array_shift( $commit_message_lines ), '@' );
$commit_subject = array_shift( $commit_message_lines );
$commit_body = join( "\n", $commit_message_lines );
if ( ! isset( $committer_tally[ $committer ] ) ) {
$committer_tally[ $committer ] = 0;
}
$committer_tally[ $committer ] += 1;
$commit_props = array();
foreach ( $team_usernames as $username ) {
if ( false !== stripos( $commit_body, $username ) ) {
$commit_props[] = $username;
}
}
// Props the committer if they are on the team and the props list is empty.
if ( empty( $commit_props ) && in_array( $committer, $team_usernames ) && ! preg_match( '/Props\s/i', $commit_body ) ) {
$commit_props[] = $committer;
}
if ( empty( $commit_props ) ) {
continue;
}
foreach ( $commit_props as $commit_prop ) {
if ( ! isset( $props_tally[ $commit_prop ] ) ) {
$props_tally[ $commit_prop ] = 0;
}
$props_tally[ $commit_prop ] += 1;
}
if ( preg_match( '/Fixes #(\d+(, #\d+)*)/i', $commit, $matches ) ) {
$fixed_tickets = array_merge( $fixed_tickets, explode( ', #', $matches[1] ) );
}
}
arsort( $props_tally );
foreach ( $props_tally as $username => $count ) {
print "$count\t$username\n";
}
sort( $fixed_tickets );
echo 'https://core.trac.wordpress.org/query?group=type&col=id&col=summary&col=owner&col=type&col=status&col=priority&col=milestone&order=priority&id=' . join( ',', $fixed_tickets ) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment