Skip to content

Instantly share code, notes, and snippets.

@matsubo
Last active December 20, 2015 05:09
Show Gist options
  • Save matsubo/6076201 to your computer and use it in GitHub Desktop.
Save matsubo/6076201 to your computer and use it in GitHub Desktop.
<?php
/**
* Create git daily release list group by author
*
* @author Yuki Matsukura
*/
class Git_Daily_List_Customize
{
/** @private string of github project url not containing the last slash */
private $github_project_url;
/** @private array of author and commit hash */
private $author_to_hash = array();
/**
* Constructor
*
* @param string github project root
* @param string output of git daily list
*/
public function __construct($github_project_url, $input)
{
$this->github_project_url = $github_project_url;
foreach (explode("\n", $input) as $line_array) {
if (!preg_match('/^\s*([a-z0-9]+) = (.*)$/', $line_array, $match)) {
continue;
}
$this->author_to_hash[$match[2]][] = $match[1];
}
}
/**
* Return string of commits group by author_to_hash
*
* @return string
*/
public function groupByAuthor()
{
if (!$this->author_to_hash) {
return;
}
ksort($this->author_to_hash);
$line = "List group by author\n";
foreach ($this->author_to_hash as $author => $hash_array) {
$line .= sprintf('[] %s', $author);
$line .= "\n";
foreach ($hash_array as $hash) {
$line .= sprintf(" %s/commit/%s\n", $this->github_project_url, $hash);
}
$line .= "\n";
}
return $line;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment