Skip to content

Instantly share code, notes, and snippets.

@caiquecastro
Last active January 26, 2018 12:52
Show Gist options
  • Save caiquecastro/d9901beb09117cd255e717f63e9b915d to your computer and use it in GitHub Desktop.
Save caiquecastro/d9901beb09117cd255e717f63e9b915d to your computer and use it in GitHub Desktop.
Commiters share
#!/usr/bin/env php
<?php
class Commiter {
public $name;
public $commits;
public function __construct($name, $commits) {
$this->name = $name;
$this->commits = $commits;
}
public function share($totalCommits) {
return ($this->commits / $totalCommits) * 100;
}
}
$handle = fopen("php://stdin", "r");
$pattern = '/(\d+)(?:\t*)([A-Za-zí ]*)/';
$totalCommits = 0;
$commiters = [];
while($line = fgets($handle)) {
$line = trim($line);
preg_match($pattern, $line, $matches);
$commiters[] = new Commiter($matches[2], (int)$matches[1]);
$totalCommits += $matches[1];
}
echo "Total commits: {$totalCommits}" . PHP_EOL;
foreach($commiters as $commiter) {
echo $commiter->name . " (" . $commiter->share($totalCommits) . "%)" . PHP_EOL;
}
echo PHP_EOL;

Usage

Change file permission:

chmod +x commiters-share.php

Move the scripts to your bin folder:

sudo mv commiters-share.php /usr/local/bin/commiters-share

Have fun :D

gitshortlog -s -n | commiters-share
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment