Skip to content

Commit

Permalink
Tidy up Owner::createRepo() to use \Api\Repo->create() properly
Browse files Browse the repository at this point in the history
Standardized responses (addresses #1)
  • Loading branch information
m4tthumphrey committed Nov 16, 2012
1 parent df4d267 commit f7f6473
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 40 deletions.
8 changes: 6 additions & 2 deletions lib/Github/Model/DeployKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Repo $repo, $id)

public function update($title, $key)
{
return $this->api('repo')->keys()->update(
$data = $this->api('repo')->keys()->update(
$this->repo->owner->name,
$this->repo->name,
$this->id,
Expand All @@ -35,14 +35,18 @@ public function update($title, $key)
'key' => $key
)
);

return DeployKey::fromArray($this->repo, $data);
}

public function remove()
{
return $this->api('repo')->keys()->remove(
$this->api('repo')->keys()->remove(
$this->repo->owner->name,
$this->repo->name,
$this->id
);

return true;
}
}
19 changes: 16 additions & 3 deletions lib/Github/Model/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ class Hook extends AbstractModel
'events',
'active',
'config',
'id'
'id',
'last_response'
);

public static function fromArray(Repo $repo, array $data)
{
$hook = Hook::factory($repo, $data['id']);

if (isset($data['last_response'])) {
$data['last_response'] = (object) $data['last_response'];
}

if (isset($data['config'])) {
$data['config'] = (object) $data['config'];
}

return $hook->hydrate($data);
}

Expand Down Expand Up @@ -54,20 +63,24 @@ public function update(array $params)

public function remove()
{
return $this->api('repo')->hooks()->remove(
$this->api('repo')->hooks()->remove(
$this->repo->owner->login,
$this->repo->name,
$this->id
);

return true;
}

public function test()
{
return $this->api('repo')->hooks()->test(
$this->api('repo')->hooks()->test(
$this->repo->owner->login,
$this->repo->name,
$this->id
);

return true;
}

}
2 changes: 1 addition & 1 deletion lib/Github/Model/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function updateMilestone($number, array $data)

public function removeMilestone($number)
{
return Milestone::factory($this, $number)->remove();
return Milestone::factory($this, $number)->remove();
}

public function comments($page = 1)
Expand Down
4 changes: 2 additions & 2 deletions lib/Github/Model/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(Repo $repo, $name)
public function update($name, $color)
{
$data = $this->api('repo')->labels()->update(
$this->owner->name,
$this->repo->owner->login,
$this->repo->name,
$this->name,
array(
Expand All @@ -42,7 +42,7 @@ public function update($name, $color)
public function remove()
{
$this->api('repo')->labels()->remove(
$this->owner->name,
$this->repo->owner->login,
$this->repo->name,
$this->name
);
Expand Down
6 changes: 4 additions & 2 deletions lib/Github/Model/Org.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

class Org extends Owner implements OwnerInterface
{
public function getCreateRepoPath()
public function createRepo($name, array $params = array())
{
return 'orgs/'.$this->name.'/repos';
$params['organization'] = $this->login;

return parent::createRepo($name, $params);
}

public function show()
Expand Down
17 changes: 7 additions & 10 deletions lib/Github/Model/Owner.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,18 @@ public function repo($name)
public function createRepo($name, array $params = array())
{
$params = array_merge(array(
'name' => $name,
'description' => null,
'homepage' => null,
'public' => true,
'has_issues' => true,
'has_wiki' => true,
'has_downloads' => true,
'team_id' => null,
'auto_init' => false,
'gitignore_template' => null
'organization' => null
), $params);

$data = $this->api('repo')->post(
$this->getCreateRepoPath(),
$params
$data = $this->api('repo')->create(
$name,
$params['description'],
$params['homepage'],
$params['public'],
$params['organization']
);

return Repo::fromArray($data);
Expand Down
1 change: 0 additions & 1 deletion lib/Github/Model/OwnerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

interface OwnerInterface
{
public function getCreateRepoPath();
}
13 changes: 11 additions & 2 deletions lib/Github/Model/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function issues(array $params = array())

public function issue($number)
{
return Issue::factory($this, $number)->show();
return Issue::factory($this, $number)->show();
}

public function labels()
Expand Down Expand Up @@ -181,14 +181,23 @@ public function addLabel($name, $color)

public function updateLabel($name, $color)
{
return Label::factory($this, $name)->update($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(
Expand Down
48 changes: 35 additions & 13 deletions lib/Github/Model/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public function update(array $params)

public function remove()
{
return $this->api('organization')->teams()->remove(
$this->api('organization')->teams()->remove(
$this->id
);

return true;
}

public function members()
Expand All @@ -69,26 +71,32 @@ public function members()

public function check($login)
{
return $this->api('organization')->teams()->check(
$this->api('organization')->teams()->check(
$this->id,
$login
);

return true;
}

public function addMember($login)
{
return $this->api('organization')->teams()->addMember(
$this->api('organization')->teams()->addMember(
$this->id,
$login
);

return true;
}

public function removeMember($login)
{
return $this->api('organization')->teams()->removeMember(
$this->api('organization')->teams()->removeMember(
$this->id,
$login
);

return true;
}

public function repositories()
Expand All @@ -105,35 +113,49 @@ public function repositories()
return $repos;
}

public function repository($login, $repository)
public function repository($repository)
{
if ($repository instanceof Repo) {
$repository = $repository->name;
}

$data = $this->api('organization')->teams()->repository(
$this->id,
$login,
$this->org->login,
$repository
);

return Repo::fromArray($data);
}

public function addRepository($login, $repository)
public function addRepository($repository)
{
$data = $this->api('organization')->teams()->addRepository(
if ($repository instanceof Repo) {
$repository = $repository->name;
}

$this->api('organization')->teams()->addRepository(
$this->id,
$login,
$this->org->login,
$repository
);

return Repo::fromArray($data);
return true;
}

public function removeRepository($login, $repository)
public function removeRepository($repository)
{
return $this->api('organization')->teams()->removeRepository(
if ($repository instanceof Repo) {
$repository = $repository->name;
}

$this->api('organization')->teams()->removeRepository(
$this->id,
$login,
$this->org->login,
$repository
);

return true;
}

}
4 changes: 0 additions & 4 deletions lib/Github/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@

class User extends Owner implements OwnerInterface
{
public function getCreateRepoPath()
{
return '/user/repos';
}
}

0 comments on commit f7f6473

Please sign in to comment.