diff --git a/README.markdown b/README.markdown index 1ac462c0a20..be4f79da35e 100755 --- a/README.markdown +++ b/README.markdown @@ -58,6 +58,22 @@ $repositories = $client->api('user')->repositories('ornicar'); From `$client` object, you can access to all GitHub. +## Model usage (WIP) + +```php +createRepo('github-api'); +$issue = $repo->createIssue('This is a problem', array( + 'body' => 'Oh dear, now what?!' +)); + +$issue->addLabel('critical'); + +print_r($issue->labels()); +``` + ## Documentation See the `doc` directory for more detailed documentation. diff --git a/lib/Github/Model/AbstractModel.php b/lib/Github/Model/AbstractModel.php new file mode 100644 index 00000000000..90a5f63ab9f --- /dev/null +++ b/lib/Github/Model/AbstractModel.php @@ -0,0 +1,71 @@ +api($api); + } + + /** + * @param array $data + * @return AbstractModel + */ + public function hydrate(array $data = array()) + { + if (!empty($data)) { + foreach ($data as $k => $v) { + $this->$k = $v; + } + } + + return $this; + } + + public function __set($property, $value) + { + if (!in_array($property, static::$_properties)) { + throw new Exception\RuntimeException(sprintf('Property "%s" does not exist for %s object', $property, get_called_class())); + } + + $this->_data[$property] = $value; + } + + public function __get($property) + { + if (!in_array($property, static::$_properties)) { + throw new Exception\RuntimeException(sprintf('Property "%s" does not exist for %s object', $property, get_called_class())); + } + + if (isset($this->_data[$property])) { + return $this->_data[$property]; + } + + return null; + } + +} diff --git a/lib/Github/Model/Comment.php b/lib/Github/Model/Comment.php new file mode 100644 index 00000000000..c9efd107e05 --- /dev/null +++ b/lib/Github/Model/Comment.php @@ -0,0 +1,72 @@ +hydrate($data); + } + + public function __construct(Issue $issue, $id) + { + $this->id = $id; + $this->issue = $issue; + } + + public function show() + { + $data = $this->api('issue')->comments()->show( + $this->issue->repo->owner->login, + $this->issue->repo->name, + $this->id + ); + + return Comment::fromArray($this->issue, $data); + } + + public function update($body) + { + $data = $this->api('issue')->comments()->update( + $this->issue->repo->owner->login, + $this->issue->repo->name, + $this->id, + array('body' => $body) + ); + + return Comment::fromArray($this->issue, $data); + } + + public function remove() + { + $this->api('issue')->comments()->remove( + $this->issue->repo->owner->login, + $this->issue->repo->name, + $this->id + ); + + return true; + } +} diff --git a/lib/Github/Model/CommentInterface.php b/lib/Github/Model/CommentInterface.php new file mode 100644 index 00000000000..d3cbf3e9499 --- /dev/null +++ b/lib/Github/Model/CommentInterface.php @@ -0,0 +1,8 @@ +hydrate($data); + } + + public function __construct(Repo $repo, $sha) + { + $this->repo = $repo; + $this->sha = $sha; + } + + public function show() + { + $data = $this->api('git_data')->commits()->show( + $this->repo->owner->login, + $this->repo->name, + $this->sha + ); + + return Commit::fromArray($this->repo, $data); + } + +} diff --git a/lib/Github/Model/DeployKey.php b/lib/Github/Model/DeployKey.php new file mode 100644 index 00000000000..a6a929928ab --- /dev/null +++ b/lib/Github/Model/DeployKey.php @@ -0,0 +1,57 @@ +hydrate($data); + } + + public function __construct(Repo $repo, $id) + { + $this->repo = $repo; + $this->id = $id; + } + + public function update($title, $key) + { + $data = $this->api('repo')->keys()->update( + $this->repo->owner->name, + $this->repo->name, + $this->id, + array( + 'title' => $title, + 'key' => $key + ) + ); + + return DeployKey::fromArray($this->repo, $data); + } + + public function remove() + { + $this->api('repo')->keys()->remove( + $this->repo->owner->name, + $this->repo->name, + $this->id + ); + + return true; + } +} diff --git a/lib/Github/Model/Event.php b/lib/Github/Model/Event.php new file mode 100644 index 00000000000..c474e52736b --- /dev/null +++ b/lib/Github/Model/Event.php @@ -0,0 +1,60 @@ +hydrate($data); + } + + public function __construct($repo, $event, $issue = null) + { + $this->repo = $repo; + $this->event = $event; + + if ($issue) { + $this->issue = $issue; + } + } + + public function show() + { + $data = $this->api('issue')->events()->show( + $this->repo->owner->login, + $this->repo->name, + $this->event + ); + + return Event::fromArray($this->repo, $data); + } +} diff --git a/lib/Github/Model/Hook.php b/lib/Github/Model/Hook.php new file mode 100644 index 00000000000..33737e5aa56 --- /dev/null +++ b/lib/Github/Model/Hook.php @@ -0,0 +1,96 @@ +hydrate($data); + } + + public function __construct(Repo $repo, $id) + { + $this->id = $id; + $this->repo = $repo; + } + + public function show() + { + $data = $this->api('repo')->hooks()->show( + $this->repo->owner->login, + $this->repo->name, + $this->id + ); + + return Hook::fromArray($this, $data); + } + + public function update(array $params) + { + $data = $this->api('repo')->hooks()->update( + $this->repo->owner->login, + $this->repo->name, + $this->id, + $params + ); + + return Hook::fromArray($this, $data); + } + + public function remove() + { + $this->api('repo')->hooks()->remove( + $this->repo->owner->login, + $this->repo->name, + $this->id + ); + + return true; + } + + public function test() + { + $this->api('repo')->hooks()->test( + $this->repo->owner->login, + $this->repo->name, + $this->id + ); + + return true; + } + +} diff --git a/lib/Github/Model/Issue.php b/lib/Github/Model/Issue.php new file mode 100644 index 00000000000..408a2d2a4a5 --- /dev/null +++ b/lib/Github/Model/Issue.php @@ -0,0 +1,294 @@ +repo, $data['pull_request']); + } + + return $issue->hydrate($data); + } + + public function __construct(Repo $repo, $number) + { + $this->repo = $repo; + $this->number = $number; + } + + public function show() + { + $data = $this->api('issue')->show( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + return Issue::fromArray($this->repo, $data); + } + + public function update(array $params) + { + $data = $this->api('issue')->update( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $params + ); + + return Issue::fromArray($this->repo, $data); + } + + public function labels() + { + $data = $this->api('issue')->labels()->all( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + $labels = array(); + foreach ($data as $label) { + $labels[] = Label::fromArray($this->repo, $label); + } + + return $labels; + } + + // todo: create label if not exists + public function addLabels(array $labels) + { + $data = $this->api('issue')->labels()->add( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $labels + ); + + $labels = array(); + foreach ($data as $label) { + $labels[] = Label::fromArray($this->repo, $label); + } + + return $labels; + } + + public function addLabel($name) + { + if ($this->hasLabel($name)) { + return $this->labels(); + } + + return $this->addLabels(array($name)); + } + + public function removeLabel($name) + { + if (!$this->hasLabel($name)) { + return true; + } + + $this->api('issue')->labels()->remove( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $name + ); + + return true; + } + + public function replaceLabels(array $labels) + { + $data = $this->api('issue')->labels()->replace( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $labels + ); + + $labels = array(); + foreach ($data as $label) { + $labels[] = Label::fromArray($this->repo, $label); + } + + return $labels; + } + + public function clearLabels() + { + $this->api('issue')->labels()->clear( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + return true; + } + + public function hasLabel($label_name) + { + foreach ($this->labels() as $label) { + if ($label_name == $label->name) { + return true; + } + } + + return false; + } + + public function milestones(array $params = array()) + { + $data = $this->api('issue')->milestones()->all( + $this->repo->owner->login, + $this->repo->name, + $params + ); + + $milestones = array(); + foreach ($data as $milestone) { + $milestones[] = Milestone::fromArray($this, $milestone); + } + + return $milestones; + } + + public function createMilestone($title, array $params = array()) + { + $params['title'] = $title; + + $data = $this->api('issue')->milestones()->create( + $this->repo->owner->login, + $this->repo->name, + $params + ); + + return Milestone::fromArray($this, $data); + } + + public function updateMilestone($number, array $data) + { + return Milestone::factory($this, $number)->update($data); + } + + public function removeMilestone($number) + { + return Milestone::factory($this, $number)->remove(); + } + + public function comments($page = 1) + { + $data = $this->api('issue')->comments()->all( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $page + ); + + $comments = array(); + foreach ($data as $comment) { + $comments[] = Comment::fromArray($this, $comment); + } + + return $comments; + } + + public function addComment($body, array $params = array()) + { + $data = $this->api('issue')->comments()->create( + $this->repo->owner->login, + $this->repo->name, + $this->number, + array('body' => $body) + ); + + return Comment::fromArray($this, $data); + } + + public function updateComment($id, $body) + { + return Comment::factory($this, $id)->update($body); + } + + public function removeComment($id) + { + return Comment::factory($this, $id)->remove($id); + } + + public function events() + { + $data = $this->api('issue')->events()->all( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + $events = array(); + foreach ($data as $event) { + $events[] = Event::fromArray($this->repo, $event, $this); + } + + return $events; + } + + public function close() + { + return $this->update(array('state' => 'closed')); + } +} diff --git a/lib/Github/Model/IssueInterface.php b/lib/Github/Model/IssueInterface.php new file mode 100644 index 00000000000..cc7fc47529a --- /dev/null +++ b/lib/Github/Model/IssueInterface.php @@ -0,0 +1,7 @@ +hydrate($data); + } + + public function __construct(Repo $repo, $name) + { + $this->repo = $repo; + $this->name = $name; + } + + public function update($name, $color) + { + $data = $this->api('repo')->labels()->update( + $this->repo->owner->login, + $this->repo->name, + $this->name, + array( + 'name' => $name, + 'color' => $color + ) + ); + + return Label::fromArray($this->repo, $data); + } + + public function remove() + { + $this->api('repo')->labels()->remove( + $this->repo->owner->login, + $this->repo->name, + $this->name + ); + + return true; + } + +} diff --git a/lib/Github/Model/Language.php b/lib/Github/Model/Language.php new file mode 100644 index 00000000000..c9f04aa1df3 --- /dev/null +++ b/lib/Github/Model/Language.php @@ -0,0 +1,26 @@ +hydrate($data); + } +} diff --git a/lib/Github/Model/Milestone.php b/lib/Github/Model/Milestone.php new file mode 100644 index 00000000000..849a645c137 --- /dev/null +++ b/lib/Github/Model/Milestone.php @@ -0,0 +1,93 @@ +hydrate($data); + } + + public function __construct(Issue $issue, $number) + { + $this->issue = $issue; + $this->number = $number; + } + + public function show() + { + $data = $this->api('issue')->milestones()->show( + $this->issue->repo->owner->login, + $this->issue->repo->name, + $this->number + ); + + return Milestone::fromArray($this->issue, $data); + } + + public function update(array $data) + { + $data = $this->api('issue')->milestones()->update( + $this->issue->repo->owner->login, + $this->issue->repo->name, + $this->number, + $data + ); + + return Milestone::fromArray($this->issue, $data); + } + + public function remove() + { + $this->api('issue')->milestones()->remove( + $this->issue->repo->owner->login, + $this->issue->repo->name, + $this->number + ); + + return true; + } + + public function labels() + { + $data = $this->api('issue')->milestones()->labels( + $this->issue->repo->owner->login, + $this->issue->repo->name, + $this->number + ); + + $labels = array(); + foreach ($data as $label) { + $labels[] = Label::fromArray($this->issue->repo, $label); + } + + return $labels; + } +} diff --git a/lib/Github/Model/Org.php b/lib/Github/Model/Org.php new file mode 100644 index 00000000000..d5278549e3f --- /dev/null +++ b/lib/Github/Model/Org.php @@ -0,0 +1,148 @@ +api('organization')->show( + $this->login + ); + + return Org::fromArray($data); + } + + /** + * @return Org + */ + public function update(array $params) + { + $data = $this->api('organization')->update( + $this->login, + $params + ); + + return Org::fromArray($data); + } + + /** + * @return Repo + */ + public function createRepo($name, array $params = array()) + { + $params['organization'] = $this->login; + + return parent::createRepo($name, $params); + } + + public function members($type = null) + { + $data = $this->api('organization')->members()->all( + $this->login, + $type + ); + + $members = array(); + foreach ($data as $member) { + $members[] = User::fromArray($member); + } + + return $members; + } + + public function publicMembers() + { + return $this->members('public'); + } + + public function checkMembership($login) + { + return $this->api('organization')->members()->show( + $this->login, + $login + ); + } + + public function checkPublicMembership($login) + { + return $this->api('organization')->members()->check( + $this->login, + $login + ); + } + + public function publicizeMember($login) + { + return $this->api('organization')->members()->publicize( + $this->login, + $login + ); + } + + public function concealMember($login) + { + return $this->api('organization')->members()->conceal( + $this->login, + $login + ); + } + + public function removeMember($login) + { + return $this->api('organization')->members()->remove( + $this->login, + $login + ); + } + + /** + * @return Team + */ + public function createTeam($name, array $params = array()) + { + $params['name'] = $name; + + $data = $this->api('organization')->teams()->create( + $this->login, + $params + ); + + return Team::fromArray($this, $data); + } + + public function teams() + { + $data = $this->api('organization')->teams()->all( + $this->login + ); + + $teams = array(); + foreach ($data as $team) { + $teams[] = Team::fromArray($this, $team); + } + + return $teams; + } + + /** + * @return Team + */ + public function team($id) + { + return Team::factory($this, $id)->show(); + } + + public function removeTeam($id) + { + return Team::factory($this, $id)->remove(); + } +} diff --git a/lib/Github/Model/Owner.php b/lib/Github/Model/Owner.php new file mode 100644 index 00000000000..80cc4661c0e --- /dev/null +++ b/lib/Github/Model/Owner.php @@ -0,0 +1,107 @@ +hydrate($data); + } + + public function __construct($login) + { + $this->login = $login; + } + + /** + * @return Repo + */ + public function repo($name) + { + return Repo::factory($this, $name)->show(); + } + + /** + * @return Repo + */ + public function createRepo($name, array $params = array()) + { + $params = array_merge(array( + 'description' => null, + 'homepage' => null, + 'public' => true, + 'organization' => null + ), $params); + + $data = $this->api('repo')->create( + $name, + $params['description'], + $params['homepage'], + $params['public'], + $params['organization'] + ); + + return Repo::fromArray($data); + } + + /** + * @return Repo + */ + public function updateRepo($name, array $params) + { + return Repo::factory($this, $name)->update($params); + } + + /** + * @return Repo + */ + public function removeRepo($name) + { + return Repo::factory($this, $name)->remove(); + } +} diff --git a/lib/Github/Model/OwnerInterface.php b/lib/Github/Model/OwnerInterface.php new file mode 100644 index 00000000000..f93a68d81db --- /dev/null +++ b/lib/Github/Model/OwnerInterface.php @@ -0,0 +1,7 @@ +hydrate($data); + } + + public function __construct(Repo $repo, $number) + { + $this->repo = $repo; + $this->number = $number; + } + + public function show() + { + $data = $this->api('pull_request')->show( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + return PullRequest::fromArray($this->repo, $data); + } + + public function update(array $params) + { + $data = $this->api('pull_request')->update( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $params + ); + + return PullRequest::fromArray($this->repo, $data); + } + + public function commits() + { + $data = $this->api('pull_request')->commits( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + $commits = array(); + foreach ($data as $commit) { + $commits[] = Commit::fromArray($this->repo, $commit); + } + + return $commits; + } + + public function files() + { + $data = $this->api('pull_request')->files( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + $files = array(); + foreach ($data as $file) { + $files[] = (object) $file; + } + + return $files; + } + + public function merged() + { + return $data = $this->api('pull_request')->merged( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + } + + // TODO: Handle result better + public function merge($message = null) + { + $data = $this->api('pull_request')->merged( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $message + ); + + return (object) $data; + } + + public function reviewComments() + { + $data = $this->api('pull_request')->comments()->all( + $this->repo->owner->login, + $this->repo->name, + $this->number + ); + + $comments = array(); + foreach ($data as $comment) { + $comments[] = ReviewComment::fromArray($this, $comment); + } + + return $comments; + } + + public function addReviewComment($body, array $params = array()) + { + $params['body'] = $body; + + $data = $this->api('pull_request')->comments()->create( + $this->repo->owner->login, + $this->repo->name, + $this->number, + $params + ); + + return ReviewComment::fromArray($this, $data); + } +} diff --git a/lib/Github/Model/Ref.php b/lib/Github/Model/Ref.php new file mode 100644 index 00000000000..24588d2c270 --- /dev/null +++ b/lib/Github/Model/Ref.php @@ -0,0 +1,40 @@ +hydrate($data); + } +} diff --git a/lib/Github/Model/Repo.php b/lib/Github/Model/Repo.php new file mode 100644 index 00000000000..a6c4ccaf225 --- /dev/null +++ b/lib/Github/Model/Repo.php @@ -0,0 +1,550 @@ +hydrate($data); + } + + public function __construct(Owner $owner, $name) + { + $this->owner = $owner; + $this->name = $name; + } + + /** + * @return Repo + */ + public function show() + { + $data = $this->api('repo')->show( + $this->owner->login, + $this->name + ); + + return Repo::fromArray($data); + } + + + /** + * @return Repo + */ + public function update(array $params) + { + $data = $this->api('repo')->update( + $this->owner->login, + $this->name, + $params + ); + + return Repo::fromArray($data); + } + + public function remove() + { + $this->api('repo')->remove( + $this->owner->login, + $this->name + ); + + return true; + } + + /** + * @return Issue + */ + public function createIssue($title, array $params = array()) + { + $params['title'] = $title; + + $issue = $this->api('issue')->create( + $this->owner->login, + $this->name, + $params + ); + + return $this->issue($issue['number']); + } + + public function issues(array $params = array()) + { + $data = $this->api('issue')->all( + $this->owner->login, + $this->name, + $params + ); + + $issues = array(); + foreach ($data as $issue) { + $issues[] = Issue::fromArray($this, $issue); + } + + return $issues; + } + + /** + * @return Issue + */ + public function issue($number) + { + try { + $issue = Issue::factory($this, $number)->show(); + } catch (\Exception $e) { + $issue = PullRequest::factory($this, $number)->show(); + } + + return $issue; + } + + public function labels() + { + $data = $this->api('repo')->labels()->all( + $this->owner->login, + $this->name + ); + + $labels = array(); + foreach ($data as $label) { + $labels[] = Label::fromArray($this, $label); + } + + return $labels; + } + + /** + * @return Issue + */ + public function label($name) + { + $data = $this->api('repo')->labels()->show( + $this->owner->login, + $this->name, + $name + ); + + return Label::fromArray($this, $data); + } + + /** + * @todo: Check label doesn't exist + * @return Label + */ + public function addLabel($name, $color) + { + $data = $this->api('repo')->labels()->create( + $this->owner->login, + $this->name, + array( + 'name' => $name, + 'color' => $color + ) + ); + + return Label::fromArray($this, $data); + } + + /** + * @return Label + */ + public function updateLabel($name, $color) + { + return Label::factory($this, $name)->update($name, $color); + } + + public function removeLabel($name) + { + return Label::factory($this, $name)->remove($name); + } + + public function removeLabels() + { + foreach ($this->labels() as $label) { + $label->remove(); + } + + return true; + } + + public function keys() + { + $data = $this->api('repo')->keys()->all( + $this->owner->login, + $this->name + ); + + $keys = array(); + foreach ($data as $key) { + $keys[] = DeployKey::fromArray($this, $key); + } + + return $keys; + } + + /** + * @return DeployKey + */ + public function key($id) + { + $data = $this->api('repo')->keys()->show( + $this->owner->login, + $this->name, + $id + ); + + return DeployKey::fromArray($this, $data); + } + + /** + * @return DeployKey + */ + public function addKey($title, $key) + { + $data = $this->api('repo')->keys()->create( + $this->owner->login, + $this->name, + array( + 'title' => $title, + 'key' => $key + ) + ); + + return DeployKey::fromArray($this, $data); + } + + /** + * @return DeployKey + */ + public function updateKey($id, $title, $key) + { + return DeployKey::factory($this, $id)->update($title, $key); + } + + public function removeKey($id) + { + return DeployKey::factory($this, $id)->remove(); + } + + public function events() + { + $data = $this->api('issue')->events()->all( + $this->owner->login, + $this->name + ); + + $events = array(); + foreach ($data as $event) { + $events[] = Event::fromArray($this, $event); + } + + return $events; + } + + /** + * @return Event + */ + public function event($event) + { + $data = $this->api('issue')->events()->show( + $this->owner->login, + $this->name, + $event + ); + + return Event::fromArray($this, $data); + } + + /** + * @return PullRequest + */ + public function createPullRequest(array $params) + { + $data = $this->api('pull_request')->create( + $this->owner->login, + $this->name, + $params + ); + + return PullRequest::fromArray($this, $data); + } + + public function pullRequests($state = null) + { + $data = $this->api('pull_request')->all( + $this->owner->login, + $this->name, + $state + ); + + $pull_requests = array(); + foreach ($data as $pull_request) { + $pull_requests[] = PullRequest::fromArray($this, $pull_request); + } + + return $pull_requests; + } + + /** + * @return PullRequest + */ + public function pullRequest($number) + { + return PullRequest::factory($this, $number)->show(); + } + + /** + * @return PullRequest + */ + public function updatePullRequest($number, array $params) + { + return PullRequest::factory($this, $number)->update($params); + } + + public function languages() + { + $data = $this->api('repos')->languages( + $this->owner->login, + $this->name + ); + + $languages = array(); + foreach ($data as $language => $id) { + $languages[] = Language::fromArray(array( + 'name' => $language, + 'size' => $id + )); + } + + return $languages; + } + + public function teams() + { + $data = $this->api('repos')->teams()->all( + $this->owner->login, + $this->name + ); + + $teams = array(); + foreach ($data as $team) { + $teams[] = Team::fromArray($this->owner, $team); + } + + return $teams; + } + + /** + * @return Hook + */ + public function addHook($name, array $config, array $events = null, $active = true) + { + $data = $this->api('repo')->hooks()->create( + $this->owner->login, + $this->name, + array( + 'name' => $name, + 'config' => $config, + 'events' => $events, + 'active' => $active + ) + ); + + return Hook::fromArray($this, $data); + } + + /** + * @return Hook + */ + public function hook($id) + { + return Hook::factory($this, $id)->show(); + } + + public function hooks() + { + $data = $this->api('repo')->hooks()->all( + $this->owner->login, + $this->name + ); + + $hooks = array(); + foreach ($data as $hook) { + $hooks[] = Hook::fromArray($this, $hook); + } + + return $hooks; + } + + /** + * @return Hook + */ + public function updateHook($id, array $params) + { + return Hook::factory($this, $id)->update($params); + } + + public function removeHook($id) + { + return Hook::factory($this, $id)->remove(); + } + + /** + * @return Repo + */ + public function fork($org = null) + { + $data = $this->api('repo')->forks()->create( + $this->owner->login, + $this->name, + array( + 'org' => $org + ) + ); + + return Repo::fromArray($data); + } + + public function forks($sort = null) + { + $data = $this->api('repo')->forks()->all( + $this->owner->login, + $this->name, + array( + 'sort' => $sort + ) + ); + + $forks = array(); + foreach ($data as $fork) { + $forks[] = Repo::fromArray($fork); + } + + return $forks; + } + + public function ref($ref) + { + $data = $this->api('git_data')->references()->show( + $this->owner->login, + $this->name, + $ref + ); + + return Ref::fromArray($data); + } + + public function removeRef($ref) + { + $this->api('git_data')->references()->remove( + $this->owner->login, + $this->name, + $ref + ); + + return true; + } +} diff --git a/lib/Github/Model/ReviewComment.php b/lib/Github/Model/ReviewComment.php new file mode 100644 index 00000000000..05a67255a5d --- /dev/null +++ b/lib/Github/Model/ReviewComment.php @@ -0,0 +1,76 @@ +hydrate($data); + } + + public function __construct(PullRequest $pull_request, $id) + { + $this->id = $id; + $this->pull_request = $pull_request; + } + + public function show() + { + $data = $this->api('pull_request')->comments()->show( + $this->pull_request->repo->owner->login, + $this->pull_request->repo->name, + $this->id + ); + + return ReviewComment::fromArray($this->pull_request, $data); + } + + public function update($body) + { + $data = $this->api('pull_request')->comments()->update( + $this->pull_request->repo->owner->login, + $this->pull_request->repo->name, + $this->id, + array('body' => $body) + ); + + return ReviewComment::fromArray($this->pull_request, $data); + } + + public function remove() + { + $this->api('pull_request')->comments()->remove( + $this->pull_request->repo->owner->login, + $this->pull_request->repo->name, + $this->id + ); + + return true; + } +} diff --git a/lib/Github/Model/Team.php b/lib/Github/Model/Team.php new file mode 100644 index 00000000000..f4599dd1793 --- /dev/null +++ b/lib/Github/Model/Team.php @@ -0,0 +1,172 @@ +hydrate($data); + } + + public function __construct(Owner $org, $id) + { + $this->org = $org; + $this->id = $id; + } + + public function show() + { + $data = $this->api('organization')->teams()->show( + $this->id + ); + + return Team::fromArray($this->org, $data); + } + + public function update(array $params) + { + $data = $this-api('organization')->teams()->update( + $this->id, + $params + ); + + return Team::fromArray($this->org, $data); + } + + public function remove() + { + $this->api('organization')->teams()->remove( + $this->id + ); + + return true; + } + + public function members() + { + $data = $this->api('organization')->teams()->members( + $this->id + ); + + $members = array(); + foreach ($data as $member) { + $members[] = User::fromArray($member); + } + + return $member; + } + + public function check($login) + { + try { + $this->api('organization')->teams()->check( + $this->id, + $login + ); + + return true; + } catch (\Exception $e) { + return false; + } + } + + public function addMember($login) + { + $this->api('organization')->teams()->addMember( + $this->id, + $login + ); + + return true; + } + + public function removeMember($login) + { + $this->api('organization')->teams()->removeMember( + $this->id, + $login + ); + + return true; + } + + public function repositories() + { + $data = $this->api('organization')->teams()->repositories( + $this->id + ); + + $repos = array(); + foreach ($data as $repo) { + $repos[] = Repo::fromArray($repo); + } + + return $repos; + } + + public function repository($repository) + { + if ($repository instanceof Repo) { + $repository = $repository->name; + } + + $data = $this->api('organization')->teams()->repository( + $this->id, + $this->org->login, + $repository + ); + + return Repo::fromArray($data); + } + + public function addRepository($repository) + { + if ($repository instanceof Repo) { + $repository = $repository->name; + } + + $this->api('organization')->teams()->addRepository( + $this->id, + $this->org->login, + $repository + ); + + return true; + } + + public function removeRepository($repository) + { + if ($repository instanceof Repo) { + $repository = $repository->name; + } + + $this->api('organization')->teams()->removeRepository( + $this->id, + $this->org->login, + $repository + ); + + return true; + } + +} diff --git a/lib/Github/Model/User.php b/lib/Github/Model/User.php new file mode 100644 index 00000000000..fbe113824a2 --- /dev/null +++ b/lib/Github/Model/User.php @@ -0,0 +1,11 @@ +