Class: Marlens::GithubToJiraComment::GithubUrl
- Inherits:
-
Object
- Object
- Marlens::GithubToJiraComment::GithubUrl
- Defined in:
- lib/marlens/github_to_jira_comment/github_url.rb
Defined Under Namespace
Classes: Source
Class Method Summary collapse
Class Method Details
.parse(url) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/marlens/github_to_jira_comment/github_url.rb', line 19 def self.parse(url) uri = URI.parse(url) segments = uri.path.split("/").reject(&:empty?) unless uri.is_a?(URI::HTTPS) && uri.host == "github.com" && segments.length == 4 raise ArgumentError, "GitHub URL must be https://github.com/<owner>/<repo>/pull/<number> or /issues/<number>" end owner, repo, path_type, number = segments unless %w[pull issues].include?(path_type) && number.match?(/\A\d+\z/) raise ArgumentError, "GitHub URL must point to a pull request or issue number" end Source.new(owner:, repo:, type: path_type == "pull" ? "pull" : "issue", number:) rescue URI::InvalidURIError raise ArgumentError, "Invalid GitHub URL" end |