Skip to content

fix(pr_create): support GitLab nested groups + add regression test#400

Merged
bakeb7j0 merged 1 commit intokahuna/390-bug-drainfrom
fix/290-pr-create-gitlab-nested-groups
May 5, 2026
Merged

fix(pr_create): support GitLab nested groups + add regression test#400
bakeb7j0 merged 1 commit intokahuna/390-bug-drainfrom
fix/290-pr-create-gitlab-nested-groups

Conversation

@bakeb7j0
Copy link
Copy Markdown
Contributor

@bakeb7j0 bakeb7j0 commented May 5, 2026

Summary

Two fixes for GitLab pr_create against nested-group projects:

  1. Repo schema accepts nested groups: analogicdev/internal/tools/blueshift/blueshift-docmancer-ui (4 levels) now validates. Previously ^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$ only allowed owner/repo.
  2. Regression test for the broken glab mr view -F json flag (already fixed by fix(pr-create-gitlab): replace broken glab mr view -F json with glab api lookup #386 on kahuna; this guards against reintroduction).

Changes

  • New lib/schemas/repo.ts — single-source-of-truth REPO_SLUG_REGEX, repoSchema, repoOptionalSchema
  • New lib/schemas/repo.test.ts — 35 tests covering flat slugs, nested groups (up to 7 levels), malformed input rejection
  • 19 handlers updated to use repoOptionalSchema instead of inline regex (pr_, ci_, label_, wave_, work_item)
  • Added regression test in lib/adapters/pr-create-gitlab.test.ts for nested-group + URL-encoded %2F handling

Tests

  • ✅ 2175 pass / 0 fail / 3 skip
  • ./scripts/ci/validate.sh green
  • ✅ Defence-in-depth GITHUB_REPO_SLUG in GitHub adapters left intact (platform constraint preserved)

Notes

The wave plan called out lib/adapters/gitlab/pr-create.ts but the actual codebase uses the flat lib/adapters/pr-create-gitlab.ts layout (file naming differs from plan, behaviour identical).

Closes #290

… flag

Two bugs in pr_create against GitLab projects with nested groups (#290):

1. The `repo` regex `^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$` rejected
   group/subgroup/.../repo paths before they reached the platform
   adapter, breaking pr_create on every nested-group GitLab project
   (`analogicdev/internal/tools/blueshift/blueshift-docmancer-ui` was
   the failing reproducer — 4 `/` levels).

2. The post-create verify step shelled to `glab mr view -F json`,
   but `-F` is not a flag on any glab subcommand in 1.36.0. The MR
   was being created server-side then the verify step would error,
   leaving callers to clean up duplicates.

Bug 2 was already fixed by #386 (a5cf34c) on the kahuna branch — the
post-create lookup now uses `glab api projects/<encoded>/merge_requests
?source_branch=<head>&state=opened` and parses the JSON in-process.
This commit adds a regression test for the nested-group path through
that adapter.

Bug 1 fix:
- Add `lib/schemas/repo.ts` as the single source of truth for the slug
  regex. New pattern: `^[a-zA-Z0-9._-]+(/[a-zA-Z0-9._-]+)+$` — accepts
  arbitrary `/` depth while still rejecting bare `owner` (no `/`),
  empty segments (`a//b`), and shell metacharacters.
- Update all 19 handlers that ship a `repo` parameter
  (`pr_*`, `ci_*`, `wave_init`, `wave_reconcile`, `label_*`, `work_item`)
  to import `repoOptionalSchema` from the shared module instead of
  rolling their own regex.
- Add `lib/schemas/repo.test.ts` covering flat slugs, nested-group
  slugs (including the exact #290 reproducer), and rejection of
  malformed input.
- Add a nested-group regression test in `pr-create-gitlab.test.ts`
  asserting the slug forwards verbatim to `-R` and URL-encodes every
  `/` as `%2F` for the api lookup path.

GitHub-side adapters keep their flat `GITHUB_REPO_SLUG` defence-
in-depth regex — that's a platform constraint, not a relaxation
target.

All 2175 unit tests pass; full ci/validate.sh green.

Closes #290
@bakeb7j0 bakeb7j0 merged commit 0f651eb into kahuna/390-bug-drain May 5, 2026
1 check failed
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.

2 participants