Skip to content

issue:setup-remote builds invalid remote name for GitLab work-item ids #359

Description

@mglaman

Problem

issue:setup-remote fails for projects that migrated to GitLab work items (e.g. Canvas). Work-item ids are not Drupal.org issue nodes, so the node lookup returns no project machine name and the command builds a remote named -<id>, which git remote add rejects as an option:

$ drupalorg issue:setup-remote 3591806

In SetupIssueRemoteAction.php line 38:

  Failed to add remote -3591806: The command "'git' 'remote' 'add' '-3591806'
   'git@git.drupal.org:issue/-3591806.git'" failed.

  Error Output:
  ================
  error: unknown switch `3'
  usage: git remote add [<options>] <name> <url>

Work item 3591806 is a Canvas issue with an existing fork at git@git.drupal.org:issue/canvas-3591806.git and an open MR (project/canvas!1352). The fork is fine; only the project name resolution fails.

Root cause

GetIssueForkAction resolves the project exclusively through the Drupal.org node API:

if ($projectMachineName === null) {
    $issue = $this->client->getNode($nid);
    $projectMachineName = $issue->fieldProjectMachineName;
}
$remoteName = $projectMachineName . '-' . $nid;
$gitLabProjectPath = 'issue/' . $remoteName;

For a work-item id the node either does not exist or is an unrelated node that happens to share the id (3591806 resolves to a restrict_login_ip release node with no project field). $projectMachineName ends up empty, producing -3591806 and issue/-3591806.git.

Proposed fix

Fall back to GitLab when the node lookup yields no project machine name:

  1. Resolve the work item via the GitLab API (/groups/project/work_items or the issue fork naming convention) to get the project machine name, or
  2. Derive it from the current repository's origin remote (git@git.drupal.org:project/canvas.gitcanvas), since the command already runs inside the project checkout.

Either way, guard against an empty machine name and fail with an explicit "could not resolve project for id" error instead of passing a --prefixed name to git.

Related: #337 handled work items in the skill docs; this is the same migration gap in the command itself.

Workaround

$ git remote add canvas-3591806 git@git.drupal.org:issue/canvas-3591806.git
$ git fetch canvas-3591806

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions