sonar-blamethrower.rb
# Yields an issue object for each issue created in the given commits
Yields an issue object for each issue created in the given commits
Yields an issue object for each issue created in the given commits
def each_issue_for_commits project_name, hashlist, &block
  hashlist.each do |revhash|
    repo = get_repo()
    debug "Fetching issues for #{revhash}"
    commit = repo.lookup(revhash)
    diff = commit.parent.diff(commit)
    diff.each_patch do |patch|
      lines = Set.new
      patch.each_hunk do |hunk|
        hunk.each_line do |line|
          if line.addition?
            lines << line.new_lineno
          end
        end
      end
      delta = patch.delta
      filename = delta.new_file[:path]
      debug "Fetching issues for file '#{filename}'"
      sonar_resource_name = project_name + ':' +
        filename.sub(SRC_PREFIX_REGEX, '') \
        .sub(/.java$/, '') \
        .gsub('/', '.')
      url = "http://sonar.zoo.lan:9000/api/issues/search?components=#{sonar_resource_name}"
      url += "&statuses=OPEN,REOPENED,CONFIRMED"
      debug "Fetching JSON from '#{url}'"
      issues_json = Net::HTTP.get_response(URI.parse(url)).body
      all_issues = JSON.parse(issues_json)
      new_issues = all_issues['issues'].select do |issue|
        included = lines.include? issue['line']
        debug "#{issue} is #{included ? 'NOT ' : ''}included"
        included
      end
      new_issues.each &block
    end
  end
end
def each_issue_for_commits project_name , hashlist , & block hashlist . each do | revhash | repo = get_repo ( ) debug "Fetching issues for #{revhash}" commit = repo . lookup ( revhash ) diff = commit . parent . diff ( commit ) diff . each_patch do | patch | lines = Set . new patch . each_hunk do | hunk | hunk . each_line do | line | if line . addition? lines << line . new_lineno end end end delta = patch . delta filename = delta . new_file [ :path ] debug "Fetching issues for file '#{filename}'" sonar_resource_name = project_name + ':' + filename . sub ( SRC_PREFIX_REGEX , '' ) . sub ( / .java$ / , '' ) . gsub ( '/' , '.' ) url = "http://sonar.zoo.lan:9000/api/issues/search?components=#{sonar_resource_name}" url += "&statuses=OPEN,REOPENED,CONFIRMED" debug "Fetching JSON from '#{url}'" issues_json = Net :: HTTP . get_response ( URI . parse ( url ) ) . body all_issues = JSON . parse ( issues_json ) new_issues = all_issues [ 'issues' ] . select do | issue | included = lines . include? issue [ 'line' ] debug "#{issue} is #{included ? 'NOT ' : ''}included" included end new_issues . each & block end end end
Yields an issue object for each issue created in the given commits
Yields an issue object for each issue created in the given commits
# Get the added lines # Get the current issues for the file # http://docs.codehaus.org/pages/viewpage.action?pageId=231080558#WebService/api/issues-GetaListofIssues # exclude already fixed issues: # print the result
project_name
<not_specific>
hashlist
<not_specific>
block
<not_specific>