#require 'sidebar' #require 'mechanize' #require 'hpricot' # #class ::Sidebar # def blocks_with_jira_issues(*args) # blocks = blocks_without_jira_issues(*args) # # if File.exists?(APP_CONFIG_FILE) # app_conf = YAML::load(ERB.new(IO.read(APP_CONFIG_FILE)).result) || {} # if jira_conf = app_conf['jira'] # jira_url = jira_conf['url'].chomp('/') # jira_user = jira_conf['user'] # jira_password = jira_conf['password'] # jira_pids = jira_conf['pids'].to_s.split(',').map{|p| "&pid=#{p.strip}"} # fix_version = jira_conf['fix_version'].to_s # limit = 20 # assignee = '' # "&assigneeSelect=specificuser&assignee=#{jira_user}" # sorting = '&sorter/field=priority&sorter/order=DESC' # resolution = 'resolution=-1' # # agent = WWW::Mechanize.new { |a| a.log = Logger.new("jira.log") } # agent.user_agent_alias = 'Mechanize' # # login_url = "#{jira_url}/login.jsp?os_username=#{jira_user}&os_password=#{jira_password}" # login_page = agent.get(login_url) # login_form = login_page.form_with(:name => 'loginform') # login_form["os_username"] = jira_user # login_form["os_username"] = jira_user # agent.submit(login_form) # # search_path = 'sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml' # url = "#{jira_url}/#{search_path}?#{resolution}#{jira_pids}#{assignee}#{sorting}&tempMax=#{limit}&fixfor=#{fix_version}" # search_results = agent.get(url) # # xml_search_doc = Hpricot.XML(search_results.body) # items = (xml_search_doc/"item") # issues = items.map do |item| # title = (item/'title').inner_html # link = (item/'link').first.inner_html # [title, link] # end # # list = "\n" # blocks << { # :id => 1, # :title => "JIRA Issues", # :options => jira_url, # :content => list # } # end # end # blocks # rescue # ActiveRecord::Base.logger.error $! # blocks # end # alias_method_chain :blocks, :jira_issues #end