Skip to content

Commit a78ae66

Browse files
committed
feat: Add visibility option to repo create
1 parent de2f278 commit a78ae66

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

lib/Github/Api/Repo.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public function showById($id)
181181
* @param int $teamId The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization.
182182
* @param bool $autoInit `true` to create an initial commit with empty README, `false` for no initial commit
183183
* @param bool $hasProjects `true` to enable projects for this repository or false to disable them.
184+
* @param string|null $visibility
184185
*
185186
* @return array returns repository data
186187
*/
@@ -195,15 +196,16 @@ public function create(
195196
$hasDownloads = false,
196197
$teamId = null,
197198
$autoInit = false,
198-
$hasProjects = true
199+
$hasProjects = true,
200+
$visibility = null
199201
) {
200202
$path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos';
201203

202204
$parameters = [
203205
'name' => $name,
204206
'description' => $description,
205207
'homepage' => $homepage,
206-
'private' => !$public,
208+
'visibility' => $visibility ?? ($public ? 'public' : 'private'),
207209
'has_issues' => $hasIssues,
208210
'has_wiki' => $hasUncyclo,
209211
'has_downloads' => $hasDownloads,

test/Github/Tests/Api/RepoTest.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function shouldCreateRepositoryUsingNameOnly()
9595
'name' => 'l3l0Repo',
9696
'description' => '',
9797
'homepage' => '',
98-
'private' => false,
98+
'visibility' => 'public',
9999
'has_issues' => false,
100100
'has_wiki' => false,
101101
'has_downloads' => false,
@@ -121,7 +121,7 @@ public function shouldCreateRepositoryForOrganization()
121121
'name' => 'KnpLabsRepo',
122122
'description' => '',
123123
'homepage' => '',
124-
'private' => false,
124+
'visibility' => 'public',
125125
'has_issues' => false,
126126
'has_wiki' => false,
127127
'has_downloads' => false,
@@ -133,6 +133,48 @@ public function shouldCreateRepositoryForOrganization()
133133
$this->assertEquals($expectedArray, $api->create('KnpLabsRepo', '', '', true, 'KnpLabs'));
134134
}
135135

136+
/**
137+
* @test
138+
*/
139+
public function shouldCreateRepositoryWithInternalVisibility()
140+
{
141+
$expectedArray = ['id' => 1, 'name' => 'KnpLabsRepo'];
142+
143+
$api = $this->getApiMock();
144+
$api->expects($this->once())
145+
->method('post')
146+
->with('/user/repos', [
147+
'name' => 'KnpLabsRepo',
148+
'description' => '',
149+
'homepage' => '',
150+
'has_issues' => false,
151+
'has_wiki' => false,
152+
'has_downloads' => false,
153+
'auto_init' => false,
154+
'has_projects' => true,
155+
'visibility' => 'internal',
156+
])
157+
->will($this->returnValue($expectedArray));
158+
159+
$this->assertEquals(
160+
$expectedArray,
161+
$api->create(
162+
'KnpLabsRepo',
163+
'',
164+
'',
165+
false,
166+
null,
167+
false,
168+
false,
169+
false,
170+
null,
171+
false,
172+
true,
173+
'internal'
174+
)
175+
);
176+
}
177+
136178
/**
137179
* @test
138180
*/
@@ -329,7 +371,7 @@ public function shouldCreateUsingAllParams()
329371
'name' => 'l3l0Repo',
330372
'description' => 'test',
331373
'homepage' => 'http://l3l0.eu',
332-
'private' => true,
374+
'visibility' => 'private',
333375
'has_issues' => false,
334376
'has_wiki' => false,
335377
'has_downloads' => false,

0 commit comments

Comments
 (0)