Skip to content

Commit

Permalink
Merge pull request #10 from Microsoft/fix/release-notes-auto-clipping
Browse files Browse the repository at this point in the history
Clip release with length > 5000 chars notes by default
  • Loading branch information
evkhramkov committed Dec 1, 2017
2 parents d47092b + da1acb1 commit a89de3d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
4 changes: 3 additions & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ lane :test_release_notes do
app_name: "MyApplication-01",
ipa: "./fastlane/app-release.ipa",
group: ENV["TEST_APPCENTER_DISTRIBUTE_GROUP"],
release_notes: sh("cat ./test_CHANGELOG.md")
release_notes: sh("cat ./test_CHANGELOG.md"),
release_notes_clipping: false,
release_notes_link: "https://raw.githubusercontent.com/Microsoft/fastlane-plugin-appcenter/master/README.md"
)
end

Expand Down
25 changes: 22 additions & 3 deletions lib/fastlane/plugin/appcenter/actions/appcenter_upload_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,24 @@ def self.run_dsym_upload(params)

# run whole upload process for release
def self.run_release_upload(params)
values = params.values
api_token = params[:api_token]
owner_name = params[:owner_name]
app_name = params[:app_name]
group = params[:group]
release_notes = params[:release_notes]
should_clip = params[:should_clip]
release_notes_link = params[:release_notes_link]

if release_notes.length >= Constants::MAX_RELEASE_NOTES_LENGTH
clip = UI.confirm("The release notes are limited to #{Constants::MAX_RELEASE_NOTES_LENGTH} characters, proceeding will clip them. Proceed anyway?")
UI.abort_with_message!("Upload aborted, please edit your release notes") unless clip
release_notes_link = UI.input("Provide a link for additional release notes, leave blank to skip")
unless should_clip
clip = UI.confirm("The release notes are limited to #{Constants::MAX_RELEASE_NOTES_LENGTH} characters, proceeding will clip them. Proceed anyway?")
UI.abort_with_message!("Upload aborted, please edit your release notes") unless clip
release_notes_link ||= UI.input("Provide a link for additional release notes, leave blank to skip")
end
read_more = "..." + (release_notes_link.to_s.empty? ? "" : "\n\n[read more](#{release_notes_link})")
release_notes = release_notes[0, Constants::MAX_RELEASE_NOTES_LENGTH - read_more.length] + read_more
values[:release_notes] = release_notes
UI.message("Release notes clipped")
end

Expand Down Expand Up @@ -509,6 +515,19 @@ def self.available_options
env_name: "APPCENTER_DISTRIBUTE_RELEASE_NOTES",
description: "Release notes",
default_value: Actions.lane_context[SharedValues::FL_CHANGELOG] || "No changelog given",
optional: true,
type: String),

FastlaneCore::ConfigItem.new(key: :should_clip,
env_name: "APPCENTER_DISTRIBUTE_RELEASE_NOTES_CLIPPING",
description: "Clip release notes if its lenght is more then #{Constants::MAX_RELEASE_NOTES_LENGTH}, true by default",
optional: true,
is_string: false,
default_value: true),

FastlaneCore::ConfigItem.new(key: :release_notes_link,
env_name: "APPCENTER_DISTRIBUTE_RELEASE_NOTES_LINK",
description: "Additional release notes link",
optional: true,
type: String)
]
Expand Down
52 changes: 52 additions & 0 deletions spec/appcenter_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,58 @@ def stub_add_to_group(status)
expect(values[:release_notes]).to eq('autogenerated changelog')
end

it "clips changelog if its lenght is more then 5000" do
stub_check_app(200)
stub_create_release_upload(200)
stub_upload_build(200)
stub_update_release_upload(200, 'committed')
stub_add_to_group(200)

release_notes = '_' * 6000
read_more = '...'
release_notes_clipped = release_notes[0, 5000 - read_more.length] + read_more

values = Fastlane::FastFile.new.parse("lane :test do
appcenter_upload({
api_token: 'xxx',
owner_name: 'owner',
app_name: 'app',
apk: './spec/fixtures/appfiles/apk_file_empty.apk',
group: 'Testers',
release_notes: '#{release_notes}'
})
end").runner.execute(:test)

expect(values[:release_notes]).to eq(release_notes_clipped)
end

it "clips changelog and adds link in the end if its lenght is more then 5000" do
stub_check_app(200)
stub_create_release_upload(200)
stub_upload_build(200)
stub_update_release_upload(200, 'committed')
stub_add_to_group(200)

release_notes = '_' * 6000
release_notes_link = 'https://text.com'
read_more = "...\n\n[read more](#{release_notes_link})"
release_notes_clipped = release_notes[0, 5000 - read_more.length] + read_more

values = Fastlane::FastFile.new.parse("lane :test do
appcenter_upload({
api_token: 'xxx',
owner_name: 'owner',
app_name: 'app',
apk: './spec/fixtures/appfiles/apk_file_empty.apk',
group: 'Testers',
release_notes: '#{release_notes}',
release_notes_link: '#{release_notes_link}'
})
end").runner.execute(:test)

expect(values[:release_notes]).to eq(release_notes_clipped)
end

it "works with valid parameters for android" do
stub_check_app(200)
stub_create_release_upload(200)
Expand Down

0 comments on commit a89de3d

Please sign in to comment.