Guest User

Untitled

a guest
Jan 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. module Script
  4. class Jira
  5.  
  6. JIRA_URL = ENV['JIRA_URL'][0] == '/' ? ENV['JIRA_URL'] : "#{ENV['JIRA_URL']}/".freeze
  7.  
  8. def self.launch
  9. new.launch
  10. end
  11.  
  12. def initialize
  13. if File.exists?('.git')
  14. @branch = branch
  15. end
  16. end
  17.  
  18. def branch
  19. current_branch = `git branch | grep "\*"`
  20. !!current_branch.match(/^fatal/) || current_branch.gsub('* ', '').strip
  21. end
  22.  
  23. def open
  24. case `uname -s`
  25. when /Darwin/i
  26. 'open'
  27. when /Linux/i
  28. 'xdg-open'
  29. end
  30. end
  31.  
  32. def launch
  33. if JIRA_URL && @branch
  34. puts "Launching Jira in your default browser..."
  35. if ['master', 'develop'].include?(@branch)
  36. `#{open} #{JIRA_URL}`
  37. JIRA_URL
  38. else
  39. url = "#{JIRA_URL}browse/#{@branch}"
  40. `#{open} #{url}`
  41. url
  42. end
  43. else
  44. puts "You need a JIRA_URL in your environment variables." if !JIRA_URL
  45. puts "There's something wrong with git. Are you sure you're in a directory with git init'd?" if !@branch
  46. end
  47. end
  48. end
  49. end
  50.  
  51. Script::Jira.launch
Add Comment
Please, Sign In to add comment