forked from puppetlabs/pxp-agent-vanagon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
42 lines (37 loc) · 1.43 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
begin
require 'packaging'
Pkg::Util::RakeUtils.load_packaging_tasks
rescue StandardError => e
puts "Error loading packaging rake tasks: #{e}"
end
desc 'run static analysis with rubocop'
task(:rubocop) do
require 'rubocop'
cli = RuboCop::CLI.new
exit_code = cli.run(%w[--display-cop-names --format simple])
raise 'RuboCop detected offenses' if exit_code != 0
end
desc 'verify that commit messages match CONTRIBUTING.md requirements'
task(:commits) do
commit_range = 'HEAD^..HEAD'
`git log --no-merges --pretty=%s #{commit_range}`.each_line do |commit_summary|
error_message = <<~HEREDOC
\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n \
\n\t\t#{commit_summary}\n \
\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n \
\t\t(docs)\n \
\t\t(maint)\n \
\t\t(packaging)\n \
\t\t(<ANY PUBLIC JIRA TICKET>)\n \
\n\tThis test for the commit summary is case-insensitive.\n\n\n
HEREDOC
next unless /^\((maint|doc|docs|packaging|pa-\d+)\)|revert|bumping|merge|promoting/i.match(commit_summary).nil?
ticket = commit_summary.match(/^\(([[:alpha:]]+-[[:digit:]]+)\).*/)
raise error_message if ticket.nil?
require 'net/http'
require 'uri'
uri = URI.parse("https://tickets.puppetlabs.com/browse/#{ticket[1]}")
response = Net::HTTP.get_response(uri)
raise error_message if response.code != '200'
end
end