Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- module Script
- class Jira
- JIRA_URL = ENV['JIRA_URL'][0] == '/' ? ENV['JIRA_URL'] : "#{ENV['JIRA_URL']}/".freeze
- def self.launch
- new.launch
- end
- def initialize
- if File.exists?('.git')
- @branch = branch
- end
- end
- def branch
- current_branch = `git branch | grep "\*"`
- !!current_branch.match(/^fatal/) || current_branch.gsub('* ', '').strip
- end
- def open
- case `uname -s`
- when /Darwin/i
- 'open'
- when /Linux/i
- 'xdg-open'
- end
- end
- def launch
- if JIRA_URL && @branch
- puts "Launching Jira in your default browser..."
- if ['master', 'develop'].include?(@branch)
- `#{open} #{JIRA_URL}`
- JIRA_URL
- else
- url = "#{JIRA_URL}browse/#{@branch}"
- `#{open} #{url}`
- url
- end
- else
- puts "You need a JIRA_URL in your environment variables." if !JIRA_URL
- puts "There's something wrong with git. Are you sure you're in a directory with git init'd?" if !@branch
- end
- end
- end
- end
- Script::Jira.launch
Add Comment
Please, Sign In to add comment