Class: Aireview::MrParser
- Inherits:
-
Object
- Object
- Aireview::MrParser
- Defined in:
- lib/aireview/mr_parser.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- MR_PATH =
%r{\A/(?<project>.+)/-/merge_requests/(?<iid>\d+)\z}
Class Method Summary collapse
Class Method Details
.parse(url) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aireview/mr_parser.rb', line 10 def self.parse(url) uri = URI.parse(url.to_s) raise ParseError, 'Merge request URL must include http:// or https://' unless uri.is_a?(URI::HTTP) match = MR_PATH.match(uri.path) raise ParseError, "Unsupported merge request URL: #{url}" unless match project_path = match[:project] Result.new( url: url, base_url: "#{uri.scheme}://#{uri.host}#{":#{uri.port}" if uri.port && ![80, 443].include?(uri.port)}", project_path: project_path, project_id: URI.encode_www_form_component(project_path), iid: match[:iid].to_i ) rescue URI::InvalidURIError => e raise ParseError, "Invalid merge request URL: #{e.}" end |