Skip to content

Commit f7f6473

Browse files
committed
Tidy up Owner::createRepo() to use \Api\Repo->create() properly
Standardized responses (addresses #1)
1 parent df4d267 commit f7f6473

File tree

10 files changed

+82
-40
lines changed

10 files changed

+82
-40
lines changed

lib/Github/Model/DeployKey.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(Repo $repo, $id)
2626

2727
public function update($title, $key)
2828
{
29-
return $this->api('repo')->keys()->update(
29+
$data = $this->api('repo')->keys()->update(
3030
$this->repo->owner->name,
3131
$this->repo->name,
3232
$this->id,
@@ -35,14 +35,18 @@ public function update($title, $key)
3535
'key' => $key
3636
)
3737
);
38+
39+
return DeployKey::fromArray($this->repo, $data);
3840
}
3941

4042
public function remove()
4143
{
42-
return $this->api('repo')->keys()->remove(
44+
$this->api('repo')->keys()->remove(
4345
$this->repo->owner->name,
4446
$this->repo->name,
4547
$this->id
4648
);
49+
50+
return true;
4751
}
4852
}

lib/Github/Model/Hook.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ class Hook extends AbstractModel
1313
'events',
1414
'active',
1515
'config',
16-
'id'
16+
'id',
17+
'last_response'
1718
);
1819

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

24+
if (isset($data['last_response'])) {
25+
$data['last_response'] = (object) $data['last_response'];
26+
}
27+
28+
if (isset($data['config'])) {
29+
$data['config'] = (object) $data['config'];
30+
}
31+
2332
return $hook->hydrate($data);
2433
}
2534

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

