Search by

adachsoft / repo-gen

Arkadiusz Adach

Tools for repository generation

Package info

gitlab.com/a.adach/repo-gen

Issues

pkg:composer/adachsoft/repo-gen

Statistics

Installs: 50

Dependents: 0

Suggesters: 0

Stars: 0

v0.6.0 2026-11-24 13:09 UTC

This package is auto-updated.

Last update: 2026-11-24 12:10:03 UTC


README

Repo Gen is a PHP library for bootstrapping new Git repositories for PHP libraries. It automates repository setup from templates, supports GitLab and GitHub through adachsoft/git-platform, and can optionally register packages on Packagist.

The core entry point is RepoGenFacadeInterface, which supports repository initialization, remote repository creation and member management, and Packagist package creation.

Features

  • Initialize a new Git repository from filesystem templates
  • Choose a custom project path, a per-repository template directory, or skip template copying
  • Create remote repositories on GitLab or GitHub through adachsoft/git-platform
  • Configure multiple hosting accounts and select a platform for each operation
  • Initialize a local Git repository, commit generated files and push to the remote
  • Register the repository as a package on Packagist
  • Add repository members and accept GitHub invitations
  • Use SSH host aliases from ~/.ssh/config for Git remotes
  • Simple factory for wiring all dependencies (RepoGenFacadeFactory)
  • CLI helper script bin_dev/initialize_repository for quick manual usage

Installation

Install via Composer:

composer require adachsoft/repo-gen

Note: The package name above assumes the library is published as adachsoft/repo-gen. Adjust it if your fork uses a different vendor or package name.

Requirements

  • PHP ^8.3, as required by composer.json
  • Git installed and available on the command line
  • An access token for every GitLab or GitHub platform account you use
  • Optional: Packagist account and API token for automatic package registration

Basic usage (Facade)

The main entry point is AdachSoft\RepoGen\RepoGenFacadeInterface. You can obtain an instance using the RepoGenFacadeFactory and a configuration DTO:

use AdachSoft\GitPlatform\Infrastructure\GitHub\Enum\GitHubOwnerTypeEnum;
use AdachSoft\GitPlatform\Infrastructure\GitHub\GitHubConfigDto;
use AdachSoft\GitPlatform\Infrastructure\GitLab\GitLabConfigDto;
use AdachSoft\RepoGen\Config\PlatformConfigDto;
use AdachSoft\RepoGen\Config\RepoGenConfigDto;
use AdachSoft\RepoGen\Dto\CreatePackagistPackageDto;
use AdachSoft\RepoGen\Dto\InitRepositoryDto;
use AdachSoft\RepoGen\Factory\RepoGenFacadeFactory;

$platforms = [
    'gitlab' => new PlatformConfigDto(
        gitPlatformConfig: new GitLabConfigDto(
            baseUrl: getenv('GIT_LAB_BASE_URL') ?: 'https://gitlab.com',
            accessToken: getenv('GIT_LAB_KEY') ?: '',
        ),
        namespace: getenv('GIT_LAB_NAMESPACE') ?: 'your-gitlab-namespace',
        sshHost: getenv('GIT_LAB_SSH_HOST') ?: 'gitlab.com',
    ),
    'github' => new PlatformConfigDto(
        gitPlatformConfig: new GitHubConfigDto(
            accessToken: getenv('GITHUB_TOKEN') ?: '',
            owner: 'your-github-owner',
            ownerType: GitHubOwnerTypeEnum::USER,
        ),
        namespace: 'your-github-owner',
        sshHost: getenv('GITHUB_SSH_HOST') ?: 'github.com',
    ),
    'github_ai' => new PlatformConfigDto(
        gitPlatformConfig: new GitHubConfigDto(
            accessToken: getenv('GITHUB_AI_TOKEN') ?: '',
            owner: 'your-github-owner',
            ownerType: GitHubOwnerTypeEnum::USER,
        ),
        namespace: 'your-github-owner',
        sshHost: 'github-ai',
    ),
];

