Skip to content

Commit 1b08f15

Browse files
rfayclaude
andcommitted
fix(docs-issue-picker): require project-qualified issue input, support GitLab issue URLs
Drupal issue IDs are no longer globally unique now that drupal.org issue queues are migrating to GitLab per-project (#163) - a bare number can silently resolve to the wrong project. Drop bare-number input, add GitLab issue URL parsing, and fall back to the GitLab Issues API when a drupal.org issue lookup comes back empty because the project migrated. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 280b263 commit 1b08f15

1 file changed

Lines changed: 97 additions & 52 deletions

File tree

‎docs/drupal-issue.html‎

Lines changed: 97 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<!-- id="main-content" is the skip link target (WCAG 2.4.1) -->
2222
<div class="cds-page" id="main-content">
2323
<h1>Drupal Issue Picker</h1>
24-
<p class="cds-page__subtitle">Paste a drupal.org core or contrib issue URL or number, or a contrib project URL or machine name. We load issue metadata and fork branches when applicable.</p>
24+
<p class="cds-page__subtitle">Paste a drupal.org or GitLab core/contrib issue URL, or a contrib project URL or machine name. We load issue metadata and fork branches when applicable.</p>
2525

2626
<div class="cds-note cds-note--intro">
2727
To create a clean Drupal core environment without contrib modules or issue forks, try the <a class="cds-link" href="drupal-core">Guided Drupal core</a> form.
@@ -31,9 +31,9 @@ <h1>Drupal Issue Picker</h1>
3131
<!-- Explicit <label> associates the field name with the input for screen readers.
3232
Visually hidden because the heading and subtitle already describe the field.
3333
WCAG 1.3.1 Info and Relationships / 3.3.2 Labels or Instructions (Level A) -->
34-
<label for="issue-input" class="cds-sr-only">Issue number, URL, or project name</label>
34+
<label for="issue-input" class="cds-sr-only">Issue URL or project name</label>
3535
<input type="text" id="issue-input"
36-
placeholder="e.g. 3568144 · drupal.org/project/drupal/issues/3568144 · drupal.org/project/token"
36+
placeholder="e.g. drupal.org/project/drupal/issues/3568144 · git.drupalcode.org/project/token/-/issues/3591879 · drupal.org/project/token"
3737
autofocus>
3838
<button class="cds-btn-load" id="load-btn" onclick="loadInput()">Load</button>
3939
</div>
@@ -617,16 +617,27 @@ <h2 id="feedback">Feedback &amp; Community</h2>
617617
currentProjectType = 'module';
618618
}
619619

620-
// Returns { type: 'issue'|'project', nid, project } or null
620+
// Returns { type: 'issue', nid, project, source: 'gitlab'|'drupalorg'|'shorthand' }
621+
// or { type: 'project', nid: null, project } or null.
622+
//
623+
// Issue numbers are not globally unique now that Drupal.org issue queues are
624+
// migrating to GitLab per-project (see github.com/ddev/coder-ddev/issues/163) —
625+
// a bare number can no longer be resolved unambiguously, so every issue match
626+
// here must carry an explicit project name.
621627
function parseInput(raw) {
622628
const s = raw.trim();
623629

624-
// Plain issue number
625-
if (/^\d+$/.test(s)) return { type: 'issue', nid: s, project: null };
630+
// GitLab issue URL: git.drupalcode.org/project/PROJECT/-/issues/IID or -/work_items/IID
631+
const gitlabIssueM = s.match(/git\.drupalcode\.org\/project\/([a-z][a-z0-9_]*)\/-\/(?:issues|work_items)\/(\d+)/);
632+
if (gitlabIssueM) return { type: 'issue', nid: gitlabIssueM[2], project: gitlabIssueM[1], source: 'gitlab' };
626633

627-
// Full issue URL: .../project/PROJECT/issues/NID
634+
// Full drupal.org issue URL: .../project/PROJECT/issues/NID
628635
const issueUrlM = s.match(/\/project\/([a-z][a-z0-9_]*)\/issues\/(\d+)/);
629-
if (issueUrlM) return { type: 'issue', nid: issueUrlM[2], project: issueUrlM[1] };
636+
if (issueUrlM) return { type: 'issue', nid: issueUrlM[2], project: issueUrlM[1], source: 'drupalorg' };
637+
638+
// Issue fork shorthand: PROJECT-NID (e.g. drupal-3568144, token-3568144)
639+
const shorthandM = s.match(/^([a-z][a-z0-9_]*)-(\d+)$/);
640+
if (shorthandM) return { type: 'issue', nid: shorthandM[2], project: shorthandM[1], source: 'shorthand' };
630641

631642
// Project URL: .../project/PROJECT (no issue segment)
632643
const projUrlM = s.match(/\/project\/([a-z][a-z0-9_]*)(?:\/|$)/);
@@ -643,7 +654,7 @@ <h2 id="feedback">Feedback &amp; Community</h2>
643654
const parsed = parseInput(raw);
644655

645656
if (!parsed) {
646-
setStatus('Could not parse input. Enter an issue number, a drupal.org issue or project URL, or a module machine name.', 'error');
657+
setStatus('Could not parse input. Enter a drupal.org or GitLab issue URL, a drupal.org project URL, or a module machine name.', 'error');
647658
return;
648659
}
649660

@@ -653,7 +664,7 @@ <h2 id="feedback">Feedback &amp; Community</h2>
653664
if (parsed.type === 'project') {
654665
await loadPlainProject(parsed.project);
655666
} else {
656-
await loadIssue(parsed.nid, parsed.project);
667+
await loadIssue(parsed.nid, parsed.project, parsed.source);
657668
}
658669

659670
document.getElementById('load-btn').disabled = false;
@@ -690,39 +701,69 @@ <h2 id="feedback">Feedback &amp; Community</h2>
690701
document.getElementById('plain-dev-form').hidden = false;
691702
}
692703

