mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-04-17 13:15:47 +00:00
git show not flying on live server so moving to reading from github api
This commit is contained in:
parent
5b5d08d1e1
commit
b41ffeb8d1
1 changed files with 17 additions and 0 deletions
17
index.php
17
index.php
|
|
@ -31,12 +31,29 @@
|
|||
// if sha specified, use that revision of licence
|
||||
$license = '';
|
||||
if ($sha != "") {
|
||||
try {
|
||||
// TODO must cache and optimise this as it'll kill my server :-(
|
||||
$gitCommitData = json_decode(@file_get_contents('https://api.github.com/repos/remy/mit-license/git/trees/' . $sha));
|
||||
if (isset($gitCommitData) && is_object($gitCommitData) && property_exists($gitCommitData, 'tree')) {
|
||||
foreach ($gitCommitData->tree as $commit) {
|
||||
if ($commit->path == 'LICENSE.html') {
|
||||
$licenseData = json_decode(file_get_contents($commit->url));
|
||||
$license = base64_decode($licenseData->content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
}
|
||||
/*
|
||||
$out = array();
|
||||
// preg_replace should save us - but: please help me Obi Wan...
|
||||
exec("git show " . $sha . ":LICENSE.html", $out, $r);
|
||||
if ($r == 0) {
|
||||
$license = implode("\n", $out);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// if we didn't manage to read one in, use latest
|
||||
|
|
|
|||
Loading…
Reference in a new issue