Skip to content

fix: derive project machine name from git remote when argument is omitted - #370

Open
mglaman wants to merge 1 commit into
mainfrom
project-name-from-remote
Open

fix: derive project machine name from git remote when argument is omitted#370
mglaman wants to merge 1 commit into
mainfrom
project-name-from-remote

Conversation

@mglaman

@mglaman mglaman commented Aug 28, 2026

Copy link
Copy Markdown
Owner

What changed

  • ProjectCommandBase::initialize() now checks the value of the project argument instead of whether the argument exists, so the git remote fallback actually runs when the argument is omitted.
  • The remote URL parsing moved out of the command into mglaman\DrupalOrg\ProjectRemote::tryParse(), a small value object that returns null for anything that is not a project/ remote on git.drupal.org or git.drupalcode.org. It handles git@host:project/name.git, ssh://, https://, and .git-less forms.
  • When no project can be derived, the CLI now says Could not determine the project from the git remote; pass the machine name as an argument. instead of Project not found.
  • git config --get remote.origin.url runs as an argv array rather than (array) 'git config ...', which passed the whole string as a single argument.

Why

Closes #346.

InputInterface::hasArgument() reports whether the argument is defined on the command, not whether the user passed it. For every project:* command it is always true, so this branch never ran and getArgument('project') ?? '' produced an empty name:

if (!$this->stdIn->hasArgument('project')) {
    $this->projectName = $this->getProjectFromRemote();
    // ...
} else {
    $projectName = $this->stdIn->getArgument('project') ?? '';

The regex itself was not the cause, but it also required a .git suffix and matched any host, so the parser was rewritten while making it testable.

Testing

vendor/bin/phpcs src tests, vendor/bin/phpstan analyse src, and vendor/bin/phpunit (179 tests, 558 assertions) pass. tests/src/ProjectRemoteTest.php covers the SSH, ssh://, HTTPS, and .git-less forms plus GitHub, issue fork, and empty remotes returning null.

Reproduction in a throwaway repo with origin set to git@git.drupal.org:project/json_form_widget.git:

Before:

$ drupalorg project:issues
Project  not found.

After:

$ drupalorg project:issues -vv
Argument project not provided. Trying to get it from the remote URL of the current repository.
Project uses GitLab work items (no Drupal.org issue queue).
json_form_widget
+----------+--------+---...

Same result with https://git.drupalcode.org/project/json_form_widget.git and https://git.drupalcode.org/project/json_form_widget. With origin set to git@github.com:mglaman/drupalorg-cli.git:

Could not determine the project from the git remote; pass the machine name as an argument.

🤖 Generated with Claude Code

…tted

ProjectCommandBase checked InputInterface::hasArgument('project'), which only reports whether the argument is defined on the command, not whether the user passed it. It was always true, so the git remote fallback never ran and the null argument became an empty project name. The parsing now lives in ProjectRemote so it can be unit tested against SSH, HTTPS, and .git-less remote forms, and a missing derivation reports a clear error.

Closes #346

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mglaman added a commit that referenced this pull request Aug 28, 2026
Drops the duplicate URL parser in src/Api/Git and moves fromRemotes() and detect() onto ProjectRemote so a single parser handles project remotes. Callers read ->machineName from the value object.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blank space returned for project name?

1 participant