'unsupported_url', 'error_description' => 'This GitHub URL is not supported', 'error_code' => 400, ]; } $headers = []; if(isset($creds['github_access_token'])) { $headers[] = 'Authorization: Bearer ' . $creds['github_access_token']; } $response = $http->get($apiurl, $headers); if($response['code'] != 200) { return [ 'error' => 'github_error', 'error_description' => $response['body'], 'code' => $response['code'], ]; } return [ 'url' => $url, 'body' => $response['body'], 'code' => $response['code'], ]; } public static function parse($http, $url, $creds, $json=null) { if(false) { } else { $data = json_decode($json, true); } if(!$data) { return [null, null, 0]; } // Start building the h-entry $entry = array( 'type' => ($type == 'repo' ? 'repo' : 'entry'), 'url' => $url, 'author' => [ 'type' => 'card', 'name' => null, 'photo' => null, 'url' => null ] ); if($type == 'repo') $authorkey = 'owner'; else $authorkey = 'user'; $entry['author']['name'] = $data[$authorkey]['login']; $entry['author']['photo'] = $data[$authorkey]['avatar_url']; $entry['author']['url'] = $data[$authorkey]['html_url']; if($type == 'pull') { $entry['name'] = '#' . $pull . ' ' . $data['title']; } elseif($type == 'issue') { $entry['name'] = '#' . $issue . ' ' . $data['title']; } elseif($type == 'repo') { $entry['name'] = $data['name']; } if($type == 'repo') { if(!empty($data['description'])) $entry['summary'] = $data['description']; } if($type != 'repo' && !empty($data['body'])) { $parser = new GithubMarkdown(); $entry['content'] = [ 'text' => $data['body'], 'html' => $parser->parse($data['body']) ]; } if($type == 'comment') { $entry['in-reply-to'] = ['https://github.com/'.$org.'/'.$repo.'/issues/'.$issue]; } if(!empty($data['labels'])) { $entry['category'] = array_map(function($l){ return $l['name']; }, $data['labels']); } $entry['published'] = $data['created_at']; $r = [ 'data' => $entry ]; return [$r, $json, $response['code']]; } }