Skip to content

Commit

Permalink
Enrich Project model
Browse files Browse the repository at this point in the history
  • Loading branch information
jmleroux committed Mar 15, 2023
1 parent 03a7381 commit 12cae31
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Jmleroux\CircleCi\Model;

use Jmleroux\CircleCi\Model\Project\VcsInfo;

/**
* @author jmleroux <[email protected]>
* @link https://circleci.com/docs/api/#get-all-followed-projects
Expand All @@ -12,10 +14,8 @@ class Project implements ApiResultInterface
{
/**
* Raw object from Circle CI API
*
* @var \stdClass
*/
private $rawObject;
private \stdClass $rawObject;

private function __construct(\stdClass $rawObject)
{
Expand All @@ -32,28 +32,38 @@ public function rawValues(): \stdClass
return $this->rawObject;
}

public function vcsUrl(): string
public function slug(): string
{
return $this->rawObject->slug;
}

public function name(): string
{
return $this->rawObject->slug;
}

public function id(): string
{
return $this->rawObject->vcs_url;
return $this->rawObject->slug;
}

public function followed(): bool
public function organizationName(): string
{
return $this->rawObject->followed ?? false;
return $this->rawObject->organization_name;
}

public function username(): string
public function organizationSlug(): string
{
return $this->rawObject->username;
return $this->rawObject->organization_slug;
}

public function reponame(): string
public function organizationId(): string
{
return $this->rawObject->reponame;
return $this->rawObject->organization_id;
}

public function branches(): \stdClass
public function vcsInfo(): VcsInfo
{
return $this->rawObject->branches;
return VcsInfo::createFromApi($this->rawObject->vcs_info);
}
}
47 changes: 47 additions & 0 deletions src/Model/Project/VcsInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Jmleroux\CircleCi\Model\Project;

use Jmleroux\CircleCi\Model\ApiResultInterface;
use Jmleroux\CircleCi\Model\Pipeline\Vcs\Commit;

/**
* @author Brice Le Boulch <[email protected]>
* @link https://circleci.com/docs/api/v2/index.html#operation/getPipelineById
*/
final class VcsInfo implements ApiResultInterface
{
private \stdClass $rawObject;

private function __construct(\stdClass $rawObject)
{
$this->rawObject = $rawObject;
}

public static function createFromApi(\stdClass $rawObject): self
{
return new self($rawObject);
}

public function rawValues(): \stdClass
{
return $this->rawObject;
}

public function vcsUrl(): string
{
return $this->rawObject->vcs_url;
}

public function provider(): string
{
return $this->rawObject->provider;
}

public function defaultBranch(): string
{
return $this->rawObject->default_branch;
}
}

0 comments on commit 12cae31

Please sign in to comment.