Skip to content

Instantly share code, notes, and snippets.

@rafaelbecks
Created July 21, 2016 15:38
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 rafaelbecks/db90275bb82508b4bbed99f8be725f18 to your computer and use it in GitHub Desktop.
Save rafaelbecks/db90275bb82508b4bbed99f8be725f18 to your computer and use it in GitHub Desktop.
<?php
//Script que copia en el portapapeles reporte del día según commits realizados
function presentToPast($sentence)
{
$past = ["ado","ido","ada","ida"];
$present = ["é","í","é","í"];
$words = split(" ",$sentence);
if($a = strposa($words[0],$past,1))
{
$verb = substr($words[0],0,$a);
$lastWord = substr($verb,-1);
$time = str_replace("s","",substr($words[0],$a));
$indexPast = array_search($time, $past);
$sufix = $present[$indexPast];
$past = $verb . (($lastWord=="g" && ($indexPast!=1 && $indexPast!=3)) ? "u" : "") . $sufix;
$past = str_replace("z","c",$past);
unset($words[0]);
$pastCommit = $past . " " . implode(" ",$words);
return $pastCommit;
}
else
{
return "Realicé ".$sentence;
}
}
function getCommitLog()
{
$git_command = 'cd adherenzien-dev && git log --since="6am" --author="Rafael" --pretty=format:"%s" > git.log';
shell_exec($git_command);
$lines = file("adherenzien-dev/git.log", FILE_IGNORE_NEW_LINES);
for($i=0;$i<count($lines);$i++)
{
if(strpos($lines[$i],"Merge")===false){
$trueCommits[] = presentToPast($lines[$i]);;
}
}
return $trueCommits;
}
//Lazy word seach
function strposa($haystack, $needles=array(), $offset=0) {
$chr = array();
foreach($needles as $needle) {
$res = strpos($haystack, $needle, $offset);
if ($res !== false) $chr[$needle] = $res;
}
if(empty($chr)) return false;
return min($chr);
}
$commits = getCommitLog();
shell_exec("echo -n '".implode("\n",$commits)."' | xclip -selection c");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment