Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements on StampChangelogAction #39

Merged
merged 9 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ before_script:
- bundle exec rake
language: ruby
rvm:
- 2.2
- 2.3
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.13.0] - 2019-02-26
### Fixed:
- Fixed `append_date` parameter of `update_changelog` action ([Issue #40](https://github.com/pajapro/fastlane-plugin-changelog/issues/40))

## [0.12.0] - 2018-11-16
### Fixed:
- Bug when creating git tags comparison link ([Issue #32](https://github.com/pajapro/fastlane-plugin-changelog/issues/32))
Expand Down Expand Up @@ -83,3 +87,4 @@ This project adheres to [Semantic Versioning](http://semver.org/).
[0.9.0]: https://github.com/pajapro/fastlane-plugin-changelog/compare/v0.8.0...v0.9.0
[0.10.0]: https://github.com/pajapro/fastlane-plugin-changelog/compare/v0.9.0...v0.10.0
[0.12.0]: https://github.com/pajapro/fastlane-plugin-changelog/compare/v0.10.0...v0.12.0
[0.13.0]: https://github.com/pajapro/fastlane-plugin-changelog/compare/v0.12.0...v0.13.0
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Additionally, you can provide an optional `git_tag` param, specifing git tag ass
``` ruby
stamp_changelog(
section_identifier: 'Build XYZ', # Specify identifier to stamp the Unreleased section with
git_tag: 'bXYZ' # Specify reference to git tag associated with this section
git_tag: 'bXYZ', # Specify reference to git tag associated with this section
stamp_date: true # Specify whether current date should be appended to stamped section line (default is `true`)
)
```

Expand Down
28 changes: 17 additions & 11 deletions lib/fastlane/plugin/changelog/actions/stamp_changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,33 @@ def self.stamp(changelog_path, section_identifier, stamp_date, git_tag, placehol
# 3. Create link to git tags diff
if !git_tag.nil? && !git_tag.empty?
last_line = file_content.lines.last
previous_tag = ""
previous_previous_tag = ""
previous_tag = ''
previous_previous_tag = ''
reversed_tags = false

if last_line.include? 'https://github.com' # GitHub uses compare/olderTag...newerTag structure
previous_previous_tag = %r{(?<=compare\/)(.*)?(?=\.{3})}.match(last_line)
previous_tag = /(?<=\.{3})(.*)?/.match(last_line)
elsif last_line.include? 'https://bitbucket.org' # Bitbucket uses compare/newerTag..olderTag structure
reversed_tags = true
previous_tag = %r{(?<=compare\/)(.*)?(?=\.{2})}.match(last_line)
previous_previous_tag = /(?<=\.{2})(.*)?/.match(last_line)
end

# Replace section identifier
cleared_git_tag = git_tag.delete('[a-z]')
cleared_previous_git_tag = previous_tag.to_s.delete('[a-z]')
last_line.sub!("[#{cleared_previous_git_tag}]", "[#{cleared_git_tag}]")

# Replace previous-previous tag with previous
last_line.sub!(previous_previous_tag.to_s, previous_tag.to_s)

# Replace previous tag with new
last_line.sub!("..#{previous_tag}", "..#{git_tag}")
previous_section_identifier = /(?<=\[)[^\]]+(?=\]:)/.match(last_line)
last_line.sub!("[#{previous_section_identifier}]:", "[#{section_identifier}]:")

# Replace first tag
last_line.sub!(
reversed_tags ? previous_tag.to_s : previous_previous_tag.to_s,
reversed_tags ? git_tag.to_s : previous_tag.to_s
)
# Replace second tag
last_line.sub!(
"..#{reversed_tags ? previous_previous_tag : previous_tag}",
"..#{reversed_tags ? previous_tag : git_tag}"
)

UI.message("Created a link for comparison between #{previous_tag} and #{git_tag} tag")

Expand Down
1 change: 1 addition & 0 deletions lib/fastlane/plugin/changelog/actions/update_changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def self.available_options
env_name: "FL_UPDATE_CHANGELOG_APPEND_DATE",
description: "Appends the current date in YYYY-MM-DD format after the section identifier",
default_value: true,
is_string: false,
optional: true),
FastlaneCore::ConfigItem.new(key: :excluded_placeholder_line,
env_name: "FL_UPDATE_CHANGELOG_EXCLUDED_PLACEHOLDER_LINE",
Expand Down
2 changes: 1 addition & 1 deletion lib/fastlane/plugin/changelog/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Fastlane
module Changelog
VERSION = "0.12.0"
VERSION = "0.13.0"
end
end
118 changes: 118 additions & 0 deletions spec/fixtures/CHANGELOG_MOCK_BITBUCKET.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- New awesome feature

## [0.3.0] - 2015-12-03
### Added
- RU translation from @aishek.
- pt-BR translation from @tallesl.
- es-ES translation from @ZeliosAriex.

## [0.2.0] - 2015-10-06
### Changed
- Remove exclusionary mentions of "open source" since this project can benefit
both "open" and "closed" source projects equally.

## [0.1.0] - 2015-10-06
### Added
- Answer "Should you ever rewrite a change log?".

### Changed
- Improve argument against commit logs.
- Start following [SemVer](http://semver.org) properly.

## [0.0.8] - 2015-02-17
### Changed
- Update year to match in every README example.
- Reluctantly stop making fun of Brits only, since most of the world
writes dates in a strange way.

### Fixed
- Fix typos in recent README changes.
- Update outdated unreleased diff link.

## [0.0.7] - 2015-02-16
### Added
- Link, and make it obvious that date format is ISO 8601.

### Changed
- Clarified the section on "Is there a standard change log format?".

### Fixed
- Fix Markdown links to tag comparison URL with footnote-style links.

## [0.0.6] - 2014-12-12
### Added
- New awesome feature

### Changed
- Onboarding flow

### Fixed
- Fix Markdown links

### Removed
- User tracking

### Work In Progress
- Sales screen

### Security
- Enable SSL pinning

### Deprecated
- Obsolete contact screen

## [0.0.5 (rc1)] - 2014-08-09
### Added
- Markdown links to version tags on release headings.
- Unreleased section to gather unreleased changes and encourage note
keeping prior to releases.

## [0.0.4] - 2014-08-09
### Added
- Better explanation of the difference between the file ("CHANGELOG")
and its function "the change log".

### Changed
- Refer to a "change log" instead of a "CHANGELOG" throughout the site
to differentiate between the file and the purpose of the file — the
logging of changes.

### Removed
- Remove empty sections from CHANGELOG, they occupy too much space and
create too much noise in the file. People will have to assume that the
missing sections were intentionally left out because they contained no
notable changes.

## [0.0.3] - 2014-08-09
### Added
- "Why should I care?" section mentioning The Changelog podcast.

## [0.0.2] - 2014-07-10
### Added
- Explanation of the recommended reverse chronological release ordering.

## [0.0.1] - 2014-05-31
### Added
- This CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG.
- CNAME file to enable GitHub Pages custom domain
- README now contains answers to common questions about CHANGELOGs
- Good examples and basic guidelines, including proper date formatting.
- Counter-examples: "What makes unicorns cry?"

[0.0.1]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/...v0.0.1
[0.0.2]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.0.2..v0.0.1
[0.0.3]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.0.3..v0.0.2
[0.0.4]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.0.4..v0.0.3
[0.0.5]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.0.5..v0.0.4
[0.0.6]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.0.6..v0.0.5
[0.0.7]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.0.7..v0.0.6
[0.0.8]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.0.8..v0.0.7
[0.1.0]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.1.0..v0.0.8
[0.2.0]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.2.0..v0.1.0
[0.3.0]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v0.3.0..v0.2.0
48 changes: 48 additions & 0 deletions spec/stamp_changelog_action_with_bitbucket_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe Fastlane::Actions::StampChangelogAction do
describe 'Stamp CHANGELOG.md action with Bitbucket repo' do
let (:changelog_mock_path) { './../spec/fixtures/CHANGELOG_MOCK_BITBUCKET.md' }
let (:changelog_mock_path_hook) { './spec/fixtures/CHANGELOG_MOCK_BITBUCKET.md' }
let (:updated_section_identifier) { '12.34.56' }

before(:each) do
@original_content = File.read(changelog_mock_path_hook)
end

after(:each) do
File.open(changelog_mock_path_hook, 'w') { |f| f.write(@original_content) }
end

it 'use correct identifier when stamping [Unreleased] section' do
# Read what's in [Unreleased]
read_result = Fastlane::FastFile.new.parse("lane :test do
read_changelog(changelog_path: '#{changelog_mock_path}')
end").runner.execute(:test)

pre_stamp_file = File.read(changelog_mock_path_hook)
expect(pre_stamp_file).not_to include("## [#{updated_section_identifier}]")

# Stamp [Unreleased] with given section identifier
Fastlane::FastFile.new.parse("lane :test do
stamp_changelog(changelog_path: '#{changelog_mock_path}',
section_identifier: '#{updated_section_identifier}')
end").runner.execute(:test)

# Read post-stamp file
post_stamp_file = File.read(changelog_mock_path_hook)

expect(post_stamp_file).to include("## [#{updated_section_identifier}]")
end

it 'creates reversed tags comparison for Bitbucket links' do
# Stamp [Unreleased] with given section identifier
Fastlane::FastFile.new.parse("lane :test do
stamp_changelog(changelog_path: '#{changelog_mock_path}',
section_identifier: '#{updated_section_identifier}',
git_tag: 'v#{updated_section_identifier}')
end").runner.execute(:test)

post_stamp_file = File.read(changelog_mock_path_hook)
expect(post_stamp_file.lines.last).to eq("[12.34.56]: https://bitbucket.org/repo/keep-a-changelog/branches/compare/v12.34.56..v0.3.0\n")
end
end
end
47 changes: 47 additions & 0 deletions spec/update_changelog_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,52 @@

expect(read_result).to eq(post_update_read_result)
end

it 'updates [Unreleased] section identifier without appending date' do
# Update [Unreleased] section identifier with new one
Fastlane::FastFile.new.parse("lane :test do
update_changelog(changelog_path: '#{changelog_mock_path}',
updated_section_identifier: '#{updated_section_identifier}',
append_date: false)
end").runner.execute(:test)

# Read updated section line
modifiedSectionLine = ""
File.open(changelog_mock_path_hook, "r") do |file|
file.each_line do |line|
if line =~ /\#{2}\s?\[#{updated_section_identifier}\]/
modifiedSectionLine = line
break
end
end
end

# Expect the modified section line to be without date
expect(modifiedSectionLine).to eq("## [12.34.56]\n")
end

it 'updates [Unreleased] section identifier with appending date' do
# Update [Unreleased] section identifier with new one
Fastlane::FastFile.new.parse("lane :test do
update_changelog(changelog_path: '#{changelog_mock_path}',
updated_section_identifier: '#{updated_section_identifier}',
append_date: true)
end").runner.execute(:test)

# Read updated section line
modifiedSectionLine = ""
File.open(changelog_mock_path_hook, "r") do |file|
file.each_line do |line|
if line =~ /\#{2}\s?\[#{updated_section_identifier}\]/
modifiedSectionLine = line
break
end
end
end

# Expect the modified section line to be with current date
now = Time.now.strftime("%Y-%m-%d")
expect(modifiedSectionLine).to eq("## [12.34.56] - #{now}\n")
end
end
end