Module: Ace::Git::Atoms::PrIdentifier
- Defined in:
- lib/ace/git/atoms/pr_identifier.rb
Overview
Parse provider-neutral pull request identifiers into structured form.
Supports the forge-neutral forms:
- Simple number: "123"
- Qualified reference: "owner/repo#456"
Provider-specific identifier formats (for example full web URLs) belong to the provider packages, not to the core.
Defined Under Namespace
Classes: ParseResult
Constant Summary collapse
- MAX_IDENTIFIER_LENGTH =
Maximum identifier length to bound regex work
256
Class Method Summary collapse
-
.parse(input) ⇒ ParseResult?
Parse a pull request identifier string.
Class Method Details
.parse(input) ⇒ ParseResult?
Parse a pull request identifier string.
Returns nil for nil/empty input (no PR specified), raises ArgumentError for invalid formats. This lets callers distinguish "no PR" (nil input) from "invalid PR" (bad format).
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ace/git/atoms/pr_identifier.rb', line 39 def self.parse(input) return nil if input.nil? input_str = input.to_s.strip return nil if input_str.empty? if input_str.length > MAX_IDENTIFIER_LENGTH raise ArgumentError, "PR identifier too long (max #{MAX_IDENTIFIER_LENGTH} characters)" end case input_str when /\A(\d+)\z/ number = ::Regexp.last_match(1) raise ArgumentError, "Invalid PR identifier format: #{input_str}" if number.to_i.zero? # Canonical form (no leading zeros) for consistent downstream use ParseResult.new(number: number.to_i.to_s, repo: nil) when /\A(?<repo>[a-zA-Z0-9_\-.]+\/[a-zA-Z0-9_\-.]+)#(?<number>\d+)\z/ match = ::Regexp.last_match ParseResult.new(number: match[:number], repo: match[:repo]) else raise ArgumentError, "Invalid PR identifier format: #{input_str}" end end |