Skip to content

[#281] Fixed 'parseUserId()' to handle Drush 12+ table output format.#324

Merged
AlexSkrypnyk merged 1 commit intomasterfrom
feature/281-parse-userid
Apr 16, 2026
Merged

[#281] Fixed 'parseUserId()' to handle Drush 12+ table output format.#324
AlexSkrypnyk merged 1 commit intomasterfrom
feature/281-parse-userid

Conversation

@AlexSkrypnyk
Copy link
Copy Markdown
Collaborator

@AlexSkrypnyk AlexSkrypnyk commented Apr 16, 2026

Closes #281

Summary

  • Fixed parseUserId() in DrushDriver to handle the table output format introduced in Drush 12+, where user info is returned as a formatted table rather than key-value pairs.
  • Preserved full backward compatibility with the legacy "User ID : 123" key-value format used by older Drush versions.
  • Added 4 unit tests via a data provider covering: legacy format, Drush 12+ table format, UID 1 edge case, and output with no user ID present.

Problem

DrushDriver::parseUserId() used a regex that only matched the legacy "User ID : 123" key-value format. Drush 12+ changed the output of user:information to a bordered table:

 --------- ----------- ----------- --------------- ------------- 
  User ID   User name   User mail   User roles      User status  
 --------- ----------- ----------- --------------- ------------- 
  550895    test        test@ex.co  authenticated   1            
 --------- ----------- ----------- --------------- ------------- 

This caused parseUserId() to return null for all users when running Drush 12+, breaking user-related operations.

Solution

The updated method tries the legacy regex first (no behaviour change for older Drush). If that does not match but the output contains a User ID header, it walks the lines and extracts the first numeric value from the first data row (the UID column).

Test plan

  • Legacy format ("User ID : 123") still parses correctly.
  • Drush 12+ table format parses correctly.
  • UID 1 (single digit) parses correctly from table format.
  • Output with no user ID present returns null without error.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced user ID extraction to support both legacy and Drush 12+ output formats while maintaining backward compatibility.
  • Tests

    • Added comprehensive test coverage for user ID parsing across different Drush output formats.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 57ba618c-8761-4421-a902-5bf8ea8883df

📥 Commits

Reviewing files that changed from the base of the PR and between 8a2b4ed and 8a0f86f.

📒 Files selected for processing (2)
  • src/Drupal/Driver/DrushDriver.php
  • tests/Drupal/Tests/Driver/DrushDriverTest.php

📝 Walkthrough

Walkthrough

Enhanced parseUserId() method in DrushDriver to support both legacy key-value drush output format and Drush 12+ table output format. Added comprehensive test coverage with data providers validating multiple output scenarios including cases where user ID is absent.

Changes

Cohort / File(s) Summary
DrushDriver Enhancement
src/Drupal/Driver/DrushDriver.php
Updated parseUserId() to parse legacy drush key-value output via regex capture, then fall back to Drush 12+ table output detection by locating "User ID" header, extracting the first numeric value from the first non-header data row.
Test Coverage
tests/Drupal/Tests/Driver/DrushDriverTest.php
Added testParseUserId() with dataProviderParseUserId() covering legacy format, Drush 12+ table format, and null return scenarios. Extended TestDrushDriver with callParseUserId() public wrapper method.

Possibly related issues

Poem

🐰 A rabbit hops through drush's output rows,
Both legacy keys and tables it knows,
With regex and splits, the IDs appear,
Version twelve's dance? The parser's sincere!
Tests hopping along, eight paws in the air! 🥕

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/281-parse-userid

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AlexSkrypnyk AlexSkrypnyk merged commit 3aa901a into master Apr 16, 2026
5 of 6 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/281-parse-userid branch April 16, 2026 22:47
@AlexSkrypnyk AlexSkrypnyk added this to the 2.5 milestone Apr 17, 2026
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.

DrushDriver: parseUserId($info) does not work anymore

1 participant