Skip to content

Commit

Permalink
feat: add support for ignore_scopes in changelog
Browse files Browse the repository at this point in the history
Resolves #32
  • Loading branch information
xotahal committed Oct 5, 2021
1 parent 79ca32c commit c507623
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def self.run(params)
hash: last_tag_hash,
debug: params[:debug]
)
parsed = parse_commits(commits)
parsed = parse_commits(commits, params)

commit_url = params[:commit_url]
format = params[:format]
Expand Down Expand Up @@ -172,7 +172,7 @@ def self.build_commit_link(commit, commit_url, format)
end
end

def self.parse_commits(commits)
def self.parse_commits(commits, params)
parsed = []
# %s|%b|%H|%h|%an|%at
format_pattern = lane_context[SharedValues::CONVENTIONAL_CHANGELOG_ACTION_FORMAT_PATTERN]
Expand All @@ -185,6 +185,14 @@ def self.parse_commits(commits)
pattern: format_pattern
)

unless commit[:scope].nil?
# if this commit has a scope, then we need to inspect to see if that is one of the scopes we're trying to exclude
scope = commit[:scope]
scopes_to_ignore = params[:ignore_scopes]
# if it is, we'll skip this commit when bumping versions
next if scopes_to_ignore.include?(scope) #=> true
end

commit[:hash] = splitted[2]
commit[:short_hash] = splitted[3]
commit[:author_name] = splitted[4]
Expand Down Expand Up @@ -273,6 +281,13 @@ def self.available_options
type: Boolean,
optional: true
),
FastlaneCore::ConfigItem.new(
key: :ignore_scopes,
description: "To ignore certain scopes when calculating releases",
default_value: [],
type: Array,
optional: true
),
FastlaneCore::ConfigItem.new(
key: :debug,
description: "True if you want to log out a debug info",
Expand Down
28 changes: 28 additions & 0 deletions spec/conventional_changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ def execute_lane_test_no_links_slack
end
end

describe 'skipping ignore_scopes' do
commits = [
"Merge ...||long_hash|short_hash|Jiri Otahal|time",
"Custom Merge...||long_hash|short_hash|Jiri Otahal|time",
"fix(bump): sub||long_hash|short_hash|Jiri Otahal|time"
]

it "should skip in markdown format" do
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\n### Other work\n- Custom Merge... ([short_hash](/long_hash))"

changelog = execute_lane_test(ignore_scopes: ['bump'])
expect(changelog).to eq(result)
end

it "should skip nothing in markdown format" do
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\n### Bug fixes\n- **bump:** sub ([short_hash](/long_hash))\n\n### Other work\n- Custom Merge... ([short_hash](/long_hash))"

changelog = execute_lane_test(ignore_scopes: ['not'])
expect(changelog).to eq(result)
end
end

describe 'skipping merge conflicts' do
commits = [
"Merge ...||long_hash|short_hash|Jiri Otahal|time",
Expand Down

0 comments on commit c507623

Please sign in to comment.