$config = new RepoGenConfigDto(
    basePath: '/var/www',
    platforms: $platforms,
    defaultPlatform: 'gitlab',
    packagistUsername: getenv('PACKAGIST_USERNAME') ?: '',
    packagistApiToken: getenv('PACKAGIST_API_TOKEN') ?: '',
    templateDirectory: __DIR__ . '/var/templates/php-library-default',
    defaultVisibility: 'public',
);

$facade = RepoGenFacadeFactory::createWithDependencies($config)->create();

// Initialize repository (local + remote)
$repositoryDto = $facade->initializeRepository(
    new InitRepositoryDto(
        name: 'my-library',
        description: 'My first library generated with Repo Gen',
        visibility: 'public',
    ),
);

// Optionally register on Packagist
$facade->createPackagistPackage(
    new CreatePackagistPackageDto(
        repositoryUrl: $repositoryDto->url ?? 'https://gitlab.com/your-namespace/my-library.git',
    ),
);

Platforms and SSH host aliases

Platform identifiers are arbitrary keys in the platforms map; names such as gitlab, github, and github_ai are examples. A platform's namespace prefixes bare repository names when Repo Gen resolves a remote repository identifier. The configured sshHost is used verbatim in the SSH remote URL, so it can be an alias from ~/.ssh/config.

For example, this SSH configuration maps the github-ai alias to GitHub while selecting a dedicated key:

Host github-ai
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github_ai
    IdentitiesOnly yes

Use sshHost: 'github-ai' for the corresponding PlatformConfigDto entry to create remotes such as git@github-ai:owner/repository.git.

Choosing a platform for each operation

InitRepositoryDto, CreateRemoteRepositoryDto, and AddRemoteRepositoryMemberDto each accept an optional platform identifier. Omitting it (null) selects RepoGenConfigDto::defaultPlatform. A platform identifier that is not configured results in AdachSoft\RepoGen\Exception\UnknownPlatformException when the platform registry resolves it.

use AdachSoft\RepoGen\Dto\AddRemoteRepositoryMemberDto;
use AdachSoft\RepoGen\Dto\CreateRemoteRepositoryDto;
use AdachSoft\RepoGen\Dto\InitRepositoryDto;

$facade->createRemoteRepository(
    new CreateRemoteRepositoryDto(name: 'my-github-library', platform: 'github'),
);

$facade->initializeRepository(
    new InitRepositoryDto(name: 'my-gitlab-library', platform: 'gitlab'),
);

$facade->addRemoteRepositoryMember(
    new AddRemoteRepositoryMemberDto(
        repositoryId: 'my-library',
        username: 'contributor',
        platform: 'github',
    ),
);

Custom project paths and templates

InitRepositoryDto accepts optional projectPath, templateDirectory, and skipTemplate arguments:

$repositoryDto = $facade->initializeRepository(
    new InitRepositoryDto(
        name: 'my-node-library',
        projectPath: '/var/www/my-node-library',
        templateDirectory: __DIR__ . '/templates/node-library',
    ),
);

projectPath is the absolute destination directory and can be outside the configured basePath. When omitted, Repo Gen uses <basePath>/<name>, preserving the default behavior. templateDirectory selects a filesystem template directory for this initialization; when omitted, the configured template provider is used.

Set skipTemplate: true to skip template loading and copying entirely, including when templateDirectory is also set:

$facade->initializeRepository(
    new InitRepositoryDto(
        name: 'generated-by-workflow',
        projectPath: '/var/www/generated-by-workflow',
        skipTemplate: true,
    ),
);

Creating only a remote repository

To create a remote repository without creating a local directory or running git init, commit, or push, use createRemoteRepository():

use AdachSoft\RepoGen\Dto\CreateRemoteRepositoryDto;
use AdachSoft\RepoGen\Factory\RepoGenFacadeFactory;

$facade = RepoGenFacadeFactory::createWithDependencies($config)->create();
$remoteRepository = $facade->createRemoteRepository(
    new CreateRemoteRepositoryDto(
        name: 'my-lib',
        visibility: 'public',
    ),
);

