Skip to content

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

Merged
mglaman merged 1 commit into
mainfrom
project-name-from-remote
Aug 31, 2026
Merged

fix: derive project machine name from git remote when argument is omitted#370
mglaman merged 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>
@mglaman
mglaman merged commit c286bc7 into main Aug 31, 2026
9 checks passed
@mglaman
mglaman deleted the project-name-from-remote branch August 31, 2026 14:08
mglaman added a commit that referenced this pull request Aug 31, 2026
Resolves the add/add overlap with #370 by keeping this branch's
ProjectRemote superset, and syncs the skills/ copy of
gitlab-mr-contribution.md with skill-data/.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mglaman added a commit that referenced this pull request Aug 31, 2026
…ssue forks (#372)

* fix: derive project machine name from git remote when argument is omitted

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>

* fix: honor project qualifiers and repository remotes when resolving issue forks

GitLab work-item ids on migrated projects share the number space with Drupal.org node ids, so a bare id can resolve to an unrelated project and build the wrong fork path. IssueProjectResolver now prefers an explicit project qualifier, then the project/<name> remote of the current repository, and only then the Drupal.org node lookup, failing loudly when the node and the repository disagree. A qualifier such as campaign#3615648 no longer triggers any Drupal.org request.

Closes #359

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* refactor: reuse ProjectRemote from #370 for repository project detection

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>

---------

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