Skip to content

feat: Add visibility option to repo create #1038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -195,15 +196,16 @@ public function create(
$hasDownloads = false,
$teamId = null,
$autoInit = false,
$hasProjects = true
$hasProjects = true,
$visibility = null
) {
$path = null !== $organization ? '/orgs/'.$organization.'/repos' : '/user/repos';

$parameters = [
'name' => $name,
'description' => $description,
'homepage' => $homepage,
'private' => !$public,
'visibility' => $visibility ?? ($public ? 'public' : 'private'),
'has_issues' => $hasIssues,
'has_wiki' => $hasUncyclo,
'has_downloads' => $hasDownloads,
Expand Down
48 changes: 45 additions & 3 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function shouldCreateRepositoryUsingNameOnly()
'name' => 'l3l0Repo',
'description' => '',
'homepage' => '',
'private' => false,
'visibility' => 'public',
'has_issues' => false,
'has_wiki' => false,
'has_downloads' => false,
Expand All @@ -121,7 +121,7 @@ public function shouldCreateRepositoryForOrganization()
'name' => 'KnpLabsRepo',
'description' => '',
'homepage' => '',
'private' => false,
'visibility' => 'public',
'has_issues' => false,
'has_wiki' => false,
'has_downloads' => false,
Expand All @@ -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
*/
Expand Down Expand Up @@ -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,
Expand Down