2018-08-02 22:35:09 +08:00
|
|
|
require 'pmdtester'
|
2018-07-23 23:06:46 +08:00
|
|
|
require 'time'
|
|
|
|
require 'logger'
|
|
|
|
|
|
|
|
@logger = Logger.new(STDOUT)
|
|
|
|
|
|
|
|
def run_pmdtester
|
|
|
|
Dir.chdir('..') do
|
2020-10-10 17:25:03 +02:00
|
|
|
argv = ['--local-git-repo', './pmd',
|
2020-10-27 17:19:42 +01:00
|
|
|
'--list-of-project', './pmd/.travis/project-list.xml',
|
2020-10-09 11:03:25 +02:00
|
|
|
'--base-branch', "#{ENV['TRAVIS_BRANCH']}",
|
|
|
|
'--patch-branch', 'HEAD',
|
|
|
|
'--patch-config', './pmd/.travis/all-java.xml',
|
|
|
|
'--mode', 'online',
|
|
|
|
'--auto-gen-config',
|
|
|
|
# '--debug',
|
|
|
|
]
|
2018-09-10 21:16:42 +08:00
|
|
|
begin
|
|
|
|
runner = PmdTester::Runner.new(argv)
|
2019-01-20 20:17:23 +01:00
|
|
|
@new_errors, @removed_errors, @new_violations, @removed_violations, @new_configerrors, @removed_configerrors = runner.run
|
2018-09-10 21:16:42 +08:00
|
|
|
upload_report
|
|
|
|
rescue StandardError => e
|
|
|
|
warn("Running pmdtester failed, this message is mainly used to remind the maintainers of PMD.")
|
|
|
|
@logger.error "Running pmdtester failed: #{e.inspect}"
|
|
|
|
end
|
2018-07-23 23:06:46 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload_report
|
|
|
|
Dir.chdir('target/reports') do
|
|
|
|
tar_filename = "pr-#{ENV['TRAVIS_PULL_REQUEST']}-diff-report-#{Time.now.strftime("%Y-%m-%dT%H-%M-%SZ")}.tar"
|
|
|
|
unless Dir.exist?('diff/')
|
|
|
|
message("No java rules are changed!", sticky: true)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
`tar -cf #{tar_filename} diff/`
|
2020-08-13 10:06:52 +02:00
|
|
|
report_url = `curl -u #{ENV['CHUNK_TOKEN']} -T #{tar_filename} https://chunk.io`
|
2019-01-20 20:17:23 +01:00
|
|
|
if $?.success?
|
|
|
|
@logger.info "Successfully uploaded #{tar_filename} to chunk.io"
|
2018-07-23 23:06:46 +08:00
|
|
|
|
|
|
|
# set value of sticky to true and the message is kept after new commits are submited to the PR
|
2019-01-20 20:17:23 +01:00
|
|
|
message("This changeset introduces #{@new_violations} new violations, #{@new_errors} new errors and " +
|
|
|
|
"#{@new_configerrors} new configuration errors,\n" +
|
|
|
|
"removes #{@removed_violations} violations, #{@removed_errors} errors and " +
|
|
|
|
"#{@removed_configerrors} configuration errors.\n" +
|
|
|
|
"[Full report](#{report_url.chomp}/diff/index.html)", sticky: true)
|
|
|
|
else
|
2018-07-23 23:06:46 +08:00
|
|
|
@logger.error "Error while uploading #{tar_filename} to chunk.io: #{report_url}"
|
|
|
|
warn("Uploading the diff report failed, this message is mainly used to remind the maintainers of PMD.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Perform regression testing
|
|
|
|
can_merge = github.pr_json['mergeable']
|
|
|
|
if can_merge
|
|
|
|
run_pmdtester
|
|
|
|
else
|
|
|
|
warn("This PR cannot be merged yet.", sticky: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: syntax=ruby
|