parsePRReference static method

int? parsePRReference(
  1. String input
)

Parses a PR reference from a string. Accepts GitHub-style PR URLs or #N format.

Implementation

static int? parsePRReference(String input) {
  // GitHub-style PR URL
  final urlMatch = RegExp(
    r'^https?://[^/]+/[^/]+/[^/]+/pull/(\d+)/?(?:[?#].*)?$',
    caseSensitive: false,
  ).firstMatch(input);
  if (urlMatch != null) {
    return int.tryParse(urlMatch.group(1)!);
  }

  // #N format
  final hashMatch = RegExp(r'^#(\d+)$').firstMatch(input);
  if (hashMatch != null) {
    return int.tryParse(hashMatch.group(1)!);
  }

  return null;
}