Module: Commiti::PrBrowserOpener
- Defined in:
- lib/services/git/pr/browser_opener.rb
Class Method Summary collapse
- .mac? ⇒ Boolean
- .open_in_browser(url) ⇒ Object
- .open_windows_browser(url) ⇒ Object
- .windows? ⇒ Boolean
Class Method Details
.mac? ⇒ Boolean
40 41 42 |
# File 'lib/services/git/pr/browser_opener.rb', line 40 def self.mac? RUBY_PLATFORM.include?('darwin') end |
.open_in_browser(url) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/services/git/pr/browser_opener.rb', line 5 def self.open_in_browser(url) success = if windows? open_windows_browser(url) elsif mac? system('open', url) else system('xdg-open', url) end raise 'Failed to open browser for PR URL.' unless success nil end |
.open_windows_browser(url) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/services/git/pr/browser_opener.rb', line 19 def self.open_windows_browser(url) cleaned_url = url.to_s.strip.sub(/\A\\+/, '') # Prefer shell protocol handler. This bypasses cmd/explorer parsing of '&'. return true if system('rundll32', 'url.dll,FileProtocolHandler', cleaned_url) # PowerShell fallback, passing URL as an argument to avoid command parsing. system( 'powershell', '-NoProfile', '-Command', '$u=$args[0]; Start-Process -FilePath $u', '--', cleaned_url ) end |
.windows? ⇒ Boolean
36 37 38 |
# File 'lib/services/git/pr/browser_opener.rb', line 36 def self.windows? RUBY_PLATFORM.include?('mingw') || RUBY_PLATFORM.include?('mswin') end |