Skip to content

Instantly share code, notes, and snippets.

@co3k
Created June 24, 2011 08:48
Show Gist options
  • Save co3k/1044456 to your computer and use it in GitHub Desktop.
Save co3k/1044456 to your computer and use it in GitHub Desktop.
バージョンに紐づいたチケットに紐づいたコミットのハッシュ値っぽい文字列をチケットのページから取ってくるやつ(こいつらのハッシュ値が意図通りのブランチに紐づいているかはちゃんと調べないとダメ)
<?php
$url = 'http://redmine.openpne.jp/versions/show/165';
function getCommitHashList($path)
{
$url = 'http://redmine.openpne.jp'.$path;
$text = file_get_contents($url);
preg_match_all('#/projects/op3/repository/revisions/([a-z0-9]+)#', $text, $matches);
return array_unique($matches[1]);
}
$document = new DOMDocument();
$document->loadHTMLFile($url);
foreach ($document->getElementsByTagName('a') as $node) {
if (false !== strpos($node->getAttribute('class'), 'issue status')) {
foreach (getCommitHashList($node->getAttribute('href')) as $hash) {
echo $hash.PHP_EOL;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment