Skip to content

Commit

Permalink
Add app_path parameter to changelog_from_git_commits (fastlane#22149)
Browse files Browse the repository at this point in the history
Adds a parameter to allow users to specify a subpath for a specific
application to scope the changelog to changes to files just in that
directory. This is useful in environments where several apps share the
same repository.
  • Loading branch information
jpignata authored Sep 25, 2024
1 parent 2de8c84 commit cc78da9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 7 additions & 3 deletions fastlane/lib/fastlane/actions/changelog_from_git_commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def self.run(params)

Dir.chdir(params[:path]) do
if params[:commits_count]
changelog = Actions.git_log_last_commits(params[:pretty], params[:commits_count], merge_commit_filtering, params[:date_format], params[:ancestry_path])
changelog = Actions.git_log_last_commits(params[:pretty], params[:commits_count], merge_commit_filtering, params[:date_format], params[:ancestry_path], params[:app_path])
else
changelog = Actions.git_log_between(params[:pretty], from, to, merge_commit_filtering, params[:date_format], params[:ancestry_path])
changelog = Actions.git_log_between(params[:pretty], from, to, merge_commit_filtering, params[:date_format], params[:ancestry_path], params[:app_path])
end

changelog = changelog.gsub("\n\n", "\n") if changelog # as there are duplicate newlines
Expand Down Expand Up @@ -147,7 +147,11 @@ def self.available_options
verify_block: proc do |value|
matches_option = GIT_MERGE_COMMIT_FILTERING_OPTIONS.any? { |opt| opt.to_s == value }
UI.user_error!("Valid values for :merge_commit_filtering are #{GIT_MERGE_COMMIT_FILTERING_OPTIONS.map { |o| "'#{o}'" }.join(', ')}") unless matches_option
end)
end),
FastlaneCore::ConfigItem.new(key: :app_path,
env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_APP_PATH',
description: "Scopes the changelog to a specific subdirectory of the repository",
optional: true)
]
end

Expand Down
6 changes: 4 additions & 2 deletions fastlane/lib/fastlane/helper/git_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ module SharedValues
end.freeze
end

def self.git_log_between(pretty_format, from, to, merge_commit_filtering, date_format = nil, ancestry_path)
def self.git_log_between(pretty_format, from, to, merge_commit_filtering, date_format = nil, ancestry_path, app_path)
command = %w(git log)
command << "--pretty=#{pretty_format}"
command << "--date=#{date_format}" if date_format
command << '--ancestry-path' if ancestry_path
command << "#{from}...#{to}"
command << git_log_merge_commit_filtering_option(merge_commit_filtering)
command << app_path if app_path
# "*command" syntax expands "command" array into variable arguments, which
# will then be individually shell-escaped by Actions.sh.
Actions.sh(*command.compact, log: false).chomp
rescue
nil
end

def self.git_log_last_commits(pretty_format, commit_count, merge_commit_filtering, date_format = nil, ancestry_path)
def self.git_log_last_commits(pretty_format, commit_count, merge_commit_filtering, date_format = nil, ancestry_path, app_path)
command = %w(git log)
command << "--pretty=#{pretty_format}"
command << "--date=#{date_format}" if date_format
command << '--ancestry-path' if ancestry_path
command << '-n' << commit_count.to_s
command << git_log_merge_commit_filtering_option(merge_commit_filtering)
command << app_path if app_path
Actions.sh(*command.compact, log: false).chomp
rescue
nil
Expand Down
11 changes: 11 additions & 0 deletions fastlane/spec/actions_specs/changelog_from_git_commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@
expect(result).to eq(changelog)
end

it "Returns a scoped log from the app's path if so requested" do
result = Fastlane::FastFile.new.parse("lane :test do
changelog_from_git_commits(app_path: './apps/ios')
end").runner.execute(:test)

tag_name = %w(git rev-list --tags --max-count=1).shelljoin
describe = %W(git describe --tags #{tag_name}).shelljoin
changelog = %W(git log --pretty=%B #{describe}...HEAD ./apps/ios).shelljoin
expect(result).to eq(changelog)
end

it "Runs between option from command line" do

options = FastlaneCore::Configuration.create(Fastlane::Actions::ChangelogFromGitCommitsAction.available_options, {
Expand Down

0 comments on commit cc78da9

Please sign in to comment.