diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index 5119d772b8e..4d8c012ff3e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -181,6 +181,7 @@ public function showById($id) * @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. * @param bool $autoInit `true` to create an initial commit with empty README, `false` for no initial commit * @param bool $hasProjects `true` to enable projects for this repository or false to disable them. + * @param string|null $visibility * * @return array returns repository data */ @@ -195,7 +196,8 @@ public function create( $hasDownloads = false, $teamId = null, $autoInit = false, - $hasProjects = true + $hasProjects = true, + $visibility = null ) { $path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos'; @@ -203,7 +205,7 @@ public function create( 'name' => $name, 'description' => $description, 'homepage' => $homepage, - 'private' => !$public, + 'visibility' => $visibility ?? ($public ? 'public' : 'private'), 'has_issues' => $hasIssues, 'has_wiki' => $hasWiki, 'has_downloads' => $hasDownloads, diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 3761b2efb7e..a934bc6b906 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -95,7 +95,7 @@ public function shouldCreateRepositoryUsingNameOnly() 'name' => 'l3l0Repo', 'description' => '', 'homepage' => '', - 'private' => false, + 'visibility' => 'public', 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, @@ -121,7 +121,7 @@ public function shouldCreateRepositoryForOrganization() 'name' => 'KnpLabsRepo', 'description' => '', 'homepage' => '', - 'private' => false, + 'visibility' => 'public', 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false, @@ -133,6 +133,48 @@ public function shouldCreateRepositoryForOrganization() $this->assertEquals($expectedArray, $api->create('KnpLabsRepo', '', '', true, 'KnpLabs')); } + /** + * @test + */ + public function shouldCreateRepositoryWithInternalVisibility() + { + $expectedArray = ['id' => 1, 'name' => 'KnpLabsRepo']; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/user/repos', [ + 'name' => 'KnpLabsRepo', + 'description' => '', + 'homepage' => '', + 'has_issues' => false, + 'has_wiki' => false, + 'has_downloads' => false, + 'auto_init' => false, + 'has_projects' => true, + 'visibility' => 'internal', + ]) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals( + $expectedArray, + $api->create( + 'KnpLabsRepo', + '', + '', + false, + null, + false, + false, + false, + null, + false, + true, + 'internal' + ) + ); + } + /** * @test */ @@ -329,7 +371,7 @@ public function shouldCreateUsingAllParams() 'name' => 'l3l0Repo', 'description' => 'test', 'homepage' => 'http://l3l0.eu', - 'private' => true, + 'visibility' => 'private', 'has_issues' => false, 'has_wiki' => false, 'has_downloads' => false,