#!/usr/bin/env ruby require 'json' JIRA = 'http://jira.bluejeansnet.com' UNTRACKED = "http://opsask.bluejeansnet.com/untracked" STRAGGLERS = "http://opsask.bluejeansnet.com/stragglers" # Don't run on the weekend exit 0 if Time.now.saturday? || Time.now.sunday? if ARGV.length != 2 $stderr.puts "Error: Wrong number of arguments" $stderr.puts "Usage: #{__FILE__} JIRA_USER JIRA_PASS" exit 1 end USER, PASS = ARGV[0], ARGV[1] def ask_jira constraints=nil constraints = "AND #{constraints}" unless constraints.nil? jql = { 'jql' => "project = Infrastructure #{constraints} ORDER BY created" } curl = %Q| curl -sL \ -u "#{USER}:#{PASS}" \ -XPOST "#{JIRA}/rest/api/latest/search" \ -H "Content-Type: application/json" -d '#{JSON.generate(jql)}' | return curl end def inf_issues_where constraints=nil # $stderr.puts constraints JSON::parse(`#{ask_jira constraints}`)['issues'] end def write_out title, issues return if issues.empty? puts "#{title}" puts '' puts '
' end untracked_today = inf_issues_where('due = endOfDay() AND resolution = unresolved AND assignee = denimcores') tracked_today = inf_issues_where('due = endOfDay() AND resolution = unresolved AND assignee != denimcores') resolved_today = inf_issues_where('due = endOfDay() AND resolution != unresolved') uncategorized = inf_issues_where('due = endOfDay() AND "Ops Work Category" is EMPTY') stragglers = inf_issues_where('due < startOfDay() AND labels in (OpsAsk) AND resolution = unresolved AND assignee != denimcores') exit if untracked_today.empty? \ && tracked_today.empty? \ && resolved_today.empty? \ && uncategorized.empty? \ && stragglers.empty? # $stderr.puts uncategorized.inspect write_out 'Untracked', untracked_today write_out 'Tracking', tracked_today write_out 'Resolved', resolved_today write_out 'Stragglers', stragglers write_out 'Uncategorized', uncategorized num_untracked_today = untracked_today.length num_untracked = inf_issues_where('due < endOfDay() AND resolution = unresolved AND assignee = denimcores').length if num_untracked == 1 && num_untracked_today == 0 puts %Q|There is an untracked issue from the past| elsif num_untracked == 1 && num_untracked_today > 0 puts %Q|There is another untracked issue from the past| elsif num_untracked > 1 && num_untracked_today == 0 puts %Q|There are #{num_untracked} untracked issues from the past| elsif num_untracked > 1 && num_untracked_today > 0 puts %Q|There are #{num_untracked} additional untracked issues from the past| end