Skip to content

Commit

Permalink
feat: plain text formatting option for TestFlight
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Lay committed Nov 8, 2019
1 parent f5e5e4d commit ea493eb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Automated version managment and generator of release notes. Inspired by [semanti

Available parameters:

- `format: 'slack|markdown'` - defaults to `markdown` and formats the changelog for the destination you need
- `format: 'slack|markdown|plain'` (defaults to `markdown`). This formats the changelog for the destination you need. If you're using this for TestFlight changelogs, we suggest using the `plain` option
- `title: 'My Title'` - is appended to the release notes title, "1.1.8 My Title (YYYY-MM-DD)"
- `display_title: true|false` (defaults to true) - allows you to hide the entire first line of the changelog
- `display_links: true|false` (defaults to true) - allows you to hide links to commits from your changelog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,46 @@ def self.note_builder(format, commits, version, commit_url, params)

def self.style_text(text, format, style)
# formats the text according to the style we're looking to use
case style
when "title"
if format == "markdown"
"# #{text}"
else
"*#{text}*"
end
when "heading"
if format == "markdown"
"### #{text}"
else
"*#{text}*"
end
when "bold"
if format == "markdown"
"**#{text}**"

# Skips all styling
if format == "plain"
text
else
case style
when "title"
if format == "markdown"
"# #{text}"
else
"*#{text}*"
end
when "heading"
if format == "markdown"
"### #{text}"
else
"*#{text}*"
end
when "bold"
if format == "markdown"
"**#{text}**"
else
"*#{text}*"
end
else
"*#{text}*"
text # catchall, shouldn't be needed
end
else
text
end
end

def self.style_link(text, url, format)
# formats the link according to the output format we need
# Slack link format is very specific, so we prefer the markdown version to be the more readable fallback
if format == "slack"
case format
when "slack"
"<#{url}|#{text}>"
else
when "markdown"
"[#{text}](#{url})"
else
url
end
end

Expand Down Expand Up @@ -205,7 +214,7 @@ def self.available_options
[
FastlaneCore::ConfigItem.new(
key: :format,
description: "You can use either markdown or slack",
description: "You can use either markdown, slack or plain",
default_value: "markdown",
optional: true
),
Expand Down
35 changes: 34 additions & 1 deletion spec/conventional_changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def execute_lane_test
Fastlane::FastFile.new.parse("lane :test do conventional_changelog end").runner.execute(:test)
end

def execute_lane_test_plain
Fastlane::FastFile.new.parse("lane :test do conventional_changelog( format: 'plain' ) end").runner.execute(:test)
end

def execute_lane_test_slack
Fastlane::FastFile.new.parse("lane :test do conventional_changelog( format: 'slack' ) end").runner.execute(:test)
end
Expand All @@ -19,6 +23,10 @@ def execute_lane_test_no_header
Fastlane::FastFile.new.parse("lane :test do conventional_changelog( display_title: false ) end").runner.execute(:test)
end

def execute_lane_test_no_header_plain
Fastlane::FastFile.new.parse("lane :test do conventional_changelog( format: 'plain', display_title: false ) end").runner.execute(:test)
end

def execute_lane_test_no_header_slack
Fastlane::FastFile.new.parse("lane :test do conventional_changelog( format: 'slack', display_title: false ) end").runner.execute(:test)
end
Expand All @@ -44,6 +52,19 @@ def execute_lane_test_no_links_slack
expect(execute_lane_test).to eq(result)
end

it "should create sections in plain format" do
commits = [
"docs: sub|body|long_hash|short_hash|Jiri Otahal|time",
"fix: sub||long_hash|short_hash|Jiri Otahal|time"
]
allow(Fastlane::Actions::ConventionalChangelogAction).to receive(:get_commits_from_hash).and_return(commits)
allow(Date).to receive(:today).and_return(Date.new(2019, 5, 25))

result = "1.0.2 (2019-05-25)\n\nBug fixes\n- sub (/long_hash)\n\nDocumentation\n- sub (/long_hash)"

expect(execute_lane_test_plain).to eq(result)
end

it "should create sections in Slack format" do
commits = [
"docs: sub|body|long_hash|short_hash|Jiri Otahal|time",
Expand All @@ -57,7 +78,7 @@ def execute_lane_test_no_links_slack
expect(execute_lane_test_slack).to eq(result)
end

it "should skip the header if display_title is false" do
it "should skip the header if display_title is false in markdown format" do
commits = [
"fix: sub|BREAKING CHANGE: Test|long_hash|short_hash|Jiri Otahal|time"
]
Expand All @@ -69,6 +90,18 @@ def execute_lane_test_no_links_slack
expect(execute_lane_test_no_header).to eq(result)
end

it "should skip the header if display_title is false in plain format" do
commits = [
"fix: sub|BREAKING CHANGE: Test|long_hash|short_hash|Jiri Otahal|time"
]
allow(Fastlane::Actions::ConventionalChangelogAction).to receive(:get_commits_from_hash).and_return(commits)
allow(Date).to receive(:today).and_return(Date.new(2019, 5, 25))

result = "Bug fixes\n- sub (/long_hash)\n\nBREAKING CHANGES\n- Test (/long_hash)"

expect(execute_lane_test_no_header_plain).to eq(result)
end

it "should skip the header if display_title is false in Slack format" do
commits = [
"fix: sub|BREAKING CHANGE: Test|long_hash|short_hash|Jiri Otahal|time"
Expand Down

0 comments on commit ea493eb

Please sign in to comment.