5564
public function remove()
5665
{
57-
return $this->api('repo')->hooks()->remove(
66+
$this->api('repo')->hooks()->remove(
5867
$this->repo->owner->login,
5968
$this->repo->name,
6069
$this->id
6170
);
71+
72+
return true;
6273
}
6374

6475
public function test()
6576
{
66-
return $this->api('repo')->hooks()->test(
77+
$this->api('repo')->hooks()->test(
6778
$this->repo->owner->login,
6879
$this->repo->name,
6980
$this->id
7081
);
82+
83+
return true;
7184
}
7285

7386
}

lib/Github/Model/Issue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function updateMilestone($number, array $data)
201201

202202
public function removeMilestone($number)
203203
{
204-
return Milestone::factory($this, $number)->remove();
204+
return Milestone::factory($this, $number)->remove();
205205
}
206206

207207
public function comments($page = 1)

lib/Github/Model/Label.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(Repo $repo, $name)
2727
public function update($name, $color)
2828
{
2929
$data = $this->api('repo')->labels()->update(
30-
$this->owner->name,
30+
$this->repo->owner->login,
3131
$this->repo->name,
3232
$this->name,
3333
array(
@@ -42,7 +42,7 @@ public function update($name, $color)
4242
public function remove()
4343
{
4444
$this->api('repo')->labels()->remove(
45-
$this->owner->name,
45+
$this->repo->owner->login,
4646
$this->repo->name,
4747
$this->name
4848
);

lib/Github/Model/Org.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
class Org extends Owner implements OwnerInterface
66
{
7-
public function getCreateRepoPath()
7+
public function createRepo($name, array $params = array())
88
{
9-
return 'orgs/'.$this->name.'/repos';
9+
$params['organization'] = $this->login;
10+
11+
return parent::createRepo($name, $params);
1012
}
1113

1214
public function show()

lib/Github/Model/Owner.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,18 @@ public function repo($name)
5151
public function createRepo($name, array $params = array())
5252
{
5353
$params = array_merge(array(
54-
'name' => $name,
5554
'description' => null,
5655
'homepage' => null,
5756
'public' => true,
58-
'has_issues' => true,
59-
'has_wiki' => true,
60-
'has_downloads' => true,
61-
'team_id' => null,
62-
'auto_init' => false,
63-
'gitignore_template' => null
57+
'organization' => null
6458
), $params);
6559

66-
$data = $this->api('repo')->post(
67-
$this->getCreateRepoPath(),
68-
$params
60+
$data = $this->api('repo')->create(
61+
$name,
62+
$params['description'],
63+
$params['homepage'],
64+
$params['public'],
65+
$params['organization']
6966
);
7067

7168
return Repo::fromArray($data);

lib/Github/Model/OwnerInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44

55
interface OwnerInterface
66
{
7-
public function getCreateRepoPath();
87
}

lib/Github/Model/Repo.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function issues(array $params = array())
135135

136136
public function issue($number)
137137
{
138-
return Issue::factory($this, $number)->show();
138+
return Issue::factory($this, $number)->show();
139139
}
140140

141141
public function labels()
@@ -181,14 +181,23 @@ public function addLabel($name, $color)
181181

182182
public function updateLabel($name, $color)
183183
{
184-
return Label::factory($this, $name)->update($name, $color);
184+
return Label::factory($this, $name)->update($name, $color);
185185
}
186186

187187
public function removeLabel($name)
188188
{
189189
return Label::factory($this, $name)->remove($name);
190190
}
191191

192+
public function removeLabels()
193+
{
194+
foreach ($this->labels() as $label) {
195+
$label->remove();
196+
}
197+
198+
return true;
199+
}
200+
192201
public function keys()
193202
{
194203
$data = $this->api('repo')->keys()->all(

lib/Github/Model/Team.php

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ public function update(array $params)
4848

4949
public function remove()
5050
{
51-
return $this->api('organization')->teams()->remove(
51+
$this->api('organization')->teams()->remove(
5252
$this->id
5353
);
54+
55+
return true;
5456
}
5557

5658
public function members()
@@ -69,26 +71,32 @@ public function members()
6971

7072
public function check($login)
7173
{
72-
return $this->api('organization')->teams()->check(
74+
$this->api('organization')->teams()->check(
7375
$this->id,
7476
$login
7577
);
78+
79+
return true;
7680
}
7781

7882
public function addMember($login)
7983
{
80-
return $this->api('organization')->teams()->addMember(
84+
$this->api('organization')->teams()->addMember(
8185
$this->id,
8286
$login
8387
);
88+
89+
return true;
8490
}
8591

8692
public function removeMember($login)
8793
{
88-
return $this->api('organization')->teams()->removeMember(
94+
$this->api('organization')->teams()->removeMember(
8995
$this->id,
9096
$login
9197
);
98+
99+
return true;
92100
}
93101

94102
public function repositories()
@@ -105,35 +113,49 @@ public function repositories()
105113
return $repos;
106114
}
107115

108-
public function repository($login, $repository)
116+
public function repository($repository)
109117
{
118+
if ($repository instanceof Repo) {
119+
$repository = $repository->name;
120+
}
121+
110122
$data = $this->api('organization')->teams()->repository(
111123
$this->id,
112-
$login,
124+
$this->org->login,
113125
$repository
114126
);
115127

116128
return Repo::fromArray($data);
117129
}
118130

119-
public function addRepository($login, $repository)
131+
public function addRepository($repository)
120132
{
121-
$data = $this->api('organization')->teams()->addRepository(
133+
if ($repository instanceof Repo) {
134+
$repository = $repository->name;
135+
}
136+
137+
$this->api('organization')->teams()->addRepository(
122138
$this->id,
123-
$login,
139+
$this->org->login,
124140
$repository
125141
);
126142

127-
return Repo::fromArray($data);
143+
return true;
128144
}
129145

130-
public function removeRepository($login, $repository)
146+
public function removeRepository($repository)
131147
{
132-
return $this->api('organization')->teams()->removeRepository(
148+
if ($repository instanceof Repo) {
149+
$repository = $repository->name;
150+
}
151+
152+
$this->api('organization')->teams()->removeRepository(
133153
$this->id,
134-
$login,
154+
$this->org->login,
135155
$repository
136156
);
157+
158+
return true;
137159
}
138160

139161
}

lib/Github/Model/User.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,4 @@
44

55
class User extends Owner implements OwnerInterface
66
{
7-
public function getCreateRepoPath()
8-
{
9-
return '/user/repos';
10-
}
117
}

0 commit comments

Comments
 (0)