Skip to content

Commit

Permalink
changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellhenke committed Jan 19, 2022
1 parent 1b6b5c9 commit 2da64d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .circleci/config.yml
Expand Up @@ -395,9 +395,11 @@ jobs:
- run:
name: Check Changelog
command: |-
if [ -z "${CIRCLE_PULL_REQUEST##*/}" ]
if [ -z "${CIRCLE_PULL_REQUEST}" ]
then
./scripts/changelog-check -b ${CIRCLE_BRANCH} -s main
exit 0
else
./scripts/changelog-check -b "${CIRCLE_BRANCH}" -s main
fi
workflows:
Expand Down
Empty file added CHANGELOG.md
Empty file.
22 changes: 10 additions & 12 deletions scripts/changelog-check
Expand Up @@ -4,7 +4,6 @@ require 'optparse'

# [skip_changelog]


CHANGELOG_REGEX = %r{^\+- (?<category>[\w ]+{2,}): (?<change>[\w\s]+{2,})}
# A valid diff line is in the form of:
# +- CATEGORY: CHANGE DESCRIPTION
Expand All @@ -14,13 +13,16 @@ def is_valid_changelog_diff_addition?(line)
end

def get_changelog_diff_lines(base_branch, source_branch)
diff, status = Open3.capture2('git', 'diff', '--merge-base', base_branch, source_branch, 'CHANGELOG.md')
raise "git diff failed" unless status.success?
diff, status = Open3.capture2(
'git', 'diff', '--merge-base', base_branch, source_branch,
'CHANGELOG.md'
)
raise 'git diff failed' unless status.success?

diff_lines = diff.chomp.split("\n")
index = diff_lines.find_index { |line| line.start_with?("@@") }
index = diff_lines.find_index { |line| line.start_with?('@@') }
return [] if index.nil?
diff_lines[(index+1)..].filter { |line| !line.start_with?("@@") && line != " " }
diff_lines[(index+1)..].filter { |line| !line.start_with?('@@') && line != ' ' }
end

def main(args)
Expand All @@ -33,7 +35,7 @@ def main(args)
EOM
opts.on('-h', '--help', 'Display this message') do
STDERR.puts opts
warn opts
exit
end

Expand All @@ -48,9 +50,7 @@ def main(args)

optparse.parse!

if options[:source_branch].nil?
abort(optparse.help)
end
abort(optparse.help) if options[:source_branch].nil?

diff_lines = get_changelog_diff_lines(options[:base_branch], options[:source_branch])

Expand All @@ -61,6 +61,4 @@ def main(args)
end
end

if __FILE__ == $0
main(ARGV)
end
main(ARGV) if __FILE__ == $0

0 comments on commit 2da64d6

Please sign in to comment.