71b45e81fcec8117f54eee96afea32c4a054388c

Author: Jonathan Bradley

Date: 2009-07-27 00:12:43 -0400

adding github plugin

diff --git a/models/datasources/github_source.php b/models/datasources/github_source.php new file mode 100644 index 0000000..5cf6d8e --- /dev/null +++ b/models/datasources/github_source.php @@ -0,0 +1,40 @@ +<?php + +App::import('Core', array('Set','Xml','HttpSocket')); +class GithubSource extends DataSource{ + + var $base = 'http://github.com/api/v1/json/'; + var $base2 = 'http://github.com/api/v2/json/'; + + var $description = "Github API Data Source"; + + function __construct($config) { + parent::__construct($config); + App::import('HttpSocket'); + $this->Http = new HttpSocket(); + } + + function repos($owner) { + $this->url = $this->base2 . 'repos/show/' . $owner; + return self::connect(); + } + + function viewCommit($owner, $project, $id) { + $this->url = $this->base2 . 'commits/show/' . $owner . '/' . $project . '/' . $id; + return self::connect(); + } + + function getCommits($owner, $project, $branch) { + $this->url = $this->base . $owner .'/'. $project . '/commits/'. $branch; + return self::connect(); + } + + function connect() { + $result = $this->Http->get($this->url); + $json = json_decode($result); + $Set = new Set(); + return $Set->reverse($json); + } + +} +?> \ No newline at end of file diff --git a/plugins/github/config/config.php b/plugins/github/config/config.php new file mode 100644 index 0000000..ebcca8f --- /dev/null +++ b/plugins/github/config/config.php @@ -0,0 +1,3 @@ +<?php +$username = 'jonathanbradley'; +?> \ No newline at end of file diff --git a/plugins/github/controllers/commits_controller.php b/plugins/github/controllers/commits_controller.php new file mode 100644 index 0000000..50f1ce8 --- /dev/null +++ b/plugins/github/controllers/commits_controller.php @@ -0,0 +1,47 @@ +<?php + +class CommitsController extends GithubAppController { + + var $name = 'Commits'; + var $uses = array(); + var $components = array('Github.Github'); + + function view($owner, $project) { + $data = $this->Github->commits($owner, $project); + $commits = $data['commits']; + for ($i = 0; $i < count($commits); $i++) { + $commit[$i]['message'] = $commits[$i]['message']; + $commit[$i]['url'] = $commits[$i]['url']; + $commit[$i]['author'] = $commits[$i]['author']['name']; + $commit[$i]['id'] = $commits[$i]['id']; + $commit[$i]['date'] = $commits[$i]['authored_date']; + } + + $info['owner'] = $this->params['pass'][0]; + $info['project'] = $this->params['pass'][1]; + $this->set('data', $commit); + $this->set('info', $info); + } + + function display($owner, $project, $id) { + $data = $this->Github->viewCommit($owner, $project, $id); + echo '<pre>'; print_r($data); die; + } + + function commands() { + foreach ($this->functions as $key => $value) { + $clean = str_replace(array('_', '-'), ' ', $value); + $clean = ucwords($clean); + $cmd[$value] = $clean; + } + return $cmd; + } + + + function sFlash($command, $response) { + $this->Session->setFlash(ucwords(str_replace('_', ' ', $response))); + $this->redirect(array('action' => 'fetch', str_replace('remove', 'list', $command) . 's'), null, false); + } + +} +?> \ No newline at end of file diff --git a/plugins/github/controllers/components/github.php b/plugins/github/controllers/components/github.php new file mode 100644 index 0000000..a4c0b56 --- /dev/null +++ b/plugins/github/controllers/components/github.php @@ -0,0 +1,39 @@ +<?php + +class GithubComponent extends Object { + + var $name = 'Github'; + var $params = array(); + var $components = array('Session'); + var $key = ''; + + function commits($owner, $project, $branch = 'master') { + return $this->github->getCommits($owner, $project, $branch); + } + + function repos($owner) { + return $this->github->repos($owner); + } + + function viewCommit($owner, $project, $id) { + $data = $this->github->viewCommit($owner, $project, $id); + + foreach ($data['commit']['removed'] as $key => $value) { + $commit['removed'][] = $value['filename']; + } + foreach ($data['commit']['added'] as $key => $value) { + $commit['added'][] = $value['filename']; + } + $commit['info']['date'] = $data['commit']['committed_date']; + $commit['info']['author'] = $data['commit']['author']['name']; + echo '<pre>'; print_r($commit); die; + } + + function startup() { + App::import('ConnectionManager'); + $this->github =& ConnectionManager::getDataSource('github'); + } + +} + +?> \ No newline at end of file diff --git a/plugins/github/controllers/repos_controller.php b/plugins/github/controllers/repos_controller.php new file mode 100644 index 0000000..7f5ad08 --- /dev/null +++ b/plugins/github/controllers/repos_controller.php @@ -0,0 +1,16 @@ +<?php + +class ReposController extends GithubAppController { + + var $name = 'Repos'; + var $uses = array(); + var $components = array('Github.Github'); + + function index() { + include(APP . 'plugins' . DS . $this->params['plugin'] . DS . 'config' . DS . 'config.php'); + $data = $this->Github->repos($username); + $this->set('data', $data['repositories']); + } + +} +?> \ No newline at end of file diff --git a/plugins/github/github_app_controller.php b/plugins/github/github_app_controller.php new file mode 100644 index 0000000..febcf6d --- /dev/null +++ b/plugins/github/github_app_controller.php @@ -0,0 +1,7 @@ +<?php + +class GithubAppController extends AppController { + //var $components = array('DebugKit.Toolbar'); + var $helpers = array('Html', 'Form', 'Javascript'); +} +?> \ No newline at end of file diff --git a/plugins/github/views/commits/view.ctp b/plugins/github/views/commits/view.ctp new file mode 100644 index 0000000..6f451e4 --- /dev/null +++ b/plugins/github/views/commits/view.ctp @@ -0,0 +1,17 @@ +<table> +<?php +echo $html->tableHeaders(array('Date','Author','Message', 'Action')); +foreach ($data as $key => $value) { + echo $html->tableCells( + array( + $value['date'], + $value['author'], + $value['message'], + $html->link('details', array('action' => 'display', $info['owner'], $info['project'], $value['id'])), + ), + array('class' => 'altrow'), + array('class' => 'row') + ); +} +?> +</table> \ No newline at end of file diff --git a/plugins/github/views/repos/index.ctp b/plugins/github/views/repos/index.ctp new file mode 100644 index 0000000..5f72668 --- /dev/null +++ b/plugins/github/views/repos/index.ctp @@ -0,0 +1,19 @@ +<table> +<?php +echo $html->tableHeaders(array('Name','Owner','Description', 'Forks', 'Watchers', 'Actions')); +foreach ($data as $key => $value) { + echo $html->tableCells( + array( + $value['name'], + $value['owner'], + $value['description'], + $value['forks'], + $value['watchers'], + $html->link('commits', array('controller' => 'commits', 'action' => 'view', $value['owner'], $value['name'])), + ), + array('class' => 'altrow'), + array('class' => 'row') + ); +} +?> +</table> \ No newline at end of file diff --git a/tmp/logs/error.log b/tmp/logs/error.log index da88bf5..a8a3fe6 100644 --- a/tmp/logs/error.log +++ b/tmp/logs/error.log @@ -27,3 +27,4 @@ 2009-07-26 04:46:13 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\controllers\dreamhost_controller.php, line 56] 2009-07-26 04:47:39 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\views\helpers\dreamhost.php, line 32] 2009-07-26 04:56:37 Warning: Warning (2): Invalid argument supplied for foreach() in [APP\views\helpers\dreamhost.php, line 37] +2009-07-27 00:11:37 Error: Fatal Error (256): ConnectionManager::getDataSource - Non-existent data source github in [CORE\cake\libs\model\connection_manager.php, line 109]