lib/danger/ci_source/bitrise.rb in danger-8.0.4 vs lib/danger/ci_source/bitrise.rb in danger-8.0.5
- old
+ new
@@ -48,18 +48,31 @@
def initialize(env)
self.pull_request_id = env["BITRISE_PULL_REQUEST"]
self.repo_url = env["GIT_REPOSITORY_URL"]
matcher_url = self.repo_url
+ self.repo_slug = repo_slug_from(self.repo_url)
+ end
- #If the URL contains https:// as :// leads to inaccurate matching. So we remove it and proceed to match.
- if repo_url.include? "https://"
- matcher_url["https://"] = ''
+ def repo_slug_from(url)
+ if url =~ URI::regexp
+ # Try to parse the URL as a valid URI. This should cover the cases of http/https/ssh URLs.
+ begin
+ uri = URI.parse(url)
+ return uri.path.sub(/^(\/)/,'').sub(/(.git)$/,'')
+ rescue URI::InvalidURIError
+ # In case URL could not be parsed fallback to git URL parsing.
+ repo_slug_asgiturl(url)
+ end
+ else
+ # In case URL could not be parsed fallback to git URL parsing. git@github.com:organization/repo.git
+ repo_slug_asgiturl(url)
end
+ end
+ def repo_slug_asgiturl(url)
+ matcher_url = url
repo_matches = matcher_url.match(%r{([\/:])(([^\/]+\/)+[^\/]+?)(\.git$|$)})[2]
-
- self.repo_slug = repo_matches unless repo_matches.nil?
-
+ return repo_matches unless repo_matches.nil?
end
end
end