use App\Models\User;
use App\Support\GitRepository;
use Github\AuthMethod;
use Github\Client;
class WithGithubApi implements CreateRepositoryContract
{
public function __construct(
protected readonly Client $github
) {
}
public function handle(GitRepository $target): array
{
if (null === $target->isOrganisation) {
throw new \InvalidArgumentException('isOrganisation parameter is required.');
}
if (null === $target->public) {
throw new \InvalidArgumentException('public parameter is required.');
}
return $this->github
->api('repo')
->create(
$target->name,
'This is the description of a repo',
public: $target->public,
organization: $target->isOrganisation ? $target->owner : null,
);
}
public function authorize(User $user): void
{
$this->github->authenticate($user->token, AuthMethod::ACCESS_TOKEN);
}
}