693-
async function loadIssue(nid, hintedProject) {
704+
// Fetches an issue title from the GitLab API for projects whose issue
705+
// queue has migrated off drupal.org. Returns null on any failure.
706+
async function fetchGitlabIssueTitle(projectName, nid) {
707+
try {
708+
const resp = await fetch(
709+
'https://git.drupalcode.org/api/v4/projects/' + encodeURIComponent('project/' + projectName) + '/issues/' + nid
710+
);
711+
if (!resp.ok) return null;
712+
const data = await resp.json();
713+
return (data && data.title) ? data.title : null;
714+
} catch (_) {
715+
return null;
716+
}
717+
}
718+
719+
async function loadIssue(nid, hintedProject, source) {
694720
currentNid = nid;
695-
setStatus('Loading issue ' + nid + '...', 'loading');
721+
const projectName = hintedProject;
722+
setStatus('Loading issue ' + projectName + '-' + nid + '...', 'loading');
696723

697724
try {
698-
// Step 1: fetch issue data from Drupal.org to determine project
699-
setStatus('Fetching issue data from drupal.org...', 'loading');
700-
let projectName = hintedProject;
701-
let title = 'Issue #' + nid;
725+
let title = null;
702726
let drupalMajor = '11';
727+
let issueIsOnGitlab = (source === 'gitlab');
703728

704-
try {
705-
const issueResp = await fetch('https://www.drupal.org/api-d7/node/' + nid + '.json');
706-
if (issueResp.ok) {
707-
const issue = await issueResp.json();
708-
if (issue.title) title = issue.title;
709-
// Resolve project name from API (overrides URL-hinted project)
710-
const apiProject = issue.field_project && issue.field_project.machine_name;
711-
if (apiProject) projectName = apiProject;
712-
// Detect Drupal major version from field_issue_version — core issues only.
713-
// For contrib, field_issue_version is the MODULE version (e.g. "8.x-1.x"
714-
// means module 1.x, not Drupal 8), so we leave drupalMajor at its default.
715-
if (!apiProject || apiProject === 'drupal') {
716-
const ver = issue.field_issue_version || '';
717-
const verM = ver.match(/^(\d+)\./);
718-
if (verM) drupalMajor = verM[1];
719-
else if (ver === 'main' || ver.startsWith('12')) drupalMajor = '12';
729+
if (issueIsOnGitlab) {
730+
setStatus('Fetching issue data from git.drupalcode.org...', 'loading');
731+
title = await fetchGitlabIssueTitle(projectName, nid);
732+
} else {
733+
// drupal.org URL or PROJECT-NID shorthand: try the classic API first.
734+
setStatus('Fetching issue data from drupal.org...', 'loading');
735+
try {
736+
const issueResp = await fetch('https://www.drupal.org/api-d7/node/' + nid + '.json');
737+
if (issueResp.ok) {
738+
const issue = await issueResp.json();
739+
if (issue.title) {
740+
title = issue.title;
741+
// Detect Drupal major version from field_issue_version — core issues only.
742+
// For contrib, field_issue_version is the MODULE version (e.g. "8.x-1.x"
743+
// means module 1.x, not Drupal 8), so we leave drupalMajor at its default.
744+
const apiProject = issue.field_project && issue.field_project.machine_name;
745+
if (!apiProject || apiProject === 'drupal') {
746+
const ver = issue.field_issue_version || '';
747+
const verM = ver.match(/^(\d+)\./);
748+
if (verM) drupalMajor = verM[1];
749+
else if (ver === 'main' || ver.startsWith('12')) drupalMajor = '12';
750+
}
751+
}
720752
}
753+
} catch (_) { /* fall through to the GitLab lookup below */ }
754+
755+
if (!title) {
756+
// Not found in the classic system — this project's issue queue has
757+
// likely migrated to GitLab. Issue IDs are not preserved across the
758+
// migration (see github.com/ddev/coder-ddev/issues/163), so we can
759+
// only re-resolve it using the project name carried in the input.
760+
setStatus('Not found on drupal.org — checking GitLab issues for ' + projectName + '...', 'loading');
761+
title = await fetchGitlabIssueTitle(projectName, nid);
762+
issueIsOnGitlab = !!title;
721763
}
722-
} catch (_) { /* title/version stay as fallback */ }
764+
}
723765

724-
// If we still don't know the project, assume it from hinted URL or default to 'drupal'
725-
if (!projectName) projectName = 'drupal';
766+
if (!title) title = 'Issue #' + nid;
726767

727768
currentProjectName = projectName;
728769
currentIsContrib = (projectName !== 'drupal');
@@ -747,17 +788,19 @@ <h2 id="feedback">Feedback &amp; Community</h2>
747788
'https://git.drupalcode.org/api/v4/projects/' + encodedFork + '/repository/branches?per_page=100'
748789
);
749790

791+
const issuePageUrl = issueIsOnGitlab
792+
? 'https://git.drupalcode.org/project/' + projectName + '/-/issues/' + nid
793+
: 'https://www.drupal.org/project/' + projectName + '/issues/' + nid;
794+
750795
if (branchResp.status === 404) {
751-
// Check if issue exists
752-
const issueUrl = 'https://www.drupal.org/project/' + projectName + '/issues/' + nid;
753796
if (currentIsContrib) {
754797
setStatus(
755-
'No issue fork exists for #' + nid + ' on ' + projectName + ' yet. Visit the issue page on drupal.org and click "Get push access" to create a fork, then come back here.',
798+
'No issue fork exists for #' + nid + ' on ' + projectName + ' yet. Visit the issue page and click "Get push access" to create a fork, then come back here.',
756799
'info'
757800
);
758801
} else {
759802
setStatus(
760-
'No issue fork exists for #' + nid + ' yet. To work on this issue, visit the issue page on drupal.org and click "Get push access" to create a fork, then come back here.',
803+
'No issue fork exists for #' + nid + ' yet. To work on this issue, visit the issue page and click "Get push access" to create a fork, then come back here.',
761804
'info'
762805
);
763806
}
@@ -766,22 +809,24 @@ <h2 id="feedback">Feedback &amp; Community</h2>
766809
if (!branchResp.ok) throw new Error('git.drupalcode.org API returned ' + branchResp.status);
767810
const branches = await branchResp.json();
768811

769-
// Step 3: try to get visible branches from Drupal.org issue page (drupalorgBranchData)
770-
const issuePageUrl = 'https://www.drupal.org/project/' + projectName + '/issues/' + nid;
812+
// Step 3: try to get visible branches from the Drupal.org issue page (drupalorgBranchData).
813+
// Only applies to classic issues — migrated GitLab issues have no drupal.org issue page.
771814
let visibleBranchNames = null;
772-
try {
773-
const pageResp = await fetch(issuePageUrl);
774-
if (pageResp.ok) {
775-
const html = await pageResp.text();
776-
const settingsMatch = html.match(/<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>([\s\S]*?)<\/script>/);
777-
if (settingsMatch) {
778-
const settings = JSON.parse(settingsMatch[1]);
779-
if (settings.drupalorgBranchData && Object.keys(settings.drupalorgBranchData).length > 0) {
780-
visibleBranchNames = new Set(Object.keys(settings.drupalorgBranchData));
815+
if (!issueIsOnGitlab) {
816+
try {
817+
const pageResp = await fetch(issuePageUrl);
818+
if (pageResp.ok) {
819+
const html = await pageResp.text();
820+
const settingsMatch = html.match(/<script[^>]+data-drupal-selector="drupal-settings-json"[^>]*>([\s\S]*?)<\/script>/);
821+
if (settingsMatch) {
822+
const settings = JSON.parse(settingsMatch[1]);
823+
if (settings.drupalorgBranchData && Object.keys(settings.drupalorgBranchData).length > 0) {
824+
visibleBranchNames = new Set(Object.keys(settings.drupalorgBranchData));
825+
}
781826
}
782827
}
783-
}
784-
} catch (_) { /* CORS or parse error — fall through */ }
828+
} catch (_) { /* CORS or parse error — fall through */ }
829+
}
785830

786831
// Filter branches: visible set from drupal.org, or fallback to NID-prefix filter
787832
const issueBranches = visibleBranchNames

0 commit comments

Comments
 (0)