diff --git a/bin/changelog b/bin/changelog index d7b2a1a2de9b524601c3fd2079383c238dd7f31d..758c036161e6d5d978f850fb7cc371a1973a81f4 100755 --- a/bin/changelog +++ b/bin/changelog @@ -23,6 +23,8 @@ module ChangelogHelpers Abort = Class.new(StandardError) Done = Class.new(StandardError) + MAX_FILENAME_LENGTH = 140 # ecryptfs has a limit of 140 characters + def capture_stdout(cmd) output = IO.popen(cmd, &:read) fail_with "command failed: #{cmd.join(' ')}" unless $?.success? @@ -142,7 +144,9 @@ class ChangelogEntry def initialize(options) @options = options + end + def execute assert_feature_branch! assert_title! assert_new_file! @@ -221,10 +225,12 @@ class ChangelogEntry end def file_path - File.join( + base_path = File.join( unreleased_path, - branch_name.gsub(/[^\w-]/, '-') << '.yml' - ) + branch_name.gsub(/[^\w-]/, '-')) + + # Add padding for .yml extension + base_path[0..MAX_FILENAME_LENGTH - 5] + '.yml' end def unreleased_path @@ -250,7 +256,7 @@ end if $0 == __FILE__ begin options = ChangelogOptionParser.parse(ARGV) - ChangelogEntry.new(options) + ChangelogEntry.new(options).execute rescue ChangelogHelpers::Abort => ex $stderr.puts ex.message exit 1 diff --git a/spec/bin/changelog_spec.rb b/spec/bin/changelog_spec.rb index f278043028f09295081c606d184e62367c46de8b..9dc4edf97d1f7d34c3feb12b96754a923b13f424 100644 --- a/spec/bin/changelog_spec.rb +++ b/spec/bin/changelog_spec.rb @@ -3,6 +3,20 @@ require 'spec_helper' load File.expand_path('../../bin/changelog', __dir__) describe 'bin/changelog' do + let(:options) { OpenStruct.new(title: 'Test title', type: 'fixed', dry_run: true) } + + describe ChangelogEntry do + it 'truncates the file path' do + entry = described_class.new(options) + + allow(entry).to receive(:ee?).and_return(false) + allow(entry).to receive(:branch_name).and_return('long-branch-' * 100) + + file_path = entry.send(:file_path) + expect(file_path.length).to eq(140) + end + end + describe ChangelogOptionParser do describe '.parse' do it 'parses --amend' do