class Glue::JiraOneTimeFilter

Public Class Methods

new() click to toggle source

Glue::Filters.add self

# File lib/glue/filters/jira_one_time_filter.rb, line 9
def initialize
  @name = "Jira One Time Filter"
  @description = "Checks that each issue that will be reported doesn't already exist in JIRA."
end

Public Instance Methods

filter(tracker) click to toggle source
# File lib/glue/filters/jira_one_time_filter.rb, line 14
def filter tracker
  @project = tracker.options[:jira_project.to_s]
  @api = tracker.options[:jira_api_url.to_s]
  @cookie = tracker.options[:jira_cookie.to_s]
  @component = tracker.options[:jira_component.to_s]
  @appname = tracker.options[:appname]

  potential_findings = Array.new(tracker.findings)
  tracker.findings.clear
  potential_findings.each do |finding|
      if confirm_new finding
              tracker.report finding
      end
  end
end

Private Instance Methods

confirm_new(finding) click to toggle source
# File lib/glue/filters/jira_one_time_filter.rb, line 31
def confirm_new finding
      json = get_jira_query_json finding
      http = Curl.post("#{@api}/search", json.to_s) do |http|
              http.headers['Content-Type'] = "application/json"
              http.headers['Cookie'] = @cookie
      end
      if http.response_code != 200 # OK ...
              Glue.error "Problem with HTTP #{http.response_code} - #{http.body_str}"
      end

      result = JSON.parse(http.body_str)
      # Glue.error "Got back #{result} with #{result['total']}"

      if result['total'] < 1
              return true
      end
      return false
end
get_jira_query_json(finding) click to toggle source
# File lib/glue/filters/jira_one_time_filter.rb, line 50
def get_jira_query_json finding
  json =
    {"jql"=>"project=#{@project} AND component='#{@component}' AND labels='#{@appname}' AND description ~ 'FINGERPRINT: #{finding.fingerprint}'"}.to_json
  json
end