Skip to content

Commit

Permalink
Simplify changelog.rb
Browse files Browse the repository at this point in the history
Only .changes files are passed to this script by the get-changed-files
action.
  • Loading branch information
agraul committed Oct 22, 2021
1 parent 40949fc commit c3863a9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions .github/scripts/changelog.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#! /usr/bin/ruby
# Check if a .changes file is added/modified in a pull request *or* the "No
# changelog needed" box in the pull request description is ticked. If neither of
# these are true, exit 1 to fail the check.
#
# List of added/modified in the pull request is stored in ARGV
require 'json'

# if true we exit with 0, so the test is sucessefull. otherwise the test fail.
def check_changelog?(pr_body, files)
return true if pr_body.match(/\[x\]\s+No\s+changelog\s+needed/i)

puts 'Looking for a .changes file...'
files.any? { |f| f.include? '.changes' }
def not_needed?(pr_body)
pr_body.match(/\[x\]\s+No\s+changelog\s+needed/i)
end

github_event = JSON.parse(File.read(ENV['GITHUB_EVENT_PATH']))
files = ARGV[0].split(' ')
puts "-" * 20, "PR Description: #{github_event['pull_request']['body']}"
puts "-" * 20, "Files modified: #{files}"
check_changelog?(github_event['pull_request']['body'], files) ? exit(0) : exit(1)
pr_body = github_event['pull_request']['body']
puts '-' * 20, "PR Description: #{github_event['pull_request']['body']}"
puts '-' * 20, "Added or modified .changes files: #{ARGV}"

exit(0) unless ARGV.empty?
not_needed?(pr_body) ? exit(0) : exit(1)

0 comments on commit c3863a9

Please sign in to comment.