Skip to content
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
10 changes: 8 additions & 2 deletions src/Github/GithubProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MBO\RemoteGit\Github;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectVisibility;

/**
* Project implementation for github.
Expand Down Expand Up @@ -33,14 +34,19 @@ public function getDefaultBranch(): ?string
return $this->rawMetadata['default_branch'];
}

public function getHttpUrl(): string
{
return $this->rawMetadata['clone_url'];
}

public function isArchived(): bool
{
return $this->rawMetadata['archived'];
}

public function getHttpUrl(): string
public function getVisibility(): ?ProjectVisibility
{
return $this->rawMetadata['clone_url'];
return $this->rawMetadata['private'] ? ProjectVisibility::PRIVATE : ProjectVisibility::PUBLIC;
}

public function getRawMetadata(): array
Expand Down
16 changes: 16 additions & 0 deletions src/Gitlab/GitlabProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace MBO\RemoteGit\Gitlab;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectVisibility;
use RuntimeException;

/**
* Common project properties between different git project host (gitlab, github, etc.).
Expand Down Expand Up @@ -47,6 +49,20 @@ public function isArchived(): bool
return $this->rawMetadata['archived'];
}

public function getVisibility(): ?ProjectVisibility
{
switch ($this->rawMetadata['visibility']) {
case 'public':
return ProjectVisibility::PUBLIC;
case 'private':
return ProjectVisibility::PRIVATE;
case 'internal':
return ProjectVisibility::INTERNAL;
default:
throw new RuntimeException("Unknown visibility: {$this->rawMetadata['visibility']}");
}
}

public function getRawMetadata(): array
{
return $this->rawMetadata;
Expand Down
12 changes: 12 additions & 0 deletions src/Gogs/GogsProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MBO\RemoteGit\Gogs;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectVisibility;

/**
* Project implementation for github.
Expand Down Expand Up @@ -43,6 +44,17 @@ public function isArchived(): bool
return $this->rawMetadata['archived'];
}

public function getVisibility(): ?ProjectVisibility
{
if ($this->rawMetadata['private']) {
return ProjectVisibility::PRIVATE;
} elseif ($this->rawMetadata['internal']) {
return ProjectVisibility::INTERNAL;
} else {
return ProjectVisibility::PUBLIC;
}
}

public function getRawMetadata(): array
{
return $this->rawMetadata;
Expand Down
6 changes: 6 additions & 0 deletions src/Local/LocalProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MBO\RemoteGit\Local;

use MBO\RemoteGit\ProjectInterface;
use MBO\RemoteGit\ProjectVisibility;

/**
* Project corresponding to a local git folder.
Expand Down Expand Up @@ -41,6 +42,11 @@ public function isArchived(): bool
return false; // Always returns false for LocalClient
}

public function getVisibility(): ?ProjectVisibility
{
return null; // Always returns null for LocalClient
}

public function getRawMetadata(): array
{
return $this->rawMetadata;
Expand Down
7 changes: 7 additions & 0 deletions src/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public function getHttpUrl(): string;
*/
public function isArchived(): bool;

/**
* Get project visibility.
*
* @warning This method will always return null for LocalClient.
*/
public function getVisibility(): ?ProjectVisibility;

/**
* Get hosting service specific properties.
*
Expand Down
15 changes: 15 additions & 0 deletions src/ProjectVisibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace MBO\RemoteGit;

/**
* Represents the visibility of a project.
*
* Note that internal is not supported by GitHub
*/
enum ProjectVisibility: string
{
case PUBLIC = 'public';
case PRIVATE = 'private';
case INTERNAL = 'internal';
}
4 changes: 4 additions & 0 deletions tests/GithubClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MBO\RemoteGit\FindOptions;
use MBO\RemoteGit\Github\GithubClient;
use MBO\RemoteGit\Github\GithubProject;
use MBO\RemoteGit\ProjectVisibility;
use Psr\Log\NullLogger;

class GithubClientTest extends TestCase
Expand Down Expand Up @@ -95,6 +96,9 @@ public function testUserAndOrgsRepositories(): void

/* test isArchived */
$this->assertFalse($project->isArchived());

/* test getVisibility */
$this->assertEquals(ProjectVisibility::PUBLIC, $project->getVisibility());
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/GitlabClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MBO\RemoteGit\FindOptions;
use MBO\RemoteGit\Gitlab\GitlabClient;
use MBO\RemoteGit\Gitlab\GitlabProject;
use MBO\RemoteGit\ProjectVisibility;
use Psr\Log\NullLogger;

class GitlabClientTest extends TestCase
Expand Down Expand Up @@ -62,18 +63,24 @@ public function testGitlabDotComByUser(): void
);

$project = $projectsByName['mborne/sample-composer'];

/* test getDefaultBranch */
$defaultBranch = $project->getDefaultBranch();
$this->assertNotNull($defaultBranch);

/* test getRawFile */
$composer = $client->getRawFile(
$project,
'composer.json',
$defaultBranch
);
$this->assertStringContainsString('mborne@users.noreply.github.com', $composer);

/* test isArchived */
$this->assertFalse($project->isArchived());

/* test getVisibility */
$this->assertEquals(ProjectVisibility::PUBLIC, $project->getVisibility());
}

public function testGitlabDotComOrgs(): void
Expand Down Expand Up @@ -140,5 +147,8 @@ public function testGitlabDotComSearch(): void

/* test isArchived */
$this->assertFalse($project->isArchived());

/* test getVisibility */
$this->assertEquals(ProjectVisibility::PUBLIC, $project->getVisibility());
}
}
4 changes: 4 additions & 0 deletions tests/GogsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MBO\RemoteGit\FindOptions;
use MBO\RemoteGit\Gogs\GogsClient;
use MBO\RemoteGit\Gogs\GogsProject;
use MBO\RemoteGit\ProjectVisibility;

/**
* Test GogsClient with https://codes.quadtreeworld.net which is a gitea instance.
Expand Down Expand Up @@ -125,5 +126,8 @@ public function testFindByUserAndOrgs(): void

/* test isArchived */
$this->assertFalse($project->isArchived());

/* test getVisibility */
$this->assertEquals(ProjectVisibility::PUBLIC, $project->getVisibility());
}
}
11 changes: 11 additions & 0 deletions tests/LocalClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ public function testIsArchived(): void
}
}

/**
* Ensure that isArchived returns public.
*/
public function testGetVisibility(): void
{
$projects = $this->findAllProjects();
foreach ($projects as $project) {
$this->assertNull($project->getVisibility());
}
}

/**
* Check that raw file content can be retreived from non bare repository.
*/
Expand Down