echo $remoteRepository->sshRemoteUrl;

This method creates only the remote repository. It does not create a local directory or a commit. The defaultBranch is null until the first push creates a branch on the hosting service. The returned RemoteRepositoryDto includes the resolved platform identifier.

Adding a member to a remote repository

addRemoteRepositoryMember() returns a RemoteRepositoryMemberResultDto containing the resolved platform, repository ID, username, status (added or invited), and an optional invitation ID:

use AdachSoft\RepoGen\Dto\AddRemoteRepositoryMemberDto;

$result = $facade->addRemoteRepositoryMember(
    new AddRemoteRepositoryMemberDto(
        repositoryId: 'my-library',
        username: 'contributor',
        role: 'developer',
        platform: 'github',
    ),
);

echo $result->status;

Supported roles are guest, reporter, developer, maintainer (the default), and owner. When repositoryId is a repository name without a path or numeric ID, Repo Gen prefixes the selected platform's namespace. Full repository paths and numeric IDs are used as provided. GitHub creates an invitation for a user who is not already a collaborator, so the result has status invited and can include an invitationId.

Accept an invitation using the configured platform entry that contains the invited member's token:

use AdachSoft\RepoGen\Dto\AcceptRemoteRepositoryInvitationDto;

$facade->acceptRemoteRepositoryInvitation(
    new AcceptRemoteRepositoryInvitationDto(
        repositoryId: 'repository-owner/my-library',
        platform: 'github_ai',
    ),
);

For a member account, configure that platform entry's namespace as the repository owner or pass a full owner/name repository ID as above. GitLab does not support invitation acceptance; the operation reports RemoteRepositoryMemberException through its invitationNotSupported factory. Invalid arguments, unsupported roles, and provider failures are also reported through RemoteRepositoryMemberException.

CLI helper

For quick manual usage there is a CLI helper script. The selected platform defaults to gitlab:

php bin_dev/initialize_repository \
    --base_path=/var/www \
    --name=my-library \
    --description="My awesome library" \
    --visibility=public \
    --platform=github

The script reads configuration from environment variables (optionally via .env):

  • GIT_LAB_KEY – GitLab access token.
  • GIT_LAB_BASE_URL – GitLab API base URL; defaults to https://gitlab.com.
  • GIT_LAB_NAMESPACE – GitLab namespace; falls back to PACKAGIST_USERNAME and is required if that is empty.
  • GIT_LAB_SSH_HOST – GitLab SSH host or alias; defaults to gitlab.com.
  • GITHUB_TOKEN – when set, enables the GitHub platform and requires GITHUB_OWNER.
  • GITHUB_OWNER – GitHub user or organization that owns the repositories.
  • GITHUB_OWNER_TYPE – user or organization; defaults to user.
  • GITHUB_SSH_HOST – GitHub SSH host or alias; defaults to github.com.
  • PACKAGIST_USERNAME and PACKAGIST_API_TOKEN – Packagist credentials; the username is also the GitLab namespace fallback.
  • --platform=<id> – selects a configured platform for initialization; defaults to gitlab.

The helper builds the configured platform map, calls RepoGenFacadeInterface::initializeRepository(), and prints the resolved platform and SSH remote URL.

Upgrading from 0.5

  • Replace the GitLab-only RepoGenConfigDto arguments (gitLabBaseUrl, gitLabAccessToken, gitLabNamespace, and gitLabSshHost) with the platforms map and defaultPlatform.
  • Replace GitLabSshRemoteUrlResolver with SshRemoteUrlResolver; custom RemoteUrlResolverInterface::resolve() implementations must accept PlatformConfigDto.
  • Update code using addRemoteRepositoryMember(), which now returns RemoteRepositoryMemberResultDto, and custom RemoteRepositoryDto construction, which now requires a platform value.
  • The package now requires adachsoft/git-platform ^0.3.

Versioning

This project follows Semantic Versioning. The first tagged release is 0.1.0, which introduces the initial public API around RepoGenFacade and its supporting services.