Skip to content

Instantly share code, notes, and snippets.

@andxyz
Last active September 21, 2015 18:26
Show Gist options
  • Save andxyz/83ef7ad4246b56df0669 to your computer and use it in GitHub Desktop.
Save andxyz/83ef7ad4246b56df0669 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Shows the jira tickets and their summary for git branches
# see http://cl.ly/image/0v3I3A3D1W3P/Image%202015-09-21%20at%202.26.13%20PM.png
#
# example usage:
# ruby -W0 jira-sickness.rb
# or
# ./jira-sickness.rb
## Make sure to export these variables in the shell for yourself
# export -- JIRA_USERNAME='astevens'
# export -- JIRA_PASSWORD='my_password'
# export -- JIRA_GIT_DIRECTORY="$HOME/score/zing"
# ruby libs
require 'logger'
require 'json'
require "erb"
include ERB::Util
# gems
# gem install faraday pry rest-client
require 'faraday'
require 'pry'
require 'rest-client'
jira_url = 'jira.thescore.com'
jira_username = ENV['JIRA_USERNAME']
jira_password = ENV['JIRA_PASSWORD']
git_directory = ENV['JIRA_GIT_DIRECTORY']
@log = Logger.new(STDOUT)
@log.level = Logger::INFO
# @log.level = Logger::DEBUG
# ruby ssl hacks
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] |= begin
OpenSSL::SSL::OP_NO_SSLv2 |
OpenSSL::SSL::OP_NO_SSLv3 |
OpenSSL::SSL::OP_ALL |
OpenSSL::SSL::OP_NO_COMPRESSION &
~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS
end
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ciphers] = '!ADH:!RC4:!aNULL:!MD5:!EXPORT:!SSLv2:HIGH'
OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ssl_version] = 'TLSv1_2'
howsmyssl_report = JSON.parse(
RestClient::Resource.new('https://www.howsmyssl.com/a/check').get
)
@log.debug(howsmyssl_report)
@log.info("SSL rating: #{howsmyssl_report.fetch('rating')}")
printable_branches = %x{cd #{git_directory}; git branch}
branch_list = printable_branches.split(/\n/)
printable_issues = %x{egrep -o '[A-Z]+-[0-9*]+' <<< "#{printable_branches}"}
issues_list = printable_issues.split(/\n/)
@log.debug(issues_list)
issues_list.each_with_index do |issue_id, index|
issue_json = JSON.parse(
RestClient::Resource.new("https://#{url_encode(jira_username)}:#{url_encode(jira_password)}@#{jira_url}/rest/api/2/issue/#{issue_id}").get
)
@log.debug("#{issue_id} -- #{issue_json['fields']['summary']} -- #{branch_list[index]} -- http://#{jira_url}/browse/#{issue_id}")
# binding.pry
puts("""
#{issue_id} -- #{branch_list[index].strip}
http://#{jira_url}/browse/#{issue_id}
#{issue_json['fields']['summary'].strip}
#{issue_json['fields']['description'].strip}
--------------------------------------------
""")
end
@andxyz
Copy link
Author

andxyz commented Sep 21, 2015

I recommend pruning older git branches that have already been merged on github from you git repo before running this ./jira-sickness.rb code. Otherwise you may have a lot of branches that we have to loop over. The unpruned branches that are merged are clearly no longer that important since they have been looked at (I get a lot of these from PR reviewing peers)

~$ cat ~/bin/git-branch-prune.sh

#!/bin/sh
# Usage: git-branch-prune
# Delete all merged branches.

# prune local
# git branch --merged | grep -v "\*" | xargs -n 1 git branch --delete

# prune github and local
git remote prune origin && git branch --merged | grep -v "\*" | grep -v master | xargs -n 1 git branch --delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment